-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue-378-spec.js
191 lines (168 loc) · 4.5 KB
/
issue-378-spec.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const expect = require('chai').expect;
const G2 = require('../../src/index');
describe('#378', () => {
it('animate axis label', done => {
const div = document.createElement('div');
document.body.appendChild(div);
const data = [
{
name: '2000',
value: 3892,
type0: '机房0'
},
{
name: '2001',
value: 7892,
type0: '机房0'
},
{
name: '2002',
value: 4714,
type0: '机房0'
},
{
name: '2003',
value: 5954,
type0: '机房0'
},
{
name: '2004',
value: 2814,
type0: '机房0'
},
{
name: '2000',
value: 11751,
type: '机房2'
},
{
name: '2001',
value: 4078,
type: '机房2'
},
{
name: '2002',
value: 2175,
type: '机房2'
},
{
name: '2003',
value: 12048,
type: '机房2'
},
{
name: '2004',
value: 1748,
type: '机房2'
}
];
const dataLine = data.filter(d => {
return !!d.type;
});
const dataBar = data.filter(d => {
return !!d.type0;
});
const chart = new G2.Chart({
container: div,
width: 500,
height: 300,
padding: [ 30, 60, 60, 60 ]
});
chart.scale({
name: {
type: 'timeCat'
},
value: {
type: 'linear',
sync: true
}
});
// chart.legend(false);
chart.tooltip({
crosshairs: {}
});
const barView = chart.view();
barView.source(dataBar);
// barView.interval().position('name*value').color('type0').adjust(['dodge']);
const lineView = chart.view();
lineView.source(dataLine);
lineView.line().position('name*value').color('type');
// chart.interval().position('name*value0').color('type0').adjust(['dodge']);
// chart.point().position('name*value0').color('type').size(3).shape('circle');
// chart.line().position('name*value1').color('type');
// chart.point().position('name*value1').color('type').size(3).shape('circle');
chart.render();
let i = 2004;
setTimeout(() => {
i += 1;
dataBar.push({
name: i + '',
value: Math.random() * 500 + 2500,
type0: '机房0'
});
dataLine.push({
name: i + '',
value: Math.random() * 500 + 2500,
type: '机房2'
});
if (dataBar.length > 10) {
dataBar.shift();
}
// barView.changeData(dataBar);
lineView.changeData(dataLine);
const scale = lineView.get('scales').name;
const ticks = scale.getTicks();
expect(ticks[0].tickValue).not.equal(undefined);
// console.log(data);
// chart.changeData(data);
chart.destroy();
done();
}, 500);
});
it('animate dodge label override', done => {
const div = document.createElement('div');
document.body.appendChild(div);
const data = [
{ genre: 'Sports', sold: 275, type: '1' },
{ genre: 'Strategy', sold: 115, type: '1' },
{ genre: 'Action', sold: 120, type: '1' },
{ genre: 'Shooter', sold: 350, type: '1' },
{ genre: 'Other', sold: 150, type: '1' },
{ genre: 'Sports', sold: 175, type: '2' },
{ genre: 'Strategy', sold: 215, type: '2' },
{ genre: 'Action', sold: 220, type: '2' },
{ genre: 'Shooter', sold: 250, type: '2' },
{ genre: 'Other', sold: 50, type: '2' }
];
const data1 = [
{ genre: 'Strategy', sold: 115, type: '1' },
{ genre: 'Sports', sold: 275, type: '1' },
{ genre: 'Action', sold: 120, type: '1' },
{ genre: 'Shooter', sold: 350, type: '1' },
{ genre: 'Other', sold: 150, type: '1' },
{ genre: 'Strategy', sold: 115, type: '2' },
{ genre: 'Sports', sold: 275, type: '2' },
{ genre: 'Action', sold: 120, type: '2' },
{ genre: 'Shooter', sold: 350, type: '2' },
{ genre: 'Other', sold: 150, type: '2' }
];
const chart = new G2.Chart({
container: div,
width: 500,
height: 540
});
chart.source(data);
const interval = chart.intervalDodge()
.position('genre*sold')
.color('type')
.label('sold');
chart.render();
setTimeout(function() {
chart.changeData(data1);
const labels = interval.get('labelContainer').get('labelsGroup').get('children');
expect(labels[0].attr('x') - labels[5].attr('x')).equal(50);
chart.destroy();
done();
}, 600);
});
});