jmchart 1.2.10 → 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/lineSeries.js
CHANGED
|
@@ -1,243 +1,224 @@
|
|
|
1
|
-
|
|
2
|
-
import jmSeries from './series.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @method
|
|
27
|
-
* @for jmLineSeries
|
|
28
|
-
*/
|
|
29
|
-
init() {
|
|
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
|
-
if(
|
|
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
|
-
this.
|
|
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
|
-
this.
|
|
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
|
-
|
|
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
|
-
// 在点集合前后加上落地到X轴的点就可以组成一个封闭的图形area
|
|
226
|
-
if(needClosePoint) {
|
|
227
|
-
area.points.unshift({
|
|
228
|
-
x: start.x,
|
|
229
|
-
y: this.baseY
|
|
230
|
-
});
|
|
231
|
-
area.points.push({
|
|
232
|
-
x: end.x,
|
|
233
|
-
y: this.baseY
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
this.addShape(area);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export {
|
|
242
|
-
jmLineSeries
|
|
243
|
-
}
|
|
1
|
+
|
|
2
|
+
import jmSeries from './series.js';
|
|
3
|
+
|
|
4
|
+
const ANIMATION_DATA_THRESHOLD = 100;
|
|
5
|
+
const DEFAULT_ANIMATION_COUNT = 10;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 线图
|
|
9
|
+
*
|
|
10
|
+
* @class jmLineSeries
|
|
11
|
+
* @module jmChart
|
|
12
|
+
* @param {jmChart} chart 当前图表
|
|
13
|
+
* @param {array} mappings 图形字段映射
|
|
14
|
+
* @param {style} style 样式
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default class jmLineSeries extends jmSeries {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
options.style = options.style || options.graph.style.line;
|
|
20
|
+
super(options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 初始化线条
|
|
25
|
+
*
|
|
26
|
+
* @method init
|
|
27
|
+
* @for jmLineSeries
|
|
28
|
+
*/
|
|
29
|
+
init() {
|
|
30
|
+
const {
|
|
31
|
+
points,
|
|
32
|
+
dataChanged
|
|
33
|
+
} = this.initDataPoint();
|
|
34
|
+
|
|
35
|
+
const len = points.length;
|
|
36
|
+
if(!len) return;
|
|
37
|
+
|
|
38
|
+
this.style.stroke = this.style.color;
|
|
39
|
+
this.style.item.stroke = this.style.color;
|
|
40
|
+
|
|
41
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
42
|
+
|
|
43
|
+
let shapePoints = [];
|
|
44
|
+
const aniCount = (this.style.aniCount || DEFAULT_ANIMATION_COUNT);
|
|
45
|
+
const aniStep = Math.floor(len / aniCount) || 1;
|
|
46
|
+
|
|
47
|
+
for(let i = 0; i < len; i++) {
|
|
48
|
+
const p = points[i];
|
|
49
|
+
|
|
50
|
+
if(typeof p.y === 'undefined' || p.y === null) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if(isRunningAni && i > this.___animateCounter) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if(this.style.showItem) {
|
|
59
|
+
this.createPointItem(p);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if(this.style.curve) {
|
|
63
|
+
shapePoints = this.createCurePoints(shapePoints, p);
|
|
64
|
+
} else if(this.style.lineType === 'dotted') {
|
|
65
|
+
shapePoints = this.createDotLine(shapePoints, p);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
shapePoints.push(p);
|
|
69
|
+
|
|
70
|
+
this.createItemLabel(p);
|
|
71
|
+
|
|
72
|
+
this.emit('onPointCreated', p);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if(this.___animateCounter >= len - 1) {
|
|
76
|
+
this.___animateCounter = 0;
|
|
77
|
+
} else if(isRunningAni) {
|
|
78
|
+
this.___animateCounter += aniStep;
|
|
79
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
80
|
+
this.needUpdate = true;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.points = shapePoints;
|
|
85
|
+
this.createArea(shapePoints);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 生成点的小圆圈
|
|
89
|
+
createPointItem(p) {
|
|
90
|
+
const pointShape = this.graph.createShape('circle', {
|
|
91
|
+
style: this.style.item,
|
|
92
|
+
center: p,
|
|
93
|
+
radius: this.style.radius || 3
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
pointShape.zIndex = (pointShape.style.zIndex || 1) + 1;
|
|
97
|
+
return this.addShape(pointShape);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 根据上下点生成平滑曲线
|
|
101
|
+
createCurePoints(shapePoints, p) {
|
|
102
|
+
const startPoint = shapePoints[shapePoints.length - 1];
|
|
103
|
+
if(startPoint && startPoint.y != undefined && startPoint.y != null) {
|
|
104
|
+
//如果需要画曲线,则计算贝塞尔曲线坐标
|
|
105
|
+
const p1 = {x: startPoint.x + (p.x - startPoint.x) / 5, y: startPoint.y};
|
|
106
|
+
const p2 = {x: startPoint.x + (p.x - startPoint.x) / 2, y: p.y - (p.y - startPoint.y) / 2};
|
|
107
|
+
const p3 = {x: p.x - (p.x - startPoint.x) / 5, y: p.y};
|
|
108
|
+
|
|
109
|
+
//圆滑线条使用的贝塞尔对象
|
|
110
|
+
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
111
|
+
this.__bezier.cpoints = [
|
|
112
|
+
startPoint,
|
|
113
|
+
p1,
|
|
114
|
+
p2,
|
|
115
|
+
p3,
|
|
116
|
+
p
|
|
117
|
+
];//设置控制点
|
|
118
|
+
|
|
119
|
+
const bzpoints = this.__bezier.initPoints();
|
|
120
|
+
shapePoints = shapePoints.concat(bzpoints);
|
|
121
|
+
}
|
|
122
|
+
return shapePoints;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 生成虚线
|
|
126
|
+
createDotLine(shapePoints, p) {
|
|
127
|
+
const startPoint = shapePoints[shapePoints.length - 1];
|
|
128
|
+
if(startPoint && startPoint.y != undefined && startPoint.y != null) {
|
|
129
|
+
//使用线条来画虚线效果
|
|
130
|
+
this.__line = this.__line || this.graph.createShape('line', {
|
|
131
|
+
style: this.style,
|
|
132
|
+
});
|
|
133
|
+
this.__line.start = startPoint;
|
|
134
|
+
this.__line.end = p;
|
|
135
|
+
|
|
136
|
+
const dots = this.__line.initPoints();
|
|
137
|
+
shapePoints = shapePoints.concat(dots);
|
|
138
|
+
}
|
|
139
|
+
return shapePoints;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 生成图例
|
|
144
|
+
*
|
|
145
|
+
* @method createLegend
|
|
146
|
+
*/
|
|
147
|
+
createLegend() {
|
|
148
|
+
|
|
149
|
+
//生成图例前的图标
|
|
150
|
+
var style = this.graph.utils.clone(this.style);
|
|
151
|
+
style.stroke = style.color;
|
|
152
|
+
var shape = this.graph.createShape('path',{style:style});
|
|
153
|
+
|
|
154
|
+
if(this.curve || this.style.curve) {
|
|
155
|
+
var p1 = {x:0,y: this.graph.style.legend.item.shape.height};
|
|
156
|
+
var p2 = {x:this.graph.style.legend.item.shape.width / 3,y:this.graph.style.legend.item.shape.height/3};
|
|
157
|
+
var p3 = {x:this.graph.style.legend.item.shape.width / 3 * 2,y:this.graph.style.legend.item.shape.height/3*2};
|
|
158
|
+
var p4 = {x:this.graph.style.legend.item.shape.width,y:0};
|
|
159
|
+
|
|
160
|
+
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
161
|
+
this.__bezier.cpoints = [
|
|
162
|
+
p1,p2,p3,p4
|
|
163
|
+
];//设置控制点
|
|
164
|
+
|
|
165
|
+
shape.points = this.__bezier.initPoints();
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
shape.points = [{
|
|
169
|
+
x:0,y: this.graph.style.legend.item.shape.height/2
|
|
170
|
+
},{
|
|
171
|
+
x: this.graph.style.legend.item.shape.width,y: this.graph.style.legend.item.shape.height/2
|
|
172
|
+
}];
|
|
173
|
+
}
|
|
174
|
+
this.graph.legend.append(this, shape);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 生成布效果
|
|
178
|
+
createArea(points, needClosePoint = true) {
|
|
179
|
+
// 有指定绘制区域效果才展示
|
|
180
|
+
if(!this.style.area || points.length < 2) return;
|
|
181
|
+
|
|
182
|
+
const start = points[0];
|
|
183
|
+
const end = points[points.length - 1];
|
|
184
|
+
|
|
185
|
+
const style = this.graph.utils.clone(this.style.area, {}, true);
|
|
186
|
+
// 连框颜色如果没指定,就透明
|
|
187
|
+
style.stroke = style.stroke || 'transparent';
|
|
188
|
+
|
|
189
|
+
if(!style.fill) {
|
|
190
|
+
const color = this.graph.utils.hexToRGBA(this.style.stroke);
|
|
191
|
+
style.fill = `linear-gradient(50% 0 50% 100%,
|
|
192
|
+
rgba(${color.r},${color.g},${color.b}, 0) 1,
|
|
193
|
+
rgba(${color.r},${color.g},${color.b}, 0.1) 0.7,
|
|
194
|
+
rgba(${color.r},${color.g},${color.b}, 0.3) 0)`;
|
|
195
|
+
}
|
|
196
|
+
else if(typeof style.fill === 'function') {
|
|
197
|
+
style.fill = style.fill.call(this, style);
|
|
198
|
+
}
|
|
199
|
+
const area = this.graph.createShape('path', {
|
|
200
|
+
points: this.graph.utils.clone(points, true),
|
|
201
|
+
style,
|
|
202
|
+
width: this.graph.chartArea.width,
|
|
203
|
+
height: this.graph.chartArea.height
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// 在点集合前后加上落地到X轴的点就可以组成一个封闭的图形area
|
|
207
|
+
if(needClosePoint) {
|
|
208
|
+
area.points.unshift({
|
|
209
|
+
x: start.x,
|
|
210
|
+
y: this.baseY
|
|
211
|
+
});
|
|
212
|
+
area.points.push({
|
|
213
|
+
x: end.x,
|
|
214
|
+
y: this.baseY
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.addShape(area);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
jmLineSeries
|
|
224
|
+
}
|