jmchart 1.2.0 → 1.2.1
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/jmchart.amd.js +59 -74
- package/dist/jmchart.cjs.js +59 -74
- package/dist/jmchart.esm.js +59 -74
- package/dist/jmchart.iife.js +59 -74
- package/dist/jmchart.system.js +59 -74
- package/example/line.html +4 -4
- package/example/vue.html +0 -2
- package/example/wk/line.html +5 -5
- package/package.json +2 -2
- package/server.js +1 -1
- package/src/core/axis/axis.js +3 -3
- package/src/core/legend/legend.js +6 -6
- package/src/core/markLine/markLine.js +1 -1
- package/src/jmChart.js +5 -5
- package/src/series/pieSeries.js +3 -3
- package/src/series/radarSeries.js +3 -3
package/dist/jmchart.esm.js
CHANGED
|
@@ -1663,9 +1663,6 @@ class jmControl extends jmProperty {
|
|
|
1663
1663
|
style = style || jmUtils.clone(this.style, true);
|
|
1664
1664
|
if(!style) return;
|
|
1665
1665
|
|
|
1666
|
-
// 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
|
|
1667
|
-
let scale = this.graph.devicePixelRatio;
|
|
1668
|
-
|
|
1669
1666
|
/**
|
|
1670
1667
|
* 样式设定
|
|
1671
1668
|
*
|
|
@@ -1715,7 +1712,7 @@ class jmControl extends jmProperty {
|
|
|
1715
1712
|
}
|
|
1716
1713
|
|
|
1717
1714
|
// 按比例需要放大的样式
|
|
1718
|
-
if(scale && style) {
|
|
1715
|
+
/*if(scale && style) {
|
|
1719
1716
|
switch(mpname) {
|
|
1720
1717
|
case 'lineWidth': {
|
|
1721
1718
|
style *= scale;
|
|
@@ -1732,7 +1729,7 @@ class jmControl extends jmProperty {
|
|
|
1732
1729
|
break;
|
|
1733
1730
|
}
|
|
1734
1731
|
}
|
|
1735
|
-
}
|
|
1732
|
+
} */
|
|
1736
1733
|
this.context[mpname] = style;
|
|
1737
1734
|
}
|
|
1738
1735
|
else {
|
|
@@ -1914,10 +1911,10 @@ class jmControl extends jmProperty {
|
|
|
1914
1911
|
local.height = this.height;
|
|
1915
1912
|
|
|
1916
1913
|
let margin = jmUtils.clone(this.style.margin, {});
|
|
1917
|
-
margin.left = (margin.left || 0)
|
|
1918
|
-
margin.top = (margin.top || 0)
|
|
1919
|
-
margin.right = (margin.right || 0)
|
|
1920
|
-
margin.bottom = (margin.bottom || 0)
|
|
1914
|
+
margin.left = (margin.left || 0);
|
|
1915
|
+
margin.top = (margin.top || 0);
|
|
1916
|
+
margin.right = (margin.right || 0);
|
|
1917
|
+
margin.bottom = (margin.bottom || 0);
|
|
1921
1918
|
|
|
1922
1919
|
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
1923
1920
|
if(local.position) {
|
|
@@ -2436,14 +2433,7 @@ class jmControl extends jmProperty {
|
|
|
2436
2433
|
|
|
2437
2434
|
const srcElement = args.srcElement || args.target;
|
|
2438
2435
|
|
|
2439
|
-
const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
|
|
2440
|
-
|
|
2441
|
-
// 如果有指定scale高清处理,需要对坐标处理
|
|
2442
|
-
// 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
|
|
2443
|
-
if(graph.devicePixelRatio > 0) {
|
|
2444
|
-
position.x = position.offsetX = position.x * graph.devicePixelRatio;
|
|
2445
|
-
position.y = position.offsetY = position.y * graph.devicePixelRatio;
|
|
2446
|
-
}
|
|
2436
|
+
const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
|
|
2447
2437
|
|
|
2448
2438
|
args = {
|
|
2449
2439
|
position: position,
|
|
@@ -4719,11 +4709,19 @@ class jmGraph$1 extends jmControl {
|
|
|
4719
4709
|
this.on('endDraw', function() {
|
|
4720
4710
|
this.context.translate(-0.5, -0.5);
|
|
4721
4711
|
});
|
|
4722
|
-
|
|
4712
|
+
|
|
4713
|
+
// devicePixelRatio初始化
|
|
4714
|
+
let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
|
|
4715
|
+
if(this.isWXMiniApp) {
|
|
4716
|
+
dpr = wx.getSystemInfoSync().pixelRatio || 1;
|
|
4717
|
+
}
|
|
4718
|
+
this.devicePixelRatio = dpr;
|
|
4719
|
+
// 为了解决锯齿问题,先放大canvas再缩放
|
|
4720
|
+
this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
|
|
4721
|
+
|
|
4723
4722
|
if(this.option.width > 0) this.width = this.option.width;
|
|
4724
4723
|
if(this.option.height > 0) this.height = this.option.height;
|
|
4725
|
-
|
|
4726
|
-
this.resize();
|
|
4724
|
+
this.resize();
|
|
4727
4725
|
|
|
4728
4726
|
//绑定事件
|
|
4729
4727
|
this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
|
|
@@ -4738,25 +4736,19 @@ class jmGraph$1 extends jmControl {
|
|
|
4738
4736
|
|
|
4739
4737
|
// 重置canvas大小,并判断高清屏,画图先放大二倍
|
|
4740
4738
|
resize(w, h) {
|
|
4739
|
+
if(!this.canvas) return;
|
|
4741
4740
|
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
scale = wx.getSystemInfoSync().pixelRatio || 1;
|
|
4745
|
-
}
|
|
4746
|
-
else if (scale > 1) {
|
|
4747
|
-
this.__normalSize = this.__normalSize || { width: 0, height: 0};
|
|
4748
|
-
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
4741
|
+
this.__normalSize = this.__normalSize || { width: 0, height: 0};
|
|
4742
|
+
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
4749
4743
|
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
this.devicePixelRatio = scale;
|
|
4759
|
-
}
|
|
4744
|
+
if(w) this.__normalSize.width = w;
|
|
4745
|
+
if(h) this.__normalSize.height = h;
|
|
4746
|
+
|
|
4747
|
+
this.css('width', w + "px");
|
|
4748
|
+
this.css('height', h + "px");
|
|
4749
|
+
this.canvas.height = h * this.dprScaleSize;
|
|
4750
|
+
this.canvas.width = w * this.dprScaleSize;
|
|
4751
|
+
this.context.scale(this.dprScaleSize, this.dprScaleSize);
|
|
4760
4752
|
}
|
|
4761
4753
|
|
|
4762
4754
|
/**
|
|
@@ -4764,10 +4756,10 @@ class jmGraph$1 extends jmControl {
|
|
|
4764
4756
|
* @param {x, y} point 内部坐标
|
|
4765
4757
|
*/
|
|
4766
4758
|
pointToPixes(point) {
|
|
4767
|
-
if(this.
|
|
4759
|
+
if(this.dprScaleSize && this.dprScaleSize !== 1) {
|
|
4768
4760
|
point = Object.assign({}, point, {
|
|
4769
|
-
x: point.x / this.
|
|
4770
|
-
y: point.y / this.
|
|
4761
|
+
x: point.x / this.dprScaleSize,
|
|
4762
|
+
y: point.y / this.dprScaleSize
|
|
4771
4763
|
});
|
|
4772
4764
|
}
|
|
4773
4765
|
return point;
|
|
@@ -4779,13 +4771,13 @@ class jmGraph$1 extends jmControl {
|
|
|
4779
4771
|
* @type {number}
|
|
4780
4772
|
*/
|
|
4781
4773
|
get width() {
|
|
4774
|
+
if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
|
|
4782
4775
|
if(this.canvas) return this.canvas.width;
|
|
4783
4776
|
return 0;
|
|
4784
4777
|
}
|
|
4785
4778
|
set width(v) {
|
|
4786
4779
|
this.needUpdate = true;
|
|
4787
4780
|
if(this.canvas) {
|
|
4788
|
-
this.canvas.width = v;
|
|
4789
4781
|
this.resize(v);
|
|
4790
4782
|
}
|
|
4791
4783
|
return v;
|
|
@@ -4797,13 +4789,13 @@ class jmGraph$1 extends jmControl {
|
|
|
4797
4789
|
* @type {number}
|
|
4798
4790
|
*/
|
|
4799
4791
|
get height() {
|
|
4792
|
+
if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
|
|
4800
4793
|
if(this.canvas) return this.canvas.height;
|
|
4801
4794
|
return 0;
|
|
4802
4795
|
}
|
|
4803
4796
|
set height(v) {
|
|
4804
4797
|
this.needUpdate = true;
|
|
4805
4798
|
if(this.canvas) {
|
|
4806
|
-
this.canvas.height = v;
|
|
4807
4799
|
this.resize(0, v);
|
|
4808
4800
|
}
|
|
4809
4801
|
return v;
|
|
@@ -4962,23 +4954,13 @@ class jmGraph$1 extends jmControl {
|
|
|
4962
4954
|
* @param {number} [h] 清除画布的高度
|
|
4963
4955
|
*/
|
|
4964
4956
|
clear(w, h) {
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
this.
|
|
4969
|
-
this.canvas.height = h;
|
|
4970
|
-
//保留原有缩放比例
|
|
4971
|
-
if(this.scaleSize) {
|
|
4972
|
-
if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
|
|
4973
|
-
}
|
|
4974
|
-
}
|
|
4975
|
-
else {
|
|
4976
|
-
w = this.canvas.width;
|
|
4977
|
-
h = this.canvas.height;
|
|
4978
|
-
if(this.scaleSize) {
|
|
4957
|
+
if(!w || !h) {
|
|
4958
|
+
w = this.width;
|
|
4959
|
+
h = this.height;
|
|
4960
|
+
/*if(this.scaleSize) {
|
|
4979
4961
|
w = w / this.scaleSize.x;
|
|
4980
4962
|
h = h / this.scaleSize.y;
|
|
4981
|
-
}
|
|
4963
|
+
}*/
|
|
4982
4964
|
}
|
|
4983
4965
|
//如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
|
|
4984
4966
|
if(this.style && this.style.fill) {
|
|
@@ -5123,6 +5105,9 @@ class jmGraph$1 extends jmControl {
|
|
|
5123
5105
|
return;// 已销毁
|
|
5124
5106
|
}
|
|
5125
5107
|
if(self.needUpdate) self.redraw();
|
|
5108
|
+
// 触发刷新事件
|
|
5109
|
+
self.emit('update');
|
|
5110
|
+
|
|
5126
5111
|
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
5127
5112
|
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
5128
5113
|
if(callback) callback();
|
|
@@ -5725,7 +5710,7 @@ class jmAxis extends jmArrowLine {
|
|
|
5725
5710
|
//字符串轴。则显示每个标签
|
|
5726
5711
|
|
|
5727
5712
|
const format = this.option.format || this.format;
|
|
5728
|
-
const top =
|
|
5713
|
+
const top = this.style.xLabel.margin.top || 0;
|
|
5729
5714
|
|
|
5730
5715
|
for (let i = 0; i < this.data.length; i++) {
|
|
5731
5716
|
const d = this.data[i];
|
|
@@ -5821,8 +5806,8 @@ class jmAxis extends jmArrowLine {
|
|
|
5821
5806
|
const mm = max - min;
|
|
5822
5807
|
let pervalue = mm / count || 1;
|
|
5823
5808
|
const format = this.option.format || this.format;
|
|
5824
|
-
const marginLeft = this.style.yLabel.margin.left
|
|
5825
|
-
const marginRight = this.style.yLabel.margin.right
|
|
5809
|
+
const marginLeft = this.style.yLabel.margin.left || 0;
|
|
5810
|
+
const marginRight = this.style.yLabel.margin.right || 0;
|
|
5826
5811
|
let p = 0;
|
|
5827
5812
|
|
|
5828
5813
|
for (let i = 0; i < count + 1; i++) {
|
|
@@ -6250,13 +6235,13 @@ jmLegend.prototype.append = function (series, shape, options = {}) {
|
|
|
6250
6235
|
|
|
6251
6236
|
if (legendPosition == 'top' || legendPosition == 'bottom') {
|
|
6252
6237
|
//顶部和底部图例横排,每次右移位一个单位图例
|
|
6253
|
-
panel.position.x = this.width + 15
|
|
6238
|
+
panel.position.x = this.width + 15;
|
|
6254
6239
|
this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
|
|
6255
6240
|
|
|
6256
6241
|
this.height = Math.max(panel.height, this.height);
|
|
6257
6242
|
} else {
|
|
6258
6243
|
//右边和左边图例竖排
|
|
6259
|
-
panel.position.y += this.height + 5
|
|
6244
|
+
panel.position.y += this.height + 5;
|
|
6260
6245
|
this.height = panel.position.y + panel.height;
|
|
6261
6246
|
this.width = Math.max(panel.width, this.width);
|
|
6262
6247
|
}
|
|
@@ -6296,21 +6281,21 @@ jmLegend.prototype.reset = function () {
|
|
|
6296
6281
|
{
|
|
6297
6282
|
this.graph.chartArea.width = this.graph.chartArea.width - this.width; //画图区域向右偏移
|
|
6298
6283
|
|
|
6299
|
-
this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right
|
|
6284
|
+
this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
|
|
6300
6285
|
break;
|
|
6301
6286
|
}
|
|
6302
6287
|
|
|
6303
6288
|
case 'top':
|
|
6304
6289
|
{
|
|
6305
6290
|
this.graph.chartArea.height = this.graph.chartArea.height - this.height;
|
|
6306
|
-
this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom
|
|
6291
|
+
this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
|
|
6307
6292
|
break;
|
|
6308
6293
|
}
|
|
6309
6294
|
|
|
6310
6295
|
case 'bottom':
|
|
6311
6296
|
{
|
|
6312
6297
|
this.graph.chartArea.height = this.graph.chartArea.height - this.height;
|
|
6313
|
-
this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top
|
|
6298
|
+
this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
|
|
6314
6299
|
break;
|
|
6315
6300
|
}
|
|
6316
6301
|
|
|
@@ -6318,7 +6303,7 @@ jmLegend.prototype.reset = function () {
|
|
|
6318
6303
|
default:
|
|
6319
6304
|
{
|
|
6320
6305
|
this.graph.chartArea.width = this.graph.chartArea.width - this.width;
|
|
6321
|
-
this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left
|
|
6306
|
+
this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
|
|
6322
6307
|
break;
|
|
6323
6308
|
}
|
|
6324
6309
|
}
|
|
@@ -7065,7 +7050,7 @@ class jmPieSeries extends jmSeries {
|
|
|
7065
7050
|
x: this.graph.chartArea.width / 2,
|
|
7066
7051
|
y: this.graph.chartArea.height / 2
|
|
7067
7052
|
};
|
|
7068
|
-
const radius = Math.min(center.x - this.style.margin.left
|
|
7053
|
+
const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right, center.y - this.style.margin.top - this.style.margin.bottom); //生成描点位
|
|
7069
7054
|
// super.init会把参数透传给 createPoints
|
|
7070
7055
|
|
|
7071
7056
|
const {
|
|
@@ -7431,7 +7416,7 @@ class jmRadarSeries extends jmSeries {
|
|
|
7431
7416
|
x: this.graph.chartArea.width / 2,
|
|
7432
7417
|
y: this.graph.chartArea.height / 2
|
|
7433
7418
|
};
|
|
7434
|
-
this.radius = Math.min(this.center.x - this.style.margin.left
|
|
7419
|
+
this.radius = Math.min(this.center.x - this.style.margin.left - this.style.margin.right, this.center.y - this.style.margin.top - this.style.margin.bottom);
|
|
7435
7420
|
const axises = this.createAxises(this.center, this.radius); // 重置所有轴
|
|
7436
7421
|
// 计算最大最小值
|
|
7437
7422
|
// 当前需要先更新axis的边界值,轴好画图
|
|
@@ -8225,7 +8210,7 @@ class jmMarkLine extends jmLine {
|
|
|
8225
8210
|
if (!p || typeof p.y === 'undefined') continue;
|
|
8226
8211
|
this.markArc = graph.createShape('circle', {
|
|
8227
8212
|
style: this.style,
|
|
8228
|
-
radius:
|
|
8213
|
+
radius: this.style.radius || 5
|
|
8229
8214
|
});
|
|
8230
8215
|
this.markArc.center.y = p.y;
|
|
8231
8216
|
this.children.add(this.markArc);
|
|
@@ -8654,7 +8639,7 @@ class jmChart extends jmGraph {
|
|
|
8654
8639
|
this.touchGraph.chartGraph = this;
|
|
8655
8640
|
this.on('propertyChange', (name, args) => {
|
|
8656
8641
|
if (['width', 'height'].includes(name)) {
|
|
8657
|
-
this.touchGraph[name] = args.newValue
|
|
8642
|
+
this.touchGraph[name] = args.newValue;
|
|
8658
8643
|
}
|
|
8659
8644
|
}); // 把上层canvse事件传递给绘图层对象
|
|
8660
8645
|
|
|
@@ -8794,10 +8779,10 @@ class jmChart extends jmGraph {
|
|
|
8794
8779
|
|
|
8795
8780
|
|
|
8796
8781
|
resetAreaPosition() {
|
|
8797
|
-
this.chartArea.position.x =
|
|
8798
|
-
this.chartArea.position.y =
|
|
8799
|
-
const w = this.width - this.style.margin.right
|
|
8800
|
-
const h = this.height - this.style.margin.bottom
|
|
8782
|
+
this.chartArea.position.x = this.style.margin.left || 0;
|
|
8783
|
+
this.chartArea.position.y = this.style.margin.top || 0;
|
|
8784
|
+
const w = this.width - this.style.margin.right - this.chartArea.position.x;
|
|
8785
|
+
const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
|
|
8801
8786
|
this.chartArea.width = w;
|
|
8802
8787
|
this.chartArea.height = h;
|
|
8803
8788
|
}
|
package/dist/jmchart.iife.js
CHANGED
|
@@ -1666,9 +1666,6 @@
|
|
|
1666
1666
|
style = style || jmUtils.clone(this.style, true);
|
|
1667
1667
|
if(!style) return;
|
|
1668
1668
|
|
|
1669
|
-
// 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
|
|
1670
|
-
let scale = this.graph.devicePixelRatio;
|
|
1671
|
-
|
|
1672
1669
|
/**
|
|
1673
1670
|
* 样式设定
|
|
1674
1671
|
*
|
|
@@ -1718,7 +1715,7 @@
|
|
|
1718
1715
|
}
|
|
1719
1716
|
|
|
1720
1717
|
// 按比例需要放大的样式
|
|
1721
|
-
if(scale && style) {
|
|
1718
|
+
/*if(scale && style) {
|
|
1722
1719
|
switch(mpname) {
|
|
1723
1720
|
case 'lineWidth': {
|
|
1724
1721
|
style *= scale;
|
|
@@ -1735,7 +1732,7 @@
|
|
|
1735
1732
|
break;
|
|
1736
1733
|
}
|
|
1737
1734
|
}
|
|
1738
|
-
}
|
|
1735
|
+
} */
|
|
1739
1736
|
this.context[mpname] = style;
|
|
1740
1737
|
}
|
|
1741
1738
|
else {
|
|
@@ -1917,10 +1914,10 @@
|
|
|
1917
1914
|
local.height = this.height;
|
|
1918
1915
|
|
|
1919
1916
|
let margin = jmUtils.clone(this.style.margin, {});
|
|
1920
|
-
margin.left = (margin.left || 0)
|
|
1921
|
-
margin.top = (margin.top || 0)
|
|
1922
|
-
margin.right = (margin.right || 0)
|
|
1923
|
-
margin.bottom = (margin.bottom || 0)
|
|
1917
|
+
margin.left = (margin.left || 0);
|
|
1918
|
+
margin.top = (margin.top || 0);
|
|
1919
|
+
margin.right = (margin.right || 0);
|
|
1920
|
+
margin.bottom = (margin.bottom || 0);
|
|
1924
1921
|
|
|
1925
1922
|
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
1926
1923
|
if(local.position) {
|
|
@@ -2439,14 +2436,7 @@
|
|
|
2439
2436
|
|
|
2440
2437
|
const srcElement = args.srcElement || args.target;
|
|
2441
2438
|
|
|
2442
|
-
const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
|
|
2443
|
-
|
|
2444
|
-
// 如果有指定scale高清处理,需要对坐标处理
|
|
2445
|
-
// 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
|
|
2446
|
-
if(graph.devicePixelRatio > 0) {
|
|
2447
|
-
position.x = position.offsetX = position.x * graph.devicePixelRatio;
|
|
2448
|
-
position.y = position.offsetY = position.y * graph.devicePixelRatio;
|
|
2449
|
-
}
|
|
2439
|
+
const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
|
|
2450
2440
|
|
|
2451
2441
|
args = {
|
|
2452
2442
|
position: position,
|
|
@@ -4722,11 +4712,19 @@
|
|
|
4722
4712
|
this.on('endDraw', function() {
|
|
4723
4713
|
this.context.translate(-0.5, -0.5);
|
|
4724
4714
|
});
|
|
4725
|
-
|
|
4715
|
+
|
|
4716
|
+
// devicePixelRatio初始化
|
|
4717
|
+
let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
|
|
4718
|
+
if(this.isWXMiniApp) {
|
|
4719
|
+
dpr = wx.getSystemInfoSync().pixelRatio || 1;
|
|
4720
|
+
}
|
|
4721
|
+
this.devicePixelRatio = dpr;
|
|
4722
|
+
// 为了解决锯齿问题,先放大canvas再缩放
|
|
4723
|
+
this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
|
|
4724
|
+
|
|
4726
4725
|
if(this.option.width > 0) this.width = this.option.width;
|
|
4727
4726
|
if(this.option.height > 0) this.height = this.option.height;
|
|
4728
|
-
|
|
4729
|
-
this.resize();
|
|
4727
|
+
this.resize();
|
|
4730
4728
|
|
|
4731
4729
|
//绑定事件
|
|
4732
4730
|
this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
|
|
@@ -4741,25 +4739,19 @@
|
|
|
4741
4739
|
|
|
4742
4740
|
// 重置canvas大小,并判断高清屏,画图先放大二倍
|
|
4743
4741
|
resize(w, h) {
|
|
4742
|
+
if(!this.canvas) return;
|
|
4744
4743
|
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
scale = wx.getSystemInfoSync().pixelRatio || 1;
|
|
4748
|
-
}
|
|
4749
|
-
else if (scale > 1) {
|
|
4750
|
-
this.__normalSize = this.__normalSize || { width: 0, height: 0};
|
|
4751
|
-
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
4744
|
+
this.__normalSize = this.__normalSize || { width: 0, height: 0};
|
|
4745
|
+
w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
|
|
4752
4746
|
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
this.devicePixelRatio = scale;
|
|
4762
|
-
}
|
|
4747
|
+
if(w) this.__normalSize.width = w;
|
|
4748
|
+
if(h) this.__normalSize.height = h;
|
|
4749
|
+
|
|
4750
|
+
this.css('width', w + "px");
|
|
4751
|
+
this.css('height', h + "px");
|
|
4752
|
+
this.canvas.height = h * this.dprScaleSize;
|
|
4753
|
+
this.canvas.width = w * this.dprScaleSize;
|
|
4754
|
+
this.context.scale(this.dprScaleSize, this.dprScaleSize);
|
|
4763
4755
|
}
|
|
4764
4756
|
|
|
4765
4757
|
/**
|
|
@@ -4767,10 +4759,10 @@
|
|
|
4767
4759
|
* @param {x, y} point 内部坐标
|
|
4768
4760
|
*/
|
|
4769
4761
|
pointToPixes(point) {
|
|
4770
|
-
if(this.
|
|
4762
|
+
if(this.dprScaleSize && this.dprScaleSize !== 1) {
|
|
4771
4763
|
point = Object.assign({}, point, {
|
|
4772
|
-
x: point.x / this.
|
|
4773
|
-
y: point.y / this.
|
|
4764
|
+
x: point.x / this.dprScaleSize,
|
|
4765
|
+
y: point.y / this.dprScaleSize
|
|
4774
4766
|
});
|
|
4775
4767
|
}
|
|
4776
4768
|
return point;
|
|
@@ -4782,13 +4774,13 @@
|
|
|
4782
4774
|
* @type {number}
|
|
4783
4775
|
*/
|
|
4784
4776
|
get width() {
|
|
4777
|
+
if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
|
|
4785
4778
|
if(this.canvas) return this.canvas.width;
|
|
4786
4779
|
return 0;
|
|
4787
4780
|
}
|
|
4788
4781
|
set width(v) {
|
|
4789
4782
|
this.needUpdate = true;
|
|
4790
4783
|
if(this.canvas) {
|
|
4791
|
-
this.canvas.width = v;
|
|
4792
4784
|
this.resize(v);
|
|
4793
4785
|
}
|
|
4794
4786
|
return v;
|
|
@@ -4800,13 +4792,13 @@
|
|
|
4800
4792
|
* @type {number}
|
|
4801
4793
|
*/
|
|
4802
4794
|
get height() {
|
|
4795
|
+
if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
|
|
4803
4796
|
if(this.canvas) return this.canvas.height;
|
|
4804
4797
|
return 0;
|
|
4805
4798
|
}
|
|
4806
4799
|
set height(v) {
|
|
4807
4800
|
this.needUpdate = true;
|
|
4808
4801
|
if(this.canvas) {
|
|
4809
|
-
this.canvas.height = v;
|
|
4810
4802
|
this.resize(0, v);
|
|
4811
4803
|
}
|
|
4812
4804
|
return v;
|
|
@@ -4965,23 +4957,13 @@
|
|
|
4965
4957
|
* @param {number} [h] 清除画布的高度
|
|
4966
4958
|
*/
|
|
4967
4959
|
clear(w, h) {
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
this.
|
|
4972
|
-
this.canvas.height = h;
|
|
4973
|
-
//保留原有缩放比例
|
|
4974
|
-
if(this.scaleSize) {
|
|
4975
|
-
if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
|
|
4976
|
-
}
|
|
4977
|
-
}
|
|
4978
|
-
else {
|
|
4979
|
-
w = this.canvas.width;
|
|
4980
|
-
h = this.canvas.height;
|
|
4981
|
-
if(this.scaleSize) {
|
|
4960
|
+
if(!w || !h) {
|
|
4961
|
+
w = this.width;
|
|
4962
|
+
h = this.height;
|
|
4963
|
+
/*if(this.scaleSize) {
|
|
4982
4964
|
w = w / this.scaleSize.x;
|
|
4983
4965
|
h = h / this.scaleSize.y;
|
|
4984
|
-
}
|
|
4966
|
+
}*/
|
|
4985
4967
|
}
|
|
4986
4968
|
//如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
|
|
4987
4969
|
if(this.style && this.style.fill) {
|
|
@@ -5126,6 +5108,9 @@
|
|
|
5126
5108
|
return;// 已销毁
|
|
5127
5109
|
}
|
|
5128
5110
|
if(self.needUpdate) self.redraw();
|
|
5111
|
+
// 触发刷新事件
|
|
5112
|
+
self.emit('update');
|
|
5113
|
+
|
|
5129
5114
|
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
5130
5115
|
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
5131
5116
|
if(callback) callback();
|
|
@@ -5728,7 +5713,7 @@
|
|
|
5728
5713
|
//字符串轴。则显示每个标签
|
|
5729
5714
|
|
|
5730
5715
|
const format = this.option.format || this.format;
|
|
5731
|
-
const top =
|
|
5716
|
+
const top = this.style.xLabel.margin.top || 0;
|
|
5732
5717
|
|
|
5733
5718
|
for (let i = 0; i < this.data.length; i++) {
|
|
5734
5719
|
const d = this.data[i];
|
|
@@ -5824,8 +5809,8 @@
|
|
|
5824
5809
|
const mm = max - min;
|
|
5825
5810
|
let pervalue = mm / count || 1;
|
|
5826
5811
|
const format = this.option.format || this.format;
|
|
5827
|
-
const marginLeft = this.style.yLabel.margin.left
|
|
5828
|
-
const marginRight = this.style.yLabel.margin.right
|
|
5812
|
+
const marginLeft = this.style.yLabel.margin.left || 0;
|
|
5813
|
+
const marginRight = this.style.yLabel.margin.right || 0;
|
|
5829
5814
|
let p = 0;
|
|
5830
5815
|
|
|
5831
5816
|
for (let i = 0; i < count + 1; i++) {
|
|
@@ -6253,13 +6238,13 @@
|
|
|
6253
6238
|
|
|
6254
6239
|
if (legendPosition == 'top' || legendPosition == 'bottom') {
|
|
6255
6240
|
//顶部和底部图例横排,每次右移位一个单位图例
|
|
6256
|
-
panel.position.x = this.width + 15
|
|
6241
|
+
panel.position.x = this.width + 15;
|
|
6257
6242
|
this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
|
|
6258
6243
|
|
|
6259
6244
|
this.height = Math.max(panel.height, this.height);
|
|
6260
6245
|
} else {
|
|
6261
6246
|
//右边和左边图例竖排
|
|
6262
|
-
panel.position.y += this.height + 5
|
|
6247
|
+
panel.position.y += this.height + 5;
|
|
6263
6248
|
this.height = panel.position.y + panel.height;
|
|
6264
6249
|
this.width = Math.max(panel.width, this.width);
|
|
6265
6250
|
}
|
|
@@ -6299,21 +6284,21 @@
|
|
|
6299
6284
|
{
|
|
6300
6285
|
this.graph.chartArea.width = this.graph.chartArea.width - this.width; //画图区域向右偏移
|
|
6301
6286
|
|
|
6302
|
-
this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right
|
|
6287
|
+
this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
|
|
6303
6288
|
break;
|
|
6304
6289
|
}
|
|
6305
6290
|
|
|
6306
6291
|
case 'top':
|
|
6307
6292
|
{
|
|
6308
6293
|
this.graph.chartArea.height = this.graph.chartArea.height - this.height;
|
|
6309
|
-
this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom
|
|
6294
|
+
this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
|
|
6310
6295
|
break;
|
|
6311
6296
|
}
|
|
6312
6297
|
|
|
6313
6298
|
case 'bottom':
|
|
6314
6299
|
{
|
|
6315
6300
|
this.graph.chartArea.height = this.graph.chartArea.height - this.height;
|
|
6316
|
-
this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top
|
|
6301
|
+
this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
|
|
6317
6302
|
break;
|
|
6318
6303
|
}
|
|
6319
6304
|
|
|
@@ -6321,7 +6306,7 @@
|
|
|
6321
6306
|
default:
|
|
6322
6307
|
{
|
|
6323
6308
|
this.graph.chartArea.width = this.graph.chartArea.width - this.width;
|
|
6324
|
-
this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left
|
|
6309
|
+
this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
|
|
6325
6310
|
break;
|
|
6326
6311
|
}
|
|
6327
6312
|
}
|
|
@@ -7068,7 +7053,7 @@
|
|
|
7068
7053
|
x: this.graph.chartArea.width / 2,
|
|
7069
7054
|
y: this.graph.chartArea.height / 2
|
|
7070
7055
|
};
|
|
7071
|
-
const radius = Math.min(center.x - this.style.margin.left
|
|
7056
|
+
const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right, center.y - this.style.margin.top - this.style.margin.bottom); //生成描点位
|
|
7072
7057
|
// super.init会把参数透传给 createPoints
|
|
7073
7058
|
|
|
7074
7059
|
const {
|
|
@@ -7434,7 +7419,7 @@
|
|
|
7434
7419
|
x: this.graph.chartArea.width / 2,
|
|
7435
7420
|
y: this.graph.chartArea.height / 2
|
|
7436
7421
|
};
|
|
7437
|
-
this.radius = Math.min(this.center.x - this.style.margin.left
|
|
7422
|
+
this.radius = Math.min(this.center.x - this.style.margin.left - this.style.margin.right, this.center.y - this.style.margin.top - this.style.margin.bottom);
|
|
7438
7423
|
const axises = this.createAxises(this.center, this.radius); // 重置所有轴
|
|
7439
7424
|
// 计算最大最小值
|
|
7440
7425
|
// 当前需要先更新axis的边界值,轴好画图
|
|
@@ -8228,7 +8213,7 @@
|
|
|
8228
8213
|
if (!p || typeof p.y === 'undefined') continue;
|
|
8229
8214
|
this.markArc = graph.createShape('circle', {
|
|
8230
8215
|
style: this.style,
|
|
8231
|
-
radius:
|
|
8216
|
+
radius: this.style.radius || 5
|
|
8232
8217
|
});
|
|
8233
8218
|
this.markArc.center.y = p.y;
|
|
8234
8219
|
this.children.add(this.markArc);
|
|
@@ -8657,7 +8642,7 @@
|
|
|
8657
8642
|
this.touchGraph.chartGraph = this;
|
|
8658
8643
|
this.on('propertyChange', (name, args) => {
|
|
8659
8644
|
if (['width', 'height'].includes(name)) {
|
|
8660
|
-
this.touchGraph[name] = args.newValue
|
|
8645
|
+
this.touchGraph[name] = args.newValue;
|
|
8661
8646
|
}
|
|
8662
8647
|
}); // 把上层canvse事件传递给绘图层对象
|
|
8663
8648
|
|
|
@@ -8797,10 +8782,10 @@
|
|
|
8797
8782
|
|
|
8798
8783
|
|
|
8799
8784
|
resetAreaPosition() {
|
|
8800
|
-
this.chartArea.position.x =
|
|
8801
|
-
this.chartArea.position.y =
|
|
8802
|
-
const w = this.width - this.style.margin.right
|
|
8803
|
-
const h = this.height - this.style.margin.bottom
|
|
8785
|
+
this.chartArea.position.x = this.style.margin.left || 0;
|
|
8786
|
+
this.chartArea.position.y = this.style.margin.top || 0;
|
|
8787
|
+
const w = this.width - this.style.margin.right - this.chartArea.position.x;
|
|
8788
|
+
const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
|
|
8804
8789
|
this.chartArea.width = w;
|
|
8805
8790
|
this.chartArea.height = h;
|
|
8806
8791
|
}
|