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/series/barSeries.js
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import jmSeries from './series.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 柱图
|
|
6
|
-
*
|
|
7
|
-
* @class jmBarSeries
|
|
8
|
-
* @module jmChart
|
|
9
|
-
* @param {jmChart} chart 当前图表
|
|
10
|
-
* @param {array} mappings 图形字段映射
|
|
11
|
-
* @param {style} style 样式
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
//构造函数
|
|
15
|
-
export default class jmBarSeries extends jmSeries {
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super(options);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 绘制当前图形
|
|
21
|
-
*
|
|
22
|
-
* @method beginDraw
|
|
23
|
-
* @for jmBarSeries
|
|
24
|
-
*/
|
|
25
|
-
init() {
|
|
26
|
-
//生成描点位
|
|
27
|
-
const {points, dataChanged} = this.initDataPoint();
|
|
28
|
-
|
|
29
|
-
const len = points.length;
|
|
30
|
-
this.initWidth(len);
|
|
31
|
-
|
|
32
|
-
// 是否正在动画中
|
|
33
|
-
// 如果数据点多于100 个,暂时不启用动画,太慢了
|
|
34
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 ) && len < 100;
|
|
35
|
-
let aniIsEnd = true;// 当次是否结束动画
|
|
36
|
-
const aniCount = (this.style.aniCount || 10);
|
|
37
|
-
|
|
38
|
-
for(let i=0; i<len; i++) {
|
|
39
|
-
//const label = this.xAxis.labels[i];
|
|
40
|
-
const point = points[i];
|
|
41
|
-
|
|
42
|
-
//如果当前点无效,则跳致下一点
|
|
43
|
-
if(typeof point.y === 'undefined' || point.y === null) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
point.style.fill = this.getColor(point);
|
|
48
|
-
const sp = this.addShape(this.graph.createPath(null, point.style));
|
|
49
|
-
|
|
50
|
-
//绑定提示框
|
|
51
|
-
//this.bindTooltip(sp, point);
|
|
52
|
-
|
|
53
|
-
//首先确定p1和p4,因为他们是底脚。会固定
|
|
54
|
-
const p1 = {x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex, y: this.baseY };
|
|
55
|
-
const p4 = {x: p1.x + this.barWidth, y: p1.y };
|
|
56
|
-
|
|
57
|
-
const p2 = {x: p1.x, y: p1.y };
|
|
58
|
-
const p3 = {x: p4.x, y: p1.y };
|
|
59
|
-
|
|
60
|
-
// 如果要动画。则动态改变高度
|
|
61
|
-
if(isRunningAni) {
|
|
62
|
-
const step = point.height / aniCount;
|
|
63
|
-
const offHeight = step * this.___animateCounter;// 动态计算当前高度
|
|
64
|
-
p2.y = p1.y - offHeight;// 计算高度
|
|
65
|
-
|
|
66
|
-
// 当次动画完成
|
|
67
|
-
if((step >= 0 && p2.y <= point.y) || (step < 0 && p2.y >= point.y)) {
|
|
68
|
-
p2.y = point.y;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
aniIsEnd = false;// 只要有一个没完成,就还没有完成动画
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
p3.y = p2.y;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
p2.y = point.y;
|
|
78
|
-
p3.y = point.y;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
sp.points.push(p1);
|
|
82
|
-
sp.points.push(p2);
|
|
83
|
-
sp.points.push(p3);
|
|
84
|
-
sp.points.push(p4);
|
|
85
|
-
|
|
86
|
-
this.createItemLabel(point);
|
|
87
|
-
|
|
88
|
-
// 生成标点的回调
|
|
89
|
-
this.emit('onPointCreated', point);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if(aniIsEnd) {
|
|
93
|
-
this.___animateCounter = 0;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.___animateCounter++;
|
|
97
|
-
// next tick 再次刷新
|
|
98
|
-
setTimeout(()=>{
|
|
99
|
-
this.needUpdate = true;//需要刷新
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 计算柱子宽度
|
|
105
|
-
initWidth(count) {
|
|
106
|
-
|
|
107
|
-
//计算每个柱子占宽
|
|
108
|
-
//每项柱子占宽除以柱子个数,默认最大宽度为30
|
|
109
|
-
const maxWidth = this.xAxis.width / count / this.graph.barSeriesCount;
|
|
110
|
-
|
|
111
|
-
if(this.style.barWidth > 0) {
|
|
112
|
-
this.barWidth = Number(this.style.barWidth);
|
|
113
|
-
this.barTotalWidth = this.barWidth * this.graph.barSeriesCount;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
this.barTotalWidth = (this.xAxis.width / count * (this.style.perWidth||0.4));
|
|
117
|
-
this.barWidth = this.barTotalWidth / this.graph.barSeriesCount;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if(this.barWidth > maxWidth) {
|
|
121
|
-
this.barWidth = maxWidth;
|
|
122
|
-
this.barTotalWidth = maxWidth * this.graph.barSeriesCount;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 在图上加下定制图形
|
|
129
|
-
* @param {jmShape} shape 图形
|
|
130
|
-
*/
|
|
131
|
-
addShape(shape) {
|
|
132
|
-
this.children.add(shape);
|
|
133
|
-
this.shapes.add(shape);
|
|
134
|
-
return shape;
|
|
135
|
-
}
|
|
1
|
+
import jmSeries from './series.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 柱图
|
|
6
|
+
*
|
|
7
|
+
* @class jmBarSeries
|
|
8
|
+
* @module jmChart
|
|
9
|
+
* @param {jmChart} chart 当前图表
|
|
10
|
+
* @param {array} mappings 图形字段映射
|
|
11
|
+
* @param {style} style 样式
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
//构造函数
|
|
15
|
+
export default class jmBarSeries extends jmSeries {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 绘制当前图形
|
|
21
|
+
*
|
|
22
|
+
* @method beginDraw
|
|
23
|
+
* @for jmBarSeries
|
|
24
|
+
*/
|
|
25
|
+
init() {
|
|
26
|
+
//生成描点位
|
|
27
|
+
const {points, dataChanged} = this.initDataPoint();
|
|
28
|
+
|
|
29
|
+
const len = points.length;
|
|
30
|
+
this.initWidth(len);
|
|
31
|
+
|
|
32
|
+
// 是否正在动画中
|
|
33
|
+
// 如果数据点多于100 个,暂时不启用动画,太慢了
|
|
34
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 ) && len < 100;
|
|
35
|
+
let aniIsEnd = true;// 当次是否结束动画
|
|
36
|
+
const aniCount = (this.style.aniCount || 10);
|
|
37
|
+
|
|
38
|
+
for(let i=0; i<len; i++) {
|
|
39
|
+
//const label = this.xAxis.labels[i];
|
|
40
|
+
const point = points[i];
|
|
41
|
+
|
|
42
|
+
//如果当前点无效,则跳致下一点
|
|
43
|
+
if(typeof point.y === 'undefined' || point.y === null) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
point.style.fill = this.getColor(point);
|
|
48
|
+
const sp = this.addShape(this.graph.createPath(null, point.style));
|
|
49
|
+
|
|
50
|
+
//绑定提示框
|
|
51
|
+
//this.bindTooltip(sp, point);
|
|
52
|
+
|
|
53
|
+
//首先确定p1和p4,因为他们是底脚。会固定
|
|
54
|
+
const p1 = {x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex, y: this.baseY };
|
|
55
|
+
const p4 = {x: p1.x + this.barWidth, y: p1.y };
|
|
56
|
+
|
|
57
|
+
const p2 = {x: p1.x, y: p1.y };
|
|
58
|
+
const p3 = {x: p4.x, y: p1.y };
|
|
59
|
+
|
|
60
|
+
// 如果要动画。则动态改变高度
|
|
61
|
+
if(isRunningAni) {
|
|
62
|
+
const step = point.height / aniCount;
|
|
63
|
+
const offHeight = step * this.___animateCounter;// 动态计算当前高度
|
|
64
|
+
p2.y = p1.y - offHeight;// 计算高度
|
|
65
|
+
|
|
66
|
+
// 当次动画完成
|
|
67
|
+
if((step >= 0 && p2.y <= point.y) || (step < 0 && p2.y >= point.y)) {
|
|
68
|
+
p2.y = point.y;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
aniIsEnd = false;// 只要有一个没完成,就还没有完成动画
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
p3.y = p2.y;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
p2.y = point.y;
|
|
78
|
+
p3.y = point.y;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
sp.points.push(p1);
|
|
82
|
+
sp.points.push(p2);
|
|
83
|
+
sp.points.push(p3);
|
|
84
|
+
sp.points.push(p4);
|
|
85
|
+
|
|
86
|
+
this.createItemLabel(point);
|
|
87
|
+
|
|
88
|
+
// 生成标点的回调
|
|
89
|
+
this.emit('onPointCreated', point);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if(aniIsEnd) {
|
|
93
|
+
this.___animateCounter = 0;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.___animateCounter++;
|
|
97
|
+
// next tick 再次刷新
|
|
98
|
+
setTimeout(()=>{
|
|
99
|
+
this.needUpdate = true;//需要刷新
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 计算柱子宽度
|
|
105
|
+
initWidth(count) {
|
|
106
|
+
|
|
107
|
+
//计算每个柱子占宽
|
|
108
|
+
//每项柱子占宽除以柱子个数,默认最大宽度为30
|
|
109
|
+
const maxWidth = this.xAxis.width / count / this.graph.barSeriesCount;
|
|
110
|
+
|
|
111
|
+
if(this.style.barWidth > 0) {
|
|
112
|
+
this.barWidth = Number(this.style.barWidth);
|
|
113
|
+
this.barTotalWidth = this.barWidth * this.graph.barSeriesCount;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.barTotalWidth = (this.xAxis.width / count * (this.style.perWidth||0.4));
|
|
117
|
+
this.barWidth = this.barTotalWidth / this.graph.barSeriesCount;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if(this.barWidth > maxWidth) {
|
|
121
|
+
this.barWidth = maxWidth;
|
|
122
|
+
this.barTotalWidth = maxWidth * this.graph.barSeriesCount;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 在图上加下定制图形
|
|
129
|
+
* @param {jmShape} shape 图形
|
|
130
|
+
*/
|
|
131
|
+
addShape(shape) {
|
|
132
|
+
this.children.add(shape);
|
|
133
|
+
this.shapes.add(shape);
|
|
134
|
+
return shape;
|
|
135
|
+
}
|
|
136
136
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
import jmSeries from './series.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* K线图
|
|
6
|
+
*
|
|
7
|
+
* @class jmCandlestickSeries
|
|
8
|
+
* @module jmChart
|
|
9
|
+
* @param {jmChart} chart 当前图表
|
|
10
|
+
* @param {array} mappings 图形字段映射
|
|
11
|
+
* @param {style} style 样式
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
//构造函数
|
|
15
|
+
export default class jmCandlestickSeries extends jmSeries {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
options.style = options.style || options.graph.style.line;
|
|
18
|
+
super(options);
|
|
19
|
+
|
|
20
|
+
//this.on('beginDraw', this[PreDrawKey]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 绘制图形前 初始化线条
|
|
25
|
+
*
|
|
26
|
+
* @method preDraw
|
|
27
|
+
* @for jmLineSeries
|
|
28
|
+
*/
|
|
29
|
+
init() {
|
|
30
|
+
//生成描点位
|
|
31
|
+
const {
|
|
32
|
+
points
|
|
33
|
+
} = this.initDataPoint();
|
|
34
|
+
|
|
35
|
+
//去除多余的线条
|
|
36
|
+
//当数据源线条数比现有的少时,删除多余的线条
|
|
37
|
+
const len = points.length;
|
|
38
|
+
this.initWidth(len);
|
|
39
|
+
|
|
40
|
+
const w = this.barWidth / 2; //实心处宽度的一半
|
|
41
|
+
|
|
42
|
+
for(let i=0; i< len;i++) {
|
|
43
|
+
const p = points[i];
|
|
44
|
+
|
|
45
|
+
//如果当前点无效,则跳致下一点
|
|
46
|
+
if(typeof p.y === 'undefined' || p.y === null) {
|
|
47
|
+
//prePoint = null;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const sp = this.addShape(this.graph.createPath([], p.style));
|
|
52
|
+
|
|
53
|
+
const bl = {
|
|
54
|
+
x: p.x - w,
|
|
55
|
+
y: p.points[0].y
|
|
56
|
+
};
|
|
57
|
+
const br = {
|
|
58
|
+
x: p.x + w,
|
|
59
|
+
y: p.points[0].y
|
|
60
|
+
};
|
|
61
|
+
const tl = {
|
|
62
|
+
x: p.x - w,
|
|
63
|
+
y: p.points[1].y
|
|
64
|
+
};
|
|
65
|
+
const tr = {
|
|
66
|
+
x: p.x + w,
|
|
67
|
+
y: p.points[1].y
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// 默认认为是阳线
|
|
71
|
+
let tm = p.points[1];
|
|
72
|
+
let bm = p.points[0];
|
|
73
|
+
p.style.stroke = p.style.fill = p.style.masculineColor || 'red';
|
|
74
|
+
|
|
75
|
+
// 开盘大于收盘,则阴线
|
|
76
|
+
if(p.points[0].yValue > p.points[1].yValue) {
|
|
77
|
+
p.style.stroke = p.style.fill = p.style.negativeColor || 'green';
|
|
78
|
+
bl.y = br.y = p.points[1].y;
|
|
79
|
+
tl.y = tr.y = p.points[0].y;
|
|
80
|
+
|
|
81
|
+
tm = p.points[0];
|
|
82
|
+
bm = p.points[1];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sp.points.push(p.points[2], tm, tl, bl, bm, p.points[3], bm, br, tr, tm, p.points[2]);
|
|
86
|
+
|
|
87
|
+
// 生成关健值标注
|
|
88
|
+
this.emit('onPointCreated', p);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 计算实心体宽度
|
|
93
|
+
initWidth(count) {
|
|
94
|
+
//计算每个柱子占宽
|
|
95
|
+
//每项柱子占宽除以柱子个数,默认最大宽度为30
|
|
96
|
+
const maxWidth = this.xAxis.width / count;
|
|
97
|
+
|
|
98
|
+
if(this.style.barWidth > 0) {
|
|
99
|
+
this.barWidth = Number(this.style.barWidth);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.barWidth = maxWidth * (this.style.perWidth||0.4);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if(this.barWidth > maxWidth) {
|
|
106
|
+
this.barWidth = maxWidth;
|
|
107
|
+
this.barTotalWidth = maxWidth * count;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export {
|
|
113
|
+
jmCandlestickSeries
|
|
114
|
+
}
|