jmchart 1.2.2 → 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.
@@ -877,21 +877,13 @@ System.register([], function (exports) {
877
877
  return r;
878
878
  }
879
879
  // window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
880
- static requestAnimationFrame(callback) {
881
- if(typeof requestAnimationFrame === 'undefined') {
882
- return setTimeout(callback, 20);
883
- }
884
- else {
885
- return requestAnimationFrame(callback);
886
- }
880
+ static requestAnimationFrame(callback, win) {
881
+ let fun = win && win.requestAnimationFrame? win.requestAnimationFrame: (typeof window !== 'undefined' && window.requestAnimationFrame? window.requestAnimationFrame: setTimeout);
882
+ return fun(callback, 20);
887
883
  }
888
- static cancelAnimationFrame(handler) {
889
- if(typeof requestAnimationFrame === 'undefined') {
890
- return clearTimeout(handler);
891
- }
892
- else {
893
- return cancelAnimationFrame(handler);
894
- }
884
+ static cancelAnimationFrame(handler, win) {
885
+ let fun = win && win.cancelAnimationFrame? win.cancelAnimationFrame: (typeof window !== 'undefined' && window.cancelAnimationFrame? window.cancelAnimationFrame: clearTimeout);
886
+ return fun(handler);
895
887
  }
896
888
  }
897
889
 
@@ -1330,8 +1322,48 @@ System.register([], function (exports) {
1330
1322
  set graph(v) {
1331
1323
  return this.__pro('graph', v);
1332
1324
  }
1325
+
1326
+ /**
1327
+ * 在下次进行重绘时执行
1328
+ * @param {Function} handler
1329
+ */
1330
+ requestAnimationFrame(handler) {
1331
+ return jmUtils.requestAnimationFrame(handler, this.graph? this.graph.canvas: null);
1332
+ }
1333
+ /**
1334
+ * 清除执行回调
1335
+ * @param {Function} handler
1336
+ * @returns
1337
+ */
1338
+ cancelAnimationFrame(handler) {
1339
+ return jmUtils.cancelAnimationFrame(handler, this.graph? this.graph.canvas: null);
1340
+ }
1333
1341
  }
1334
1342
 
1343
+ //样式名称,也当做白名单使用
1344
+ const jmStyleMap = {
1345
+ 'fill':'fillStyle',
1346
+ 'stroke':'strokeStyle',
1347
+ 'shadow.blur':'shadowBlur',
1348
+ 'shadow.x':'shadowOffsetX',
1349
+ 'shadow.y':'shadowOffsetY',
1350
+ 'shadow.color':'shadowColor',
1351
+ 'lineWidth' : 'lineWidth',
1352
+ 'miterLimit': 'miterLimit',
1353
+ 'fillStyle' : 'fillStyle',
1354
+ 'strokeStyle' : 'strokeStyle',
1355
+ 'font' : 'font',
1356
+ 'opacity' : 'globalAlpha',
1357
+ 'textAlign' : 'textAlign',
1358
+ 'textBaseline' : 'textBaseline',
1359
+ 'shadowBlur' : 'shadowBlur',
1360
+ 'shadowOffsetX' : 'shadowOffsetX',
1361
+ 'shadowOffsetY' : 'shadowOffsetY',
1362
+ 'shadowColor' : 'shadowColor',
1363
+ 'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
1364
+ 'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
1365
+ };
1366
+
1335
1367
  /**
1336
1368
  * 控件基础对象
1337
1369
  * 控件的基础属性和方法
@@ -1358,30 +1390,6 @@ System.register([], function (exports) {
1358
1390
  this.zIndex = params.zIndex || 0;
1359
1391
  this.interactive = typeof params.interactive == 'undefined'? true : params.interactive;
1360
1392
 
1361
- //样式名称,也当做白名单使用
1362
- this.jmStyleMap = {
1363
- 'fill':'fillStyle',
1364
- 'stroke':'strokeStyle',
1365
- 'shadow.blur':'shadowBlur',
1366
- 'shadow.x':'shadowOffsetX',
1367
- 'shadow.y':'shadowOffsetY',
1368
- 'shadow.color':'shadowColor',
1369
- 'lineWidth' : 'lineWidth',
1370
- 'miterLimit': 'miterLimit',
1371
- 'fillStyle' : 'fillStyle',
1372
- 'strokeStyle' : 'strokeStyle',
1373
- 'font' : 'font',
1374
- 'opacity' : 'globalAlpha',
1375
- 'textAlign' : 'textAlign',
1376
- 'textBaseline' : 'textBaseline',
1377
- 'shadowBlur' : 'shadowBlur',
1378
- 'shadowOffsetX' : 'shadowOffsetX',
1379
- 'shadowOffsetY' : 'shadowOffsetY',
1380
- 'shadowColor' : 'shadowColor',
1381
- 'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
1382
- 'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
1383
- };
1384
-
1385
1393
  this.initializing();
1386
1394
 
1387
1395
  this.on = this.bind;
@@ -1679,120 +1687,93 @@ System.register([], function (exports) {
1679
1687
  * @param {string} mpkey 样式名称在映射中的key(例如:shadow.blur为模糊值)
1680
1688
  */
1681
1689
  let __setStyle = (style, name, mpkey) => {
1682
- //let styleValue = style[mpkey||name]||style;
1683
- if(style) {
1684
- if(typeof style === 'function') {
1690
+
1691
+ if(style) {
1692
+ let styleValue = style;
1693
+ if(typeof styleValue === 'function') {
1685
1694
  try {
1686
- style = style.call(this);
1695
+ styleValue = styleValue.call(this);
1687
1696
  }
1688
1697
  catch(e) {
1689
1698
  console.warn(e);
1690
1699
  return;
1691
1700
  }
1692
1701
  }
1693
- let t = typeof style;
1694
- let mpname = this.jmStyleMap[mpkey || name];
1702
+ let t = typeof styleValue;
1703
+ let mpname = jmStyleMap[mpkey || name];
1695
1704
 
1696
1705
  //如果为渐变对象
1697
- if((style instanceof jmGradient) || (t == 'string' && style.indexOf('-gradient') > -1)) {
1706
+ if((styleValue instanceof jmGradient) || (t == 'string' && styleValue.indexOf('-gradient') > -1)) {
1698
1707
  //如果是渐变,则需要转换
1699
- if(t == 'string' && style.indexOf('-gradient') > -1) {
1700
- style = new jmGradient(style);
1701
- }
1702
- __setStyle(style.toGradient(this), mpname||name);
1703
- }
1704
- else if(t == 'function') {
1705
- if(mpname) {
1706
- style = style.call(this, mpname);
1707
- if(style) {
1708
- __setStyle(style, mpname);
1709
- }
1708
+ if(t == 'string' && styleValue.indexOf('-gradient') > -1) {
1709
+ styleValue = new jmGradient(styleValue);
1710
1710
  }
1711
+ __setStyle(styleValue.toGradient(this), mpname||name);
1711
1712
  }
1712
1713
  else if(mpname) {
1713
1714
  //只有存在白名单中才处理
1714
1715
  //颜色转换
1715
1716
  if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
1716
- style = jmUtils.toColor(style);
1717
+ styleValue = jmUtils.toColor(styleValue);
1717
1718
  }
1718
-
1719
- // 按比例需要放大的样式
1720
- /*if(scale && style) {
1721
- switch(mpname) {
1722
- case 'lineWidth': {
1723
- style *= scale;
1724
- break;
1725
- }
1726
- // 字体放大
1727
- case 'fontSize':
1728
- case 'font': {
1729
- const ms = style.toString().match(/[\d\.]+/);
1730
- if(ms && ms.length) {
1731
- const size = Number(ms[0]) * scale;
1732
- style = style.toString().replace(ms[0], size);
1733
- }
1734
- break;
1735
- }
1736
- }
1737
- } */
1738
- this.context[mpname] = style;
1719
+ this.context[mpname] = styleValue;
1739
1720
  }
1740
1721
  else {
1741
1722
  switch(name) {
1742
1723
  //阴影样式
1743
1724
  case 'shadow' : {
1744
1725
  if(t == 'string') {
1745
- __setStyle(new jmShadow(style), name);
1726
+ __setStyle(new jmShadow(styleValue), name);
1746
1727
  break;
1747
1728
  }
1748
- for(let k in style) {
1749
- __setStyle(style[k], k, name + '.' + k);
1729
+ for(let k in styleValue) {
1730
+ __setStyle(styleValue[k], k, name + '.' + k);
1750
1731
  }
1751
1732
  break;
1752
1733
  }
1753
1734
  //平移
1754
1735
  case 'translate' : {
1755
- this.context.translate(style.x,style.y);
1736
+ this.context.translate(styleValue.x, styleValue.y);
1756
1737
  break;
1757
1738
  }
1758
1739
  //旋转
1759
1740
  case 'rotation' : {
1760
- if(!style.angle) break;
1741
+ if(!styleValue.angle) break;
1761
1742
  //旋 转先移位偏移量
1762
1743
  let tranX = 0;
1763
1744
  let tranY = 0;
1764
1745
  //旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
1765
1746
  //这里只有style中的旋转才能生效,不然会导至子控件多次旋转
1766
- if(style.point) {
1747
+ if(styleValue.point) {
1767
1748
  let bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
1768
- style = this.getRotation(style);
1749
+ styleValue = this.getRotation(styleValue);
1769
1750
 
1770
- tranX = style.rotateX + bounds.left;
1771
- tranY = style.rotateY + bounds.top;
1751
+ tranX = styleValue.rotateX + bounds.left;
1752
+ tranY = styleValue.rotateY + bounds.top;
1772
1753
  }
1773
1754
 
1774
1755
  if(tranX!=0 || tranY != 0) this.context.translate(tranX,tranY);
1775
- this.context.rotate(style.angle);
1756
+ this.context.rotate(styleValue.angle);
1776
1757
  if(tranX!=0 || tranY != 0) this.context.translate(-tranX,-tranY);
1777
1758
  break;
1778
1759
  }
1779
1760
  case 'transform' : {
1780
- if(Array.isArray(style)) {
1781
- this.context.transform.apply(this.context, style);
1761
+ if(Array.isArray(styleValue)) {
1762
+ this.context.transform.apply(this.context, styleValue);
1782
1763
  }
1783
- else if(typeof style == 'object') {
1784
- this.context.transform(style.scaleX,//水平缩放
1785
- style.skewX,//水平倾斜
1786
- style.skewY,//垂直倾斜
1787
- style.scaleY,//垂直缩放
1788
- style.offsetX,//水平位移
1789
- style.offsetY);//垂直位移
1764
+ else if(typeof styleValue == 'object') {
1765
+ this.context.transform(styleValue.scaleX,//水平缩放
1766
+ styleValue.skewX,//水平倾斜
1767
+ styleValue.skewY,//垂直倾斜
1768
+ styleValue.scaleY,//垂直缩放
1769
+ styleValue.offsetX,//水平位移
1770
+ styleValue.offsetY);//垂直位移
1790
1771
  }
1791
1772
  break;
1792
1773
  }
1793
1774
  //鼠标指针
1794
1775
  case 'cursor' : {
1795
- this.cursor = style;
1776
+ this.cursor = styleValue;
1796
1777
  break;
1797
1778
  }
1798
1779
  }
@@ -2221,8 +2202,6 @@ System.register([], function (exports) {
2221
2202
  this.emit('endDraw',this);
2222
2203
  this.context.restore();
2223
2204
 
2224
- //兼容小程序
2225
- if(this.is('jmGraph') && this.context.draw) this.context.draw();
2226
2205
  this.needUpdate = false;
2227
2206
  }
2228
2207
  }
@@ -5107,12 +5086,12 @@ System.register([], function (exports) {
5107
5086
  // 触发刷新事件
5108
5087
  self.emit('update');
5109
5088
 
5110
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5111
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5089
+ self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5090
+ self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5112
5091
  if(callback) callback();
5113
5092
  }
5114
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5115
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5093
+ self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5094
+ self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5116
5095
  return this;
5117
5096
  }
5118
5097
 
@@ -6819,7 +6798,7 @@ System.register([], function (exports) {
6819
6798
  } else {
6820
6799
  this.___animateCounter++; // next tick 再次刷新
6821
6800
 
6822
- setTimeout(() => {
6801
+ this.graph.utils.requestAnimationFrame(() => {
6823
6802
  this.needUpdate = true; //需要刷新
6824
6803
  });
6825
6804
  }
@@ -6971,7 +6950,7 @@ System.register([], function (exports) {
6971
6950
  } else {
6972
6951
  this.___animateCounter++; // next tick 再次刷新
6973
6952
 
6974
- setTimeout(() => {
6953
+ this.graph.utils.requestAnimationFrame(() => {
6975
6954
  this.needUpdate = true; //需要刷新
6976
6955
  });
6977
6956
  }
@@ -7087,7 +7066,7 @@ System.register([], function (exports) {
7087
7066
  } else {
7088
7067
  this.___animateCounter++; // next tick 再次刷新
7089
7068
 
7090
- setTimeout(() => {
7069
+ this.graph.utils.requestAnimationFrame(() => {
7091
7070
  this.needUpdate = true; //需要刷新
7092
7071
  });
7093
7072
  }
@@ -7729,7 +7708,7 @@ System.register([], function (exports) {
7729
7708
  } else if (isRunningAni) {
7730
7709
  this.___animateCounter += aniStep; // next tick 再次刷新
7731
7710
 
7732
- setTimeout(() => {
7711
+ this.graph.utils.requestAnimationFrame(() => {
7733
7712
  this.needUpdate = true; //需要刷新
7734
7713
  });
7735
7714
  }
@@ -7976,7 +7955,7 @@ System.register([], function (exports) {
7976
7955
  } else if (isRunningAni) {
7977
7956
  this.___animateCounter += aniStep; // next tick 再次刷新
7978
7957
 
7979
- setTimeout(() => {
7958
+ this.graph.utils.requestAnimationFrame(() => {
7980
7959
  this.needUpdate = true; //需要刷新
7981
7960
  });
7982
7961
  }
@@ -8231,7 +8210,7 @@ System.register([], function (exports) {
8231
8210
  } // 触发touch数据点改变事件
8232
8211
 
8233
8212
 
8234
- touchChange && setTimeout(() => {
8213
+ touchChange && this.graph.utils.requestAnimationFrame(() => {
8235
8214
  graph.emit('touchPointChange', {
8236
8215
  points: touchPoints
8237
8216
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "directories": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/jiamao/jmchart#readme",
30
30
  "dependencies": {
31
- "jmgraph": "^3.1.97"
31
+ "jmgraph": "^3.1.98"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/core": "^7.10.2",
@@ -98,7 +98,7 @@ export default class jmMarkLine extends jmLine {
98
98
  }
99
99
 
100
100
  // 触发touch数据点改变事件
101
- touchChange && setTimeout(()=>{
101
+ touchChange && this.graph.utils.requestAnimationFrame(()=>{
102
102
  graph.emit('touchPointChange', {
103
103
  points: touchPoints
104
104
  });
@@ -95,7 +95,7 @@ export default class jmBarSeries extends jmSeries {
95
95
  else {
96
96
  this.___animateCounter++;
97
97
  // next tick 再次刷新
98
- setTimeout(()=>{
98
+ this.graph.utils.requestAnimationFrame(()=>{
99
99
  this.needUpdate = true;//需要刷新
100
100
  });
101
101
  }
@@ -95,7 +95,7 @@ export default class jmLineSeries extends jmSeries {
95
95
  else if(isRunningAni) {
96
96
  this.___animateCounter += aniStep;
97
97
  // next tick 再次刷新
98
- setTimeout(()=>{
98
+ this.graph.utils.requestAnimationFrame(()=>{
99
99
  this.needUpdate = true;//需要刷新
100
100
  });
101
101
  }
@@ -85,7 +85,7 @@ export default class jmPieSeries extends jmSeries {
85
85
  else {
86
86
  this.___animateCounter ++;
87
87
  // next tick 再次刷新
88
- setTimeout(()=>{
88
+ this.graph.utils.requestAnimationFrame(()=>{
89
89
  this.needUpdate = true;//需要刷新
90
90
  });
91
91
  }
@@ -106,7 +106,7 @@ export default class jmStackBarSeries extends jmBarSeries {
106
106
  else {
107
107
  this.___animateCounter++;
108
108
  // next tick 再次刷新
109
- setTimeout(()=>{
109
+ this.graph.utils.requestAnimationFrame(()=>{
110
110
  this.needUpdate = true;//需要刷新
111
111
  });
112
112
  }
@@ -91,7 +91,7 @@ export default class jmStackLineSeries extends jmLineSeries {
91
91
  else if(isRunningAni) {
92
92
  this.___animateCounter += aniStep;
93
93
  // next tick 再次刷新
94
- setTimeout(()=>{
94
+ this.graph.utils.requestAnimationFrame(()=>{
95
95
  this.needUpdate = true;//需要刷新
96
96
  });
97
97
  }