jmchart 1.2.19 → 1.2.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://surl.fit/tools/tools/jmchart",
31
31
  "dependencies": {
32
- "jmgraph": "^3.2.27"
32
+ "jmgraph": "^3.2.29"
33
33
  },
34
34
  "publishConfig": {
35
35
  "registry": "https://registry.npmjs.org/"
@@ -1,8 +1,8 @@
1
1
 
2
2
  /**
3
- * 显示提示控件
4
- * params参数:style=样式,value=显示的文字
5
- *
3
+ * 显示提示控件(已废弃)
4
+ *
5
+ * @deprecated 此模块已废弃,未被任何代码引用,保留仅供参考
6
6
  * @class jmTooltip
7
7
  * @for jmGraph
8
8
  * @module jmGraph
@@ -17,6 +17,6 @@ export default {
17
17
  }
18
18
  return false;
19
19
  }
20
- return source != target;
20
+ return source !== target;
21
21
  }
22
22
  }
@@ -199,7 +199,7 @@ export default class jmAxis extends jmArrowLine {
199
199
  const index = this.index || 1;
200
200
  // 如果是雷达图,则画发散的线
201
201
  if(this.radarOption) {
202
- this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;;
202
+ this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;
203
203
  this.end.y = this.radarOption.center.y - this.radarOption.sin * this.radarOption.radius + bounds.top;
204
204
  this.start.x = this.radarOption.center.x + bounds.left;
205
205
  this.start.y = this.radarOption.center.y + bounds.top;
@@ -602,7 +602,7 @@ export default class jmAxis extends jmArrowLine {
602
602
  /**
603
603
  * 获取或设置当前轴最小值
604
604
  *
605
- * @method max
605
+ * @method min
606
606
  * @param {number/date/string} 当前轴的最小值
607
607
  * @return 当前轴的最小值
608
608
  */
@@ -11,7 +11,6 @@ import {
11
11
  */
12
12
 
13
13
  export default class jmLegend extends jmRect {
14
-
15
14
  constructor(options) {
16
15
  //当前图例位置偏移量
17
16
  options.position = options.position || {
@@ -25,122 +24,121 @@ export default class jmLegend extends jmRect {
25
24
  * 图例放置位置
26
25
  */
27
26
  legendPosition = '';
28
- }
29
27
 
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;
28
+ /**
29
+ * 添加图例
30
+ *
31
+ * @method append
32
+ * @param {jmSeries} series 当前图序列
33
+ * @param {jmControl} shape 当前图例的图形对象
34
+ */
35
+ append(series, shape, options = {}) {
36
+ // 如果不显示图例,就不处理
37
+ if(this.visible === false) return;
40
38
 
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);
39
+ const panel = this.graph.createShape('rect',{
40
+ style: this.graph.utils.clone(this.style.item),
41
+ position: {
42
+ x: 0,
43
+ y: 0
44
+ }
45
+ });
46
+
47
+ this.children.add(panel);
48
+ panel.children.add(shape);
51
49
 
52
- shape.width = panel.style.shape.width;
53
- shape.height = panel.style.shape.height;
50
+ shape.width = panel.style.shape.width;
51
+ shape.height = panel.style.shape.height;
54
52
 
55
- let name = options.name || series.legendLabel;
56
- name = series.option.legendFormat? series.option.legendFormat.call(series, options): name;
53
+ let name = options.name || series.legendLabel;
54
+ name = series.option.legendFormat? series.option.legendFormat.call(series, options): name;
57
55
 
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);
56
+ if(name) {
57
+ //生成图例名称
58
+ const label = this.graph.createShape('label', {
59
+ style: panel.style.label,
60
+ text: name || ''
61
+ });
62
+ label.height = shape.height;
63
+ label.position = {x: shape.width + 4, y: 0};
64
+ panel.children.add(label);
67
65
 
68
- panel.width = shape.width + label.testSize().width;
69
- }
70
- else {
71
- panel.width = shape.width;
72
- }
73
- panel.height = shape.height;
66
+ panel.width = shape.width + label.testSize().width;
67
+ }
68
+ else {
69
+ panel.width = shape.width;
70
+ }
71
+ panel.height = shape.height;
74
72
 
75
- //执行进入事件
76
- options.hover && panel.bind('mouseover touchover', options.hover);
77
- options.leave && panel.bind('mouseleave touchleave', options.leave);
73
+ //执行进入事件
74
+ options.hover && panel.bind('mouseover touchover', options.hover);
75
+ options.leave && panel.bind('mouseleave touchleave', options.leave);
78
76
 
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
- }
77
+ const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
78
+ if(legendPosition == 'top' || legendPosition == 'bottom') {
79
+ //顶部和底部图例横排,每次右移位一个单位图例
80
+ panel.position.x = this.width + 15;
81
+ this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
82
+ this.height = Math.max(panel.height, this.height);
83
+ }
84
+ else {
85
+ //右边和左边图例竖排
86
+ panel.position.y += this.height + 5;
87
+ this.height = panel.position.y + panel.height;
88
+ this.width = Math.max(panel.width, this.width);
89
+ }
92
90
 
93
- this.needUpdate = true;
94
- }
91
+ this.needUpdate = true;
92
+ }
95
93
 
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
- }
94
+ /**
95
+ * 初始化图例
96
+ *
97
+ * @method init
98
+ */
99
+ init() {
100
+ this.position.x = 0;
101
+ this.position.y = 0;
102
+ this.width = 0;
103
+ this.height = 0;
104
+ this.style.lineWidth = 0;
105
+ this.children.clear();
106
+ }
109
107
 
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
- }
108
+ /**
109
+ * 重置图例属性,根据图例内容计算期大小并更新画图区域大小
110
+ *
111
+ * @method reset
112
+ */
113
+ reset() {
114
+ if(this.visible !== false) {
115
+ this.position.x = this.graph.chartArea.position.x;
116
+ this.position.y = this.graph.chartArea.position.y;
117
+ const legendPosition = this.legendPosition || this.style.legendPosition;
118
+ switch(legendPosition) {
119
+ case 'left': {
120
+ this.graph.chartArea.width = this.graph.chartArea.width - this.width;
121
+ //画图区域向右偏移
122
+ this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
123
+ break;
124
+ }
125
+ case 'top': {
126
+ this.graph.chartArea.height = this.graph.chartArea.height - this.height;
127
+ this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
128
+ break;
129
+ }
130
+ case 'bottom': {
131
+ this.graph.chartArea.height = this.graph.chartArea.height - this.height;
132
+ this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
133
+ break;
134
+ }
135
+ case 'right':
136
+ default: {
137
+ this.graph.chartArea.width = this.graph.chartArea.width - this.width;
138
+ this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
139
+ break;
140
+ }
141
+ }
144
142
  }
145
- }
146
- }
143
+ }
144
+ }
@@ -20,6 +20,8 @@ export default class jmMarkLineManager {
20
20
 
21
21
  // 初始化
22
22
  init(chart) {
23
+ // 没有坐标系的图表不需要标线
24
+ if(!chart.xAxis || !chart.yAxises) return;
23
25
  const graph = chart.touchGraph || chart;
24
26
 
25
27
  graph.on('beginDraw', () => {
@@ -3,7 +3,7 @@ import { jmList, jmLine } from 'jmgraph';
3
3
  /**
4
4
  * 轴
5
5
  *
6
- * @class jmAxis
6
+ * @class jmMarkLine
7
7
  * @module jmChart
8
8
  * @param {jmChart} chart 当前图表
9
9
  * @param {string} [type] 轴类型(x/y/radar),默认为x
@@ -69,7 +69,8 @@ export default class jmMarkLine extends jmLine {
69
69
  // 如果在操作图层上, 点的X轴需要加上图表图层区域偏移量
70
70
  this.start.x = this.end.x = isTocuhGraph? (point.x + graph.chartArea.position.x): point.x;
71
71
 
72
- for(const p of point.points) {
72
+ const points = point.points || (point.y !== undefined ? [point] : []);
73
+ for(const p of points) {
73
74
  if(!p || typeof p.y === 'undefined') continue;
74
75
  this.markArc = graph.createShape('circle', {
75
76
  style: this.style,
package/src/jmChart.js CHANGED
@@ -27,9 +27,6 @@ import jmBoxPlotSeries from './series/boxPlotSeries.js';
27
27
  import jmWordCloudSeries from './series/wordCloudSeries.js';
28
28
  import jmMarkLineManager from './core/markLine/manager';
29
29
 
30
- const ANIMATION_DATA_THRESHOLD = 100;
31
- const DEFAULT_ANIMATION_COUNT = 10;
32
-
33
30
  /**
34
31
  * jm图表组件
35
32
  * option参数:graph=jmgraph
@@ -47,7 +44,7 @@ export default class jmChart extends jmGraph {
47
44
  options.autoRefresh = typeof options.autoRefresh === 'undefined' ? enableAnimate : options.autoRefresh;
48
45
 
49
46
  if(enableAnimate && !options.autoRefresh) {
50
- console.warn('开启了动画,却没有开户自动刷新');
47
+ console.warn('开启了动画,却没有开启自动刷新');
51
48
  }
52
49
 
53
50
  options.style = jmUtils.clone(defaultStyle, options.style, true);
@@ -409,7 +406,7 @@ export default class jmChart extends jmGraph {
409
406
  options.maxYValue = typeof options.maxYValue === 'undefined'?this.option.maxYValue:Math.max(this.option.maxYValue, options.maxYValue);
410
407
  }
411
408
 
412
- var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
409
+ const yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
413
410
  return yaxis;
414
411
  }
415
412
 
@@ -20,16 +20,16 @@ export default class jmAreaSeries extends jmLineSeries {
20
20
  * 生成图例
21
21
  */
22
22
  createLegend() {
23
- var style = this.graph.utils.clone(this.style);
23
+ const style = this.graph.utils.clone(this.style);
24
24
  style.stroke = style.color;
25
25
  style.fill = style.color;
26
- var shape = this.graph.createShape('path',{style:style});
26
+ const shape = this.graph.createShape('path',{style:style});
27
27
 
28
28
  if(this.curve || this.style.curve) {
29
- var p1 = {x:0,y: this.graph.style.legend.item.shape.height};
30
- var p2 = {x:this.graph.style.legend.item.shape.width / 3,y:this.graph.style.legend.item.shape.height/3};
31
- var p3 = {x:this.graph.style.legend.item.shape.width / 3 * 2,y:this.graph.style.legend.item.shape.height/3*2};
32
- var p4 = {x:this.graph.style.legend.item.shape.width,y:0};
29
+ const p1 = {x:0,y: this.graph.style.legend.item.shape.height};
30
+ const p2 = {x:this.graph.style.legend.item.shape.width / 3,y:this.graph.style.legend.item.shape.height/3};
31
+ const p3 = {x:this.graph.style.legend.item.shape.width / 3 * 2,y:this.graph.style.legend.item.shape.height/3*2};
32
+ const p4 = {x:this.graph.style.legend.item.shape.width,y:0};
33
33
 
34
34
  this.__bezier = this.__bezier || this.graph.createShape('bezier');
35
35
  this.__bezier.cpoints = [
@@ -59,8 +59,8 @@ export default class jmBoxPlotSeries extends jmSeries {
59
59
 
60
60
  if(allValues.length === 0) return;
61
61
 
62
- const minValue = Math.min(...allValues);
63
- const maxValue = Math.max(...allValues);
62
+ const minValue = allValues.reduce((a, b) => Math.min(a, b));
63
+ const maxValue = allValues.reduce((a, b) => Math.max(a, b));
64
64
  const valueRange = maxValue - minValue || 1;
65
65
 
66
66
  const boxWidth = this.style.boxWidth || (chartWidth / data.length * 0.5);
@@ -250,5 +250,3 @@ export default class jmBoxPlotSeries extends jmSeries {
250
250
  this.graph.legend.append(this, shape);
251
251
  }
252
252
  }
253
-
254
- export { jmBoxPlotSeries };
@@ -107,13 +107,12 @@ export default class jmBubbleSeries extends jmSeries {
107
107
  * @for jmBubbleSeries
108
108
  */
109
109
  createLegend() {
110
- // 生成图例前的图标
111
- var style = this.graph.utils.clone(this.style);
110
+ const style = this.graph.utils.clone(this.style);
112
111
  style.stroke = style.color;
113
112
  style.fill = style.color;
114
113
  style.opacity = style.opacity || 0.6;
115
-
116
- var shape = this.graph.createShape('circle', {
114
+
115
+ const shape = this.graph.createShape('circle', {
117
116
  style: style,
118
117
  center: {
119
118
  x: this.graph.style.legend.item.shape.width / 2,
@@ -124,8 +123,4 @@ export default class jmBubbleSeries extends jmSeries {
124
123
 
125
124
  this.graph.legend.append(this, shape);
126
125
  }
127
- }
128
-
129
- export {
130
- jmBubbleSeries
131
126
  }
@@ -28,7 +28,7 @@ import jmSeries from './series.js';
28
28
 
29
29
  export default class jmCandlestickSeries extends jmSeries {
30
30
  constructor(options) {
31
- options.style = options.style || options.graph.style.line;
31
+ options.style = options.style || options.graph.style.candlestick || options.graph.style.line;
32
32
  super(options);
33
33
  }
34
34
 
@@ -123,7 +123,3 @@ export default class jmCandlestickSeries extends jmSeries {
123
123
  }
124
124
  }
125
125
  }
126
-
127
- export {
128
- jmCandlestickSeries
129
- }
@@ -50,7 +50,7 @@ export default class jmFunnelSeries extends jmSeries {
50
50
  const xField = this.option.xField || 'name';
51
51
 
52
52
  const values = data.map(item => Math.abs(item[field] || 0));
53
- const maxValue = Math.max(...values);
53
+ const maxValue = values.reduce((a, b) => Math.max(a, b));
54
54
 
55
55
  if(maxValue === 0) return;
56
56
 
@@ -186,5 +186,3 @@ export default class jmFunnelSeries extends jmSeries {
186
186
  this.graph.legend.append(this, shape);
187
187
  }
188
188
  }
189
-
190
- export { jmFunnelSeries };
@@ -238,11 +238,11 @@ export default class jmGaugeSeries extends jmSeries {
238
238
  * 生成图例
239
239
  */
240
240
  createLegend() {
241
- var style = this.graph.utils.clone(this.style);
241
+ const style = this.graph.utils.clone(this.style);
242
242
  style.stroke = style.color;
243
243
  style.fill = style.color;
244
-
245
- var shape = this.graph.createShape('arc', {
244
+
245
+ const shape = this.graph.createShape('arc', {
246
246
  style: style,
247
247
  center: {
248
248
  x: this.graph.style.legend.item.shape.width / 2,
@@ -256,7 +256,3 @@ export default class jmGaugeSeries extends jmSeries {
256
256
  this.graph.legend.append(this, shape);
257
257
  }
258
258
  }
259
-
260
- export {
261
- jmGaugeSeries
262
- }
@@ -160,12 +160,11 @@ export default class jmHeatmapSeries extends jmSeries {
160
160
  * @for jmHeatmapSeries
161
161
  */
162
162
  createLegend() {
163
- // 生成图例前的图标
164
- var style = this.graph.utils.clone(this.style);
163
+ const style = this.graph.utils.clone(this.style);
165
164
  style.stroke = style.color;
166
165
  style.fill = style.color;
167
-
168
- var shape = this.graph.createShape('rect', {
166
+
167
+ const shape = this.graph.createShape('rect', {
169
168
  style: style,
170
169
  position: {
171
170
  x: 0,
@@ -177,8 +176,4 @@ export default class jmHeatmapSeries extends jmSeries {
177
176
 
178
177
  this.graph.legend.append(this, shape);
179
178
  }
180
- }
181
-
182
- export {
183
- jmHeatmapSeries
184
179
  }
@@ -161,9 +161,9 @@ export default class jmLineSeries extends jmSeries {
161
161
  createLegend() {
162
162
 
163
163
  //生成图例前的图标
164
- var style = this.graph.utils.clone(this.style);
164
+ const style = this.graph.utils.clone(this.style);
165
165
  style.stroke = style.color;
166
- var shape = this.graph.createShape('path',{style:style});
166
+ const shape = this.graph.createShape('path',{style:style});
167
167
 
168
168
  if(this.curve || this.style.curve) {
169
169
  var p1 = {x:0,y: this.graph.style.legend.item.shape.height};
@@ -332,7 +332,3 @@ export default class jmLineSeries extends jmSeries {
332
332
  }
333
333
  }
334
334
  }
335
-
336
- export {
337
- jmLineSeries
338
- }
@@ -122,7 +122,7 @@ export default class jmPieSeries extends jmSeries {
122
122
  // 每项之间的间隔角度 顺时钟为正,否则为负
123
123
  const marginAngle = (Number(this.style.marginAngle) || 0);
124
124
 
125
- for(var i=0;i< this.data.length;i++) {
125
+ for(let i=0;i< this.data.length;i++) {
126
126
  const s = this.data[i];
127
127
 
128
128
  const yv = s[this.field];
@@ -186,6 +186,7 @@ export default class jmPieSeries extends jmSeries {
186
186
  startAngle: p.startAngle,
187
187
  endAngle: p.endAngle,
188
188
  anticlockwise: anticlockwise,
189
+ interactive: true,
189
190
  isFan: true, // 表示画扇形
190
191
  center: p.center,
191
192
  radius: p.radius,
@@ -219,6 +220,9 @@ export default class jmPieSeries extends jmSeries {
219
220
  this.addShape(p.shape);
220
221
 
221
222
  // 如果有点击事件
223
+ if(this.option.onClick || this.option.onOver || this.option.onLeave) {
224
+ p.shape.interactive = true;
225
+ }
222
226
  if(this.option.onClick) {
223
227
  p.shape.on('click', (e) => {
224
228
  return this.option.onClick.call(this, p, e);
@@ -302,38 +306,39 @@ export default class jmPieSeries extends jmSeries {
302
306
 
303
307
  point.shape.children.add(label);
304
308
  }
305
- }
306
309
 
310
+ /**
311
+ * 生成图例
312
+ *
313
+ * @method createLegend
314
+ */
315
+ createLegend() {
316
+ if(!this.data || !this.data.length) return;
307
317
 
318
+ const len = this.data.length;
319
+ for(let k = 0; k < len; k++) {
320
+ const s = this.data[k];
321
+ if(!s) continue;
322
+ const yv = s[this.field];
323
+ if(yv == null || typeof yv === 'undefined') continue;
308
324
 
309
- /**
310
- * 生成图例
311
- *
312
- * @method createLegend
313
- */
314
- jmPieSeries.prototype.createLegend = function() {
315
-
316
- const points = this.createPoints();
317
- if(!points || !points.length) return;
318
-
319
- for(let k=0; k < points.length; k++) {
320
- const p = points[k];
321
- if(!p) continue;
322
-
323
- //生成图例前的图标
324
- const style = this.graph.utils.clone(p.style);
325
- style.fill = style.fill;
326
- //delete style.stroke;
327
- const shape = this.graph.createShape('rect',{
328
- style: style,
329
- position : {x: 0, y: 0}
330
- });
331
- //shape.targetShape = p.shape;
332
- //此处重写图例事件
333
- this.graph.legend.append(this, shape, {
334
- name: this.legendLabel,
335
- data: this.data[k]
336
- });
337
- }
325
+ const style = this.graph.utils.clone(this.style);
326
+ if(style.color && typeof style.color === 'function') {
327
+ style.fill = style.color.call(this, { data: s, index: k });
328
+ }
329
+ else {
330
+ style.fill = this.graph.getColor(k);
331
+ }
332
+
333
+ const shape = this.graph.createShape('rect',{
334
+ style: style,
335
+ position : {x: 0, y: 0}
336
+ });
337
+ this.graph.legend.append(this, shape, {
338
+ name: this.legendLabel,
339
+ data: s
340
+ });
341
+ }
342
+ }
338
343
  }
339
344