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.
@@ -1,136 +1,124 @@
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
- this.graph.utils.requestAnimationFrame(()=>{
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
+ const ANIMATION_DATA_THRESHOLD = 100;
4
+ const DEFAULT_ANIMATION_COUNT = 10;
5
+
6
+ /**
7
+ * 柱图
8
+ *
9
+ * @class jmBarSeries
10
+ * @module jmChart
11
+ * @param {jmChart} chart 当前图表
12
+ * @param {array} mappings 图形字段映射
13
+ * @param {style} style 样式
14
+ */
15
+
16
+ export default class jmBarSeries extends jmSeries {
17
+ constructor(options) {
18
+ super(options);
19
+ }
20
+
21
+ /**
22
+ * 初始化柱图
23
+ *
24
+ * @method init
25
+ * @for jmBarSeries
26
+ */
27
+ init() {
28
+ const {points, dataChanged} = this.initDataPoint();
29
+
30
+ const len = points.length;
31
+ if(!len) return;
32
+
33
+ this.initWidth(len);
34
+
35
+ const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
36
+ let aniIsEnd = true;
37
+ const aniCount = (this.style.aniCount || DEFAULT_ANIMATION_COUNT);
38
+
39
+ for(let i = 0; i < len; i++) {
40
+ const point = points[i];
41
+
42
+ if(typeof point.y === 'undefined' || point.y === null) {
43
+ continue;
44
+ }
45
+
46
+ point.style.fill = this.getColor(point);
47
+ const sp = this.addShape(this.graph.createPath(null, point.style));
48
+
49
+ const p1 = {x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex, y: this.baseY };
50
+ const p4 = {x: p1.x + this.barWidth, y: p1.y };
51
+
52
+ const p2 = {x: p1.x, y: p1.y };
53
+ const p3 = {x: p4.x, y: p1.y };
54
+
55
+ if(isRunningAni) {
56
+ const step = point.height / aniCount;
57
+ const offHeight = step * this.___animateCounter;
58
+ p2.y = p1.y - offHeight;
59
+
60
+ if((step >= 0 && p2.y <= point.y) || (step < 0 && p2.y >= point.y)) {
61
+ p2.y = point.y;
62
+ } else {
63
+ aniIsEnd = false;
64
+ }
65
+
66
+ p3.y = p2.y;
67
+ } else {
68
+ p2.y = point.y;
69
+ p3.y = point.y;
70
+ }
71
+
72
+ sp.points.push(p1);
73
+ sp.points.push(p2);
74
+ sp.points.push(p3);
75
+ sp.points.push(p4);
76
+
77
+ this.createItemLabel(point);
78
+
79
+ this.emit('onPointCreated', point);
80
+ }
81
+
82
+ if(aniIsEnd) {
83
+ this.___animateCounter = 0;
84
+ } else {
85
+ this.___animateCounter++;
86
+ this.graph.utils.requestAnimationFrame(() => {
87
+ this.needUpdate = true;
88
+ });
89
+ }
90
+ }
91
+
92
+ // 计算柱子宽度
93
+ initWidth(count) {
94
+
95
+ //计算每个柱子占宽
96
+ //每项柱子占宽除以柱子个数,默认最大宽度为30
97
+ const maxWidth = this.xAxis.width / count / this.graph.barSeriesCount;
98
+
99
+ if(this.style.barWidth > 0) {
100
+ this.barWidth = Number(this.style.barWidth);
101
+ this.barTotalWidth = this.barWidth * this.graph.barSeriesCount;
102
+ }
103
+ else {
104
+ this.barTotalWidth = (this.xAxis.width / count * (this.style.perWidth||0.4));
105
+ this.barWidth = this.barTotalWidth / this.graph.barSeriesCount;
106
+ }
107
+
108
+ if(this.barWidth > maxWidth) {
109
+ this.barWidth = maxWidth;
110
+ this.barTotalWidth = maxWidth * this.graph.barSeriesCount;
111
+ }
112
+ }
113
+
114
+
115
+ /**
116
+ * 在图上加下定制图形
117
+ * @param {jmShape} shape 图形
118
+ */
119
+ addShape(shape) {
120
+ this.children.add(shape);
121
+ this.shapes.add(shape);
122
+ return shape;
123
+ }
136
124
  }
@@ -1,114 +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
- }
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
+ }