jmgraph 3.1.91 → 3.1.93
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 +54 -30
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +1 -1
- package/src/core/jmGraph.js +12 -9
- 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;
|
|
@@ -2592,7 +2592,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2592
2592
|
_this.util = _this.utils = _jmUtils.jmUtils; //如果是小程序
|
|
2593
2593
|
|
|
2594
2594
|
if (typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
|
|
2595
|
-
canvas = wx.createSelectorQuery().select('#' + canvas);
|
|
2595
|
+
if (typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
|
|
2596
2596
|
_this.isWXMiniApp = true; // 微信小程序平台
|
|
2597
2597
|
} else {
|
|
2598
2598
|
if (typeof canvas === 'string' && typeof document != 'undefined') {
|
|
@@ -2613,8 +2613,8 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2613
2613
|
}
|
|
2614
2614
|
}
|
|
2615
2615
|
|
|
2616
|
-
if (!_this.context) _this.context = canvas.getContext('2d');
|
|
2617
2616
|
_this.canvas = canvas;
|
|
2617
|
+
_this.context = canvas.getContext('2d');
|
|
2618
2618
|
|
|
2619
2619
|
_this.__init(callback);
|
|
2620
2620
|
|
|
@@ -2670,7 +2670,9 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2670
2670
|
value: function resize(w, h) {
|
|
2671
2671
|
var scale = typeof window != 'undefined' && window.devicePixelRatio > 1 ? window.devicePixelRatio : 1;
|
|
2672
2672
|
|
|
2673
|
-
if (
|
|
2673
|
+
if (this.isWXMiniApp) {
|
|
2674
|
+
scale = wx.getSystemInfoSync().pixelRatio || 1;
|
|
2675
|
+
} else if (scale > 1) {
|
|
2674
2676
|
this.__normalSize = this.__normalSize || {
|
|
2675
2677
|
width: 0,
|
|
2676
2678
|
height: 0
|
|
@@ -2678,8 +2680,8 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2678
2680
|
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
2679
2681
|
if (w) this.__normalSize.width = w;
|
|
2680
2682
|
if (h) this.__normalSize.height = h;
|
|
2681
|
-
this.canvas.style.width = w + "px";
|
|
2682
|
-
this.canvas.style.height = h + "px";
|
|
2683
|
+
this.canvas.style && (this.canvas.style.width = w + "px");
|
|
2684
|
+
this.canvas.style && (this.canvas.style.height = h + "px");
|
|
2683
2685
|
this.canvas.height = h * scale;
|
|
2684
2686
|
this.canvas.width = w * scale;
|
|
2685
2687
|
this.context.scale(scale, scale);
|
|
@@ -5762,37 +5764,59 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
|
5762
5764
|
}, {
|
|
5763
5765
|
key: "draw",
|
|
5764
5766
|
value: function draw() {
|
|
5767
|
+
var _this2 = this;
|
|
5768
|
+
|
|
5765
5769
|
try {
|
|
5766
|
-
var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
5767
|
-
if (!bounds) bounds = this.parent && this.parent.getAbsoluteBounds ? this.parent.getAbsoluteBounds() : this.getAbsoluteBounds();
|
|
5768
|
-
var p = this.getLocation();
|
|
5769
|
-
p.left += bounds.left;
|
|
5770
|
-
p.top += bounds.top;
|
|
5771
|
-
var sp = this.sourcePosition;
|
|
5772
|
-
var sw = this.sourceWidth;
|
|
5773
|
-
var sh = this.sourceHeight;
|
|
5774
5770
|
var img = this.getImage();
|
|
5775
5771
|
|
|
5776
|
-
if (
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
} else this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, sh);
|
|
5788
|
-
} else if (p) {
|
|
5789
|
-
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);
|
|
5772
|
+
if (this.graph.isWXMiniApp && this.graph.canvas) {
|
|
5773
|
+
// 图片对象
|
|
5774
|
+
var image = this.graph.canvas.createImage(); // 图片加载完成回调
|
|
5775
|
+
|
|
5776
|
+
image.onload = function () {
|
|
5777
|
+
// 将图片绘制到 canvas 上
|
|
5778
|
+
_this2.drawImg(image);
|
|
5779
|
+
}; // 设置图片src
|
|
5780
|
+
|
|
5781
|
+
|
|
5782
|
+
image.src = img;
|
|
5790
5783
|
} else {
|
|
5791
|
-
this.
|
|
5784
|
+
this.drawImg(img);
|
|
5792
5785
|
}
|
|
5793
5786
|
} catch (e) {
|
|
5794
5787
|
console.error && console.error(e);
|
|
5795
5788
|
}
|
|
5789
|
+
} // 绘制
|
|
5790
|
+
|
|
5791
|
+
}, {
|
|
5792
|
+
key: "drawImg",
|
|
5793
|
+
value: function drawImg(img) {
|
|
5794
|
+
var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
5795
|
+
if (!bounds) bounds = this.parent && this.parent.getAbsoluteBounds ? this.parent.getAbsoluteBounds() : this.getAbsoluteBounds();
|
|
5796
|
+
var p = this.getLocation();
|
|
5797
|
+
p.left += bounds.left;
|
|
5798
|
+
p.top += bounds.top;
|
|
5799
|
+
var sp = this.sourcePosition;
|
|
5800
|
+
var sw = this.sourceWidth;
|
|
5801
|
+
var sh = this.sourceHeight;
|
|
5802
|
+
|
|
5803
|
+
if (sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
|
|
5804
|
+
if (typeof sw == 'undefined') sw = p.width || img.width || 0;
|
|
5805
|
+
if (typeof sh == 'undefined') sh = p.height || img.height || 0;
|
|
5806
|
+
sp = sp || {
|
|
5807
|
+
x: 0,
|
|
5808
|
+
y: 0
|
|
5809
|
+
};
|
|
5810
|
+
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) {
|
|
5811
|
+
this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, p.width, sh);
|
|
5812
|
+
} else if (p.height) {
|
|
5813
|
+
this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, p.height);
|
|
5814
|
+
} else this.context.drawImage(img, sp.x, sp.y, sw, sh, p.left, p.top, sw, sh);
|
|
5815
|
+
} else if (p) {
|
|
5816
|
+
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);
|
|
5817
|
+
} else {
|
|
5818
|
+
this.context.drawImage(img);
|
|
5819
|
+
}
|
|
5796
5820
|
}
|
|
5797
5821
|
/**
|
|
5798
5822
|
* 获取当前控件的边界
|
|
@@ -5833,7 +5857,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
|
5833
5857
|
return this.__img;
|
|
5834
5858
|
} else if (src && src.src) {
|
|
5835
5859
|
this.__img = src;
|
|
5836
|
-
} else if (document && document.createElement) {
|
|
5860
|
+
} else if (typeof document !== 'undefined' && document.createElement) {
|
|
5837
5861
|
this.__img = document.createElement('img');
|
|
5838
5862
|
if (src && typeof src == 'string') this.__img.src = src;
|
|
5839
5863
|
} else {
|