-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
link-by-color-spec.ts
149 lines (137 loc) · 3.96 KB
/
link-by-color-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { IGroup } from '@antv/g-base';
import { Chart } from '../../../../src/index';
import Link from '../../../../src/interaction/action/element/link-by-color';
import Context from '../../../../src/interaction/context';
import { createDiv } from '../../../util/dom';
import 'jest-extended';
describe('list highlight test', () => {
const chart = new Chart({
container: createDiv(),
width: 400,
height: 400,
autoFit: false,
});
chart.data([
{ year: '1991', value: 13, type: '1' },
{ year: '1992', value: 34, type: '1' },
{ year: '1993', value: 5, type: '1' },
{ year: '1994', value: 34, type: '1' },
{ year: '1991', value: 13, type: '2' },
{ year: '1992', value: 34, type: '2' },
{ year: '1993', value: 5, type: '2' },
{ year: '1994', value: 34, type: '2' },
]);
chart.animate(false);
chart.tooltip(false);
const interval = chart.interval().position('year*value').color('type').adjust('stack');
chart.render();
const context = new Context(chart);
const link = new Link(context);
const elements = interval.elements;
let linkGroup: IGroup;
it('link', () => {
context.event = {};
link.unlink();
link.clear(); // 事先调用,保证不出错
context.event = {
target: elements[0].shape,
};
link.link();
//@ts-ignore
linkGroup = link.linkGroup;
expect(linkGroup.getCount()).toBe(1);
});
it('unlink', () => {
context.event = {
target: null,
};
link.unlink();
expect(linkGroup.getCount()).toBe(1);
context.event = {
target: elements[0].shape,
};
link.unlink();
expect(linkGroup.getCount()).toBe(0);
});
it('multiple link', () => {
context.event = {
target: elements[0].shape,
};
link.link();
context.event = {
target: elements[4].shape,
};
link.link();
expect(linkGroup.getCount()).toBe(2);
});
it('custom link active-style', () => {
context.event = {};
link.unlink();
link.clear(); // 事先调用,保证不出错
context.event = {
target: elements[0].shape,
};
link.link();
//@ts-ignore
linkGroup = link.linkGroup;
expect(linkGroup.getCount()).toBe(1);
// @ts-ignore
expect(linkGroup.getChildren()[0].getChildren()[0].attr('fill')).toBe(elements[0].shape.attr('fill'));
link.unlink();
link.clear(); // 事先调用,保证不出错
context.event = {
target: elements[0].shape,
};
link.link({ style: { fill: 'red' } });
// @ts-ignore
expect(linkGroup.getChildren()[0].getChildren()[0].attr('fill')).toBe('red');
});
it('clear', () => {
link.clear();
expect(linkGroup.getCount()).toBe(0);
// @ts-ignore
expect(link.cache).toBeEmpty();
});
it('link null', () => {
context.event = {
target: null,
};
expect(linkGroup.getCount()).toBe(0);
});
it('no color', () => {
chart.clear();
const interval1 = chart.interval().position('year*value');
chart.render();
context.event = {
target: interval1.elements[0].shape,
};
link.link();
expect(linkGroup.getCount()).toBe(0);
link.unlink();
});
it('transposed coord', () => {
chart.clear();
chart.coordinate().transpose();
const interval2 = chart.interval().position('year*value').color('type').adjust('stack');
chart.render();
const firstBBox = interval2.elements[0].shape.getCanvasBBox();
const secondBBox = interval2.elements[1].shape.getCanvasBBox();
context.event = {};
link.clear();
context.event = {
target: interval2.elements[0].shape,
};
link.link();
expect(linkGroup.getCount()).toBe(1);
const group = linkGroup.getFirst() as IGroup;
expect(group.getCount()).toBe(3);
const path = group.getFirst();
expect(path.attr('path')).toEqual([
['M', firstBBox.minX, firstBBox.minY],
['L', secondBBox.minX, secondBBox.maxY],
['L', secondBBox.maxX, secondBBox.maxY],
['L', firstBBox.maxX, firstBBox.minY],
['Z'],
]);
});
});