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.
@@ -1,146 +1,146 @@
1
- import {
2
- jmRect
3
- } from 'jmgraph';
4
-
5
- /**
6
- * 图例的容器
7
- *
8
- * @class jmLegend
9
- * @module jmChart
10
- * @param {jmChart} chart 当前图表
11
- */
12
-
13
- export default class jmLegend extends jmRect {
14
-
15
- constructor(options) {
16
- //当前图例位置偏移量
17
- options.position = options.position || {
18
- x: 0,
19
- y: 0
20
- };
21
- super(options);
22
- }
23
-
24
- /**
25
- * 图例放置位置
26
- */
27
- legendPosition = '';
28
- }
29
-
30
- /**
31
- * 添加图例
32
- *
33
- * @method append
34
- * @param {jmSeries} series 当前图序列
35
- * @param {jmControl} shape 当前图例的图形对象
36
- */
37
- jmLegend.prototype.append = function(series, shape, options = {}) {
38
- // 如果不显示图例,就不处理
39
- if(this.visible === false) return;
40
-
41
- const panel = this.graph.createShape('rect',{
42
- style: this.graph.utils.clone(this.style.item),
43
- position: {
44
- x: 0,
45
- y: 0
46
- }
47
- });
48
-
49
- this.children.add(panel);
50
- panel.children.add(shape);
51
-
52
- shape.width = panel.style.shape.width;
53
- shape.height = panel.style.shape.height;
54
-
55
- let name = options.name || series.legendLabel;
56
- name = series.option.legendFormat? series.option.legendFormat.call(series, options): name;
57
-
58
- if(name) {
59
- //生成图例名称
60
- const label = this.graph.createShape('label', {
61
- style: panel.style.label,
62
- text: name || ''
63
- });
64
- label.height = shape.height;
65
- label.position = {x: shape.width + 4, y: 0};
66
- panel.children.add(label);
67
-
68
- panel.width = shape.width + label.testSize().width;
69
- }
70
- else {
71
- panel.width = shape.width;
72
- }
73
- panel.height = shape.height;
74
-
75
- //执行进入事件
76
- options.hover && panel.bind('mouseover touchover', options.hover);
77
- options.leave && panel.bind('mouseleave touchleave', options.leave);
78
-
79
- const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
80
- if(legendPosition == 'top' || legendPosition == 'bottom') {
81
- //顶部和底部图例横排,每次右移位一个单位图例
82
- panel.position.x = this.width + 15;
83
- this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
84
- this.height = Math.max(panel.height, this.height);
85
- }
86
- else {
87
- //右边和左边图例竖排
88
- panel.position.y += this.height + 5;
89
- this.height = panel.position.y + panel.height;
90
- this.width = Math.max(panel.width, this.width);
91
- }
92
-
93
- this.needUpdate = true;
94
- }
95
-
96
- /**
97
- * 初始化图例
98
- *
99
- * @method init
100
- */
101
- jmLegend.prototype.init = function() {
102
- this.position.x = 0;
103
- this.position.y = 0;
104
- this.width = 0;
105
- this.height = 0;
106
- this.style.lineWidth = 0;
107
- this.children.clear();
108
- }
109
-
110
- /**
111
- * 重置图例属性,根据图例内容计算期大小并更新画图区域大小
112
- *
113
- * @method reset
114
- */
115
- jmLegend.prototype.reset = function() {
116
-
117
- if(this.visible !== false) {
118
- this.position.x = this.graph.chartArea.position.x;
119
- this.position.y = this.graph.chartArea.position.y;
120
- var legendPosition = this.legendPosition || this.style.legendPosition;
121
- switch(legendPosition) {
122
- case 'left': {
123
- this.graph.chartArea.width = this.graph.chartArea.width - this.width;
124
- //画图区域向右偏移
125
- this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
126
- break;
127
- }
128
- case 'top': {
129
- this.graph.chartArea.height = this.graph.chartArea.height - this.height;
130
- this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
131
- break;
132
- }
133
- case 'bottom': {
134
- this.graph.chartArea.height = this.graph.chartArea.height - this.height;
135
- this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
136
- break;
137
- }
138
- case 'right':
139
- default: {
140
- this.graph.chartArea.width = this.graph.chartArea.width - this.width;
141
- this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
142
- break;
143
- }
144
- }
145
- }
1
+ import {
2
+ jmRect
3
+ } from 'jmgraph';
4
+
5
+ /**
6
+ * 图例的容器
7
+ *
8
+ * @class jmLegend
9
+ * @module jmChart
10
+ * @param {jmChart} chart 当前图表
11
+ */
12
+
13
+ export default class jmLegend extends jmRect {
14
+
15
+ constructor(options) {
16
+ //当前图例位置偏移量
17
+ options.position = options.position || {
18
+ x: 0,
19
+ y: 0
20
+ };
21
+ super(options);
22
+ }
23
+
24
+ /**
25
+ * 图例放置位置
26
+ */
27
+ legendPosition = '';
28
+ }
29
+
30
+ /**
31
+ * 添加图例
32
+ *
33
+ * @method append
34
+ * @param {jmSeries} series 当前图序列
35
+ * @param {jmControl} shape 当前图例的图形对象
36
+ */
37
+ jmLegend.prototype.append = function(series, shape, options = {}) {
38
+ // 如果不显示图例,就不处理
39
+ if(this.visible === false) return;
40
+
41
+ const panel = this.graph.createShape('rect',{
42
+ style: this.graph.utils.clone(this.style.item),
43
+ position: {
44
+ x: 0,
45
+ y: 0
46
+ }
47
+ });
48
+
49
+ this.children.add(panel);
50
+ panel.children.add(shape);
51
+
52
+ shape.width = panel.style.shape.width;
53
+ shape.height = panel.style.shape.height;
54
+
55
+ let name = options.name || series.legendLabel;
56
+ name = series.option.legendFormat? series.option.legendFormat.call(series, options): name;
57
+
58
+ if(name) {
59
+ //生成图例名称
60
+ const label = this.graph.createShape('label', {
61
+ style: panel.style.label,
62
+ text: name || ''
63
+ });
64
+ label.height = shape.height;
65
+ label.position = {x: shape.width + 4, y: 0};
66
+ panel.children.add(label);
67
+
68
+ panel.width = shape.width + label.testSize().width;
69
+ }
70
+ else {
71
+ panel.width = shape.width;
72
+ }
73
+ panel.height = shape.height;
74
+
75
+ //执行进入事件
76
+ options.hover && panel.bind('mouseover touchover', options.hover);
77
+ options.leave && panel.bind('mouseleave touchleave', options.leave);
78
+
79
+ const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
80
+ if(legendPosition == 'top' || legendPosition == 'bottom') {
81
+ //顶部和底部图例横排,每次右移位一个单位图例
82
+ panel.position.x = this.width + 15;
83
+ this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
84
+ this.height = Math.max(panel.height, this.height);
85
+ }
86
+ else {
87
+ //右边和左边图例竖排
88
+ panel.position.y += this.height + 5;
89
+ this.height = panel.position.y + panel.height;
90
+ this.width = Math.max(panel.width, this.width);
91
+ }
92
+
93
+ this.needUpdate = true;
94
+ }
95
+
96
+ /**
97
+ * 初始化图例
98
+ *
99
+ * @method init
100
+ */
101
+ jmLegend.prototype.init = function() {
102
+ this.position.x = 0;
103
+ this.position.y = 0;
104
+ this.width = 0;
105
+ this.height = 0;
106
+ this.style.lineWidth = 0;
107
+ this.children.clear();
108
+ }
109
+
110
+ /**
111
+ * 重置图例属性,根据图例内容计算期大小并更新画图区域大小
112
+ *
113
+ * @method reset
114
+ */
115
+ jmLegend.prototype.reset = function() {
116
+
117
+ if(this.visible !== false) {
118
+ this.position.x = this.graph.chartArea.position.x;
119
+ this.position.y = this.graph.chartArea.position.y;
120
+ var legendPosition = this.legendPosition || this.style.legendPosition;
121
+ switch(legendPosition) {
122
+ case 'left': {
123
+ this.graph.chartArea.width = this.graph.chartArea.width - this.width;
124
+ //画图区域向右偏移
125
+ this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
126
+ break;
127
+ }
128
+ case 'top': {
129
+ this.graph.chartArea.height = this.graph.chartArea.height - this.height;
130
+ this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
131
+ break;
132
+ }
133
+ case 'bottom': {
134
+ this.graph.chartArea.height = this.graph.chartArea.height - this.height;
135
+ this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
136
+ break;
137
+ }
138
+ case 'right':
139
+ default: {
140
+ this.graph.chartArea.width = this.graph.chartArea.width - this.width;
141
+ this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
142
+ break;
143
+ }
144
+ }
145
+ }
146
146
  }
@@ -1,186 +1,186 @@
1
-
2
- import jmMarkLine from './markLine';
3
-
4
- /**
5
- * 轴
6
- *
7
- * @class jmMarkLineManager
8
- * @module jmChart
9
- * @param {jmChart} chart 当前图表
10
- * @param {string} [type] 轴类型(x/y/radar),默认为x
11
- * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
12
- * @param {object} [style] 样式
13
- */
14
-
15
- export default class jmMarkLineManager {
16
- constructor(chart) {
17
- this.chart = chart;
18
- this.init(chart);
19
- }
20
-
21
- // 初始化
22
- init(chart) {
23
- const graph = chart.touchGraph || chart;
24
-
25
- graph.on('beginDraw', () => {
26
- // 重置标线,会处理小圆圈问题
27
- this.xMarkLine && this.xMarkLine.init();
28
- this.yMarkLine && this.yMarkLine.init();
29
- });
30
-
31
- if(chart.style.markLine) {
32
- // 生成标线,可以跟随鼠标或手指滑动
33
- if(chart.style.markLine && chart.style.markLine.x) {
34
- this.xMarkLine = graph.createShape(jmMarkLine, {
35
- type: 'x',
36
- style: chart.style.markLine
37
- });
38
- const area = graph.chartArea || graph;
39
- area.children.add(this.xMarkLine);
40
- }
41
-
42
- if(chart.style.markLine && chart.style.markLine.y) {
43
- this.yMarkLine = graph.createShape(jmMarkLine, {
44
- type: 'y',
45
- style: chart.style.markLine
46
- });
47
- const area = graph.chartArea || graph;
48
- area.children.add(this.yMarkLine);
49
- }
50
-
51
- let longtap = 0; // 是否有长按, 0 未开始,1已按下,2识别为长按
52
- let lineTouching = 0; // 1=启用标线状态,2=非标线,则可以触发系统行为
53
- let longtapHandler = 0;
54
- let touchStartPos = {
55
- x: 0,
56
- y: 0
57
- };
58
- graph.on('mousedown touchstart', (args) => {
59
- lineTouching = 0;
60
- // 如果长按才启用
61
- if(chart.style.markLine.longtap) {
62
- longtap = 1;
63
- longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
64
- let tapStartTime = Date.now();
65
- const reqFun = ()=>{
66
- const elapsed = Date.now() - tapStartTime;
67
- if(longtap === 1 || longtap === 2) {
68
- // 如果还未过一定时间,则继续等待
69
- if(elapsed < 500) {
70
- longtapHandler = graph.utils.requestAnimationFrame(reqFun);
71
- return;
72
- }
73
- longtap = 2;
74
- this.startMove(args);
75
- chart.emit('marklinelongtapstart', args);
76
- }
77
- };
78
- // 如果一定时间后还没有取消,则表示长按了
79
- longtapHandler = graph.utils.requestAnimationFrame(reqFun);
80
-
81
- //args.event.stopPropagation();
82
- //args.event.preventDefault();// 阻止默认行为
83
- }
84
- else {
85
- this.startMove(args);
86
- }
87
- args.longtap = longtap;
88
- touchStartPos = args.position;
89
- });
90
- // 移动标线
91
- graph.on('mousemove touchmove', (args) => {
92
- args.offsetInfo = {
93
- x: 0,
94
- y: 0,
95
- offset: 0
96
- };
97
- args.offsetInfo.x = args.position.x - touchStartPos.x;
98
- args.offsetInfo.y = args.position.y - touchStartPos.y;
99
- args.offsetInfo.offset = Math.sqrt(args.offsetInfo.x * args.offsetInfo.x + args.offsetInfo.y * args.offsetInfo.y);
100
-
101
- // 记录当次滑动的位置
102
- touchStartPos = args.position;
103
-
104
- // 如果是长按启用,但手指又滑动了。则取消标线
105
- if(longtap === 1) {
106
- if(args.offsetInfo.offset > 15) longtap = 0; // 如果移动了,则取消长按
107
- else lineTouching = 1;
108
- }
109
-
110
- args.event && args.event.stopPropagation && args.event.stopPropagation();
111
- // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
112
- if(chart.style.markLine.lock){
113
- // 标线状态一直禁用系统能力
114
- // 如果指定了锁定值,只需要一项符合要求就进行锁定
115
- if((lineTouching === 0 &&
116
- ((chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y) ||
117
- (chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x)))
118
- || lineTouching === 1) {
119
-
120
- lineTouching = 1;
121
- args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
122
- }
123
- }
124
-
125
- if(lineTouching === 0) lineTouching = 2;
126
-
127
- args.longtap = longtap;
128
- this.move(args);
129
- });
130
- // 取消移动
131
- graph.on('mouseup touchend touchcancel touchleave', (args) => {
132
- longtap = 0;
133
- lineTouching = 0;
134
- this.endMove(args);
135
- });
136
- }
137
- }
138
-
139
- // 开始移动标线
140
- startMove(args, markLineType = 'xy') {
141
- if(this.xMarkLine && markLineType.includes('x')) {
142
- this.xMarkLine.visible = true;
143
- this.xMarkLine.move(args);
144
- }
145
- if(this.yMarkLine && markLineType.includes('y')) {
146
- this.yMarkLine.visible = true;
147
- this.yMarkLine.move(args);
148
- }
149
-
150
- if(!args.cancel) this.chart.emit('marklinestartmove', args);
151
- }
152
-
153
- // 移动标线
154
- move(args) {
155
- let moved = false;
156
- if(this.xMarkLine && this.xMarkLine.visible) {
157
- this.xMarkLine.move(args);
158
- moved = true;
159
- }
160
- if(this.yMarkLine && this.yMarkLine.visible) {
161
- this.yMarkLine.move(args);
162
- moved = true;
163
- }
164
- if(moved) {
165
- if(args.longtap === 2 && args.event) {
166
- args.event.preventDefault && args.event.preventDefault();// 阻止默认行为
167
- args.event.stopPropagation && args.event.stopPropagation();
168
- }
169
-
170
- if(!args.cancel) this.chart.emit('marklinemove', args);
171
- }
172
- }
173
- // 终止动移
174
- endMove(args) {
175
- if(this.xMarkLine && this.xMarkLine.visible) {
176
- this.xMarkLine.cancel(args);
177
- }
178
- if(this.yMarkLine && this.yMarkLine.visible) {
179
- this.yMarkLine.cancel(args);
180
- }
181
- if(!args.cancel) this.chart.emit('marklineendmove', args);
182
- }
183
- }
184
-
185
-
186
-
1
+
2
+ import jmMarkLine from './markLine';
3
+
4
+ /**
5
+ * 轴
6
+ *
7
+ * @class jmMarkLineManager
8
+ * @module jmChart
9
+ * @param {jmChart} chart 当前图表
10
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
11
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
12
+ * @param {object} [style] 样式
13
+ */
14
+
15
+ export default class jmMarkLineManager {
16
+ constructor(chart) {
17
+ this.chart = chart;
18
+ this.init(chart);
19
+ }
20
+
21
+ // 初始化
22
+ init(chart) {
23
+ const graph = chart.touchGraph || chart;
24
+
25
+ graph.on('beginDraw', () => {
26
+ // 重置标线,会处理小圆圈问题
27
+ this.xMarkLine && this.xMarkLine.init();
28
+ this.yMarkLine && this.yMarkLine.init();
29
+ });
30
+
31
+ if(chart.style.markLine) {
32
+ // 生成标线,可以跟随鼠标或手指滑动
33
+ if(chart.style.markLine && chart.style.markLine.x) {
34
+ this.xMarkLine = graph.createShape(jmMarkLine, {
35
+ type: 'x',
36
+ style: chart.style.markLine
37
+ });
38
+ const area = graph.chartArea || graph;
39
+ area.children.add(this.xMarkLine);
40
+ }
41
+
42
+ if(chart.style.markLine && chart.style.markLine.y) {
43
+ this.yMarkLine = graph.createShape(jmMarkLine, {
44
+ type: 'y',
45
+ style: chart.style.markLine
46
+ });
47
+ const area = graph.chartArea || graph;
48
+ area.children.add(this.yMarkLine);
49
+ }
50
+
51
+ let longtap = 0; // 是否有长按, 0 未开始,1已按下,2识别为长按
52
+ let lineTouching = 0; // 1=启用标线状态,2=非标线,则可以触发系统行为
53
+ let longtapHandler = 0;
54
+ let touchStartPos = {
55
+ x: 0,
56
+ y: 0
57
+ };
58
+ graph.on('mousedown touchstart', (args) => {
59
+ lineTouching = 0;
60
+ // 如果长按才启用
61
+ if(chart.style.markLine.longtap) {
62
+ longtap = 1;
63
+ longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
64
+ let tapStartTime = Date.now();
65
+ const reqFun = ()=>{
66
+ const elapsed = Date.now() - tapStartTime;
67
+ if(longtap === 1 || longtap === 2) {
68
+ // 如果还未过一定时间,则继续等待
69
+ if(elapsed < 500) {
70
+ longtapHandler = graph.utils.requestAnimationFrame(reqFun);
71
+ return;
72
+ }
73
+ longtap = 2;
74
+ this.startMove(args);
75
+ chart.emit('marklinelongtapstart', args);
76
+ }
77
+ };
78
+ // 如果一定时间后还没有取消,则表示长按了
79
+ longtapHandler = graph.utils.requestAnimationFrame(reqFun);
80
+
81
+ //args.event.stopPropagation();
82
+ //args.event.preventDefault();// 阻止默认行为
83
+ }
84
+ else {
85
+ this.startMove(args);
86
+ }
87
+ args.longtap = longtap;
88
+ touchStartPos = args.position;
89
+ });
90
+ // 移动标线
91
+ graph.on('mousemove touchmove', (args) => {
92
+ args.offsetInfo = {
93
+ x: 0,
94
+ y: 0,
95
+ offset: 0
96
+ };
97
+ args.offsetInfo.x = args.position.x - touchStartPos.x;
98
+ args.offsetInfo.y = args.position.y - touchStartPos.y;
99
+ args.offsetInfo.offset = Math.sqrt(args.offsetInfo.x * args.offsetInfo.x + args.offsetInfo.y * args.offsetInfo.y);
100
+
101
+ // 记录当次滑动的位置
102
+ touchStartPos = args.position;
103
+
104
+ // 如果是长按启用,但手指又滑动了。则取消标线
105
+ if(longtap === 1) {
106
+ if(args.offsetInfo.offset > 15) longtap = 0; // 如果移动了,则取消长按
107
+ else lineTouching = 1;
108
+ }
109
+
110
+ args.event && args.event.stopPropagation && args.event.stopPropagation();
111
+ // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
112
+ if(chart.style.markLine.lock){
113
+ // 标线状态一直禁用系统能力
114
+ // 如果指定了锁定值,只需要一项符合要求就进行锁定
115
+ if((lineTouching === 0 &&
116
+ ((chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y) ||
117
+ (chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x)))
118
+ || lineTouching === 1) {
119
+
120
+ lineTouching = 1;
121
+ args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
122
+ }
123
+ }
124
+
125
+ if(lineTouching === 0) lineTouching = 2;
126
+
127
+ args.longtap = longtap;
128
+ this.move(args);
129
+ });
130
+ // 取消移动
131
+ graph.on('mouseup touchend touchcancel touchleave', (args) => {
132
+ longtap = 0;
133
+ lineTouching = 0;
134
+ this.endMove(args);
135
+ });
136
+ }
137
+ }
138
+
139
+ // 开始移动标线
140
+ startMove(args, markLineType = 'xy') {
141
+ if(this.xMarkLine && markLineType.includes('x')) {
142
+ this.xMarkLine.visible = true;
143
+ this.xMarkLine.move(args);
144
+ }
145
+ if(this.yMarkLine && markLineType.includes('y')) {
146
+ this.yMarkLine.visible = true;
147
+ this.yMarkLine.move(args);
148
+ }
149
+
150
+ if(!args.cancel) this.chart.emit('marklinestartmove', args);
151
+ }
152
+
153
+ // 移动标线
154
+ move(args) {
155
+ let moved = false;
156
+ if(this.xMarkLine && this.xMarkLine.visible) {
157
+ this.xMarkLine.move(args);
158
+ moved = true;
159
+ }
160
+ if(this.yMarkLine && this.yMarkLine.visible) {
161
+ this.yMarkLine.move(args);
162
+ moved = true;
163
+ }
164
+ if(moved) {
165
+ if(args.longtap === 2 && args.event) {
166
+ args.event.preventDefault && args.event.preventDefault();// 阻止默认行为
167
+ args.event.stopPropagation && args.event.stopPropagation();
168
+ }
169
+
170
+ if(!args.cancel) this.chart.emit('marklinemove', args);
171
+ }
172
+ }
173
+ // 终止动移
174
+ endMove(args) {
175
+ if(this.xMarkLine && this.xMarkLine.visible) {
176
+ this.xMarkLine.cancel(args);
177
+ }
178
+ if(this.yMarkLine && this.yMarkLine.visible) {
179
+ this.yMarkLine.cancel(args);
180
+ }
181
+ if(!args.cancel) this.chart.emit('marklineendmove', args);
182
+ }
183
+ }
184
+
185
+
186
+