|
| 1 | +import { salesByArea, subSalesByArea } from '../../../data/sales'; |
| 2 | +import { Rose } from '../../../../src'; |
| 3 | +import { createDiv } from '../../../utils/dom'; |
| 4 | + |
| 5 | +describe('rose-changeData', () => { |
| 6 | + it('basic rose: change Data', () => { |
| 7 | + const rosePlot = new Rose(createDiv(), { |
| 8 | + width: 400, |
| 9 | + height: 300, |
| 10 | + data: salesByArea, |
| 11 | + xField: 'area', |
| 12 | + yField: 'sales', |
| 13 | + }); |
| 14 | + |
| 15 | + rosePlot.render(); |
| 16 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(salesByArea.length); |
| 17 | + |
| 18 | + const newData = salesByArea.slice(0, 3); |
| 19 | + rosePlot.changeData(newData); |
| 20 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); |
| 21 | + expect(rosePlot.options.data).toEqual(newData); |
| 22 | + |
| 23 | + rosePlot.destroy(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('basic rose: from empty to have data', () => { |
| 27 | + const rosePlot = new Rose(createDiv(), { |
| 28 | + width: 400, |
| 29 | + height: 300, |
| 30 | + data: [], |
| 31 | + xField: 'area', |
| 32 | + yField: 'sales', |
| 33 | + }); |
| 34 | + |
| 35 | + rosePlot.render(); |
| 36 | + |
| 37 | + rosePlot.changeData(salesByArea); |
| 38 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(salesByArea.length); |
| 39 | + expect(rosePlot.options.data).toEqual(salesByArea); |
| 40 | + |
| 41 | + rosePlot.destroy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('group rose: change data', () => { |
| 45 | + const rosePlot = new Rose(createDiv(), { |
| 46 | + width: 400, |
| 47 | + height: 300, |
| 48 | + data: subSalesByArea, |
| 49 | + xField: 'area', |
| 50 | + yField: 'sales', |
| 51 | + isGroup: true, |
| 52 | + seriesField: 'series', |
| 53 | + }); |
| 54 | + |
| 55 | + rosePlot.render(); |
| 56 | + |
| 57 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); |
| 58 | + |
| 59 | + const newData = subSalesByArea.filter((item) => item.area !== '东北' || item.series !== '消费者'); |
| 60 | + rosePlot.changeData(newData); |
| 61 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); |
| 62 | + expect(rosePlot.options.data).toEqual(newData); |
| 63 | + |
| 64 | + rosePlot.destroy(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('group rose: from empty to have data', () => { |
| 68 | + const rosePlot = new Rose(createDiv(), { |
| 69 | + width: 400, |
| 70 | + height: 300, |
| 71 | + data: [], |
| 72 | + xField: 'area', |
| 73 | + yField: 'sales', |
| 74 | + isGroup: true, |
| 75 | + seriesField: 'series', |
| 76 | + }); |
| 77 | + |
| 78 | + rosePlot.render(); |
| 79 | + |
| 80 | + rosePlot.changeData(subSalesByArea); |
| 81 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); |
| 82 | + expect(rosePlot.options.data).toEqual(subSalesByArea); |
| 83 | + |
| 84 | + rosePlot.destroy(); |
| 85 | + }); |
| 86 | + |
| 87 | + it('stacked rose: change data', () => { |
| 88 | + const rosePlot = new Rose(createDiv(), { |
| 89 | + width: 400, |
| 90 | + height: 300, |
| 91 | + data: subSalesByArea, |
| 92 | + xField: 'area', |
| 93 | + yField: 'sales', |
| 94 | + isStack: true, |
| 95 | + seriesField: 'series', |
| 96 | + }); |
| 97 | + |
| 98 | + rosePlot.render(); |
| 99 | + |
| 100 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); |
| 101 | + |
| 102 | + const newData = subSalesByArea.filter((item) => item.area !== '东北' || item.series !== '消费者'); |
| 103 | + rosePlot.changeData(newData); |
| 104 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); |
| 105 | + expect(rosePlot.options.data).toEqual(newData); |
| 106 | + |
| 107 | + rosePlot.destroy(); |
| 108 | + }); |
| 109 | + |
| 110 | + it('stack rose: from empty to have data', () => { |
| 111 | + const rosePlot = new Rose(createDiv(), { |
| 112 | + width: 400, |
| 113 | + height: 300, |
| 114 | + data: [], |
| 115 | + xField: 'area', |
| 116 | + yField: 'sales', |
| 117 | + isStack: true, |
| 118 | + seriesField: 'series', |
| 119 | + }); |
| 120 | + |
| 121 | + rosePlot.render(); |
| 122 | + |
| 123 | + rosePlot.changeData(subSalesByArea); |
| 124 | + expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); |
| 125 | + expect(rosePlot.options.data).toEqual(subSalesByArea); |
| 126 | + |
| 127 | + rosePlot.destroy(); |
| 128 | + }); |
| 129 | +}); |
0 commit comments