jmgraph 3.1.90 → 3.1.92
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.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +66 -35
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +1 -1
- package/src/core/jmGraph.js +22 -14
- package/src/shapes/jmImage.js +49 -30
package/dist/jmgraph.js
CHANGED
|
@@ -359,7 +359,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
359
359
|
get: function get() {
|
|
360
360
|
var s = this.__pro('context');
|
|
361
361
|
|
|
362
|
-
if (s) return s;else if (this.is('jmGraph') && this.canvas) {
|
|
362
|
+
if (s) return s;else if (this.is('jmGraph') && this.canvas && this.canvas.getContext) {
|
|
363
363
|
return this.context = this.canvas.getContext('2d');
|
|
364
364
|
}
|
|
365
365
|
var g = this.graph;
|
|
@@ -2591,9 +2591,8 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2591
2591
|
|
|
2592
2592
|
_this.util = _this.utils = _jmUtils.jmUtils; //如果是小程序
|
|
2593
2593
|
|
|
2594
|
-
if (typeof wx != 'undefined' && wx.
|
|
2595
|
-
|
|
2596
|
-
canvas = wx.createSelectorQuery().select('#' + canvas);
|
|
2594
|
+
if (typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
|
|
2595
|
+
if (typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
|
|
2597
2596
|
_this.isWXMiniApp = true; // 微信小程序平台
|
|
2598
2597
|
} else {
|
|
2599
2598
|
if (typeof canvas === 'string' && typeof document != 'undefined') {
|
|
@@ -2612,11 +2611,10 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2612
2611
|
} else {
|
|
2613
2612
|
_this.container = canvas.parentElement;
|
|
2614
2613
|
}
|
|
2615
|
-
|
|
2616
|
-
_this.context = canvas.getContext('2d');
|
|
2617
2614
|
}
|
|
2618
2615
|
|
|
2619
2616
|
_this.canvas = canvas;
|
|
2617
|
+
if (!_this.context) _this.context = canvas.getContext('2d');
|
|
2620
2618
|
|
|
2621
2619
|
_this.__init(callback);
|
|
2622
2620
|
|
|
@@ -2672,6 +2670,10 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2672
2670
|
value: function resize(w, h) {
|
|
2673
2671
|
var scale = typeof window != 'undefined' && window.devicePixelRatio > 1 ? window.devicePixelRatio : 1;
|
|
2674
2672
|
|
|
2673
|
+
if (this.isWXMiniApp) {
|
|
2674
|
+
scale = wx.getSystemInfoSync().pixelRatio || 1;
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2675
2677
|
if (scale > 1) {
|
|
2676
2678
|
this.__normalSize = this.__normalSize || {
|
|
2677
2679
|
width: 0,
|
|
@@ -2680,11 +2682,18 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2680
2682
|
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
2681
2683
|
if (w) this.__normalSize.width = w;
|
|
2682
2684
|
if (h) this.__normalSize.height = h;
|
|
2683
|
-
|
|
2684
|
-
this.canvas.style
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2685
|
+
|
|
2686
|
+
if (this.canvas.style) {
|
|
2687
|
+
this.canvas.style.width = w + "px";
|
|
2688
|
+
this.canvas.style.height = h + "px";
|
|
2689
|
+
this.canvas.height = h * scale;
|
|
2690
|
+
this.canvas.width = w * scale;
|
|
2691
|
+
this.context.scale(scale, scale);
|
|
2692
|
+
} else {
|
|
2693
|
+
this.canvas.height = h;
|
|
2694
|
+
this.canvas.width = w;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2688
2697
|
this.devicePixelRatio = scale;
|
|
2689
2698
|
}
|
|
2690
2699
|
}
|
|
@@ -5764,37 +5773,59 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
|
5764
5773
|
}, {
|
|
5765
5774
|
key: "draw",
|
|
5766
5775
|
value: function draw() {
|
|
5776
|
+
var _this2 = this;
|
|
5777
|
+
|
|
5767
5778
|
try {
|
|
5768
|
-
var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
5769
|
-
if (!bounds) bounds = this.parent && this.parent.getAbsoluteBounds ? this.parent.getAbsoluteBounds() : this.getAbsoluteBounds();
|
|
5770
|
-
var p = this.getLocation();
|
|
5771
|
-
p.left += bounds.left;
|
|
5772
|
-
p.top += bounds.top;
|
|
5773
|
-
var sp = this.sourcePosition;
|
|
5774
|
-
var sw = this.sourceWidth;
|
|
5775
|
-
var sh = this.sourceHeight;
|
|
5776
5779
|
var img = this.getImage();
|
|
5777
5780
|
|
|
5778
|
-
if (
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
} else this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, sh);
|
|
5790
|
-
} else if (p) {
|
|
5791
|
-
if (p.width && p.height) this.context.drawImage(img, p.left, p.top, p.width, p.height);else if (p.width) this.context.drawImage(img, p.left, p.top, p.width, img.height);else if (p.height) this.context.drawImage(img, p.left, p.top, img.width, p.height);else this.context.drawImage(img, p.left, p.top);
|
|
5781
|
+
if (this.graph.isWXMiniApp && this.graph.canvas) {
|
|
5782
|
+
// 图片对象
|
|
5783
|
+
var image = this.graph.canvas.createImage(); // 图片加载完成回调
|
|
5784
|
+
|
|
5785
|
+
image.onload = function () {
|
|
5786
|
+
// 将图片绘制到 canvas 上
|
|
5787
|
+
_this2.drawImg(image);
|
|
5788
|
+
}; // 设置图片src
|
|
5789
|
+
|
|
5790
|
+
|
|
5791
|
+
image.src = img;
|
|
5792
5792
|
} else {
|
|
5793
|
-
this.
|
|
5793
|
+
this.drawImg(img);
|
|
5794
5794
|
}
|
|
5795
5795
|
} catch (e) {
|
|
5796
5796
|
console.error && console.error(e);
|
|
5797
5797
|
}
|
|
5798
|
+
} // 绘制
|
|
5799
|
+
|
|
5800
|
+
}, {
|
|
5801
|
+
key: "drawImg",
|
|
5802
|
+
value: function drawImg(img) {
|
|
5803
|
+
var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
5804
|
+
if (!bounds) bounds = this.parent && this.parent.getAbsoluteBounds ? this.parent.getAbsoluteBounds() : this.getAbsoluteBounds();
|
|
5805
|
+
var p = this.getLocation();
|
|
5806
|
+
p.left += bounds.left;
|
|
5807
|
+
p.top += bounds.top;
|
|
5808
|
+
var sp = this.sourcePosition;
|
|
5809
|
+
var sw = this.sourceWidth;
|
|
5810
|
+
var sh = this.sourceHeight;
|
|
5811
|
+
|
|
5812
|
+
if (sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
|
|
5813
|
+
if (typeof sw == 'undefined') sw = p.width || img.width || 0;
|
|
5814
|
+
if (typeof sh == 'undefined') sh = p.height || img.height || 0;
|
|
5815
|
+
sp = sp || {
|
|
5816
|
+
x: 0,
|
|
5817
|
+
y: 0
|
|
5818
|
+
};
|
|
5819
|
+
if (p.width && p.height) this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, p.width, p.height);else if (p.width) {
|
|
5820
|
+
this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, p.width, sh);
|
|
5821
|
+
} else if (p.height) {
|
|
5822
|
+
this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, p.height);
|
|
5823
|
+
} else this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, sh);
|
|
5824
|
+
} else if (p) {
|
|
5825
|
+
if (p.width && p.height) this.context.drawImage(img, p.left, p.top, p.width, p.height);else if (p.width) this.context.drawImage(img, p.left, p.top, p.width, img.height);else if (p.height) this.context.drawImage(img, p.left, p.top, img.width, p.height);else this.context.drawImage(img, p.left, p.top);
|
|
5826
|
+
} else {
|
|
5827
|
+
this.context.drawImage(img);
|
|
5828
|
+
}
|
|
5798
5829
|
}
|
|
5799
5830
|
/**
|
|
5800
5831
|
* 获取当前控件的边界
|
|
@@ -5835,7 +5866,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
|
5835
5866
|
return this.__img;
|
|
5836
5867
|
} else if (src && src.src) {
|
|
5837
5868
|
this.__img = src;
|
|
5838
|
-
} else if (document && document.createElement) {
|
|
5869
|
+
} else if (typeof document !== 'undefined' && document.createElement) {
|
|
5839
5870
|
this.__img = document.createElement('img');
|
|
5840
5871
|
if (src && typeof src == 'string') this.__img.src = src;
|
|
5841
5872
|
} else {
|