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
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import { jmList, jmLine } from 'jmgraph';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 轴
|
|
5
|
-
*
|
|
6
|
-
* @class jmAxis
|
|
7
|
-
* @module jmChart
|
|
8
|
-
* @param {jmChart} chart 当前图表
|
|
9
|
-
* @param {string} [type] 轴类型(x/y/radar),默认为x
|
|
10
|
-
* @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
|
|
11
|
-
* @param {object} [style] 样式
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default class jmMarkLine extends jmLine {
|
|
15
|
-
constructor(options) {
|
|
16
|
-
|
|
17
|
-
super(options);
|
|
18
|
-
|
|
19
|
-
this.visible = false;
|
|
20
|
-
|
|
21
|
-
this.markLineType = options.type || 'x';// 为横轴x或纵轴y
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 当前图形下的所有子图
|
|
25
|
-
*/
|
|
26
|
-
this.shapes = new jmList();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 初始化轴
|
|
30
|
-
init() {
|
|
31
|
-
if(!this.visible) return;
|
|
32
|
-
|
|
33
|
-
// 纵标线,中间标小圆圈
|
|
34
|
-
if(this.markLineType === 'y') {
|
|
35
|
-
// 重置所有图形
|
|
36
|
-
let shape;
|
|
37
|
-
while(shape = this.shapes.shift()) {
|
|
38
|
-
shape && shape.remove();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.changeTouchPoint();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 滑动点改变事件
|
|
46
|
-
changeTouchPoint() {
|
|
47
|
-
// 纵标线,中间标小圆圈
|
|
48
|
-
if(this.markLineType === 'y') {
|
|
49
|
-
const touchPoints = []; // 命中的数据点
|
|
50
|
-
let touchChange = false;
|
|
51
|
-
// chartGraph 表示图表层,有可能当前graph为操作层
|
|
52
|
-
const graph = this.graph.chartGraph || this.graph;
|
|
53
|
-
const isTocuhGraph = graph !== this.graph;// 不在图表图层,在操作图层的情况
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
|
|
57
|
-
// 查找最近的X坐标
|
|
58
|
-
const findX = isTocuhGraph? (this.start.x - graph.chartArea.position.x) : this.start.x;
|
|
59
|
-
|
|
60
|
-
// 根据线条数生成标点个数
|
|
61
|
-
for(const serie of graph.series) {
|
|
62
|
-
// 得有数据描点的才展示圆
|
|
63
|
-
if(!serie.getDataPointByX) continue;
|
|
64
|
-
|
|
65
|
-
const point = serie.getDataPointByX(findX); // 找到最近的数据点
|
|
66
|
-
if(!point) continue;
|
|
67
|
-
|
|
68
|
-
// 锁定在有数据点的X轴上
|
|
69
|
-
// 如果在操作图层上, 点的X轴需要加上图表图层区域偏移量
|
|
70
|
-
this.start.x = this.end.x = isTocuhGraph? (point.x + graph.chartArea.position.x): point.x;
|
|
71
|
-
|
|
72
|
-
for(const p of point.points) {
|
|
73
|
-
if(!p || typeof p.y === 'undefined') continue;
|
|
74
|
-
this.markArc = graph.createShape('circle', {
|
|
75
|
-
style: this.style,
|
|
76
|
-
radius: (this.style.radius || 5)
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this.markArc.center.y = p.y;
|
|
80
|
-
|
|
81
|
-
this.children.add(this.markArc);
|
|
82
|
-
this.shapes.add(this.markArc);
|
|
83
|
-
}
|
|
84
|
-
// x轴改变,表示变换了位置
|
|
85
|
-
if(!touchChange && (!serie.lastMarkPoint || serie.lastMarkPoint.x != point.x)) touchChange = true;
|
|
86
|
-
|
|
87
|
-
touchPoints.push(point);
|
|
88
|
-
serie.lastMarkPoint = point;// 记下最后一次改变的点
|
|
89
|
-
|
|
90
|
-
// 同时改变下X轴标线的位置,它的Y坐标跟随最后一个命中的线点
|
|
91
|
-
if(graph && graph.markLine && graph.markLine.xMarkLine) {
|
|
92
|
-
graph.markLine.xMarkLine.start.y = graph.markLine.xMarkLine.end.y = isTocuhGraph? (point.y + graph.chartArea.position.y): point.y;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch(e) {
|
|
97
|
-
console.error(e);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 触发touch数据点改变事件
|
|
101
|
-
touchChange && this.graph.utils.requestAnimationFrame(()=>{
|
|
102
|
-
graph.emit('touchPointChange', {
|
|
103
|
-
points: touchPoints
|
|
104
|
-
});
|
|
105
|
-
}, 10);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 移动标线
|
|
111
|
-
* @param { object } args 移动事件参数
|
|
112
|
-
*/
|
|
113
|
-
move(args) {
|
|
114
|
-
// 事件是挂在graph下的,,但此轴是放在chartArea中的。所以事件判断用graph坐标,但是当前位置要相对于chartArea
|
|
115
|
-
|
|
116
|
-
if(this.visible && this.markLineType === 'x') {
|
|
117
|
-
// 有操作层的情况下,相对于左上角,否则是chartarea
|
|
118
|
-
if(this.graph.chartGraph) {
|
|
119
|
-
if(args.position.y <= this.graph.chartGraph.chartArea.position.y) {
|
|
120
|
-
this.start.y = this.end.y = this.graph.chartGraph.chartArea.position.y;
|
|
121
|
-
}
|
|
122
|
-
else if(args.position.y > this.graph.chartGraph.chartArea.height + this.graph.chartGraph.chartArea.position.y) {
|
|
123
|
-
this.start.y = this.end.y = this.graph.chartGraph.chartArea.height + this.graph.chartGraph.chartArea.position.y;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
this.start.y = this.end.y = args.position.y;
|
|
127
|
-
}
|
|
128
|
-
this.start.x = this.graph.chartGraph.chartArea.position.x;
|
|
129
|
-
this.end.x = this.start.x + this.graph.chartGraph.chartArea.width;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
if(args.position.y <= this.graph.chartArea.position.y) {
|
|
133
|
-
this.start.y = this.end.y = 0;
|
|
134
|
-
}
|
|
135
|
-
else if(args.position.y > this.graph.chartArea.height + this.graph.chartArea.position.y) {
|
|
136
|
-
this.start.y = this.end.y = this.graph.chartArea.height;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
this.start.y = this.end.y = args.position.y - this.graph.chartArea.position.y;
|
|
140
|
-
}
|
|
141
|
-
this.start.x = 0;
|
|
142
|
-
this.end.x = this.graph.chartArea.width;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.needUpdate = true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if(this.visible && this.markLineType === 'y') {
|
|
149
|
-
// 有操作层的情况下,相对于左上角,否则是chartarea
|
|
150
|
-
if(this.graph.chartGraph) {
|
|
151
|
-
if(args.position.x < this.graph.chartGraph.chartArea.position.x) {
|
|
152
|
-
this.start.x = this.end.x = this.graph.chartGraph.chartArea.position.x;
|
|
153
|
-
}
|
|
154
|
-
else if(args.position.x > this.graph.chartGraph.chartArea.width + this.graph.chartGraph.chartArea.position.x) {
|
|
155
|
-
this.start.x = this.end.x = this.graph.chartGraph.chartArea.width + this.graph.chartGraph.chartArea.position.x;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
this.start.x = this.end.x = args.position.x;
|
|
159
|
-
}
|
|
160
|
-
this.start.y = this.graph.chartGraph.chartArea.position.y;
|
|
161
|
-
this.end.y = this.start.y + this.graph.chartGraph.chartArea.height;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
if(args.position.x < this.graph.chartArea.position.x) {
|
|
165
|
-
this.start.x = this.end.x = 0;
|
|
166
|
-
}
|
|
167
|
-
else if(args.position.x > this.graph.chartArea.width + this.graph.chartArea.position.x) {
|
|
168
|
-
this.start.x = this.end.x = this.graph.chartArea.width;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
this.start.x = this.end.x = args.position.x - this.graph.chartArea.position.x;
|
|
172
|
-
}
|
|
173
|
-
this.start.y = 0;
|
|
174
|
-
this.end.y = this.graph.chartArea.height;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
this.needUpdate = true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 中止
|
|
183
|
-
*/
|
|
184
|
-
cancel() {
|
|
185
|
-
this.visible = false;
|
|
186
|
-
this.needUpdate = true;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
1
|
+
import { jmList, jmLine } from 'jmgraph';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 轴
|
|
5
|
+
*
|
|
6
|
+
* @class jmAxis
|
|
7
|
+
* @module jmChart
|
|
8
|
+
* @param {jmChart} chart 当前图表
|
|
9
|
+
* @param {string} [type] 轴类型(x/y/radar),默认为x
|
|
10
|
+
* @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
|
|
11
|
+
* @param {object} [style] 样式
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export default class jmMarkLine extends jmLine {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
|
|
17
|
+
super(options);
|
|
18
|
+
|
|
19
|
+
this.visible = false;
|
|
20
|
+
|
|
21
|
+
this.markLineType = options.type || 'x';// 为横轴x或纵轴y
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 当前图形下的所有子图
|
|
25
|
+
*/
|
|
26
|
+
this.shapes = new jmList();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 初始化轴
|
|
30
|
+
init() {
|
|
31
|
+
if(!this.visible) return;
|
|
32
|
+
|
|
33
|
+
// 纵标线,中间标小圆圈
|
|
34
|
+
if(this.markLineType === 'y') {
|
|
35
|
+
// 重置所有图形
|
|
36
|
+
let shape;
|
|
37
|
+
while(shape = this.shapes.shift()) {
|
|
38
|
+
shape && shape.remove();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.changeTouchPoint();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 滑动点改变事件
|
|
46
|
+
changeTouchPoint() {
|
|
47
|
+
// 纵标线,中间标小圆圈
|
|
48
|
+
if(this.markLineType === 'y') {
|
|
49
|
+
const touchPoints = []; // 命中的数据点
|
|
50
|
+
let touchChange = false;
|
|
51
|
+
// chartGraph 表示图表层,有可能当前graph为操作层
|
|
52
|
+
const graph = this.graph.chartGraph || this.graph;
|
|
53
|
+
const isTocuhGraph = graph !== this.graph;// 不在图表图层,在操作图层的情况
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
|
|
57
|
+
// 查找最近的X坐标
|
|
58
|
+
const findX = isTocuhGraph? (this.start.x - graph.chartArea.position.x) : this.start.x;
|
|
59
|
+
|
|
60
|
+
// 根据线条数生成标点个数
|
|
61
|
+
for(const serie of graph.series) {
|
|
62
|
+
// 得有数据描点的才展示圆
|
|
63
|
+
if(!serie.getDataPointByX) continue;
|
|
64
|
+
|
|
65
|
+
const point = serie.getDataPointByX(findX); // 找到最近的数据点
|
|
66
|
+
if(!point) continue;
|
|
67
|
+
|
|
68
|
+
// 锁定在有数据点的X轴上
|
|
69
|
+
// 如果在操作图层上, 点的X轴需要加上图表图层区域偏移量
|
|
70
|
+
this.start.x = this.end.x = isTocuhGraph? (point.x + graph.chartArea.position.x): point.x;
|
|
71
|
+
|
|
72
|
+
for(const p of point.points) {
|
|
73
|
+
if(!p || typeof p.y === 'undefined') continue;
|
|
74
|
+
this.markArc = graph.createShape('circle', {
|
|
75
|
+
style: this.style,
|
|
76
|
+
radius: (this.style.radius || 5)
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
this.markArc.center.y = p.y;
|
|
80
|
+
|
|
81
|
+
this.children.add(this.markArc);
|
|
82
|
+
this.shapes.add(this.markArc);
|
|
83
|
+
}
|
|
84
|
+
// x轴改变,表示变换了位置
|
|
85
|
+
if(!touchChange && (!serie.lastMarkPoint || serie.lastMarkPoint.x != point.x)) touchChange = true;
|
|
86
|
+
|
|
87
|
+
touchPoints.push(point);
|
|
88
|
+
serie.lastMarkPoint = point;// 记下最后一次改变的点
|
|
89
|
+
|
|
90
|
+
// 同时改变下X轴标线的位置,它的Y坐标跟随最后一个命中的线点
|
|
91
|
+
if(graph && graph.markLine && graph.markLine.xMarkLine) {
|
|
92
|
+
graph.markLine.xMarkLine.start.y = graph.markLine.xMarkLine.end.y = isTocuhGraph? (point.y + graph.chartArea.position.y): point.y;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch(e) {
|
|
97
|
+
console.error(e);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 触发touch数据点改变事件
|
|
101
|
+
touchChange && this.graph.utils.requestAnimationFrame(()=>{
|
|
102
|
+
graph.emit('touchPointChange', {
|
|
103
|
+
points: touchPoints
|
|
104
|
+
});
|
|
105
|
+
}, 10);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 移动标线
|
|
111
|
+
* @param { object } args 移动事件参数
|
|
112
|
+
*/
|
|
113
|
+
move(args) {
|
|
114
|
+
// 事件是挂在graph下的,,但此轴是放在chartArea中的。所以事件判断用graph坐标,但是当前位置要相对于chartArea
|
|
115
|
+
|
|
116
|
+
if(this.visible && this.markLineType === 'x') {
|
|
117
|
+
// 有操作层的情况下,相对于左上角,否则是chartarea
|
|
118
|
+
if(this.graph.chartGraph) {
|
|
119
|
+
if(args.position.y <= this.graph.chartGraph.chartArea.position.y) {
|
|
120
|
+
this.start.y = this.end.y = this.graph.chartGraph.chartArea.position.y;
|
|
121
|
+
}
|
|
122
|
+
else if(args.position.y > this.graph.chartGraph.chartArea.height + this.graph.chartGraph.chartArea.position.y) {
|
|
123
|
+
this.start.y = this.end.y = this.graph.chartGraph.chartArea.height + this.graph.chartGraph.chartArea.position.y;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.start.y = this.end.y = args.position.y;
|
|
127
|
+
}
|
|
128
|
+
this.start.x = this.graph.chartGraph.chartArea.position.x;
|
|
129
|
+
this.end.x = this.start.x + this.graph.chartGraph.chartArea.width;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if(args.position.y <= this.graph.chartArea.position.y) {
|
|
133
|
+
this.start.y = this.end.y = 0;
|
|
134
|
+
}
|
|
135
|
+
else if(args.position.y > this.graph.chartArea.height + this.graph.chartArea.position.y) {
|
|
136
|
+
this.start.y = this.end.y = this.graph.chartArea.height;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.start.y = this.end.y = args.position.y - this.graph.chartArea.position.y;
|
|
140
|
+
}
|
|
141
|
+
this.start.x = 0;
|
|
142
|
+
this.end.x = this.graph.chartArea.width;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.needUpdate = true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if(this.visible && this.markLineType === 'y') {
|
|
149
|
+
// 有操作层的情况下,相对于左上角,否则是chartarea
|
|
150
|
+
if(this.graph.chartGraph) {
|
|
151
|
+
if(args.position.x < this.graph.chartGraph.chartArea.position.x) {
|
|
152
|
+
this.start.x = this.end.x = this.graph.chartGraph.chartArea.position.x;
|
|
153
|
+
}
|
|
154
|
+
else if(args.position.x > this.graph.chartGraph.chartArea.width + this.graph.chartGraph.chartArea.position.x) {
|
|
155
|
+
this.start.x = this.end.x = this.graph.chartGraph.chartArea.width + this.graph.chartGraph.chartArea.position.x;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.start.x = this.end.x = args.position.x;
|
|
159
|
+
}
|
|
160
|
+
this.start.y = this.graph.chartGraph.chartArea.position.y;
|
|
161
|
+
this.end.y = this.start.y + this.graph.chartGraph.chartArea.height;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
if(args.position.x < this.graph.chartArea.position.x) {
|
|
165
|
+
this.start.x = this.end.x = 0;
|
|
166
|
+
}
|
|
167
|
+
else if(args.position.x > this.graph.chartArea.width + this.graph.chartArea.position.x) {
|
|
168
|
+
this.start.x = this.end.x = this.graph.chartArea.width;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.start.x = this.end.x = args.position.x - this.graph.chartArea.position.x;
|
|
172
|
+
}
|
|
173
|
+
this.start.y = 0;
|
|
174
|
+
this.end.y = this.graph.chartArea.height;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.needUpdate = true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 中止
|
|
183
|
+
*/
|
|
184
|
+
cancel() {
|
|
185
|
+
this.visible = false;
|
|
186
|
+
this.needUpdate = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|