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.
@@ -876,21 +876,13 @@ class jmUtils {
876
876
  return r;
877
877
  }
878
878
  // window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
879
- static requestAnimationFrame(callback) {
880
- if(typeof requestAnimationFrame === 'undefined') {
881
- return setTimeout(callback, 20);
882
- }
883
- else {
884
- return requestAnimationFrame(callback);
885
- }
879
+ static requestAnimationFrame(callback, win) {
880
+ let fun = win && win.requestAnimationFrame? win.requestAnimationFrame: (typeof window !== 'undefined' && window.requestAnimationFrame? window.requestAnimationFrame: setTimeout);
881
+ return fun(callback, 20);
886
882
  }
887
- static cancelAnimationFrame(handler) {
888
- if(typeof requestAnimationFrame === 'undefined') {
889
- return clearTimeout(handler);
890
- }
891
- else {
892
- return cancelAnimationFrame(handler);
893
- }
883
+ static cancelAnimationFrame(handler, win) {
884
+ let fun = win && win.cancelAnimationFrame? win.cancelAnimationFrame: (typeof window !== 'undefined' && window.cancelAnimationFrame? window.cancelAnimationFrame: clearTimeout);
885
+ return fun(handler);
894
886
  }
895
887
  }
896
888
 
@@ -1329,8 +1321,48 @@ class jmProperty extends jmObject {
1329
1321
  set graph(v) {
1330
1322
  return this.__pro('graph', v);
1331
1323
  }
1324
+
1325
+ /**
1326
+ * 在下次进行重绘时执行
1327
+ * @param {Function} handler
1328
+ */
1329
+ requestAnimationFrame(handler) {
1330
+ return jmUtils.requestAnimationFrame(handler, this.graph? this.graph.canvas: null);
1331
+ }
1332
+ /**
1333
+ * 清除执行回调
1334
+ * @param {Function} handler
1335
+ * @returns
1336
+ */
1337
+ cancelAnimationFrame(handler) {
1338
+ return jmUtils.cancelAnimationFrame(handler, this.graph? this.graph.canvas: null);
1339
+ }
1332
1340
  }
1333
1341
 
1342
+ //样式名称,也当做白名单使用
1343
+ const jmStyleMap = {
1344
+ 'fill':'fillStyle',
1345
+ 'stroke':'strokeStyle',
1346
+ 'shadow.blur':'shadowBlur',
1347
+ 'shadow.x':'shadowOffsetX',
1348
+ 'shadow.y':'shadowOffsetY',
1349
+ 'shadow.color':'shadowColor',
1350
+ 'lineWidth' : 'lineWidth',
1351
+ 'miterLimit': 'miterLimit',
1352
+ 'fillStyle' : 'fillStyle',
1353
+ 'strokeStyle' : 'strokeStyle',
1354
+ 'font' : 'font',
1355
+ 'opacity' : 'globalAlpha',
1356
+ 'textAlign' : 'textAlign',
1357
+ 'textBaseline' : 'textBaseline',
1358
+ 'shadowBlur' : 'shadowBlur',
1359
+ 'shadowOffsetX' : 'shadowOffsetX',
1360
+ 'shadowOffsetY' : 'shadowOffsetY',
1361
+ 'shadowColor' : 'shadowColor',
1362
+ 'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
1363
+ 'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
1364
+ };
1365
+
1334
1366
  /**
1335
1367
  * 控件基础对象
1336
1368
  * 控件的基础属性和方法
@@ -1357,30 +1389,6 @@ class jmControl extends jmProperty {
1357
1389
  this.zIndex = params.zIndex || 0;
1358
1390
  this.interactive = typeof params.interactive == 'undefined'? true : params.interactive;
1359
1391
 
1360
- //样式名称,也当做白名单使用
1361
- this.jmStyleMap = {
1362
- 'fill':'fillStyle',
1363
- 'stroke':'strokeStyle',
1364
- 'shadow.blur':'shadowBlur',
1365
- 'shadow.x':'shadowOffsetX',
1366
- 'shadow.y':'shadowOffsetY',
1367
- 'shadow.color':'shadowColor',
1368
- 'lineWidth' : 'lineWidth',
1369
- 'miterLimit': 'miterLimit',
1370
- 'fillStyle' : 'fillStyle',
1371
- 'strokeStyle' : 'strokeStyle',
1372
- 'font' : 'font',
1373
- 'opacity' : 'globalAlpha',
1374
- 'textAlign' : 'textAlign',
1375
- 'textBaseline' : 'textBaseline',
1376
- 'shadowBlur' : 'shadowBlur',
1377
- 'shadowOffsetX' : 'shadowOffsetX',
1378
- 'shadowOffsetY' : 'shadowOffsetY',
1379
- 'shadowColor' : 'shadowColor',
1380
- 'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
1381
- 'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
1382
- };
1383
-
1384
1392
  this.initializing();
1385
1393
 
1386
1394
  this.on = this.bind;
@@ -1678,120 +1686,93 @@ class jmControl extends jmProperty {
1678
1686
  * @param {string} mpkey 样式名称在映射中的key(例如:shadow.blur为模糊值)
1679
1687
  */
1680
1688
  let __setStyle = (style, name, mpkey) => {
1681
- //let styleValue = style[mpkey||name]||style;
1682
- if(style) {
1683
- if(typeof style === 'function') {
1689
+
1690
+ if(style) {
1691
+ let styleValue = style;
1692
+ if(typeof styleValue === 'function') {
1684
1693
  try {
1685
- style = style.call(this);
1694
+ styleValue = styleValue.call(this);
1686
1695
  }
1687
1696
  catch(e) {
1688
1697
  console.warn(e);
1689
1698
  return;
1690
1699
  }
1691
1700
  }
1692
- let t = typeof style;
1693
- let mpname = this.jmStyleMap[mpkey || name];
1701
+ let t = typeof styleValue;
1702
+ let mpname = jmStyleMap[mpkey || name];
1694
1703
 
1695
1704
  //如果为渐变对象
1696
- if((style instanceof jmGradient) || (t == 'string' && style.indexOf('-gradient') > -1)) {
1705
+ if((styleValue instanceof jmGradient) || (t == 'string' && styleValue.indexOf('-gradient') > -1)) {
1697
1706
  //如果是渐变,则需要转换
1698
- if(t == 'string' && style.indexOf('-gradient') > -1) {
1699
- style = new jmGradient(style);
1700
- }
1701
- __setStyle(style.toGradient(this), mpname||name);
1702
- }
1703
- else if(t == 'function') {
1704
- if(mpname) {
1705
- style = style.call(this, mpname);
1706
- if(style) {
1707
- __setStyle(style, mpname);
1708
- }
1707
+ if(t == 'string' && styleValue.indexOf('-gradient') > -1) {
1708
+ styleValue = new jmGradient(styleValue);
1709
1709
  }
1710
+ __setStyle(styleValue.toGradient(this), mpname||name);
1710
1711
  }
1711
1712
  else if(mpname) {
1712
1713
  //只有存在白名单中才处理
1713
1714
  //颜色转换
1714
1715
  if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
1715
- style = jmUtils.toColor(style);
1716
+ styleValue = jmUtils.toColor(styleValue);
1716
1717
  }
1717
-
1718
- // 按比例需要放大的样式
1719
- /*if(scale && style) {
1720
- switch(mpname) {
1721
- case 'lineWidth': {
1722
- style *= scale;
1723
- break;
1724
- }
1725
- // 字体放大
1726
- case 'fontSize':
1727
- case 'font': {
1728
- const ms = style.toString().match(/[\d\.]+/);
1729
- if(ms && ms.length) {
1730
- const size = Number(ms[0]) * scale;
1731
- style = style.toString().replace(ms[0], size);
1732
- }
1733
- break;
1734
- }
1735
- }
1736
- } */
1737
- this.context[mpname] = style;
1718
+ this.context[mpname] = styleValue;
1738
1719
  }
1739
1720
  else {
1740
1721
  switch(name) {
1741
1722
  //阴影样式
1742
1723
  case 'shadow' : {
1743
1724
  if(t == 'string') {
1744
- __setStyle(new jmShadow(style), name);
1725
+ __setStyle(new jmShadow(styleValue), name);
1745
1726
  break;
1746
1727
  }
1747
- for(let k in style) {
1748
- __setStyle(style[k], k, name + '.' + k);
1728
+ for(let k in styleValue) {
1729
+ __setStyle(styleValue[k], k, name + '.' + k);
1749
1730
  }
1750
1731
  break;
1751
1732
  }
1752
1733
  //平移
1753
1734
  case 'translate' : {
1754
- this.context.translate(style.x,style.y);
1735
+ this.context.translate(styleValue.x, styleValue.y);
1755
1736
  break;
1756
1737
  }
1757
1738
  //旋转
1758
1739
  case 'rotation' : {
1759
- if(!style.angle) break;
1740
+ if(!styleValue.angle) break;
1760
1741
  //旋 转先移位偏移量
1761
1742
  let tranX = 0;
1762
1743
  let tranY = 0;
1763
1744
  //旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
1764
1745
  //这里只有style中的旋转才能生效,不然会导至子控件多次旋转
1765
- if(style.point) {
1746
+ if(styleValue.point) {
1766
1747
  let bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
1767
- style = this.getRotation(style);
1748
+ styleValue = this.getRotation(styleValue);
1768
1749
 
1769
- tranX = style.rotateX + bounds.left;
1770
- tranY = style.rotateY + bounds.top;
1750
+ tranX = styleValue.rotateX + bounds.left;
1751
+ tranY = styleValue.rotateY + bounds.top;
1771
1752
  }
1772
1753
 
1773
1754
  if(tranX!=0 || tranY != 0) this.context.translate(tranX,tranY);
1774
- this.context.rotate(style.angle);
1755
+ this.context.rotate(styleValue.angle);
1775
1756
  if(tranX!=0 || tranY != 0) this.context.translate(-tranX,-tranY);
1776
1757
  break;
1777
1758
  }
1778
1759
  case 'transform' : {
1779
- if(Array.isArray(style)) {
1780
- this.context.transform.apply(this.context, style);
1760
+ if(Array.isArray(styleValue)) {
1761
+ this.context.transform.apply(this.context, styleValue);
1781
1762
  }
1782
- else if(typeof style == 'object') {
1783
- this.context.transform(style.scaleX,//水平缩放
1784
- style.skewX,//水平倾斜
1785
- style.skewY,//垂直倾斜
1786
- style.scaleY,//垂直缩放
1787
- style.offsetX,//水平位移
1788
- style.offsetY);//垂直位移
1763
+ else if(typeof styleValue == 'object') {
1764
+ this.context.transform(styleValue.scaleX,//水平缩放
1765
+ styleValue.skewX,//水平倾斜
1766
+ styleValue.skewY,//垂直倾斜
1767
+ styleValue.scaleY,//垂直缩放
1768
+ styleValue.offsetX,//水平位移
1769
+ styleValue.offsetY);//垂直位移
1789
1770
  }
1790
1771
  break;
1791
1772
  }
1792
1773
  //鼠标指针
1793
1774
  case 'cursor' : {
1794
- this.cursor = style;
1775
+ this.cursor = styleValue;
1795
1776
  break;
1796
1777
  }
1797
1778
  }
@@ -1840,9 +1821,6 @@ class jmControl extends jmProperty {
1840
1821
  if(typeof this.canvas.width === 'function') {
1841
1822
  rect.right = this.canvas.width();
1842
1823
  }
1843
- else if(this.canvas.width) {
1844
- rect.right = this.canvas.width;
1845
- }
1846
1824
  else if(this.width) {
1847
1825
  rect.right = this.width;
1848
1826
  }
@@ -1850,9 +1828,6 @@ class jmControl extends jmProperty {
1850
1828
  if(typeof this.canvas.height === 'function') {
1851
1829
  rect.bottom = this.canvas.height();
1852
1830
  }
1853
- else if(this.canvas.height) {
1854
- rect.bottom = this.canvas.height;
1855
- }
1856
1831
  else if(this.height) {
1857
1832
  rect.bottom = this.height;
1858
1833
  }
@@ -2226,8 +2201,6 @@ class jmControl extends jmProperty {
2226
2201
  this.emit('endDraw',this);
2227
2202
  this.context.restore();
2228
2203
 
2229
- //兼容小程序
2230
- if(this.is('jmGraph') && this.context.draw) this.context.draw();
2231
2204
  this.needUpdate = false;
2232
2205
  }
2233
2206
  }
@@ -2347,8 +2320,8 @@ class jmControl extends jmProperty {
2347
2320
  //获取dom位置
2348
2321
  let position = this.getPosition();
2349
2322
  // 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
2350
- const right = position.left + (this.canvas.clientWidth || this.canvas.offsetWidth || this.canvas.width);
2351
- const bottom = position.top + (this.canvas.clientHeight || this.canvas.offsetHeight || this.canvas.height);
2323
+ const right = position.left + this.width;
2324
+ const bottom = position.top + this.height;
2352
2325
  if(p.pageX > right || p.pageX < position.left) {
2353
2326
  return false;
2354
2327
  }
@@ -4823,8 +4796,8 @@ class jmGraph$1 extends jmControl {
4823
4796
  */
4824
4797
  getPosition() {
4825
4798
  let p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
4826
- p.width = this.canvas.width;
4827
- p.height = this.canvas.height;
4799
+ p.width = this.width;
4800
+ p.height = this.height;
4828
4801
  p.right = p.left + p.width;
4829
4802
  p.bottom = p.top + p.height;
4830
4803
  return p;
@@ -5112,12 +5085,12 @@ class jmGraph$1 extends jmControl {
5112
5085
  // 触发刷新事件
5113
5086
  self.emit('update');
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
  if(callback) callback();
5118
5091
  }
5119
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5120
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5092
+ self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5093
+ self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5121
5094
  return this;
5122
5095
  }
5123
5096
 
@@ -6824,7 +6797,7 @@ class jmBarSeries extends jmSeries {
6824
6797
  } else {
6825
6798
  this.___animateCounter++; // next tick 再次刷新
6826
6799
 
6827
- setTimeout(() => {
6800
+ this.graph.utils.requestAnimationFrame(() => {
6828
6801
  this.needUpdate = true; //需要刷新
6829
6802
  });
6830
6803
  }
@@ -6976,7 +6949,7 @@ class jmStackBarSeries extends jmBarSeries {
6976
6949
  } else {
6977
6950
  this.___animateCounter++; // next tick 再次刷新
6978
6951
 
6979
- setTimeout(() => {
6952
+ this.graph.utils.requestAnimationFrame(() => {
6980
6953
  this.needUpdate = true; //需要刷新
6981
6954
  });
6982
6955
  }
@@ -7092,7 +7065,7 @@ class jmPieSeries extends jmSeries {
7092
7065
  } else {
7093
7066
  this.___animateCounter++; // next tick 再次刷新
7094
7067
 
7095
- setTimeout(() => {
7068
+ this.graph.utils.requestAnimationFrame(() => {
7096
7069
  this.needUpdate = true; //需要刷新
7097
7070
  });
7098
7071
  }
@@ -7734,7 +7707,7 @@ class jmLineSeries extends jmSeries {
7734
7707
  } else if (isRunningAni) {
7735
7708
  this.___animateCounter += aniStep; // next tick 再次刷新
7736
7709
 
7737
- setTimeout(() => {
7710
+ this.graph.utils.requestAnimationFrame(() => {
7738
7711
  this.needUpdate = true; //需要刷新
7739
7712
  });
7740
7713
  }
@@ -7981,7 +7954,7 @@ class jmStackLineSeries extends jmLineSeries {
7981
7954
  } else if (isRunningAni) {
7982
7955
  this.___animateCounter += aniStep; // next tick 再次刷新
7983
7956
 
7984
- setTimeout(() => {
7957
+ this.graph.utils.requestAnimationFrame(() => {
7985
7958
  this.needUpdate = true; //需要刷新
7986
7959
  });
7987
7960
  }
@@ -8236,7 +8209,7 @@ class jmMarkLine extends jmLine {
8236
8209
  } // 触发touch数据点改变事件
8237
8210
 
8238
8211
 
8239
- touchChange && setTimeout(() => {
8212
+ touchChange && this.graph.utils.requestAnimationFrame(() => {
8240
8213
  graph.emit('touchPointChange', {
8241
8214
  points: touchPoints
8242
8215
  });
@@ -8428,14 +8401,14 @@ class jmMarkLineManager {
8428
8401
  else lineTouching = 1;
8429
8402
  }
8430
8403
 
8431
- args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
8404
+ args.event && args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
8432
8405
 
8433
8406
  if (chart.style.markLine.lock) {
8434
8407
  // 标线状态一直禁用系统能力
8435
8408
  // 如果指定了锁定值,只需要一项符合要求就进行锁定
8436
8409
  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) {
8437
8410
  lineTouching = 1;
8438
- args.event.preventDefault(); // 阻止默认行为
8411
+ args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
8439
8412
  }
8440
8413
  }
8441
8414