jmgraph 3.1.94 → 3.1.96

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/dist/jmgraph.js CHANGED
@@ -657,9 +657,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
657
657
  var _this3 = this;
658
658
 
659
659
  style = style || _jmUtils.jmUtils.clone(this.style, true);
660
- if (!style) return; // 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
661
-
662
- var scale = this.graph.devicePixelRatio;
660
+ if (!style) return;
663
661
  /**
664
662
  * 样式设定
665
663
  *
@@ -709,30 +707,25 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
709
707
  style = _jmUtils.jmUtils.toColor(style);
710
708
  } // 按比例需要放大的样式
711
709
 
710
+ /*if(scale && style) {
711
+ switch(mpname) {
712
+ case 'lineWidth': {
713
+ style *= scale;
714
+ break;
715
+ }
716
+ // 字体放大
717
+ case 'fontSize':
718
+ case 'font': {
719
+ const ms = style.toString().match(/[\d\.]+/);
720
+ if(ms && ms.length) {
721
+ const size = Number(ms[0]) * scale;
722
+ style = style.toString().replace(ms[0], size);
723
+ }
724
+ break;
725
+ }
726
+ }
727
+ } */
712
728
 
713
- if (scale && style) {
714
- switch (mpname) {
715
- case 'lineWidth':
716
- {
717
- style *= scale;
718
- break;
719
- }
720
- // 字体放大
721
-
722
- case 'fontSize':
723
- case 'font':
724
- {
725
- var ms = style.toString().match(/[\d\.]+/);
726
-
727
- if (ms && ms.length) {
728
- var size = Number(ms[0]) * scale;
729
- style = style.toString().replace(ms[0], size);
730
- }
731
-
732
- break;
733
- }
734
- }
735
- }
736
729
 
737
730
  _this3.context[mpname] = style;
738
731
  } else {
@@ -946,10 +939,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
946
939
 
947
940
  var margin = _jmUtils.jmUtils.clone(this.style.margin, {});
948
941
 
949
- margin.left = (margin.left || 0) * this.graph.devicePixelRatio;
950
- margin.top = (margin.top || 0) * this.graph.devicePixelRatio;
951
- margin.right = (margin.right || 0) * this.graph.devicePixelRatio;
952
- margin.bottom = (margin.bottom || 0) * this.graph.devicePixelRatio; //如果没有指定位置,但指定了margin。则位置取margin偏移量
942
+ margin.left = margin.left || 0;
943
+ margin.top = margin.top || 0;
944
+ margin.right = margin.right || 0;
945
+ margin.bottom = margin.bottom || 0; //如果没有指定位置,但指定了margin。则位置取margin偏移量
953
946
 
954
947
  if (local.position) {
955
948
  local.left = local.position.x;
@@ -1570,16 +1563,9 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1570
1563
  var graph = this.graph;
1571
1564
  var srcElement = args.srcElement || args.target;
1572
1565
 
1573
- var position = _jmUtils.jmUtils.getEventPosition(args, graph.scaleSize); //初始化事件位置
1574
- // 如果有指定scale高清处理,需要对坐标处理
1575
- // 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
1566
+ var position = _jmUtils.jmUtils.getEventPosition(args, graph.scaleSize); //初始化事件位置
1576
1567
 
1577
1568
 
1578
- if (graph.devicePixelRatio > 0) {
1579
- position.x = position.offsetX = position.x * graph.devicePixelRatio;
1580
- position.y = position.offsetY = position.y * graph.devicePixelRatio;
1581
- }
1582
-
1583
1569
  args = {
1584
1570
  position: position,
1585
1571
  button: args.button == 0 || position.isTouch ? 1 : args.button,
@@ -2651,7 +2637,17 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2651
2637
 
2652
2638
  this.on('endDraw', function () {
2653
2639
  this.context.translate(-0.5, -0.5);
2654
- });
2640
+ }); // devicePixelRatio初始化
2641
+
2642
+ var dpr = typeof window != 'undefined' && window.devicePixelRatio > 1 ? window.devicePixelRatio : 1;
2643
+
2644
+ if (this.isWXMiniApp) {
2645
+ dpr = wx.getSystemInfoSync().pixelRatio || 1;
2646
+ }
2647
+
2648
+ this.devicePixelRatio = dpr; // 为了解决锯齿问题,先放大canvas再缩放
2649
+
2650
+ this.dprScaleSize = this.devicePixelRatio > 1 ? this.devicePixelRatio : 2;
2655
2651
  if (this.option.width > 0) this.width = this.option.width;
2656
2652
  if (this.option.height > 0) this.height = this.option.height;
2657
2653
  this.resize(); //绑定事件
@@ -2668,25 +2664,19 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2668
2664
  }, {
2669
2665
  key: "resize",
2670
2666
  value: function resize(w, h) {
2671
- var scale = typeof window != 'undefined' && window.devicePixelRatio > 1 ? window.devicePixelRatio : 1;
2672
-
2673
- if (this.isWXMiniApp) {
2674
- scale = wx.getSystemInfoSync().pixelRatio || 1;
2675
- } else if (scale > 1) {
2676
- this.__normalSize = this.__normalSize || {
2677
- width: 0,
2678
- height: 0
2679
- };
2680
- w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
2681
- if (w) this.__normalSize.width = w;
2682
- if (h) this.__normalSize.height = h;
2683
- this.canvas.style && (this.canvas.style.width = w + "px");
2684
- this.canvas.style && (this.canvas.style.height = h + "px");
2685
- this.canvas.height = h * scale;
2686
- this.canvas.width = w * scale;
2687
- this.context.scale(scale, scale);
2688
- this.devicePixelRatio = scale;
2689
- }
2667
+ if (!this.canvas) return;
2668
+ this.__normalSize = this.__normalSize || {
2669
+ width: 0,
2670
+ height: 0
2671
+ };
2672
+ w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
2673
+ if (w) this.__normalSize.width = w;
2674
+ if (h) this.__normalSize.height = h;
2675
+ this.css('width', w + "px");
2676
+ this.css('height', h + "px");
2677
+ this.canvas.height = h * this.dprScaleSize;
2678
+ this.canvas.width = w * this.dprScaleSize;
2679
+ this.context.scale(this.dprScaleSize, this.dprScaleSize);
2690
2680
  }
2691
2681
  /**
2692
2682
  * 内部坐标转为页面坐标,这里主要是有devicePixelRatio倍数问题
@@ -2696,10 +2686,10 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2696
2686
  }, {
2697
2687
  key: "pointToPixes",
2698
2688
  value: function pointToPixes(point) {
2699
- if (this.devicePixelRatio && this.devicePixelRatio !== 1) {
2689
+ if (this.dprScaleSize && this.dprScaleSize !== 1) {
2700
2690
  point = Object.assign({}, point, {
2701
- x: point.x / this.devicePixelRatio,
2702
- y: point.y / this.devicePixelRatio
2691
+ x: point.x / this.dprScaleSize,
2692
+ y: point.y / this.dprScaleSize
2703
2693
  });
2704
2694
  }
2705
2695
 
@@ -2714,6 +2704,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2714
2704
  }, {
2715
2705
  key: "width",
2716
2706
  get: function get() {
2707
+ if (this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
2717
2708
  if (this.canvas) return this.canvas.width;
2718
2709
  return 0;
2719
2710
  },
@@ -2721,7 +2712,6 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2721
2712
  this.needUpdate = true;
2722
2713
 
2723
2714
  if (this.canvas) {
2724
- this.canvas.width = v;
2725
2715
  this.resize(v);
2726
2716
  }
2727
2717
 
@@ -2736,6 +2726,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2736
2726
  }, {
2737
2727
  key: "height",
2738
2728
  get: function get() {
2729
+ if (this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
2739
2730
  if (this.canvas) return this.canvas.height;
2740
2731
  return 0;
2741
2732
  },
@@ -2743,7 +2734,6 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2743
2734
  this.needUpdate = true;
2744
2735
 
2745
2736
  if (this.canvas) {
2746
- this.canvas.height = v;
2747
2737
  this.resize(0, v);
2748
2738
  }
2749
2739
 
@@ -2921,23 +2911,13 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2921
2911
  }, {
2922
2912
  key: "clear",
2923
2913
  value: function clear(w, h) {
2924
- //this.canvas.width = this.canvas.width;
2925
- if (w && h) {
2926
- //this.zoomActual();//恢复比例缩放
2927
- this.canvas.width = w;
2928
- this.canvas.height = h; //保留原有缩放比例
2929
-
2930
- if (this.scaleSize) {
2931
- if (this.context.scale) this.context.scale(this.scaleSize.x, this.scaleSize.y);
2932
- }
2933
- } else {
2934
- w = this.canvas.width;
2935
- h = this.canvas.height;
2936
-
2937
- if (this.scaleSize) {
2938
- w = w / this.scaleSize.x;
2939
- h = h / this.scaleSize.y;
2940
- }
2914
+ if (!w || !h) {
2915
+ w = this.width;
2916
+ h = this.height;
2917
+ /*if(this.scaleSize) {
2918
+ w = w / this.scaleSize.x;
2919
+ h = h / this.scaleSize.y;
2920
+ }*/
2941
2921
  } //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
2942
2922
 
2943
2923
 
@@ -3113,7 +3093,9 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3113
3093
  return; // 已销毁
3114
3094
  }
3115
3095
 
3116
- if (self.needUpdate) self.redraw();
3096
+ if (self.needUpdate) self.redraw(); // 触发刷新事件
3097
+
3098
+ self.emit('update');
3117
3099
  self.__requestAnimationFrameFunHandler && _jmUtils.jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
3118
3100
  self.__requestAnimationFrameFunHandler = _jmUtils.jmUtils.requestAnimationFrame(update);
3119
3101
  if (callback) callback();
@@ -5769,7 +5751,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
5769
5751
  try {
5770
5752
  var img = this.getImage();
5771
5753
 
5772
- if (this.graph.isWXMiniApp && this.graph.canvas) {
5754
+ if (this.graph.isWXMiniApp && this.graph.canvas && typeof img === 'string') {
5773
5755
  // 图片对象
5774
5756
  var image = this.graph.canvas.createImage(); // 图片加载完成回调
5775
5757
 
@@ -5791,6 +5773,11 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
5791
5773
  }, {
5792
5774
  key: "drawImg",
5793
5775
  value: function drawImg(img) {
5776
+ if (!img) {
5777
+ console.warn('image is empty');
5778
+ return;
5779
+ }
5780
+
5794
5781
  var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
5795
5782
  if (!bounds) bounds = this.parent && this.parent.getAbsoluteBounds ? this.parent.getAbsoluteBounds() : this.getAbsoluteBounds();
5796
5783
  var p = this.getLocation();