jmchart 1.2.10 → 1.2.12

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,150 +1,150 @@
1
- import jmBarSeries from './barSeries.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 jmStackBarSeries extends jmBarSeries {
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
-
31
- this.initWidth(len);
32
-
33
- // 是否正在动画中
34
- // 如果数据点多于100 个,暂时不启用动画,太慢了
35
- const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 ) && len < 100;
36
- let aniIsEnd = true;// 当次是否结束动画
37
- const aniCount = (this.style.aniCount || 10);
38
-
39
- for(let i=0; i<len; i++) {
40
- const point = points[i];
41
-
42
- let topStartY = this.baseY;
43
- let bottomStartY = this.baseY;
44
- for(let index=0; index < point.points.length; index ++) {
45
- const style = this.graph.utils.clone(this.style);
46
- const p = point.points[index];
47
-
48
- if(style.color && typeof style.color === 'function') {
49
- style.fill = style.color.call(this, {
50
- index,
51
- point: p
52
- });
53
- }
54
- else {
55
- style.fill = this.graph.getColor(index);
56
- }
57
- const sp = this.addShape(this.graph.createPath(null, style));
58
-
59
- let startY = topStartY;
60
- if(p.yValue < this.baseYValue) startY = bottomStartY;
61
-
62
- //首先确定p1和p4,因为他们是底脚。会固定
63
- const p1 = {x: p.x - this.barTotalWidth / 2, y: startY };
64
- const p4 = {x: p1.x + this.barWidth, y: p1.y };
65
-
66
- const p2 = {x: p1.x, y: p1.y };
67
- const p3 = {x: p4.x, y: p1.y };
68
-
69
- // 如果要动画。则动态改变高度
70
- if(isRunningAni) {
71
- const step = p.height / aniCount;
72
- const offHeight = step * this.___animateCounter;// 动态计算当前高度
73
- p2.y = startY - offHeight;// 计算高度
74
-
75
- // 当次动画完成
76
- if((step >= 0 && offHeight >= p.height) || (step < 0 && offHeight <= p.height)) {
77
- p2.y = startY - p.height;
78
- }
79
- else {
80
- aniIsEnd = false;// 只要有一个没完成,就还没有完成动画
81
- }
82
-
83
- p.y = p3.y = p2.y;
84
- }
85
- else {
86
- p2.y = startY - p.height;
87
- p.y = p3.y = p2.y;
88
- }
89
-
90
- if(p.yValue < this.baseYValue) bottomStartY = p2.y;// 下一个又从它顶部开始画
91
- else topStartY = p2.y;
92
-
93
- sp.points.push(p1);
94
- sp.points.push(p2);
95
- sp.points.push(p3);
96
- sp.points.push(p4);
97
- }
98
-
99
- // 生成标点的回调
100
- this.emit('onPointCreated', point);
101
- }
102
-
103
- if(aniIsEnd) {
104
- this.___animateCounter = 0;
105
- }
106
- else {
107
- this.___animateCounter++;
108
- // next tick 再次刷新
109
- this.graph.utils.requestAnimationFrame(()=>{
110
- this.needUpdate = true;//需要刷新
111
- });
112
- }
113
- }
114
-
115
- // 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
116
- initAxisValue() {
117
- // 计算最大最小值
118
- // 当前需要先更新axis的边界值,轴好画图
119
- const fields = Array.isArray(this.field)? this.field: [this.field];
120
-
121
- for(const row of this.data) {
122
- let max, min;
123
- for(let i=0; i<fields.length; i++) {
124
- const f = fields[i];
125
- const v = Number(row[f]);
126
- if(typeof max === 'undefined') max = v;
127
- else {
128
- if(v < 0 || max < 0) max = Math.max(max, v);
129
- else {
130
- max += v;
131
- }
132
- }
133
-
134
- if(typeof min === 'undefined') min = v;
135
- else {
136
- if(v >= 0 || min >= 0) min = Math.min(min, v);
137
- else {
138
- min += v;
139
- }
140
- }
141
- }
142
- this.yAxis.max(max);
143
- this.yAxis.min(min);
144
-
145
- const xv = row[this.xAxis.field];
146
- this.xAxis.max(xv);
147
- this.xAxis.min(xv);
148
- }
149
- }
1
+ import jmBarSeries from './barSeries.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 jmStackBarSeries extends jmBarSeries {
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
+
31
+ this.initWidth(len);
32
+
33
+ // 是否正在动画中
34
+ // 如果数据点多于100 个,暂时不启用动画,太慢了
35
+ const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 ) && len < 100;
36
+ let aniIsEnd = true;// 当次是否结束动画
37
+ const aniCount = (this.style.aniCount || 10);
38
+
39
+ for(let i=0; i<len; i++) {
40
+ const point = points[i];
41
+
42
+ let topStartY = this.baseY;
43
+ let bottomStartY = this.baseY;
44
+ for(let index=0; index < point.points.length; index ++) {
45
+ const style = this.graph.utils.clone(this.style);
46
+ const p = point.points[index];
47
+
48
+ if(style.color && typeof style.color === 'function') {
49
+ style.fill = style.color.call(this, {
50
+ index,
51
+ point: p
52
+ });
53
+ }
54
+ else {
55
+ style.fill = this.graph.getColor(index);
56
+ }
57
+ const sp = this.addShape(this.graph.createPath(null, style));
58
+
59
+ let startY = topStartY;
60
+ if(p.yValue < this.baseYValue) startY = bottomStartY;
61
+
62
+ //首先确定p1和p4,因为他们是底脚。会固定
63
+ const p1 = {x: p.x - this.barTotalWidth / 2, y: startY };
64
+ const p4 = {x: p1.x + this.barWidth, y: p1.y };
65
+
66
+ const p2 = {x: p1.x, y: p1.y };
67
+ const p3 = {x: p4.x, y: p1.y };
68
+
69
+ // 如果要动画。则动态改变高度
70
+ if(isRunningAni) {
71
+ const step = p.height / aniCount;
72
+ const offHeight = step * this.___animateCounter;// 动态计算当前高度
73
+ p2.y = startY - offHeight;// 计算高度
74
+
75
+ // 当次动画完成
76
+ if((step >= 0 && offHeight >= p.height) || (step < 0 && offHeight <= p.height)) {
77
+ p2.y = startY - p.height;
78
+ }
79
+ else {
80
+ aniIsEnd = false;// 只要有一个没完成,就还没有完成动画
81
+ }
82
+
83
+ p.y = p3.y = p2.y;
84
+ }
85
+ else {
86
+ p2.y = startY - p.height;
87
+ p.y = p3.y = p2.y;
88
+ }
89
+
90
+ if(p.yValue < this.baseYValue) bottomStartY = p2.y;// 下一个又从它顶部开始画
91
+ else topStartY = p2.y;
92
+
93
+ sp.points.push(p1);
94
+ sp.points.push(p2);
95
+ sp.points.push(p3);
96
+ sp.points.push(p4);
97
+ }
98
+
99
+ // 生成标点的回调
100
+ this.emit('onPointCreated', point);
101
+ }
102
+
103
+ if(aniIsEnd) {
104
+ this.___animateCounter = 0;
105
+ }
106
+ else {
107
+ this.___animateCounter++;
108
+ // next tick 再次刷新
109
+ this.graph.utils.requestAnimationFrame(()=>{
110
+ this.needUpdate = true;//需要刷新
111
+ });
112
+ }
113
+ }
114
+
115
+ // 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
116
+ initAxisValue() {
117
+ // 计算最大最小值
118
+ // 当前需要先更新axis的边界值,轴好画图
119
+ const fields = Array.isArray(this.field)? this.field: [this.field];
120
+
121
+ for(const row of this.data) {
122
+ let max, min;
123
+ for(let i=0; i<fields.length; i++) {
124
+ const f = fields[i];
125
+ const v = Number(row[f]);
126
+ if(typeof max === 'undefined') max = v;
127
+ else {
128
+ if(v < 0 || max < 0) max = Math.max(max, v);
129
+ else {
130
+ max += v;
131
+ }
132
+ }
133
+
134
+ if(typeof min === 'undefined') min = v;
135
+ else {
136
+ if(v >= 0 || min >= 0) min = Math.min(min, v);
137
+ else {
138
+ min += v;
139
+ }
140
+ }
141
+ }
142
+ this.yAxis.max(max);
143
+ this.yAxis.min(min);
144
+
145
+ const xv = row[this.xAxis.field];
146
+ this.xAxis.max(xv);
147
+ this.xAxis.min(xv);
148
+ }
149
+ }
150
150
  }
@@ -1,145 +1,145 @@
1
-
2
- import jmLineSeries from './lineSeries.js';
3
-
4
- /**
5
- * 二条线组成的区域图表
6
- *
7
- * @class jmStackLineSeries
8
- * @module jmChart
9
- * @param {jmChart} chart 当前图表
10
- * @param {array} mappings 图形字段映射
11
- * @param {style} style 样式
12
- */
13
-
14
- //构造函数
15
- export default class jmStackLineSeries extends jmLineSeries {
16
- constructor(options) {
17
- options.style = options.style || options.graph.style.stackLine;
18
- super(options);
19
- }
20
-
21
- /**
22
- * 绘制图形前 初始化线条
23
- *
24
- * @method preDraw
25
- * @for jmLineSeries
26
- */
27
- init() {
28
- //生成描点位
29
- const {
30
- points,
31
- dataChanged
32
- } = this.initDataPoint();
33
-
34
- //去除多余的线条
35
- //当数据源线条数比现有的少时,删除多余的线条
36
- const len = points.length;
37
-
38
- //设定其填充颜色
39
- //if(!this.style.fill) this.style.fill = jmUtils.toColor(this.style.stroke,null,null,20);
40
- this.style.stroke = this.style.color;
41
- //是否启用动画效果
42
- //var ani = typeof this.enableAnimate === 'undefined'? this.graph.enableAnimate: this.enableAnimate;
43
- this.style.item.stroke = this.style.color;
44
-
45
- // 是否正在动画中
46
- // 如果数据点多于100 个,暂时不启用动画,太慢了
47
- const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 );
48
-
49
- let startShapePoints = []; // 计算出来的曲线点集合
50
- let endShapePoints = []; // 计算出来的曲线点集合
51
- const aniCount = (this.style.aniCount || 10);
52
- const aniStep = Math.floor(len / aniCount) || 1;// 每次动画播放点个数
53
-
54
- for(let i=0; i< len;i++) {
55
- const p = points[i];
56
-
57
- if(isRunningAni) {
58
- if(i > this.___animateCounter) {
59
- break;
60
- }
61
- }
62
-
63
- // 是否显示数值点圆
64
- if(this.style.showItem) {
65
- this.createPointItem(p.points[0]);
66
- this.createPointItem(p.points[1]);
67
- }
68
- // 平滑曲线
69
- if(this.style.curve) {
70
- startShapePoints = this.createCurePoints(startShapePoints, p.points[0]);
71
- endShapePoints = this.createCurePoints(endShapePoints, p.points[1]);
72
- }
73
- // 如果是虚线
74
- else if(this.style.lineType === 'dotted') {
75
- startShapePoints = this.createDotLine(startShapePoints, p.points[0]);
76
- endShapePoints = this.createDotLine(endShapePoints, p.points[1]);
77
- }
78
-
79
- startShapePoints.push(p.points[0]);
80
- endShapePoints.push(p.points[1]);
81
-
82
-
83
- // 生成标点的回调
84
- this.emit('onPointCreated', p);
85
- }
86
-
87
- // 如果所有都已经结束,则重置成初始化状态
88
- if(this.___animateCounter >= len - 1) {
89
- this.___animateCounter = 0;
90
- }
91
- else if(isRunningAni) {
92
- this.___animateCounter += aniStep;
93
- // next tick 再次刷新
94
- this.graph.utils.requestAnimationFrame(()=>{
95
- this.needUpdate = true;//需要刷新
96
- });
97
- }
98
- if(endShapePoints.length) endShapePoints[0].m = true;// 第二条线重新开始画
99
- this.points = startShapePoints.concat(endShapePoints);
100
- // 仓建区域效果 这里的endShapePoints要倒过来画,才能形成一个封闭区域
101
- const areaPoints = startShapePoints.concat(endShapePoints.reverse());
102
- const areaEnd = areaPoints[areaPoints.length - 1] = this.graph.utils.clone(areaPoints[areaPoints.length - 1]);
103
- areaEnd.m = false;
104
- this.createArea(areaPoints, false);
105
- }
106
-
107
- /**
108
- * 生成图例
109
- *
110
- * @method createLegend
111
- */
112
- createLegend() {
113
-
114
- //生成图例前的图标
115
- var style = this.graph.utils.clone(this.style);
116
- style.stroke = style.color;
117
- var shape = this.graph.createShape('path',{style:style});
118
-
119
- if(this.curve || this.style.curve) {
120
- var p1 = {x:0,y: this.graph.style.legend.item.shape.height};
121
- var p2 = {x:this.graph.style.legend.item.shape.width / 3,y:this.graph.style.legend.item.shape.height/3};
122
- var p3 = {x:this.graph.style.legend.item.shape.width / 3 * 2,y:this.graph.style.legend.item.shape.height/3*2};
123
- var p4 = {x:this.graph.style.legend.item.shape.width,y:0};
124
-
125
- this.__bezier = this.__bezier || this.graph.createShape('bezier');
126
- this.__bezier.cpoints = [
127
- p1,p2,p3,p4
128
- ];//设置控制点
129
-
130
- shape.points = this.__bezier.initPoints();
131
- }
132
- else {
133
- shape.points = [{
134
- x:0,y: this.graph.style.legend.item.shape.height/2
135
- },{
136
- x: this.graph.style.legend.item.shape.width,y: this.graph.style.legend.item.shape.height/2
137
- }];
138
- }
139
- this.graph.legend.append(this, shape);
140
- }
141
- }
142
-
143
- export {
144
- jmStackLineSeries
145
- }
1
+
2
+ import jmLineSeries from './lineSeries.js';
3
+
4
+ /**
5
+ * 二条线组成的区域图表
6
+ *
7
+ * @class jmStackLineSeries
8
+ * @module jmChart
9
+ * @param {jmChart} chart 当前图表
10
+ * @param {array} mappings 图形字段映射
11
+ * @param {style} style 样式
12
+ */
13
+
14
+ //构造函数
15
+ export default class jmStackLineSeries extends jmLineSeries {
16
+ constructor(options) {
17
+ options.style = options.style || options.graph.style.stackLine;
18
+ super(options);
19
+ }
20
+
21
+ /**
22
+ * 绘制图形前 初始化线条
23
+ *
24
+ * @method preDraw
25
+ * @for jmLineSeries
26
+ */
27
+ init() {
28
+ //生成描点位
29
+ const {
30
+ points,
31
+ dataChanged
32
+ } = this.initDataPoint();
33
+
34
+ //去除多余的线条
35
+ //当数据源线条数比现有的少时,删除多余的线条
36
+ const len = points.length;
37
+
38
+ //设定其填充颜色
39
+ //if(!this.style.fill) this.style.fill = jmUtils.toColor(this.style.stroke,null,null,20);
40
+ this.style.stroke = this.style.color;
41
+ //是否启用动画效果
42
+ //var ani = typeof this.enableAnimate === 'undefined'? this.graph.enableAnimate: this.enableAnimate;
43
+ this.style.item.stroke = this.style.color;
44
+
45
+ // 是否正在动画中
46
+ // 如果数据点多于100 个,暂时不启用动画,太慢了
47
+ const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 );
48
+
49
+ let startShapePoints = []; // 计算出来的曲线点集合
50
+ let endShapePoints = []; // 计算出来的曲线点集合
51
+ const aniCount = (this.style.aniCount || 10);
52
+ const aniStep = Math.floor(len / aniCount) || 1;// 每次动画播放点个数
53
+
54
+ for(let i=0; i< len;i++) {
55
+ const p = points[i];
56
+
57
+ if(isRunningAni) {
58
+ if(i > this.___animateCounter) {
59
+ break;
60
+ }
61
+ }
62
+
63
+ // 是否显示数值点圆
64
+ if(this.style.showItem) {
65
+ this.createPointItem(p.points[0]);
66
+ this.createPointItem(p.points[1]);
67
+ }
68
+ // 平滑曲线
69
+ if(this.style.curve) {
70
+ startShapePoints = this.createCurePoints(startShapePoints, p.points[0]);
71
+ endShapePoints = this.createCurePoints(endShapePoints, p.points[1]);
72
+ }
73
+ // 如果是虚线
74
+ else if(this.style.lineType === 'dotted') {
75
+ startShapePoints = this.createDotLine(startShapePoints, p.points[0]);
76
+ endShapePoints = this.createDotLine(endShapePoints, p.points[1]);
77
+ }
78
+
79
+ startShapePoints.push(p.points[0]);
80
+ endShapePoints.push(p.points[1]);
81
+
82
+
83
+ // 生成标点的回调
84
+ this.emit('onPointCreated', p);
85
+ }
86
+
87
+ // 如果所有都已经结束,则重置成初始化状态
88
+ if(this.___animateCounter >= len - 1) {
89
+ this.___animateCounter = 0;
90
+ }
91
+ else if(isRunningAni) {
92
+ this.___animateCounter += aniStep;
93
+ // next tick 再次刷新
94
+ this.graph.utils.requestAnimationFrame(()=>{
95
+ this.needUpdate = true;//需要刷新
96
+ });
97
+ }
98
+ if(endShapePoints.length) endShapePoints[0].m = true;// 第二条线重新开始画
99
+ this.points = startShapePoints.concat(endShapePoints);
100
+ // 仓建区域效果 这里的endShapePoints要倒过来画,才能形成一个封闭区域
101
+ const areaPoints = startShapePoints.concat(endShapePoints.reverse());
102
+ const areaEnd = areaPoints[areaPoints.length - 1] = this.graph.utils.clone(areaPoints[areaPoints.length - 1]);
103
+ areaEnd.m = false;
104
+ this.createArea(areaPoints, false);
105
+ }
106
+
107
+ /**
108
+ * 生成图例
109
+ *
110
+ * @method createLegend
111
+ */
112
+ createLegend() {
113
+
114
+ //生成图例前的图标
115
+ var style = this.graph.utils.clone(this.style);
116
+ style.stroke = style.color;
117
+ var shape = this.graph.createShape('path',{style:style});
118
+
119
+ if(this.curve || this.style.curve) {
120
+ var p1 = {x:0,y: this.graph.style.legend.item.shape.height};
121
+ var p2 = {x:this.graph.style.legend.item.shape.width / 3,y:this.graph.style.legend.item.shape.height/3};
122
+ var p3 = {x:this.graph.style.legend.item.shape.width / 3 * 2,y:this.graph.style.legend.item.shape.height/3*2};
123
+ var p4 = {x:this.graph.style.legend.item.shape.width,y:0};
124
+
125
+ this.__bezier = this.__bezier || this.graph.createShape('bezier');
126
+ this.__bezier.cpoints = [
127
+ p1,p2,p3,p4
128
+ ];//设置控制点
129
+
130
+ shape.points = this.__bezier.initPoints();
131
+ }
132
+ else {
133
+ shape.points = [{
134
+ x:0,y: this.graph.style.legend.item.shape.height/2
135
+ },{
136
+ x: this.graph.style.legend.item.shape.width,y: this.graph.style.legend.item.shape.height/2
137
+ }];
138
+ }
139
+ this.graph.legend.append(this, shape);
140
+ }
141
+ }
142
+
143
+ export {
144
+ jmStackLineSeries
145
+ }