|
| 1 | +import { DualAxes } from '../../src'; |
| 2 | +import { createDiv } from '../utils/dom'; |
| 3 | +import { delay } from '../utils/delay'; |
| 4 | + |
| 5 | +describe('DualAxes', () => { |
| 6 | + it('change data', async () => { |
| 7 | + const uvData = [ |
| 8 | + { time: '2019-03', value: 35 }, |
| 9 | + { time: '2019-04', value: 90 }, |
| 10 | + { time: '2019-05', value: 30 }, |
| 11 | + { time: '2019-06', value: 45 }, |
| 12 | + { time: '2019-07', value: 47 }, |
| 13 | + ]; |
| 14 | + |
| 15 | + const transformData = [ |
| 16 | + { time: '2019-03', count: 800, name: 'a' }, |
| 17 | + { time: '2019-04', count: 600, name: 'a' }, |
| 18 | + { time: '2019-05', count: 400, name: 'a' }, |
| 19 | + { time: '2019-06', count: 380, name: 'a' }, |
| 20 | + { time: '2019-07', count: 220, name: 'a' }, |
| 21 | + { time: '2019-03', count: 750, name: 'b' }, |
| 22 | + { time: '2019-04', count: 650, name: 'b' }, |
| 23 | + { time: '2019-05', count: 450, name: 'b' }, |
| 24 | + { time: '2019-06', count: 400, name: 'b' }, |
| 25 | + { time: '2019-07', count: 320, name: 'b' }, |
| 26 | + { time: '2019-03', count: 900, name: 'c' }, |
| 27 | + { time: '2019-04', count: 600, name: 'c' }, |
| 28 | + { time: '2019-05', count: 450, name: 'c' }, |
| 29 | + { time: '2019-06', count: 300, name: 'c' }, |
| 30 | + { time: '2019-07', count: 200, name: 'c' }, |
| 31 | + ]; |
| 32 | + const DualAxesPlot = new DualAxes(createDiv(), { |
| 33 | + width: 400, |
| 34 | + height: 400, |
| 35 | + data: [[], []], |
| 36 | + xField: 'time', |
| 37 | + yField: ['value', 'count'], |
| 38 | + animation: false, |
| 39 | + geometryOptions: [ |
| 40 | + { |
| 41 | + geometry: 'column', |
| 42 | + color: '#5B8FF9', |
| 43 | + columnWidthRatio: 0.4, |
| 44 | + }, |
| 45 | + { |
| 46 | + geometry: 'line', |
| 47 | + seriesField: 'name', |
| 48 | + color: ['#CDDDFD', '#CDF3E4', '#CED4DE'], |
| 49 | + }, |
| 50 | + ], |
| 51 | + }); |
| 52 | + DualAxesPlot.render(); |
| 53 | + expect(DualAxesPlot.options.yField).toEqual(['value', 'count']); |
| 54 | + await delay(500); |
| 55 | + DualAxesPlot.changeData([uvData, transformData]); |
| 56 | + expect(DualAxesPlot.options.geometryOptions[0].geometry).toBe('column'); |
| 57 | + expect(DualAxesPlot.chart.views[0].geometries[0].shapeType).toBe('interval'); |
| 58 | + }); |
| 59 | +}); |
0 commit comments