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