jmchart 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +322 -40
- package/build.js +35 -35
- package/dist/jmchart.amd.js +8206 -6502
- package/dist/jmchart.cjs.js +8203 -6499
- package/dist/jmchart.esm.js +8202 -6498
- package/dist/jmchart.iife.js +8204 -6500
- package/dist/jmchart.system.js +8204 -6500
- package/index.js +8 -8
- package/package.json +7 -7
- package/rollup.config.js +26 -26
- package/server.js +48 -48
- package/src/common/style.js +285 -285
- package/src/common/tooltip.js +165 -165
- package/src/common/utils.js +21 -21
- package/src/component/vchart.js +130 -143
- package/src/core/axis/axis.js +727 -727
- package/src/core/legend/legend.js +145 -145
- package/src/core/markLine/manager.js +186 -186
- package/src/core/markLine/markLine.js +191 -191
- package/src/jmChart.js +427 -427
- package/src/series/barSeries.js +123 -135
- package/src/series/candlestickSeries.js +114 -114
- package/src/series/lineSeries.js +224 -243
- package/src/series/pieSeries.js +337 -337
- package/src/series/radarSeries.js +313 -313
- package/src/series/series.js +387 -404
- package/src/series/stackBarSeries.js +149 -149
- package/src/series/stackLineSeries.js +145 -145
package/src/series/series.js
CHANGED
|
@@ -1,404 +1,387 @@
|
|
|
1
|
-
|
|
2
|
-
import { jmPath, jmList, jmControl } from 'jmgraph';
|
|
3
|
-
import utils from '../common/utils.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @param {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.yAxis.init({
|
|
37
|
-
field: Array.isArray(this.field)? this.field[0]: this.field,
|
|
38
|
-
minYValue: options.minYValue,
|
|
39
|
-
maxYValue: options.maxYValue
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 关联访问的是chart的数据源
|
|
45
|
-
*/
|
|
46
|
-
get data() {
|
|
47
|
-
return this.graph.data;
|
|
48
|
-
}
|
|
49
|
-
set data(d) {
|
|
50
|
-
this.graph.data = d;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//是否启用动画效果
|
|
54
|
-
get enableAnimate() {
|
|
55
|
-
if(typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;
|
|
56
|
-
else {
|
|
57
|
-
return this.graph.enableAnimate;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
set enableAnimate(v) {
|
|
61
|
-
this.option.enableAnimate = v;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 图例名称
|
|
66
|
-
*
|
|
67
|
-
* @property legendLabel
|
|
68
|
-
* @type string
|
|
69
|
-
*/
|
|
70
|
-
legendLabel = '';
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 当前图形下的所有子图
|
|
74
|
-
*/
|
|
75
|
-
shapes = new jmList();
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 关健点集合
|
|
79
|
-
*/
|
|
80
|
-
keyPoints = [];
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 标注集合
|
|
84
|
-
*/
|
|
85
|
-
labels = [];
|
|
86
|
-
|
|
87
|
-
// 图绑定的属性名
|
|
88
|
-
field = '';
|
|
89
|
-
/**
|
|
90
|
-
* Y轴的基线跟最底层的高度
|
|
91
|
-
*/
|
|
92
|
-
baseYHeight = 0;
|
|
93
|
-
/**
|
|
94
|
-
* Y轴基线的Y坐标
|
|
95
|
-
*/
|
|
96
|
-
baseY = 0;
|
|
97
|
-
/**
|
|
98
|
-
* 当前基线Y的值,不给basey就会默认采用当前Y轴最小值
|
|
99
|
-
*/
|
|
100
|
-
baseYValue = 0;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
dataChanged
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
this.graph.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const event = this.option? this.option[name]: null;
|
|
390
|
-
if(!event) {
|
|
391
|
-
return super.getEvent(name);
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
const events = new jmList();
|
|
395
|
-
events.add(event);
|
|
396
|
-
|
|
397
|
-
const oldevents = super.getEvent(name);
|
|
398
|
-
if(oldevents) {
|
|
399
|
-
events.concat(oldevents);
|
|
400
|
-
}
|
|
401
|
-
return events;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
};
|
|
1
|
+
|
|
2
|
+
import { jmPath, jmList, jmControl } from 'jmgraph';
|
|
3
|
+
import utils from '../common/utils.js';
|
|
4
|
+
|
|
5
|
+
const ANIMATION_DATA_THRESHOLD = 100;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 图形基类
|
|
9
|
+
*
|
|
10
|
+
* @class jmSeries
|
|
11
|
+
* @module jmChart
|
|
12
|
+
* @param {jmChart} chart 当前图表
|
|
13
|
+
* @param {array} mappings 图形字段映射
|
|
14
|
+
* @param {style} style 样式
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default class jmSeries extends jmPath {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
|
|
21
|
+
this.option = options;
|
|
22
|
+
|
|
23
|
+
this.field = options.field || options.fields || '';
|
|
24
|
+
this.index = options.index || 1;
|
|
25
|
+
this.legendLabel = options.legendLabel || '';
|
|
26
|
+
this.___animateCounter = 0;
|
|
27
|
+
this._cache = new Map();
|
|
28
|
+
|
|
29
|
+
this.xAxis = this.graph.createXAxis();
|
|
30
|
+
|
|
31
|
+
this.yAxis = this.yAxis || this.graph.createYAxis({
|
|
32
|
+
index: this.index,
|
|
33
|
+
format: options.yLabelFormat || this.graph.option.yLabelFormat
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.yAxis.init({
|
|
37
|
+
field: Array.isArray(this.field) ? this.field[0] : this.field,
|
|
38
|
+
minYValue: options.minYValue,
|
|
39
|
+
maxYValue: options.maxYValue
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 关联访问的是chart的数据源
|
|
45
|
+
*/
|
|
46
|
+
get data() {
|
|
47
|
+
return this.graph.data;
|
|
48
|
+
}
|
|
49
|
+
set data(d) {
|
|
50
|
+
this.graph.data = d;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//是否启用动画效果
|
|
54
|
+
get enableAnimate() {
|
|
55
|
+
if(typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;
|
|
56
|
+
else {
|
|
57
|
+
return this.graph.enableAnimate;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
set enableAnimate(v) {
|
|
61
|
+
this.option.enableAnimate = v;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 图例名称
|
|
66
|
+
*
|
|
67
|
+
* @property legendLabel
|
|
68
|
+
* @type string
|
|
69
|
+
*/
|
|
70
|
+
legendLabel = '';
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 当前图形下的所有子图
|
|
74
|
+
*/
|
|
75
|
+
shapes = new jmList();
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 关健点集合
|
|
79
|
+
*/
|
|
80
|
+
keyPoints = [];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 标注集合
|
|
84
|
+
*/
|
|
85
|
+
labels = [];
|
|
86
|
+
|
|
87
|
+
// 图绑定的属性名
|
|
88
|
+
field = '';
|
|
89
|
+
/**
|
|
90
|
+
* Y轴的基线跟最底层的高度
|
|
91
|
+
*/
|
|
92
|
+
baseYHeight = 0;
|
|
93
|
+
/**
|
|
94
|
+
* Y轴基线的Y坐标
|
|
95
|
+
*/
|
|
96
|
+
baseY = 0;
|
|
97
|
+
/**
|
|
98
|
+
* 当前基线Y的值,不给basey就会默认采用当前Y轴最小值
|
|
99
|
+
*/
|
|
100
|
+
baseYValue = 0;
|
|
101
|
+
|
|
102
|
+
initDataPoint(...args) {
|
|
103
|
+
let dataChanged = false;
|
|
104
|
+
|
|
105
|
+
if(this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD) {
|
|
106
|
+
this.lastPoints = this.graph.utils.clone(this.dataPoints, null, true, (obj) => {
|
|
107
|
+
if(obj instanceof jmControl) return obj;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
this.dataPoints = this.createPoints(...args);
|
|
111
|
+
dataChanged = utils.arrayIsChange(this.lastPoints, this.dataPoints, (s, t) => {
|
|
112
|
+
return s.x === t.x && s.y === t.y;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if(dataChanged) {
|
|
116
|
+
this.___animateCounter = 0;
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
this.dataPoints = this.createPoints(...args);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if(this.option && this.option.onInit) {
|
|
123
|
+
this.option.onInit.apply(this, args);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
dataChanged,
|
|
128
|
+
points: this.dataPoints
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 根据X轴坐标,获取它最近的数据描点
|
|
134
|
+
* 离点最近的一个描点
|
|
135
|
+
* @param {number} x X轴坐标
|
|
136
|
+
*/
|
|
137
|
+
getDataPointByX(x) {
|
|
138
|
+
if(!this.dataPoints) return null;
|
|
139
|
+
// 获取最近的那个
|
|
140
|
+
let prePoint = undefined, nextPoint = undefined; // 跟上一个点和下一个点的距离,哪个近用哪个
|
|
141
|
+
for(let i=0; i< this.dataPoints.length; i++) {
|
|
142
|
+
const p = this.dataPoints[i];
|
|
143
|
+
if(p.x == x) return p;
|
|
144
|
+
|
|
145
|
+
// 上一个点
|
|
146
|
+
if(p.x < x) {
|
|
147
|
+
if(i === this.dataPoints.length - 1) return p;
|
|
148
|
+
prePoint = p;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 下一个点
|
|
152
|
+
if(typeof nextPoint === 'undefined' && p.x > x) {
|
|
153
|
+
// 没有上一个,只能返回这个了
|
|
154
|
+
if(prePoint && x - prePoint.x < p.x - x) return prePoint;
|
|
155
|
+
else return p
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 根据X轴值获取数据点
|
|
163
|
+
* @param {number} xValue X轴值
|
|
164
|
+
*/
|
|
165
|
+
getDataPointByXValue(xValue) {
|
|
166
|
+
if(!this.dataPoints) return null;
|
|
167
|
+
|
|
168
|
+
for(let i=0; i< this.dataPoints.length; i++) {
|
|
169
|
+
const p = this.dataPoints[i];
|
|
170
|
+
if(p.xValue == xValue) return p;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
reset() {
|
|
177
|
+
var shape;
|
|
178
|
+
while(shape = this.shapes.shift()) {
|
|
179
|
+
shape && shape.remove();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.initAxisValue();
|
|
183
|
+
this.createLegend();
|
|
184
|
+
|
|
185
|
+
return this.chartInfo = {
|
|
186
|
+
xAxis: this.xAxis,
|
|
187
|
+
yAxis: this.yAxis
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
initAxisValue() {
|
|
192
|
+
if(!this.data || !this.data.length) return;
|
|
193
|
+
|
|
194
|
+
for(var i = 0; i < this.data.length; i++) {
|
|
195
|
+
if(Array.isArray(this.field)) {
|
|
196
|
+
this.field.forEach((f) => {
|
|
197
|
+
const v = this.data[i][f];
|
|
198
|
+
if(v != null) {
|
|
199
|
+
this.yAxis.max(v);
|
|
200
|
+
this.yAxis.min(v);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
const v = this.data[i][this.field];
|
|
205
|
+
if(v != null) {
|
|
206
|
+
this.yAxis.max(v);
|
|
207
|
+
this.yAxis.min(v);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const xv = this.data[i][this.xAxis.field];
|
|
212
|
+
if(xv != null) {
|
|
213
|
+
this.xAxis.max(xv);
|
|
214
|
+
this.xAxis.min(xv);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
createPoints(data) {
|
|
220
|
+
data = data || this.data;
|
|
221
|
+
if(!data || !data.length) return [];
|
|
222
|
+
|
|
223
|
+
const xstep = this.xAxis.step();
|
|
224
|
+
const minY = this.yAxis.min();
|
|
225
|
+
const ystep = this.yAxis.step();
|
|
226
|
+
|
|
227
|
+
this.baseYValue = typeof this.graph.baseY === 'undefined' ? minY : (this.graph.baseY || 0);
|
|
228
|
+
this.baseYHeight = (this.baseYValue - minY) * ystep;
|
|
229
|
+
this.baseY = this.graph.chartArea.height - this.baseYHeight;
|
|
230
|
+
|
|
231
|
+
const fields = Array.isArray(this.field) ? this.field : [this.field];
|
|
232
|
+
const dataPoints = [];
|
|
233
|
+
|
|
234
|
+
for(let i = 0; i < data.length; i++) {
|
|
235
|
+
const s = data[i];
|
|
236
|
+
const xv = s[this.xAxis.field];
|
|
237
|
+
|
|
238
|
+
const p = {
|
|
239
|
+
data: s,
|
|
240
|
+
index: i,
|
|
241
|
+
xValue: xv,
|
|
242
|
+
xLabel: xv,
|
|
243
|
+
points: [],
|
|
244
|
+
style: this.graph.utils.clone(this.style),
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
p.x = xstep * i + this.xAxis.labelStart;
|
|
248
|
+
|
|
249
|
+
for(let j = 0; j < fields.length; j++) {
|
|
250
|
+
const f = fields[j];
|
|
251
|
+
const yv = s[f];
|
|
252
|
+
p.yLabel = p.yValue = yv;
|
|
253
|
+
p.height = (yv - this.baseYValue) * ystep;
|
|
254
|
+
|
|
255
|
+
const point = {
|
|
256
|
+
x: p.x,
|
|
257
|
+
height: p.height,
|
|
258
|
+
yValue: yv,
|
|
259
|
+
field: f
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if(yv == null || typeof yv == 'undefined') {
|
|
263
|
+
point.m = p.m = true;
|
|
264
|
+
} else {
|
|
265
|
+
if(this.yAxis.dataType != 'number') {
|
|
266
|
+
yv = i;
|
|
267
|
+
}
|
|
268
|
+
point.y = p.y = this.baseY - point.height;
|
|
269
|
+
}
|
|
270
|
+
p.points.push(point);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if(typeof this.option.initItemHandler === 'function') {
|
|
274
|
+
this.option.initItem.call(this, p);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
dataPoints.push(p);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.dataPoints = dataPoints;
|
|
281
|
+
return this.dataPoints;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 生成颜色
|
|
285
|
+
getColor(p) {
|
|
286
|
+
if(typeof this.style.color === 'function') {
|
|
287
|
+
return this.style.color.call(this, p);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
return this.style.color;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 生成图例
|
|
296
|
+
*
|
|
297
|
+
* @method createLegend
|
|
298
|
+
*/
|
|
299
|
+
createLegend() {
|
|
300
|
+
//生成图例前的图标
|
|
301
|
+
const style = this.graph.utils.clone(this.style);
|
|
302
|
+
style.fill = this.getColor();
|
|
303
|
+
//delete style.stroke;
|
|
304
|
+
const shape = this.graph.createShape('rect',{
|
|
305
|
+
style
|
|
306
|
+
});
|
|
307
|
+
this.graph.legend.append(this, shape);
|
|
308
|
+
return shape;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 生成柱图的标注
|
|
312
|
+
createItemLabel(point, position) {
|
|
313
|
+
if(!this.style.label || this.style.label.show !== true) return;
|
|
314
|
+
|
|
315
|
+
const text = this.option.itemLabelFormat?this.option.itemLabelFormat.call(this, point): point.yValue;
|
|
316
|
+
if(!text) return;
|
|
317
|
+
|
|
318
|
+
// v如果指定了为控件,则直接加入
|
|
319
|
+
if(text instanceof jmControl) {
|
|
320
|
+
this.addShape(text);
|
|
321
|
+
return text;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const style = this.graph.utils.clone(this.graph.style.itemLabel, {
|
|
325
|
+
zIndex: 21,
|
|
326
|
+
...this.style.label
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
if(typeof style.fill === 'function') {
|
|
330
|
+
style.fill = style.fill.call(this, point);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const barWidth = (this.barTotalWidth||0) / 2 - (this.barWidth||0) * (this.barIndex||0) - (this.barWidth||0) / 2;
|
|
334
|
+
const baseOffset = point.y - this.baseY;
|
|
335
|
+
const label = this.graph.createShape('label', {
|
|
336
|
+
style,
|
|
337
|
+
text: text,
|
|
338
|
+
data: point,
|
|
339
|
+
position: function() {
|
|
340
|
+
const offh = style.offset || 5;
|
|
341
|
+
const size = this.testSize();
|
|
342
|
+
return {
|
|
343
|
+
x: point.x - size.width / 2 - barWidth,
|
|
344
|
+
y: baseOffset>0?(point.y + offh): (point.y - size.height - offh)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
this.addShape(label);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* 在图上加下定制图形
|
|
354
|
+
* @param {jmShape} shape 图形
|
|
355
|
+
*/
|
|
356
|
+
addShape(shape) {
|
|
357
|
+
this.graph.chartArea.children.add(shape);
|
|
358
|
+
this.shapes.add(shape);
|
|
359
|
+
return shape;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 获取指定事件的集合
|
|
364
|
+
* 比如mousedown,mouseup等
|
|
365
|
+
*
|
|
366
|
+
* @method getEvent
|
|
367
|
+
* @param {string} name 事件名称
|
|
368
|
+
* @return {list} 事件委托的集合
|
|
369
|
+
*/
|
|
370
|
+
getEvent(name) {
|
|
371
|
+
|
|
372
|
+
const event = this.option? this.option[name]: null;
|
|
373
|
+
if(!event) {
|
|
374
|
+
return super.getEvent(name);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const events = new jmList();
|
|
378
|
+
events.add(event);
|
|
379
|
+
|
|
380
|
+
const oldevents = super.getEvent(name);
|
|
381
|
+
if(oldevents) {
|
|
382
|
+
events.concat(oldevents);
|
|
383
|
+
}
|
|
384
|
+
return events;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|