|
| 1 | +import { Chart } from '../../src'; |
| 2 | +import { COMPONENT_TYPE } from '../../src/constant'; |
| 3 | +import { createDiv } from '../util/dom'; |
| 4 | + |
| 5 | +describe('#5409', () => { |
| 6 | + const data = [ |
| 7 | + { type: '我是一段很长很长很长很长很长的文本', value: 654, percent: 0.02 }, |
| 8 | + { type: '18-24 岁', value: 4400, percent: 0.2 }, |
| 9 | + { type: '25-29 岁', value: 5300, percent: 0.24 }, |
| 10 | + { type: '30-39 岁', value: 6200, percent: 0.28 }, |
| 11 | + { type: '40-49 岁', value: 3300, percent: 0.14 }, |
| 12 | + { type: '50 岁以上', value: 1500, percent: 0.06 }, |
| 13 | + { type: '未知', value: 654, percent: 0.02 }, |
| 14 | + ]; |
| 15 | + const container = createDiv(); |
| 16 | + const chart = new Chart({ |
| 17 | + container, |
| 18 | + width: 400, |
| 19 | + height: 300, |
| 20 | + autoFit: true, |
| 21 | + }); |
| 22 | + chart.data(data); |
| 23 | + chart.interval().position('type*value').color('type'); |
| 24 | + chart.render(); |
| 25 | + it('legend tooltip position should be changed when chart resize', async () => { |
| 26 | + const legend = chart.getComponents().filter((co) => co.type === COMPONENT_TYPE.LEGEND)[0]; |
| 27 | + const legendTarget = legend.component |
| 28 | + .get('container') |
| 29 | + .findById('-legend-item-我是一段很长很长很长很长很长的文本-name'); |
| 30 | + |
| 31 | + chart.emit('legend-item-name:mousemove', { |
| 32 | + x: 50, |
| 33 | + y: 330, |
| 34 | + target: legendTarget, |
| 35 | + }); |
| 36 | + |
| 37 | + const tooltipDom = container.getElementsByClassName('g2-tooltip')[0] as HTMLElement; |
| 38 | + expect(tooltipDom.style.visibility).toBe('visible'); |
| 39 | + |
| 40 | + const top = tooltipDom.style.top; |
| 41 | + chart.emit('legend-item-name:mouseleave', { |
| 42 | + target: legendTarget, |
| 43 | + }); |
| 44 | + // 等待 render 完毕 |
| 45 | + await new Promise((resolve) => { |
| 46 | + setTimeout(() => { |
| 47 | + resolve(''); |
| 48 | + }, 100); |
| 49 | + }); |
| 50 | + chart.changeSize(400, 500); |
| 51 | + chart.emit('legend-item-name:mousemove', { |
| 52 | + x: 50, |
| 53 | + y: 480, |
| 54 | + target: legendTarget, |
| 55 | + }); |
| 56 | + expect(tooltipDom.style.visibility).toBe('visible'); |
| 57 | + // top 应该不一致 |
| 58 | + expect(tooltipDom.style.top).not.toBe(top); |
| 59 | + }); |
| 60 | +}); |
0 commit comments