jmchart 1.2.1 → 1.2.3
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 +95 -122
- package/dist/jmchart.cjs.js +95 -122
- package/dist/jmchart.esm.js +95 -122
- package/dist/jmchart.iife.js +95 -122
- package/dist/jmchart.system.js +95 -122
- package/package.json +2 -2
- package/src/core/markLine/manager.js +2 -2
- package/src/core/markLine/markLine.js +1 -1
- package/src/series/barSeries.js +1 -1
- package/src/series/lineSeries.js +1 -1
- package/src/series/pieSeries.js +1 -1
- package/src/series/stackBarSeries.js +1 -1
- package/src/series/stackLineSeries.js +1 -1
package/dist/jmchart.esm.js
CHANGED
|
@@ -872,21 +872,13 @@ class jmUtils {
|
|
|
872
872
|
return r;
|
|
873
873
|
}
|
|
874
874
|
// window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
|
|
875
|
-
static requestAnimationFrame(callback) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
return requestAnimationFrame(callback);
|
|
881
|
-
}
|
|
875
|
+
static requestAnimationFrame(callback, win) {
|
|
876
|
+
let fun = win && win.requestAnimationFrame? win.requestAnimationFrame: (typeof window !== 'undefined' && window.requestAnimationFrame? window.requestAnimationFrame: setTimeout);
|
|
877
|
+
return fun(callback, 20);
|
|
882
878
|
}
|
|
883
|
-
static cancelAnimationFrame(handler) {
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
else {
|
|
888
|
-
return cancelAnimationFrame(handler);
|
|
889
|
-
}
|
|
879
|
+
static cancelAnimationFrame(handler, win) {
|
|
880
|
+
let fun = win && win.cancelAnimationFrame? win.cancelAnimationFrame: (typeof window !== 'undefined' && window.cancelAnimationFrame? window.cancelAnimationFrame: clearTimeout);
|
|
881
|
+
return fun(handler);
|
|
890
882
|
}
|
|
891
883
|
}
|
|
892
884
|
|
|
@@ -1325,8 +1317,48 @@ class jmProperty extends jmObject {
|
|
|
1325
1317
|
set graph(v) {
|
|
1326
1318
|
return this.__pro('graph', v);
|
|
1327
1319
|
}
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* 在下次进行重绘时执行
|
|
1323
|
+
* @param {Function} handler
|
|
1324
|
+
*/
|
|
1325
|
+
requestAnimationFrame(handler) {
|
|
1326
|
+
return jmUtils.requestAnimationFrame(handler, this.graph? this.graph.canvas: null);
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* 清除执行回调
|
|
1330
|
+
* @param {Function} handler
|
|
1331
|
+
* @returns
|
|
1332
|
+
*/
|
|
1333
|
+
cancelAnimationFrame(handler) {
|
|
1334
|
+
return jmUtils.cancelAnimationFrame(handler, this.graph? this.graph.canvas: null);
|
|
1335
|
+
}
|
|
1328
1336
|
}
|
|
1329
1337
|
|
|
1338
|
+
//样式名称,也当做白名单使用
|
|
1339
|
+
const jmStyleMap = {
|
|
1340
|
+
'fill':'fillStyle',
|
|
1341
|
+
'stroke':'strokeStyle',
|
|
1342
|
+
'shadow.blur':'shadowBlur',
|
|
1343
|
+
'shadow.x':'shadowOffsetX',
|
|
1344
|
+
'shadow.y':'shadowOffsetY',
|
|
1345
|
+
'shadow.color':'shadowColor',
|
|
1346
|
+
'lineWidth' : 'lineWidth',
|
|
1347
|
+
'miterLimit': 'miterLimit',
|
|
1348
|
+
'fillStyle' : 'fillStyle',
|
|
1349
|
+
'strokeStyle' : 'strokeStyle',
|
|
1350
|
+
'font' : 'font',
|
|
1351
|
+
'opacity' : 'globalAlpha',
|
|
1352
|
+
'textAlign' : 'textAlign',
|
|
1353
|
+
'textBaseline' : 'textBaseline',
|
|
1354
|
+
'shadowBlur' : 'shadowBlur',
|
|
1355
|
+
'shadowOffsetX' : 'shadowOffsetX',
|
|
1356
|
+
'shadowOffsetY' : 'shadowOffsetY',
|
|
1357
|
+
'shadowColor' : 'shadowColor',
|
|
1358
|
+
'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
|
|
1359
|
+
'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1330
1362
|
/**
|
|
1331
1363
|
* 控件基础对象
|
|
1332
1364
|
* 控件的基础属性和方法
|
|
@@ -1353,30 +1385,6 @@ class jmControl extends jmProperty {
|
|
|
1353
1385
|
this.zIndex = params.zIndex || 0;
|
|
1354
1386
|
this.interactive = typeof params.interactive == 'undefined'? true : params.interactive;
|
|
1355
1387
|
|
|
1356
|
-
//样式名称,也当做白名单使用
|
|
1357
|
-
this.jmStyleMap = {
|
|
1358
|
-
'fill':'fillStyle',
|
|
1359
|
-
'stroke':'strokeStyle',
|
|
1360
|
-
'shadow.blur':'shadowBlur',
|
|
1361
|
-
'shadow.x':'shadowOffsetX',
|
|
1362
|
-
'shadow.y':'shadowOffsetY',
|
|
1363
|
-
'shadow.color':'shadowColor',
|
|
1364
|
-
'lineWidth' : 'lineWidth',
|
|
1365
|
-
'miterLimit': 'miterLimit',
|
|
1366
|
-
'fillStyle' : 'fillStyle',
|
|
1367
|
-
'strokeStyle' : 'strokeStyle',
|
|
1368
|
-
'font' : 'font',
|
|
1369
|
-
'opacity' : 'globalAlpha',
|
|
1370
|
-
'textAlign' : 'textAlign',
|
|
1371
|
-
'textBaseline' : 'textBaseline',
|
|
1372
|
-
'shadowBlur' : 'shadowBlur',
|
|
1373
|
-
'shadowOffsetX' : 'shadowOffsetX',
|
|
1374
|
-
'shadowOffsetY' : 'shadowOffsetY',
|
|
1375
|
-
'shadowColor' : 'shadowColor',
|
|
1376
|
-
'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
|
|
1377
|
-
'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
|
|
1378
|
-
};
|
|
1379
|
-
|
|
1380
1388
|
this.initializing();
|
|
1381
1389
|
|
|
1382
1390
|
this.on = this.bind;
|
|
@@ -1674,120 +1682,93 @@ class jmControl extends jmProperty {
|
|
|
1674
1682
|
* @param {string} mpkey 样式名称在映射中的key(例如:shadow.blur为模糊值)
|
|
1675
1683
|
*/
|
|
1676
1684
|
let __setStyle = (style, name, mpkey) => {
|
|
1677
|
-
|
|
1678
|
-
if(style) {
|
|
1679
|
-
|
|
1685
|
+
|
|
1686
|
+
if(style) {
|
|
1687
|
+
let styleValue = style;
|
|
1688
|
+
if(typeof styleValue === 'function') {
|
|
1680
1689
|
try {
|
|
1681
|
-
|
|
1690
|
+
styleValue = styleValue.call(this);
|
|
1682
1691
|
}
|
|
1683
1692
|
catch(e) {
|
|
1684
1693
|
console.warn(e);
|
|
1685
1694
|
return;
|
|
1686
1695
|
}
|
|
1687
1696
|
}
|
|
1688
|
-
let t = typeof
|
|
1689
|
-
let mpname =
|
|
1697
|
+
let t = typeof styleValue;
|
|
1698
|
+
let mpname = jmStyleMap[mpkey || name];
|
|
1690
1699
|
|
|
1691
1700
|
//如果为渐变对象
|
|
1692
|
-
if((
|
|
1701
|
+
if((styleValue instanceof jmGradient) || (t == 'string' && styleValue.indexOf('-gradient') > -1)) {
|
|
1693
1702
|
//如果是渐变,则需要转换
|
|
1694
|
-
if(t == 'string' &&
|
|
1695
|
-
|
|
1696
|
-
}
|
|
1697
|
-
__setStyle(style.toGradient(this), mpname||name);
|
|
1698
|
-
}
|
|
1699
|
-
else if(t == 'function') {
|
|
1700
|
-
if(mpname) {
|
|
1701
|
-
style = style.call(this, mpname);
|
|
1702
|
-
if(style) {
|
|
1703
|
-
__setStyle(style, mpname);
|
|
1704
|
-
}
|
|
1703
|
+
if(t == 'string' && styleValue.indexOf('-gradient') > -1) {
|
|
1704
|
+
styleValue = new jmGradient(styleValue);
|
|
1705
1705
|
}
|
|
1706
|
+
__setStyle(styleValue.toGradient(this), mpname||name);
|
|
1706
1707
|
}
|
|
1707
1708
|
else if(mpname) {
|
|
1708
1709
|
//只有存在白名单中才处理
|
|
1709
1710
|
//颜色转换
|
|
1710
1711
|
if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
|
|
1711
|
-
|
|
1712
|
+
styleValue = jmUtils.toColor(styleValue);
|
|
1712
1713
|
}
|
|
1713
|
-
|
|
1714
|
-
// 按比例需要放大的样式
|
|
1715
|
-
/*if(scale && style) {
|
|
1716
|
-
switch(mpname) {
|
|
1717
|
-
case 'lineWidth': {
|
|
1718
|
-
style *= scale;
|
|
1719
|
-
break;
|
|
1720
|
-
}
|
|
1721
|
-
// 字体放大
|
|
1722
|
-
case 'fontSize':
|
|
1723
|
-
case 'font': {
|
|
1724
|
-
const ms = style.toString().match(/[\d\.]+/);
|
|
1725
|
-
if(ms && ms.length) {
|
|
1726
|
-
const size = Number(ms[0]) * scale;
|
|
1727
|
-
style = style.toString().replace(ms[0], size);
|
|
1728
|
-
}
|
|
1729
|
-
break;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
} */
|
|
1733
|
-
this.context[mpname] = style;
|
|
1714
|
+
this.context[mpname] = styleValue;
|
|
1734
1715
|
}
|
|
1735
1716
|
else {
|
|
1736
1717
|
switch(name) {
|
|
1737
1718
|
//阴影样式
|
|
1738
1719
|
case 'shadow' : {
|
|
1739
1720
|
if(t == 'string') {
|
|
1740
|
-
__setStyle(new jmShadow(
|
|
1721
|
+
__setStyle(new jmShadow(styleValue), name);
|
|
1741
1722
|
break;
|
|
1742
1723
|
}
|
|
1743
|
-
for(let k in
|
|
1744
|
-
__setStyle(
|
|
1724
|
+
for(let k in styleValue) {
|
|
1725
|
+
__setStyle(styleValue[k], k, name + '.' + k);
|
|
1745
1726
|
}
|
|
1746
1727
|
break;
|
|
1747
1728
|
}
|
|
1748
1729
|
//平移
|
|
1749
1730
|
case 'translate' : {
|
|
1750
|
-
this.context.translate(
|
|
1731
|
+
this.context.translate(styleValue.x, styleValue.y);
|
|
1751
1732
|
break;
|
|
1752
1733
|
}
|
|
1753
1734
|
//旋转
|
|
1754
1735
|
case 'rotation' : {
|
|
1755
|
-
if(!
|
|
1736
|
+
if(!styleValue.angle) break;
|
|
1756
1737
|
//旋 转先移位偏移量
|
|
1757
1738
|
let tranX = 0;
|
|
1758
1739
|
let tranY = 0;
|
|
1759
1740
|
//旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
|
|
1760
1741
|
//这里只有style中的旋转才能生效,不然会导至子控件多次旋转
|
|
1761
|
-
if(
|
|
1742
|
+
if(styleValue.point) {
|
|
1762
1743
|
let bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
|
|
1763
|
-
|
|
1744
|
+
styleValue = this.getRotation(styleValue);
|
|
1764
1745
|
|
|
1765
|
-
tranX =
|
|
1766
|
-
tranY =
|
|
1746
|
+
tranX = styleValue.rotateX + bounds.left;
|
|
1747
|
+
tranY = styleValue.rotateY + bounds.top;
|
|
1767
1748
|
}
|
|
1768
1749
|
|
|
1769
1750
|
if(tranX!=0 || tranY != 0) this.context.translate(tranX,tranY);
|
|
1770
|
-
this.context.rotate(
|
|
1751
|
+
this.context.rotate(styleValue.angle);
|
|
1771
1752
|
if(tranX!=0 || tranY != 0) this.context.translate(-tranX,-tranY);
|
|
1772
1753
|
break;
|
|
1773
1754
|
}
|
|
1774
1755
|
case 'transform' : {
|
|
1775
|
-
if(Array.isArray(
|
|
1776
|
-
this.context.transform.apply(this.context,
|
|
1756
|
+
if(Array.isArray(styleValue)) {
|
|
1757
|
+
this.context.transform.apply(this.context, styleValue);
|
|
1777
1758
|
}
|
|
1778
|
-
else if(typeof
|
|
1779
|
-
this.context.transform(
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1759
|
+
else if(typeof styleValue == 'object') {
|
|
1760
|
+
this.context.transform(styleValue.scaleX,//水平缩放
|
|
1761
|
+
styleValue.skewX,//水平倾斜
|
|
1762
|
+
styleValue.skewY,//垂直倾斜
|
|
1763
|
+
styleValue.scaleY,//垂直缩放
|
|
1764
|
+
styleValue.offsetX,//水平位移
|
|
1765
|
+
styleValue.offsetY);//垂直位移
|
|
1785
1766
|
}
|
|
1786
1767
|
break;
|
|
1787
1768
|
}
|
|
1788
1769
|
//鼠标指针
|
|
1789
1770
|
case 'cursor' : {
|
|
1790
|
-
this.cursor =
|
|
1771
|
+
this.cursor = styleValue;
|
|
1791
1772
|
break;
|
|
1792
1773
|
}
|
|
1793
1774
|
}
|
|
@@ -1836,9 +1817,6 @@ class jmControl extends jmProperty {
|
|
|
1836
1817
|
if(typeof this.canvas.width === 'function') {
|
|
1837
1818
|
rect.right = this.canvas.width();
|
|
1838
1819
|
}
|
|
1839
|
-
else if(this.canvas.width) {
|
|
1840
|
-
rect.right = this.canvas.width;
|
|
1841
|
-
}
|
|
1842
1820
|
else if(this.width) {
|
|
1843
1821
|
rect.right = this.width;
|
|
1844
1822
|
}
|
|
@@ -1846,9 +1824,6 @@ class jmControl extends jmProperty {
|
|
|
1846
1824
|
if(typeof this.canvas.height === 'function') {
|
|
1847
1825
|
rect.bottom = this.canvas.height();
|
|
1848
1826
|
}
|
|
1849
|
-
else if(this.canvas.height) {
|
|
1850
|
-
rect.bottom = this.canvas.height;
|
|
1851
|
-
}
|
|
1852
1827
|
else if(this.height) {
|
|
1853
1828
|
rect.bottom = this.height;
|
|
1854
1829
|
}
|
|
@@ -2222,8 +2197,6 @@ class jmControl extends jmProperty {
|
|
|
2222
2197
|
this.emit('endDraw',this);
|
|
2223
2198
|
this.context.restore();
|
|
2224
2199
|
|
|
2225
|
-
//兼容小程序
|
|
2226
|
-
if(this.is('jmGraph') && this.context.draw) this.context.draw();
|
|
2227
2200
|
this.needUpdate = false;
|
|
2228
2201
|
}
|
|
2229
2202
|
}
|
|
@@ -2343,8 +2316,8 @@ class jmControl extends jmProperty {
|
|
|
2343
2316
|
//获取dom位置
|
|
2344
2317
|
let position = this.getPosition();
|
|
2345
2318
|
// 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
|
|
2346
|
-
const right = position.left +
|
|
2347
|
-
const bottom = position.top +
|
|
2319
|
+
const right = position.left + this.width;
|
|
2320
|
+
const bottom = position.top + this.height;
|
|
2348
2321
|
if(p.pageX > right || p.pageX < position.left) {
|
|
2349
2322
|
return false;
|
|
2350
2323
|
}
|
|
@@ -4819,8 +4792,8 @@ class jmGraph$1 extends jmControl {
|
|
|
4819
4792
|
*/
|
|
4820
4793
|
getPosition() {
|
|
4821
4794
|
let p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
|
|
4822
|
-
p.width = this.
|
|
4823
|
-
p.height = this.
|
|
4795
|
+
p.width = this.width;
|
|
4796
|
+
p.height = this.height;
|
|
4824
4797
|
p.right = p.left + p.width;
|
|
4825
4798
|
p.bottom = p.top + p.height;
|
|
4826
4799
|
return p;
|
|
@@ -5108,12 +5081,12 @@ class jmGraph$1 extends jmControl {
|
|
|
5108
5081
|
// 触发刷新事件
|
|
5109
5082
|
self.emit('update');
|
|
5110
5083
|
|
|
5111
|
-
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
5112
|
-
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
5084
|
+
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
|
|
5085
|
+
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
|
|
5113
5086
|
if(callback) callback();
|
|
5114
5087
|
}
|
|
5115
|
-
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
5116
|
-
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
5088
|
+
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
|
|
5089
|
+
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
|
|
5117
5090
|
return this;
|
|
5118
5091
|
}
|
|
5119
5092
|
|
|
@@ -6820,7 +6793,7 @@ class jmBarSeries extends jmSeries {
|
|
|
6820
6793
|
} else {
|
|
6821
6794
|
this.___animateCounter++; // next tick 再次刷新
|
|
6822
6795
|
|
|
6823
|
-
|
|
6796
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
6824
6797
|
this.needUpdate = true; //需要刷新
|
|
6825
6798
|
});
|
|
6826
6799
|
}
|
|
@@ -6972,7 +6945,7 @@ class jmStackBarSeries extends jmBarSeries {
|
|
|
6972
6945
|
} else {
|
|
6973
6946
|
this.___animateCounter++; // next tick 再次刷新
|
|
6974
6947
|
|
|
6975
|
-
|
|
6948
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
6976
6949
|
this.needUpdate = true; //需要刷新
|
|
6977
6950
|
});
|
|
6978
6951
|
}
|
|
@@ -7088,7 +7061,7 @@ class jmPieSeries extends jmSeries {
|
|
|
7088
7061
|
} else {
|
|
7089
7062
|
this.___animateCounter++; // next tick 再次刷新
|
|
7090
7063
|
|
|
7091
|
-
|
|
7064
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
7092
7065
|
this.needUpdate = true; //需要刷新
|
|
7093
7066
|
});
|
|
7094
7067
|
}
|
|
@@ -7730,7 +7703,7 @@ class jmLineSeries extends jmSeries {
|
|
|
7730
7703
|
} else if (isRunningAni) {
|
|
7731
7704
|
this.___animateCounter += aniStep; // next tick 再次刷新
|
|
7732
7705
|
|
|
7733
|
-
|
|
7706
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
7734
7707
|
this.needUpdate = true; //需要刷新
|
|
7735
7708
|
});
|
|
7736
7709
|
}
|
|
@@ -7977,7 +7950,7 @@ class jmStackLineSeries extends jmLineSeries {
|
|
|
7977
7950
|
} else if (isRunningAni) {
|
|
7978
7951
|
this.___animateCounter += aniStep; // next tick 再次刷新
|
|
7979
7952
|
|
|
7980
|
-
|
|
7953
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
7981
7954
|
this.needUpdate = true; //需要刷新
|
|
7982
7955
|
});
|
|
7983
7956
|
}
|
|
@@ -8232,7 +8205,7 @@ class jmMarkLine extends jmLine {
|
|
|
8232
8205
|
} // 触发touch数据点改变事件
|
|
8233
8206
|
|
|
8234
8207
|
|
|
8235
|
-
touchChange &&
|
|
8208
|
+
touchChange && this.graph.utils.requestAnimationFrame(() => {
|
|
8236
8209
|
graph.emit('touchPointChange', {
|
|
8237
8210
|
points: touchPoints
|
|
8238
8211
|
});
|
|
@@ -8424,14 +8397,14 @@ class jmMarkLineManager {
|
|
|
8424
8397
|
else lineTouching = 1;
|
|
8425
8398
|
}
|
|
8426
8399
|
|
|
8427
|
-
args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
|
|
8400
|
+
args.event && args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
|
|
8428
8401
|
|
|
8429
8402
|
if (chart.style.markLine.lock) {
|
|
8430
8403
|
// 标线状态一直禁用系统能力
|
|
8431
8404
|
// 如果指定了锁定值,只需要一项符合要求就进行锁定
|
|
8432
8405
|
if (lineTouching === 0 && (chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y || chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x) || lineTouching === 1) {
|
|
8433
8406
|
lineTouching = 1;
|
|
8434
|
-
args.event.preventDefault(); // 阻止默认行为
|
|
8407
|
+
args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
|
|
8435
8408
|
}
|
|
8436
8409
|
}
|
|
8437
8410
|
|