jmchart 1.1.79 → 1.1.90
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 +30 -28
- package/build.js +35 -35
- package/dist/jmchart.amd.js +700 -444
- package/dist/jmchart.cjs.js +699 -443
- package/dist/jmchart.esm.js +699 -444
- package/dist/jmchart.iife.js +701 -443
- package/dist/jmchart.system.js +699 -443
- package/example/bar.html +180 -180
- package/example/candlestick.html +288 -0
- package/example/index.html +294 -0
- package/example/js/vconsole.js +10 -0
- package/example/line.html +300 -297
- package/example/pie.html +353 -353
- package/example/stackBar.html +142 -142
- package/example/stackLine.html +147 -147
- package/example/test.html +40 -40
- package/example/vue.html +322 -322
- package/example/wk/line.html +314 -312
- package/index.js +8 -8
- package/package.json +42 -42
- package/rollup.config.js +26 -26
- package/server.js +45 -45
- package/src/common/style.js +259 -242
- package/src/common/tooltip.js +165 -165
- package/src/common/utils.js +21 -21
- package/src/component/vchart.js +130 -130
- package/src/core/axis/axis.js +622 -622
- package/src/core/legend/legend.js +163 -163
- package/src/core/markLine/manager.js +152 -0
- package/src/core/{axis → markLine}/markLine.js +190 -190
- package/src/jmChart.js +416 -464
- package/src/series/barSeries.js +135 -135
- package/src/series/candlestickSeries.js +114 -0
- package/src/series/lineSeries.js +243 -243
- package/src/series/pieSeries.js +350 -350
- package/src/series/series.js +397 -396
- package/src/series/stackBarSeries.js +144 -144
- package/src/series/stackLineSeries.js +145 -145
package/src/jmChart.js
CHANGED
|
@@ -1,465 +1,417 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
jmGraph,
|
|
4
|
-
jmUtils,
|
|
5
|
-
jmList
|
|
6
|
-
} from 'jmgraph';
|
|
7
|
-
import defaultStyle from './common/style.js';
|
|
8
|
-
import jmAxis from './core/axis/axis.js';
|
|
9
|
-
import jmLegend from './core/legend/legend.js';
|
|
10
|
-
import jmBarSeries from './series/barSeries.js';
|
|
11
|
-
import jmStackBarSeries from './series/stackBarSeries.js';
|
|
12
|
-
import jmPieSeries from './series/pieSeries.js';
|
|
13
|
-
|
|
14
|
-
import jmLineSeries from './series/lineSeries.js';
|
|
15
|
-
import jmStackLineSeries from './series/stackLineSeries.js';
|
|
16
|
-
import
|
|
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
|
-
this.
|
|
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
|
-
//this.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
cn.
|
|
149
|
-
cn.
|
|
150
|
-
cn.style.
|
|
151
|
-
cn.style.
|
|
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
|
-
|
|
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
|
-
this.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this.
|
|
295
|
-
|
|
296
|
-
this.
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
this.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @
|
|
355
|
-
* @
|
|
356
|
-
* @param {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
options
|
|
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
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
zeroBase: this.baseY === 0,
|
|
418
|
-
...this.option.xAxisOption,
|
|
419
|
-
}, options || {});
|
|
420
|
-
if(typeof this.option.minYValue !== 'undefined') {
|
|
421
|
-
options.minYValue = typeof options.minYValue === 'undefined'?this.option.minYValue:Math.min(this.option.minYValue, options.minYValue);
|
|
422
|
-
}
|
|
423
|
-
if(typeof this.option.maxYValue !== 'undefined') {
|
|
424
|
-
options.maxYValue = typeof options.maxYValue === 'undefined'?this.option.maxYValue:Math.max(this.option.maxYValue, options.maxYValue);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
|
|
428
|
-
return yaxis;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* 创建图形
|
|
433
|
-
*
|
|
434
|
-
* @method createSeries
|
|
435
|
-
* @for jmChart
|
|
436
|
-
* @param {string} [type] 图类型,(line/bar/pie/radar)
|
|
437
|
-
* @param {object} [options] 生成图表选项 {xField, yField, index}
|
|
438
|
-
* @return {series} 图形
|
|
439
|
-
*/
|
|
440
|
-
createSeries(type, options = {}) {
|
|
441
|
-
if(!this.serieTypes) {
|
|
442
|
-
this.serieTypes = {
|
|
443
|
-
'line' : jmLineSeries,
|
|
444
|
-
'bar' : jmBarSeries,
|
|
445
|
-
'stackBar' : jmStackBarSeries,
|
|
446
|
-
'pie' : jmPieSeries,
|
|
447
|
-
'stackLine' : jmStackLineSeries
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
//默认样式为类型对应的样式
|
|
452
|
-
const style = this.style[type] || this.style['line'];
|
|
453
|
-
// 深度组件默认样式
|
|
454
|
-
options.style = this.utils.clone(style, options.style, true);
|
|
455
|
-
|
|
456
|
-
if(typeof type == 'string') type = this.serieTypes[type];
|
|
457
|
-
|
|
458
|
-
const serie = this.createShape(type, options);
|
|
459
|
-
if(serie) {
|
|
460
|
-
this.series.add(serie);
|
|
461
|
-
this.chartArea.children.add(serie);
|
|
462
|
-
}
|
|
463
|
-
return serie;
|
|
464
|
-
}
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
jmGraph,
|
|
4
|
+
jmUtils,
|
|
5
|
+
jmList
|
|
6
|
+
} from 'jmgraph';
|
|
7
|
+
import defaultStyle from './common/style.js';
|
|
8
|
+
import jmAxis from './core/axis/axis.js';
|
|
9
|
+
import jmLegend from './core/legend/legend.js';
|
|
10
|
+
import jmBarSeries from './series/barSeries.js';
|
|
11
|
+
import jmStackBarSeries from './series/stackBarSeries.js';
|
|
12
|
+
import jmPieSeries from './series/pieSeries.js';
|
|
13
|
+
|
|
14
|
+
import jmLineSeries from './series/lineSeries.js';
|
|
15
|
+
import jmStackLineSeries from './series/stackLineSeries.js';
|
|
16
|
+
import jmCandlestickSeries from './series/candlestickSeries.js';
|
|
17
|
+
import jmMarkLineManager from './core/markLine/manager';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* jm图表组件
|
|
21
|
+
* option参数:graph=jmgraph
|
|
22
|
+
*
|
|
23
|
+
* @class jmChart
|
|
24
|
+
* @module jmChart
|
|
25
|
+
* @param {element} container 图表容器
|
|
26
|
+
*/
|
|
27
|
+
export default class jmChart extends jmGraph {
|
|
28
|
+
|
|
29
|
+
constructor(container, options) {
|
|
30
|
+
options = options||{};
|
|
31
|
+
|
|
32
|
+
const enableAnimate = !!options.enableAnimate;
|
|
33
|
+
options.autoRefresh = typeof options.autoRefresh === 'undefined'? enableAnimate: options.autoRefresh;
|
|
34
|
+
|
|
35
|
+
if(enableAnimate && !options.autoRefresh) {
|
|
36
|
+
console.warn('开启了动画,却没有开户自动刷新');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 深度复制默认样式,以免被改
|
|
40
|
+
options.style = jmUtils.clone(defaultStyle, options.style, true);
|
|
41
|
+
|
|
42
|
+
super(container, options);
|
|
43
|
+
|
|
44
|
+
this.enableAnimate = enableAnimate;
|
|
45
|
+
this.data = options.data || [];
|
|
46
|
+
// x轴绑定的字段名
|
|
47
|
+
this.xField = options.xField || '';
|
|
48
|
+
|
|
49
|
+
this.init(options);
|
|
50
|
+
|
|
51
|
+
// 创建操作图层
|
|
52
|
+
this.createTouchGraph(this.container, options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 绑定的数据源
|
|
57
|
+
*/
|
|
58
|
+
data = [];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 当前所有图
|
|
62
|
+
*/
|
|
63
|
+
series = new jmList();
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 是否启用动画
|
|
67
|
+
*/
|
|
68
|
+
get enableAnimate() {
|
|
69
|
+
if(typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;
|
|
70
|
+
else {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
set enableAnimate(v) {
|
|
75
|
+
this.option.enableAnimate = v;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Y轴的基线 默认是0
|
|
80
|
+
*/
|
|
81
|
+
get baseY() {
|
|
82
|
+
return this.option.baseY;
|
|
83
|
+
}
|
|
84
|
+
set baseY(v) {
|
|
85
|
+
this.option.baseY = v;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 初始化图表
|
|
89
|
+
init(options) {
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 绘图区域
|
|
93
|
+
*
|
|
94
|
+
* @property chartArea
|
|
95
|
+
* @type jmControl
|
|
96
|
+
*/
|
|
97
|
+
if(!this.chartArea) {
|
|
98
|
+
this.chartArea = this.createShape('rect', {
|
|
99
|
+
style: this.style.chartArea,
|
|
100
|
+
position: { x: 0, y: 0}
|
|
101
|
+
});
|
|
102
|
+
this.children.add(this.chartArea);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 图例
|
|
107
|
+
*
|
|
108
|
+
* @property legend
|
|
109
|
+
* @type jmLegend
|
|
110
|
+
*/
|
|
111
|
+
this.legend = this.legend || this.createShape(jmLegend, {
|
|
112
|
+
style: this.style.legend
|
|
113
|
+
});
|
|
114
|
+
this.children.add(this.legend);
|
|
115
|
+
// 不显示图例
|
|
116
|
+
if(options.legendVisible === false) {
|
|
117
|
+
this.legend.visible = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 图表提示控件
|
|
122
|
+
*
|
|
123
|
+
* @property tooltip
|
|
124
|
+
* @type jmTooltip
|
|
125
|
+
*/
|
|
126
|
+
//this.tooltip = this.graph.createShape('tooltip',{style:this.style.tooltip});
|
|
127
|
+
//this.chartArea.children.add(this.tooltip);
|
|
128
|
+
|
|
129
|
+
this.createXAxis();// 生成X轴
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 创建一个操作层,以免每次刷新
|
|
133
|
+
createTouchGraph(container, options) {
|
|
134
|
+
if(container && container.tagName === 'CANVAS') {
|
|
135
|
+
container = container.parentElement;
|
|
136
|
+
}
|
|
137
|
+
container && (container.style.position = 'relative');
|
|
138
|
+
|
|
139
|
+
options = this.utils.clone(options, {
|
|
140
|
+
autoRefresh: true
|
|
141
|
+
}, true);
|
|
142
|
+
|
|
143
|
+
// 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
|
|
144
|
+
// isWXMiniApp 非微信小程序下才能创建
|
|
145
|
+
if(!this.isWXMiniApp && container && options.touchGraph) {
|
|
146
|
+
let cn = document.createElement('canvas');
|
|
147
|
+
cn.width = container.offsetWidth||container.clientWidth;
|
|
148
|
+
cn.height = container.offsetHeight||container.clientHeight;
|
|
149
|
+
cn.style.position = 'absolute';
|
|
150
|
+
cn.style.top = 0;
|
|
151
|
+
cn.style.left = 0;
|
|
152
|
+
|
|
153
|
+
this.touchGraph = new jmGraph(cn, options);
|
|
154
|
+
|
|
155
|
+
container.appendChild(cn);
|
|
156
|
+
|
|
157
|
+
this.touchGraph.chartGraph = this;
|
|
158
|
+
|
|
159
|
+
this.on('propertyChange', (name, args) => {
|
|
160
|
+
if(['width', 'height'].includes(name)) {
|
|
161
|
+
this.touchGraph[name] = args.newValue / this.devicePixelRatio;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
// 把上层canvse事件传递给绘图层对象
|
|
165
|
+
this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', (args) => {
|
|
166
|
+
const eventName = args.event.eventName || args.event.type;
|
|
167
|
+
if(eventName) {
|
|
168
|
+
this.emit(eventName, args);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// 初始化标线
|
|
173
|
+
this.markLine = new jmMarkLineManager(this);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 重置整个图表
|
|
177
|
+
reset() {
|
|
178
|
+
// 清空当前图形,重新生成
|
|
179
|
+
let serie;
|
|
180
|
+
while(serie = this.series.shift()) {
|
|
181
|
+
|
|
182
|
+
// 重置所有图形
|
|
183
|
+
let shape;
|
|
184
|
+
while(shape = serie.shapes.shift()) {
|
|
185
|
+
shape && shape.remove();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
serie.remove();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 轴删除
|
|
192
|
+
if(this.xAxis) {
|
|
193
|
+
this.xAxis.remove();
|
|
194
|
+
delete this.xAxis;
|
|
195
|
+
}
|
|
196
|
+
if(this.yAxises) {
|
|
197
|
+
for(let i in this.yAxises) {
|
|
198
|
+
this.yAxises[i].remove();
|
|
199
|
+
}
|
|
200
|
+
delete this.yAxises;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 获取颜色
|
|
205
|
+
*
|
|
206
|
+
* @method getColor
|
|
207
|
+
* @param {int} index 颜色索引
|
|
208
|
+
*/
|
|
209
|
+
getColor(index) {
|
|
210
|
+
//如果颜色超过最大个数,则重新获取
|
|
211
|
+
if(index >= this.style.chartColors.length) {
|
|
212
|
+
index = Math.floor((index - 1) / this.style.chartColors.length)
|
|
213
|
+
}
|
|
214
|
+
return this.style.chartColors[index];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 绘制当前图表
|
|
219
|
+
* 先绘制轴等基础信息
|
|
220
|
+
*
|
|
221
|
+
* @method beginDraw
|
|
222
|
+
*/
|
|
223
|
+
beginDraw() {
|
|
224
|
+
//const startTime = Date.now();
|
|
225
|
+
//重置图例
|
|
226
|
+
this.legend && this.legend.init();
|
|
227
|
+
|
|
228
|
+
//先定位图例等信息,确定画图区域
|
|
229
|
+
this.resetAreaPosition();
|
|
230
|
+
|
|
231
|
+
if(this.xAxis) {
|
|
232
|
+
this.xAxis.clear();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
//计算Y轴位置
|
|
236
|
+
if(this.yAxises) {
|
|
237
|
+
for(let i in this.yAxises) {
|
|
238
|
+
this.yAxises[i].clear();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//console.log('beginDraw1', Date.now() - startTime);
|
|
243
|
+
|
|
244
|
+
//计算柱形图个数
|
|
245
|
+
this.barSeriesCount = 0;
|
|
246
|
+
//初始化图序列,并初始化轴值,生成图例项
|
|
247
|
+
this.series.each(function(i, serie) {
|
|
248
|
+
//设定边框颜色和数据项图示颜 色
|
|
249
|
+
if(!serie.style.color) serie.style.color = serie.graph.getColor(i);
|
|
250
|
+
//如果排版指定非内缩的方式,但出现了柱图,还是会采用内缩一个刻度的方式
|
|
251
|
+
if(serie.graph.style.layout != 'inside') {
|
|
252
|
+
if(serie instanceof jmBarSeries) {
|
|
253
|
+
serie.graph.style.layout = 'inside';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//对柱图计算,并标记为第几个柱图,用为排列
|
|
258
|
+
if(serie instanceof jmBarSeries) {
|
|
259
|
+
serie.barIndex = serie.graph.barSeriesCount;
|
|
260
|
+
serie.graph.barSeriesCount ++;
|
|
261
|
+
}
|
|
262
|
+
serie.reset();
|
|
263
|
+
});
|
|
264
|
+
//console.log('beginDraw2', Date.now() - startTime);
|
|
265
|
+
//重置图例
|
|
266
|
+
this.legend && this.legend.reset();
|
|
267
|
+
|
|
268
|
+
//计算Y轴位置
|
|
269
|
+
if(this.yAxises) {
|
|
270
|
+
for(var i in this.yAxises) {
|
|
271
|
+
this.yAxises[i].reset();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// y 处理完才能处理x
|
|
275
|
+
if(this.xAxis) {
|
|
276
|
+
this.xAxis.reset();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//console.log('beginDraw3', Date.now() - startTime);
|
|
280
|
+
//最后再来初始化图形,这个必须在轴初始化完后才能执行
|
|
281
|
+
this.series.each(function(i, serie) {
|
|
282
|
+
serie.init && serie.init();
|
|
283
|
+
});
|
|
284
|
+
//console.log('beginDraw4', Date.now() - startTime);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 重新定位区域的位置
|
|
289
|
+
*
|
|
290
|
+
* @method resetAreaPosition
|
|
291
|
+
*/
|
|
292
|
+
resetAreaPosition() {
|
|
293
|
+
this.chartArea.position.x = (this.style.margin.left || 0) * this.graph.devicePixelRatio;
|
|
294
|
+
this.chartArea.position.y = (this.style.margin.top || 0) * this.graph.devicePixelRatio;
|
|
295
|
+
const w = this.width - (this.style.margin.right * this.graph.devicePixelRatio) - this.chartArea.position.x;
|
|
296
|
+
const h = this.height - (this.style.margin.bottom * this.graph.devicePixelRatio) - this.chartArea.position.y;
|
|
297
|
+
|
|
298
|
+
this.chartArea.width = w;
|
|
299
|
+
this.chartArea.height = h;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 创建轴
|
|
304
|
+
*
|
|
305
|
+
* @method createAxis
|
|
306
|
+
* @for jmChart
|
|
307
|
+
* @param {string} [type] 轴类型(x/y/radar),默认为x
|
|
308
|
+
* @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
|
|
309
|
+
* @param {object} [style] 样式
|
|
310
|
+
* @return {axis} 轴
|
|
311
|
+
*/
|
|
312
|
+
createAxis(options) {
|
|
313
|
+
// 深度组件默认样式
|
|
314
|
+
options.style = options.style? this.utils.clone(this.style.axis, options.style, true) : this.style.axis;
|
|
315
|
+
|
|
316
|
+
const axis = this.createShape(jmAxis, options);
|
|
317
|
+
if(typeof options.visible !== 'undefined') axis.visible = options.visible;
|
|
318
|
+
this.children.add(axis);
|
|
319
|
+
return axis;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* 生成X轴
|
|
324
|
+
*
|
|
325
|
+
* @method createXAxis
|
|
326
|
+
* @param {string} x轴的数据类型(string/number/date)
|
|
327
|
+
* @param {bool} 是否从0开始
|
|
328
|
+
*/
|
|
329
|
+
createXAxis(options) {
|
|
330
|
+
if(!this.xAxis) {
|
|
331
|
+
options = Object.assign({
|
|
332
|
+
field: this.xField,
|
|
333
|
+
type: 'x',
|
|
334
|
+
visible: this.style.axis.x === false? false: true,
|
|
335
|
+
format: this.option.xLabelFormat,
|
|
336
|
+
...this.option.yAxisOption
|
|
337
|
+
}, options || {});
|
|
338
|
+
|
|
339
|
+
if(typeof this.option.minXValue !== 'undefined') {
|
|
340
|
+
options.minXValue = typeof options.minXValue === 'undefined'?this.option.minXValue:Math.min(this.option.minXValue, options.minXValue);
|
|
341
|
+
}
|
|
342
|
+
if(typeof this.option.maxXValue !== 'undefined') {
|
|
343
|
+
options.maxXValue = typeof options.maxXValue === 'undefined'?this.option.maxXValue:Math.max(this.option.maxXValue, options.maxXValue);
|
|
344
|
+
}
|
|
345
|
+
this.xAxis = this.createAxis(options);
|
|
346
|
+
}
|
|
347
|
+
return this.xAxis;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 生成Y轴
|
|
352
|
+
*
|
|
353
|
+
* @method createYAxis
|
|
354
|
+
* @param {int} Y轴索引,可以创建多个Y轴
|
|
355
|
+
* @param {string} y轴的数据类型(string/number/date)
|
|
356
|
+
* @param {bool} 是否从0开始
|
|
357
|
+
*/
|
|
358
|
+
createYAxis(options) {
|
|
359
|
+
|
|
360
|
+
if(!this.yAxises) {
|
|
361
|
+
this.yAxises = {};
|
|
362
|
+
}
|
|
363
|
+
options = Object.assign({
|
|
364
|
+
index: 1,
|
|
365
|
+
type: 'y',
|
|
366
|
+
visible: this.style.axis.y === false? false: true,
|
|
367
|
+
format: this.option.yLabelFormat,
|
|
368
|
+
zeroBase: this.baseY === 0,
|
|
369
|
+
...this.option.xAxisOption,
|
|
370
|
+
}, options || {});
|
|
371
|
+
if(typeof this.option.minYValue !== 'undefined') {
|
|
372
|
+
options.minYValue = typeof options.minYValue === 'undefined'?this.option.minYValue:Math.min(this.option.minYValue, options.minYValue);
|
|
373
|
+
}
|
|
374
|
+
if(typeof this.option.maxYValue !== 'undefined') {
|
|
375
|
+
options.maxYValue = typeof options.maxYValue === 'undefined'?this.option.maxYValue:Math.max(this.option.maxYValue, options.maxYValue);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
|
|
379
|
+
return yaxis;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* 创建图形
|
|
384
|
+
*
|
|
385
|
+
* @method createSeries
|
|
386
|
+
* @for jmChart
|
|
387
|
+
* @param {string} [type] 图类型,(line/bar/pie/radar)
|
|
388
|
+
* @param {object} [options] 生成图表选项 {xField, yField, index}
|
|
389
|
+
* @return {series} 图形
|
|
390
|
+
*/
|
|
391
|
+
createSeries(type, options = {}) {
|
|
392
|
+
if(!this.serieTypes) {
|
|
393
|
+
this.serieTypes = {
|
|
394
|
+
'line' : jmLineSeries,
|
|
395
|
+
'bar' : jmBarSeries,
|
|
396
|
+
'stackBar' : jmStackBarSeries,
|
|
397
|
+
'pie' : jmPieSeries,
|
|
398
|
+
'stackLine' : jmStackLineSeries,
|
|
399
|
+
'candlestick': jmCandlestickSeries
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//默认样式为类型对应的样式
|
|
404
|
+
const style = this.style[type] || this.style['line'];
|
|
405
|
+
// 深度组件默认样式
|
|
406
|
+
options.style = this.utils.clone(style, options.style, true);
|
|
407
|
+
|
|
408
|
+
if(typeof type == 'string') type = this.serieTypes[type];
|
|
409
|
+
|
|
410
|
+
const serie = this.createShape(type, options);
|
|
411
|
+
if(serie) {
|
|
412
|
+
this.series.add(serie);
|
|
413
|
+
this.chartArea.children.add(serie);
|
|
414
|
+
}
|
|
415
|
+
return serie;
|
|
416
|
+
}
|
|
465
417
|
}
|