|
| 1 | +import { Column, ColumnOptions, Bar, BarOptions } from '@antv/g2plot/src'; |
| 2 | +import { createDiv } from '@antv/g2plot/__tests__/utils/dom'; |
| 3 | + |
| 4 | +const DATA = [ |
| 5 | + { year: '2014', type: 'Sales', sales: 1000 }, |
| 6 | + { year: '2015', type: 'Sales', sales: 1170 }, |
| 7 | + { year: '2016', type: 'Sales', sales: 660 }, |
| 8 | + { year: '2017', type: 'Sales', sales: 1030 }, |
| 9 | + { year: '2014', type: 'Expenses', sales: 400 }, |
| 10 | + { year: '2015', type: 'Expenses', sales: 460 }, |
| 11 | + { year: '2016', type: 'Expenses', sales: 1120 }, |
| 12 | + { year: '2017', type: 'Expenses', sales: 540 }, |
| 13 | + { year: '2014', type: 'Profit', sales: 300 }, |
| 14 | + { year: '2015', type: 'Profit', sales: 300 }, |
| 15 | + { year: '2016', type: 'Profit', sales: 300 }, |
| 16 | + { year: '2017', type: 'Profit', sales: 350 }, |
| 17 | +]; |
| 18 | + |
| 19 | +describe('column connected area', () => { |
| 20 | + const options: ColumnOptions = { |
| 21 | + data: DATA, |
| 22 | + autoFit: false, |
| 23 | + width: 600, |
| 24 | + height: 400, |
| 25 | + xField: 'year', |
| 26 | + yField: 'sales', |
| 27 | + seriesField: 'type', |
| 28 | + isStack: true, |
| 29 | + yAxis: { |
| 30 | + nice: true, |
| 31 | + }, |
| 32 | + connectedArea: {}, |
| 33 | + }; |
| 34 | + const plot = new Column(createDiv(), options); |
| 35 | + // @ts-ignore |
| 36 | + window.__column__ = plot; |
| 37 | + |
| 38 | + it('render', () => { |
| 39 | + plot.render(); |
| 40 | + const hover = plot.chart.interactions['__interval-connected-area-hover__']; |
| 41 | + const click = plot.chart.interactions['__interval-connected-area-click__']; |
| 42 | + expect(hover).toBeDefined(); |
| 43 | + expect(click).toBeUndefined(); |
| 44 | + // @ts-ignore |
| 45 | + expect(hover.cfg.start).toHaveLength(1); |
| 46 | + // @ts-ignore |
| 47 | + expect(hover.cfg.start[0]).toMatchObject({ |
| 48 | + trigger: `interval:mouseenter`, |
| 49 | + action: ['element-highlight-by-color:highlight', 'element-link-by-color:link'], |
| 50 | + }); |
| 51 | + // @ts-ignore |
| 52 | + expect(hover.cfg.end).toHaveLength(1); |
| 53 | + // @ts-ignore |
| 54 | + expect(hover.cfg.end[0]).toMatchObject({ |
| 55 | + trigger: 'interval:mouseleave', |
| 56 | + action: ['element-highlight-by-color:reset', 'element-link-by-color:unlink'], |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + /* |
| 61 | + it('update', () => { |
| 62 | + plot.update({ |
| 63 | + ...options, |
| 64 | + connectedArea: { |
| 65 | + trigger: 'click', |
| 66 | + }, |
| 67 | + }); |
| 68 | + plot.render(); |
| 69 | + const hover = plot.chart.interactions['__interval-connected-area-hover__']; |
| 70 | + const click = plot.chart.interactions['__interval-connected-area-click__']; |
| 71 | + expect(hover).toBeUndefined(); |
| 72 | + expect(click).toBeDefined(); |
| 73 | + // @ts-ignore |
| 74 | + expect(click.cfg.start).toHaveLength(1); |
| 75 | + // @ts-ignore |
| 76 | + expect(click.cfg.start[0]).toMatchObject({ |
| 77 | + trigger: `interval:click`, |
| 78 | + action: [ |
| 79 | + 'element-highlight-by-color:clear', |
| 80 | + 'element-highlight-by-color:highlight', |
| 81 | + 'element-link-by-color:clear', |
| 82 | + 'element-link-by-color:unlink', |
| 83 | + 'element-link-by-color:link', |
| 84 | + ], |
| 85 | + }); |
| 86 | + // @ts-ignore |
| 87 | + expect(click.cfg.end).toHaveLength(1); |
| 88 | + // @ts-ignore |
| 89 | + expect(click.cfg.end[0]).toMatchObject({ |
| 90 | + trigger: 'document:mousedown', |
| 91 | + action: ['element-highlight-by-color:clear', 'element-link-by-color:clear'], |
| 92 | + }); |
| 93 | + }); |
| 94 | +
|
| 95 | + it('off', () => { |
| 96 | + plot.update({ |
| 97 | + ...options, |
| 98 | + connectedArea: false, |
| 99 | + }); |
| 100 | + plot.render(); |
| 101 | + const interaction = plot.chart.interactions['__interval-connected-area-hover__']; |
| 102 | + expect(interaction).toBeUndefined(); |
| 103 | + }); |
| 104 | + */ |
| 105 | +}); |
| 106 | + |
| 107 | +describe('bar connected area', () => { |
| 108 | + const options: BarOptions = { |
| 109 | + data: DATA, |
| 110 | + autoFit: false, |
| 111 | + width: 600, |
| 112 | + height: 400, |
| 113 | + yField: 'year', |
| 114 | + xField: 'sales', |
| 115 | + seriesField: 'type', |
| 116 | + isStack: true, |
| 117 | + xAxis: { |
| 118 | + nice: true, |
| 119 | + }, |
| 120 | + connectedArea: {}, |
| 121 | + }; |
| 122 | + const plot = new Bar(createDiv(), options); |
| 123 | + // @ts-ignore |
| 124 | + window.__bar__ = plot; |
| 125 | + |
| 126 | + it('render', () => { |
| 127 | + plot.render(); |
| 128 | + const hover = plot.chart.interactions['__interval-connected-area-hover__']; |
| 129 | + const click = plot.chart.interactions['__interval-connected-area-click__']; |
| 130 | + expect(hover).toBeDefined(); |
| 131 | + expect(click).toBeUndefined(); |
| 132 | + // @ts-ignore |
| 133 | + expect(hover.cfg.start).toHaveLength(1); |
| 134 | + // @ts-ignore |
| 135 | + expect(hover.cfg.start[0]).toMatchObject({ |
| 136 | + trigger: `interval:mouseenter`, |
| 137 | + action: ['element-highlight-by-color:highlight', 'element-link-by-color:link'], |
| 138 | + }); |
| 139 | + // @ts-ignore |
| 140 | + expect(hover.cfg.end).toHaveLength(1); |
| 141 | + // @ts-ignore |
| 142 | + expect(hover.cfg.end[0]).toMatchObject({ |
| 143 | + trigger: 'interval:mouseleave', |
| 144 | + action: ['element-highlight-by-color:reset', 'element-link-by-color:unlink'], |
| 145 | + }); |
| 146 | + }); |
| 147 | + |
| 148 | + /* |
| 149 | + it('update', () => { |
| 150 | + plot.update({ |
| 151 | + ...options, |
| 152 | + connectedArea: { |
| 153 | + trigger: 'click', |
| 154 | + }, |
| 155 | + }); |
| 156 | + plot.render(); |
| 157 | + const hover = plot.chart.interactions['__interval-connected-area-hover__']; |
| 158 | + const click = plot.chart.interactions['__interval-connected-area-click__']; |
| 159 | + expect(hover).toBeUndefined(); |
| 160 | + expect(click).toBeDefined(); |
| 161 | + // @ts-ignore |
| 162 | + expect(click.cfg.start).toHaveLength(1); |
| 163 | + // @ts-ignore |
| 164 | + expect(click.cfg.start[0]).toMatchObject({ |
| 165 | + trigger: `interval:click`, |
| 166 | + action: [ |
| 167 | + 'element-highlight-by-color:clear', |
| 168 | + 'element-highlight-by-color:highlight', |
| 169 | + 'element-link-by-color:clear', |
| 170 | + 'element-link-by-color:unlink', |
| 171 | + 'element-link-by-color:link', |
| 172 | + ], |
| 173 | + }); |
| 174 | + // @ts-ignore |
| 175 | + expect(click.cfg.end).toHaveLength(1); |
| 176 | + // @ts-ignore |
| 177 | + expect(click.cfg.end[0]).toMatchObject({ |
| 178 | + trigger: 'document:mousedown', |
| 179 | + action: ['element-highlight-by-color:clear', 'element-link-by-color:clear'], |
| 180 | + }); |
| 181 | + }); |
| 182 | +
|
| 183 | + it('off', () => { |
| 184 | + plot.update({ |
| 185 | + ...options, |
| 186 | + connectedArea: false, |
| 187 | + }); |
| 188 | + plot.render(); |
| 189 | + const interaction = plot.chart.interactions['__interval-connected-area-hover__']; |
| 190 | + expect(interaction).toBeUndefined(); |
| 191 | + }); |
| 192 | + */ |
| 193 | +}); |
0 commit comments