jmchart 1.2.12 → 1.2.15

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.12",
3
+ "version": "1.2.15",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "directories": {
@@ -26,16 +26,19 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/fefeding/jmchart/issues"
28
28
  },
29
- "homepage": "https://github.com/fefeding/jmchart#readme",
29
+ "homepage": "https://surl.fit/tools/tools/jmchart",
30
30
  "dependencies": {
31
- "jmgraph": "^3.2.17"
31
+ "jmgraph": "^3.2.22"
32
+ },
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org/"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@babel/core": "^7.29.0",
35
38
  "@babel/plugin-proposal-class-properties": "^7.18.6",
36
39
  "canvas": "^2.11.2",
37
40
  "express": "^4.22.1",
38
- "rollup": "^2.79.2",
41
+ "rollup": "^2.80.0",
39
42
  "rollup-plugin-babel": "^4.4.0",
40
43
  "rollup-plugin-node-resolve": "^5.2.0",
41
44
  "rollup-plugin-sourcemaps": "^0.6.3"
package/server.js CHANGED
@@ -1,48 +1,80 @@
1
1
  const express = require('express');
2
-
3
- /*
4
2
  const rollup = require('rollup');
5
3
  const rollupOptions = require('./rollup.config.js');
6
4
 
5
+ // 配置 rollup 监视选项
6
+ rollupOptions.watch = {
7
+ include: 'src/**',
8
+ exclude: 'node_modules/**',
9
+ clearScreen: false
10
+ };
7
11
 
8
-
9
- //rollupOptions.output.format = 'esm';// 方便调用
10
- const esmWatcher = rollup.watch(rollupOptions);
11
-
12
-
13
- esmWatcher.on('event', event => {
14
- // event.code 会是下面其中一个:
15
- // START — 监听器正在启动(重启)
16
- // BUNDLE_START — 构建单个文件束
17
- // BUNDLE_END — 完成文件束构建
18
- // END — 完成所有文件束构建
19
- // ERROR — 构建时遇到错误
20
- // FATAL — 遇到无可修复的错误
21
- console.log(event);
22
-
23
- //const bundle = await rollup.rollup(inputOptions);
24
- if(event && event.code == 'END') {
25
- startServer();
26
- }
27
- });
28
- */
29
-
30
- // 启动server
31
-
12
+ // 启动 rollup 监视
13
+ const watcher = rollup.watch(rollupOptions);
32
14
 
33
15
  let serverInstance = null;
34
16
  const port = process.env.PORT || 8801;
35
17
  const ip = process.env.IP || '127.0.0.1';
36
18
 
37
- startServer();
19
+ // 处理 rollup 监视事件
20
+ watcher.on('event', event => {
21
+ switch (event.code) {
22
+ case 'START':
23
+ console.log('构建开始...');
24
+ break;
25
+ case 'BUNDLE_START':
26
+ console.log('开始构建文件束...');
27
+ break;
28
+ case 'BUNDLE_END':
29
+ console.log('构建完成!');
30
+ console.log(`文件: ${event.output[0]}`);
31
+ console.log(`耗时: ${event.duration}ms`);
32
+ // 确保服务器已经启动
33
+ if (!serverInstance) {
34
+ startServer();
35
+ }
36
+ break;
37
+ case 'END':
38
+ console.log('所有构建完成!');
39
+ break;
40
+ case 'ERROR':
41
+ console.error('构建错误:', event.error);
42
+ break;
43
+ case 'FATAL':
44
+ console.error('致命错误:', event.error);
45
+ break;
46
+ default:
47
+ break;
48
+ }
49
+ });
38
50
 
51
+ // 启动服务器
39
52
  function startServer() {
40
-
41
- if(!serverInstance) {
53
+ if (!serverInstance) {
42
54
  const app = express();
43
55
  app.use(express.static("."));
44
- serverInstance = app.listen(port, ip);
56
+ serverInstance = app.listen(port, ip, () => {
57
+ console.log(`\n🔥 开发服务器启动成功!`);
58
+ console.log(`🌐 访问地址: http://${ip}:${port}`);
59
+ console.log(`🔄 热更新已启用,修改代码会自动重新构建`);
60
+ console.log(`📁 项目根目录: ${process.cwd()}\n`);
61
+ });
45
62
  }
46
-
47
- console.log(`dev server listend at ${port}`);
48
63
  }
64
+
65
+ // 启动服务器
66
+ startServer();
67
+
68
+ // 处理进程终止
69
+ process.on('SIGINT', () => {
70
+ console.log('\n正在关闭服务器...');
71
+ watcher.close();
72
+ if (serverInstance) {
73
+ serverInstance.close(() => {
74
+ console.log('服务器已关闭');
75
+ process.exit(0);
76
+ });
77
+ } else {
78
+ process.exit(0);
79
+ }
80
+ });
@@ -184,6 +184,31 @@ export default {
184
184
  // 默认不填充,需要填满请配置{fill:'',stroke:''}
185
185
  area: false
186
186
  },
187
+ range: {
188
+ normal: {
189
+ lineWidth: 1,
190
+ zIndex: 18,
191
+ cursor: 'default'
192
+ },
193
+ hover: {
194
+ lineWidth:4,
195
+ cursor: 'pointer'
196
+ },
197
+ lineWidth:1,
198
+ zIndex: 18,
199
+ cursor: 'default',
200
+ radius: 3,
201
+ fill: null,
202
+ showItem: true,
203
+ item: {
204
+ fill: '#fff',
205
+ zIndex: 19
206
+ },
207
+ area: {
208
+ fill: null,
209
+ opacity: 0.3
210
+ }
211
+ },
187
212
  bar : {
188
213
  normal: {
189
214
  lineWidth: 1,
@@ -282,5 +307,274 @@ export default {
282
307
  // 阳线颜色
283
308
  masculineColor: 'red',
284
309
  lineWidth: 1
310
+ },
311
+ scatter: {
312
+ normal: {
313
+ lineWidth: 1,
314
+ zIndex: 18,
315
+ cursor: 'default'
316
+ },
317
+ hover: {
318
+ //zIndex: 100,
319
+ cursor: 'pointer'
320
+ },
321
+ radius: 5,
322
+ lineWidth: 1,
323
+ zIndex: 18,
324
+ cursor: 'default',
325
+ item: {
326
+ fill: '#fff',
327
+ zIndex: 19
328
+ }
329
+ },
330
+ bubble: {
331
+ normal: {
332
+ lineWidth: 1,
333
+ zIndex: 18,
334
+ cursor: 'default'
335
+ },
336
+ hover: {
337
+ //zIndex: 100,
338
+ cursor: 'pointer'
339
+ },
340
+ radius: 5,
341
+ radiusScale: 1,
342
+ opacity: 0.6,
343
+ lineWidth: 1,
344
+ zIndex: 18,
345
+ cursor: 'default',
346
+ item: {
347
+ fill: '#fff',
348
+ zIndex: 19
349
+ }
350
+ },
351
+ heatmap: {
352
+ normal: {
353
+ lineWidth: 1,
354
+ zIndex: 18,
355
+ cursor: 'default'
356
+ },
357
+ hover: {
358
+ //zIndex: 100,
359
+ cursor: 'pointer'
360
+ },
361
+ cellWidth: 20,
362
+ cellHeight: 20,
363
+ lineWidth: 1,
364
+ zIndex: 18,
365
+ cursor: 'default',
366
+ defaultColor: '#ccc',
367
+ colorGradient: [
368
+ '#313695', // 蓝色(最小值)
369
+ '#4575b4',
370
+ '#74add1',
371
+ '#abd9e9',
372
+ '#e0f3f8',
373
+ '#ffffbf',
374
+ '#fee090',
375
+ '#fdae61',
376
+ '#f46d43',
377
+ '#d73027',
378
+ '#a50026' // 红色(最大值)
379
+ ],
380
+ item: {
381
+ fill: '#fff',
382
+ zIndex: 19
383
+ }
384
+ },
385
+ gauge: {
386
+ normal: {
387
+ lineWidth: 1,
388
+ zIndex: 11,
389
+ cursor: 'default'
390
+ },
391
+ hover: {
392
+ //zIndex: 100,
393
+ cursor: 'pointer'
394
+ },
395
+ min: 0,
396
+ max: 100,
397
+ startAngle: -150,
398
+ endAngle: 150,
399
+ radiusScale: 0.8,
400
+ lineWidth: 15,
401
+ backgroundStroke: '#e0e0e0',
402
+ backgroundFill: 'transparent',
403
+ backgroundLineWidth: 20,
404
+ gradient: true,
405
+ gradientColors: [
406
+ { offset: 0, color: '#52c41a' }, // 绿色
407
+ { offset: 0.7, color: '#faad14' }, // 黄色
408
+ { offset: 1, color: '#f5222d' } // 红色
409
+ ],
410
+ tickCount: 10,
411
+ tickColor: '#666',
412
+ tickLabelColor: '#333',
413
+ pointerColor: '#333',
414
+ pointerWidth: 3,
415
+ centerColor: '#333',
416
+ centerRadius: 8,
417
+ valueColor: '#333',
418
+ valueFont: '24px Arial',
419
+ unit: '',
420
+ unitColor: '#666',
421
+ unitFont: '14px Arial',
422
+ zIndex: 11,
423
+ cursor: 'default'
424
+ },
425
+ area: {
426
+ normal: {
427
+ lineWidth: 1,
428
+ zIndex: 18,
429
+ cursor: 'default'
430
+ },
431
+ hover: {
432
+ lineWidth:4,
433
+ //zIndex: 100,
434
+ cursor: 'pointer'
435
+ },
436
+ lineWidth:1,
437
+ zIndex: 18,
438
+ cursor: 'default',
439
+ radius: 3,
440
+ fill: null,
441
+ showItem: false, // 是否展示圆点
442
+ item: {
443
+ fill: '#fff',
444
+ zIndex: 19
445
+ },
446
+ // 默认填充,使用渐变色
447
+ area: {
448
+ stroke: 'transparent',
449
+ fill: null
450
+ }
451
+ },
452
+ waterfall: {
453
+ normal: {
454
+ lineWidth: 1,
455
+ zIndex: 17,
456
+ cursor: 'default',
457
+ opacity: 0.8
458
+ },
459
+ hover: {
460
+ lineWidth:4,
461
+ //zIndex: 100,
462
+ opacity: 1,
463
+ cursor: 'pointer'
464
+ },
465
+ lineWidth: 1,
466
+ // 柱子宽占比,决定了柱子相对于总宽度
467
+ perWidth: 0.5,
468
+ zIndex: 17,
469
+ cursor: 'default',
470
+ increaseColor: '#52c41a', // 增长颜色
471
+ decreaseColor: '#f5222d', // 减少颜色
472
+ connectorColor: '#999', // 连接线颜色
473
+ close : true,
474
+ shadow: {
475
+ x: 1,
476
+ y: 1,
477
+ blur: 2,
478
+ color: '#000'
479
+ }
480
+ },
481
+ funnel: {
482
+ normal: {
483
+ lineWidth: 1,
484
+ zIndex: 17,
485
+ cursor: 'default',
486
+ opacity: 0.9
487
+ },
488
+ hover: {
489
+ opacity: 1,
490
+ cursor: 'pointer'
491
+ },
492
+ lineWidth: 1,
493
+ zIndex: 17,
494
+ cursor: 'default',
495
+ align: 'center',
496
+ gap: 2,
497
+ stroke: '#fff',
498
+ label: {
499
+ show: true,
500
+ fill: '#fff',
501
+ font: '12px Arial'
502
+ }
503
+ },
504
+ ringProgress: {
505
+ normal: {
506
+ zIndex: 11,
507
+ cursor: 'default'
508
+ },
509
+ hover: {
510
+ cursor: 'pointer'
511
+ },
512
+ lineWidth: 20,
513
+ startAngle: -90,
514
+ max: 100,
515
+ ringGap: 10,
516
+ backgroundColor: '#e0e0e0',
517
+ showLabel: true,
518
+ labelColor: '#333',
519
+ labelFont: '14px Arial',
520
+ zIndex: 11,
521
+ cursor: 'default'
522
+ },
523
+ boxPlot: {
524
+ normal: {
525
+ lineWidth: 1,
526
+ zIndex: 17,
527
+ cursor: 'default'
528
+ },
529
+ hover: {
530
+ cursor: 'pointer'
531
+ },
532
+ lineWidth: 1,
533
+ boxWidth: null,
534
+ whiskerWidth: 1,
535
+ whiskerLength: 20,
536
+ boxFill: 'transparent',
537
+ zIndex: 17,
538
+ cursor: 'default',
539
+ label: {
540
+ show: true,
541
+ fill: '#333',
542
+ font: '12px Arial'
543
+ }
544
+ },
545
+ wordCloud: {
546
+ normal: {
547
+ zIndex: 11,
548
+ cursor: 'default'
549
+ },
550
+ hover: {
551
+ cursor: 'pointer'
552
+ },
553
+ minFontSize: 12,
554
+ maxFontSize: 60,
555
+ spiral: true,
556
+ zIndex: 11,
557
+ cursor: 'default'
558
+ },
559
+ sunburst: {
560
+ normal: {
561
+ zIndex: 11,
562
+ cursor: 'default'
563
+ },
564
+ hover: {
565
+ cursor: 'pointer'
566
+ },
567
+ innerRadius: 0,
568
+ startAngle: 0,
569
+ showLabels: true,
570
+ showCenter: true,
571
+ centerFill: '#fff',
572
+ centerStroke: '#e0e0e0',
573
+ stroke: '#fff',
574
+ lineWidth: 1,
575
+ labelColor: '#fff',
576
+ labelFont: '12px Arial',
577
+ zIndex: 11,
578
+ cursor: 'default'
285
579
  }
286
580
  }
@@ -36,7 +36,7 @@ export default {
36
36
  },
37
37
 
38
38
  updated() {
39
- this.initChart();
39
+ this.refresh();
40
40
  },
41
41
 
42
42
  destroyed() {
@@ -44,8 +44,29 @@ export default {
44
44
  },
45
45
 
46
46
  watch: {
47
- chartData: function(newData, oldData) {
48
- this.refresh();
47
+ chartData: {
48
+ handler: function(newData, oldData) {
49
+ this.refresh();
50
+ },
51
+ deep: false // 仅监听引用变化,由使用者显式替换数组时触发
52
+ },
53
+ chartOptions: {
54
+ handler: function(newOptions, oldOptions) {
55
+ // 配置变化时需要重建图表
56
+ if(this.chartInstance) {
57
+ this.chartInstance.destroy();
58
+ this.chartInstance = null;
59
+ }
60
+ this.option = Object.assign({
61
+ enableAnimate: false,
62
+ legendPosition: 'top',
63
+ legendVisible: true,
64
+ width: this.width,
65
+ height: this.height
66
+ }, newOptions);
67
+ this.$nextTick(() => this.initChart());
68
+ },
69
+ deep: false
49
70
  },
50
71
  width: function(newWidth, oldWidth) {
51
72
  if(!this.chartInstance) return;
@@ -662,13 +662,16 @@ export default class jmAxis extends jmArrowLine {
662
662
  clear() {
663
663
  this._min = null;
664
664
  this._max = null;
665
+ this._width = null; // 清除宽度缓存
665
666
  this.children.each((i, c) => {
666
667
  c.remove();
667
668
  }, true);
668
669
  // 清空栅格线
669
- this.gridLines && this.gridLines.forEach((line)=>{
670
- line.remove();
671
- });
670
+ if(this.gridLines && this.gridLines.length) {
671
+ for(let i = 0; i < this.gridLines.length; i++) {
672
+ this.gridLines[i].remove();
673
+ }
674
+ }
672
675
  this.labels && this.labels.forEach((label)=>{
673
676
  label.remove();
674
677
  });
@@ -55,18 +55,20 @@ export default class jmMarkLineManager {
55
55
  x: 0,
56
56
  y: 0
57
57
  };
58
+ let lastMoveTime = 0;
59
+ const MOVE_THROTTLE = 16; // 约60fps
60
+
58
61
  graph.on('mousedown touchstart', (args) => {
59
62
  lineTouching = 0;
60
63
  // 如果长按才启用
61
64
  if(chart.style.markLine.longtap) {
62
65
  longtap = 1;
63
66
  longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
64
- let tapStartTime = Date.now();
67
+ const tapStartTime = Date.now();
65
68
  const reqFun = ()=>{
66
- const elapsed = Date.now() - tapStartTime;
67
69
  if(longtap === 1 || longtap === 2) {
68
70
  // 如果还未过一定时间,则继续等待
69
- if(elapsed < 500) {
71
+ if(Date.now() - tapStartTime < 500) {
70
72
  longtapHandler = graph.utils.requestAnimationFrame(reqFun);
71
73
  return;
72
74
  }
@@ -77,9 +79,6 @@ export default class jmMarkLineManager {
77
79
  };
78
80
  // 如果一定时间后还没有取消,则表示长按了
79
81
  longtapHandler = graph.utils.requestAnimationFrame(reqFun);
80
-
81
- //args.event.stopPropagation();
82
- //args.event.preventDefault();// 阻止默认行为
83
82
  }
84
83
  else {
85
84
  this.startMove(args);
@@ -89,6 +88,13 @@ export default class jmMarkLineManager {
89
88
  });
90
89
  // 移动标线
91
90
  graph.on('mousemove touchmove', (args) => {
91
+ // 添加节流,减少重绘次数
92
+ const now = Date.now();
93
+ if(now - lastMoveTime < MOVE_THROTTLE) {
94
+ return;
95
+ }
96
+ lastMoveTime = now;
97
+
92
98
  args.offsetInfo = {
93
99
  x: 0,
94
100
  y: 0,
@@ -115,7 +121,7 @@ export default class jmMarkLineManager {
115
121
  if((lineTouching === 0 &&
116
122
  ((chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y) ||
117
123
  (chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x)))
118
- || lineTouching === 1) {
124
+ || lineTouching === 1) {
119
125
 
120
126
  lineTouching = 1;
121
127
  args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
@@ -163,7 +169,7 @@ export default class jmMarkLineManager {
163
169
  }
164
170
  if(moved) {
165
171
  if(args.longtap === 2 && args.event) {
166
- args.event.preventDefault && args.event.preventDefault();// 阻止默认行为
172
+ args.event.preventDefault && args.event.preventDefault();// 阻止默认行为
167
173
  args.event.stopPropagation && args.event.stopPropagation();
168
174
  }
169
175