|
| 1 | +import { Facet } from '../../../../src'; |
| 2 | +import { createDiv } from '../../../utils/dom'; |
| 3 | + |
| 4 | +describe('facet animation', () => { |
| 5 | + const data = [ |
| 6 | + { type: '1', date: '2014-01', value: 1, name: 'a' }, |
| 7 | + { type: '1', date: '2015-01', value: 1, name: 'b' }, |
| 8 | + { type: '1', date: '2016-01', value: 1, name: 'c' }, |
| 9 | + { type: '1', date: '2017-01', value: 1, name: 'd' }, |
| 10 | + { type: '2', date: '2014-01', value: 1, name: 'a' }, |
| 11 | + { type: '2', date: '2015-01', value: 1, name: 'b' }, |
| 12 | + { type: '2', date: '2016-01', value: 1, name: 'a' }, |
| 13 | + { type: '2', date: '2017-01', value: 1, name: 'd' }, |
| 14 | + { type: '3', date: '2014-01', value: 1, name: 'b' }, |
| 15 | + { type: '4', date: '2015-01', value: 1, name: 'd' }, |
| 16 | + { type: '4', date: '2016-01', value: 10, name: 'b' }, |
| 17 | + { type: '4', date: '2017-01', value: 1, name: 'c' }, |
| 18 | + ]; |
| 19 | + const plot = new Facet(createDiv(), { |
| 20 | + data, |
| 21 | + type: 'rect', |
| 22 | + fields: ['type'], |
| 23 | + eachView: () => { |
| 24 | + return { |
| 25 | + geometries: [ |
| 26 | + { type: 'interval', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }, |
| 27 | + { type: 'point', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }, |
| 28 | + ], |
| 29 | + animation: { |
| 30 | + appear: { |
| 31 | + animation: 'fade-in', |
| 32 | + duration: 3500, |
| 33 | + }, |
| 34 | + leave: { |
| 35 | + animation: 'wave-in', |
| 36 | + duration: 200, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }; |
| 40 | + }, |
| 41 | + meta: { date: { sync: true } }, |
| 42 | + }); |
| 43 | + plot.render(); |
| 44 | + |
| 45 | + it('default animation', () => { |
| 46 | + const geometries = plot.chart.views[0].geometries; |
| 47 | + |
| 48 | + expect(geometries[0].animateOption).toMatchObject({ |
| 49 | + appear: { |
| 50 | + animation: 'fade-in', |
| 51 | + duration: 3500, |
| 52 | + }, |
| 53 | + leave: { |
| 54 | + animation: 'wave-in', |
| 55 | + duration: 200, |
| 56 | + }, |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it('callback animation', () => { |
| 61 | + plot.update({ |
| 62 | + eachView: () => { |
| 63 | + return { |
| 64 | + geometries: [ |
| 65 | + { type: 'interval', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }, |
| 66 | + { type: 'point', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }, |
| 67 | + ], |
| 68 | + animation: (type) => ({ |
| 69 | + appear: { |
| 70 | + animation: type === 'point' ? 'fade-in' : 'wave-in', |
| 71 | + duration: 500, |
| 72 | + }, |
| 73 | + leave: { |
| 74 | + animation: type === 'interval' ? 'fade-out' : 'wave-out', |
| 75 | + duration: 300, |
| 76 | + }, |
| 77 | + }), |
| 78 | + }; |
| 79 | + }, |
| 80 | + }); |
| 81 | + |
| 82 | + const geometries = plot.chart.views[0].geometries; |
| 83 | + |
| 84 | + expect(geometries[0].animateOption).toMatchObject({ |
| 85 | + appear: { |
| 86 | + animation: 'wave-in', |
| 87 | + duration: 500, |
| 88 | + }, |
| 89 | + leave: { |
| 90 | + animation: 'fade-out', |
| 91 | + duration: 300, |
| 92 | + }, |
| 93 | + }); |
| 94 | + |
| 95 | + expect(geometries[1].animateOption).toMatchObject({ |
| 96 | + appear: { |
| 97 | + animation: 'fade-in', |
| 98 | + duration: 500, |
| 99 | + }, |
| 100 | + leave: { |
| 101 | + animation: 'wave-out', |
| 102 | + duration: 300, |
| 103 | + }, |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + afterAll(() => { |
| 108 | + plot.destroy(); |
| 109 | + }); |
| 110 | +}); |
0 commit comments