jmchart 1.2.3 → 1.2.6

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.
@@ -232,9 +232,13 @@ define(['exports'], function (exports) { 'use strict';
232
232
 
233
233
  for(let k in source) {
234
234
  if(k === 'constructor') continue;
235
+ const v = source[k];
236
+ // 不复制页面元素和class对象
237
+ if(v && (v.tagName || v.getContext)) continue;
238
+
235
239
  // 如果不是对象和空,则采用target的属性
236
240
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
237
- target[k] = this.clone(source[k], target[k], deep, copyHandler, deepIndex);
241
+ target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
238
242
  }
239
243
  }
240
244
  return target;
@@ -5083,12 +5087,12 @@ define(['exports'], function (exports) { 'use strict';
5083
5087
  // 触发刷新事件
5084
5088
  self.emit('update');
5085
5089
 
5086
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5087
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5090
+ self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5091
+ self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
5088
5092
  if(callback) callback();
5089
5093
  }
5090
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5091
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5094
+ self.__requestAnimationFrameFunHandler && this.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5095
+ self.__requestAnimationFrameFunHandler = this.requestAnimationFrame(update);
5092
5096
  return this;
5093
5097
  }
5094
5098
 
@@ -8596,35 +8600,43 @@ define(['exports'], function (exports) { 'use strict';
8596
8600
  container = container.parentElement;
8597
8601
  }
8598
8602
 
8599
- container && (container.style.position = 'relative');
8603
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8604
+
8605
+ let cn = options.touchCanvas;
8600
8606
  options = this.utils.clone(options, {
8601
8607
  autoRefresh: true
8602
8608
  }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8603
8609
  // isWXMiniApp 非微信小程序下才能创建
8604
8610
 
8605
- if (!this.isWXMiniApp && container && options.touchGraph) {
8606
- let cn = document.createElement('canvas');
8607
- cn.width = container.offsetWidth || container.clientWidth;
8608
- cn.height = container.offsetHeight || container.clientHeight;
8609
- cn.style.position = 'absolute';
8610
- cn.style.top = 0;
8611
- cn.style.left = 0;
8612
- this.touchGraph = new jmGraph(cn, options);
8613
- container.appendChild(cn);
8614
- this.touchGraph.chartGraph = this;
8615
- this.on('propertyChange', (name, args) => {
8616
- if (['width', 'height'].includes(name)) {
8617
- this.touchGraph[name] = args.newValue;
8618
- }
8619
- }); // 把上层canvse事件传递给绘图层对象
8611
+ if (container && (options.touchGraph || cn)) {
8612
+ if (!cn && !this.isWXMiniApp) {
8613
+ cn = document.createElement('canvas');
8614
+ cn.width = container.offsetWidth || container.clientWidth;
8615
+ cn.height = container.offsetHeight || container.clientHeight;
8616
+ cn.style.position = 'absolute';
8617
+ cn.style.top = 0;
8618
+ cn.style.left = 0;
8619
+ container.appendChild(cn);
8620
+ }
8620
8621
 
8621
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8622
- const eventName = args.event.eventName || args.event.type;
8622
+ if (cn) {
8623
+ this.touchGraph = new jmGraph(cn, options);
8624
+ this.touchGraph.chartGraph = this;
8625
+ this.on('propertyChange', (name, args) => {
8626
+ if (['width', 'height'].includes(name)) {
8627
+ this.touchGraph[name] = args.newValue;
8628
+ }
8629
+ }); // 把上层canvse事件传递给绘图层对象
8623
8630
 
8624
- if (eventName) {
8625
- this.emit(eventName, args);
8626
- }
8627
- });
8631
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8632
+ const eventName = args.event.eventName || args.event.type;
8633
+
8634
+ if (eventName) {
8635
+ this.emit(eventName, args);
8636
+ args.event.stopPropagation && args.event.stopPropagation();
8637
+ }
8638
+ });
8639
+ }
8628
8640
  } // 初始化标线
8629
8641
 
8630
8642
 
@@ -234,9 +234,13 @@ class jmUtils {
234
234
 
235
235
  for(let k in source) {
236
236
  if(k === 'constructor') continue;
237
+ const v = source[k];
238
+ // 不复制页面元素和class对象
239
+ if(v && (v.tagName || v.getContext)) continue;
240
+
237
241
  // 如果不是对象和空,则采用target的属性
238
242
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
239
- target[k] = this.clone(source[k], target[k], deep, copyHandler, deepIndex);
243
+ target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
240
244
  }
241
245
  }
242
246
  return target;
@@ -5085,12 +5089,12 @@ class jmGraph$1 extends jmControl {
5085
5089
  // 触发刷新事件
5086
5090
  self.emit('update');
5087
5091
 
5088
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5089
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5092
+ self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5093
+ self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
5090
5094
  if(callback) callback();
5091
5095
  }
5092
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5093
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5096
+ self.__requestAnimationFrameFunHandler && this.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5097
+ self.__requestAnimationFrameFunHandler = this.requestAnimationFrame(update);
5094
5098
  return this;
5095
5099
  }
5096
5100
 
@@ -8598,35 +8602,43 @@ class jmChart extends jmGraph {
8598
8602
  container = container.parentElement;
8599
8603
  }
8600
8604
 
8601
- container && (container.style.position = 'relative');
8605
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8606
+
8607
+ let cn = options.touchCanvas;
8602
8608
  options = this.utils.clone(options, {
8603
8609
  autoRefresh: true
8604
8610
  }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8605
8611
  // isWXMiniApp 非微信小程序下才能创建
8606
8612
 
8607
- if (!this.isWXMiniApp && container && options.touchGraph) {
8608
- let cn = document.createElement('canvas');
8609
- cn.width = container.offsetWidth || container.clientWidth;
8610
- cn.height = container.offsetHeight || container.clientHeight;
8611
- cn.style.position = 'absolute';
8612
- cn.style.top = 0;
8613
- cn.style.left = 0;
8614
- this.touchGraph = new jmGraph(cn, options);
8615
- container.appendChild(cn);
8616
- this.touchGraph.chartGraph = this;
8617
- this.on('propertyChange', (name, args) => {
8618
- if (['width', 'height'].includes(name)) {
8619
- this.touchGraph[name] = args.newValue;
8620
- }
8621
- }); // 把上层canvse事件传递给绘图层对象
8613
+ if (container && (options.touchGraph || cn)) {
8614
+ if (!cn && !this.isWXMiniApp) {
8615
+ cn = document.createElement('canvas');
8616
+ cn.width = container.offsetWidth || container.clientWidth;
8617
+ cn.height = container.offsetHeight || container.clientHeight;
8618
+ cn.style.position = 'absolute';
8619
+ cn.style.top = 0;
8620
+ cn.style.left = 0;
8621
+ container.appendChild(cn);
8622
+ }
8622
8623
 
8623
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8624
- const eventName = args.event.eventName || args.event.type;
8624
+ if (cn) {
8625
+ this.touchGraph = new jmGraph(cn, options);
8626
+ this.touchGraph.chartGraph = this;
8627
+ this.on('propertyChange', (name, args) => {
8628
+ if (['width', 'height'].includes(name)) {
8629
+ this.touchGraph[name] = args.newValue;
8630
+ }
8631
+ }); // 把上层canvse事件传递给绘图层对象
8625
8632
 
8626
- if (eventName) {
8627
- this.emit(eventName, args);
8628
- }
8629
- });
8633
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8634
+ const eventName = args.event.eventName || args.event.type;
8635
+
8636
+ if (eventName) {
8637
+ this.emit(eventName, args);
8638
+ args.event.stopPropagation && args.event.stopPropagation();
8639
+ }
8640
+ });
8641
+ }
8630
8642
  } // 初始化标线
8631
8643
 
8632
8644
 
@@ -230,9 +230,13 @@ class jmUtils {
230
230
 
231
231
  for(let k in source) {
232
232
  if(k === 'constructor') continue;
233
+ const v = source[k];
234
+ // 不复制页面元素和class对象
235
+ if(v && (v.tagName || v.getContext)) continue;
236
+
233
237
  // 如果不是对象和空,则采用target的属性
234
238
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
235
- target[k] = this.clone(source[k], target[k], deep, copyHandler, deepIndex);
239
+ target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
236
240
  }
237
241
  }
238
242
  return target;
@@ -5081,12 +5085,12 @@ class jmGraph$1 extends jmControl {
5081
5085
  // 触发刷新事件
5082
5086
  self.emit('update');
5083
5087
 
5084
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5085
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5088
+ self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5089
+ self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
5086
5090
  if(callback) callback();
5087
5091
  }
5088
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5089
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5092
+ self.__requestAnimationFrameFunHandler && this.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5093
+ self.__requestAnimationFrameFunHandler = this.requestAnimationFrame(update);
5090
5094
  return this;
5091
5095
  }
5092
5096
 
@@ -8594,35 +8598,43 @@ class jmChart extends jmGraph {
8594
8598
  container = container.parentElement;
8595
8599
  }
8596
8600
 
8597
- container && (container.style.position = 'relative');
8601
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8602
+
8603
+ let cn = options.touchCanvas;
8598
8604
  options = this.utils.clone(options, {
8599
8605
  autoRefresh: true
8600
8606
  }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8601
8607
  // isWXMiniApp 非微信小程序下才能创建
8602
8608
 
8603
- if (!this.isWXMiniApp && container && options.touchGraph) {
8604
- let cn = document.createElement('canvas');
8605
- cn.width = container.offsetWidth || container.clientWidth;
8606
- cn.height = container.offsetHeight || container.clientHeight;
8607
- cn.style.position = 'absolute';
8608
- cn.style.top = 0;
8609
- cn.style.left = 0;
8610
- this.touchGraph = new jmGraph(cn, options);
8611
- container.appendChild(cn);
8612
- this.touchGraph.chartGraph = this;
8613
- this.on('propertyChange', (name, args) => {
8614
- if (['width', 'height'].includes(name)) {
8615
- this.touchGraph[name] = args.newValue;
8616
- }
8617
- }); // 把上层canvse事件传递给绘图层对象
8609
+ if (container && (options.touchGraph || cn)) {
8610
+ if (!cn && !this.isWXMiniApp) {
8611
+ cn = document.createElement('canvas');
8612
+ cn.width = container.offsetWidth || container.clientWidth;
8613
+ cn.height = container.offsetHeight || container.clientHeight;
8614
+ cn.style.position = 'absolute';
8615
+ cn.style.top = 0;
8616
+ cn.style.left = 0;
8617
+ container.appendChild(cn);
8618
+ }
8618
8619
 
8619
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8620
- const eventName = args.event.eventName || args.event.type;
8620
+ if (cn) {
8621
+ this.touchGraph = new jmGraph(cn, options);
8622
+ this.touchGraph.chartGraph = this;
8623
+ this.on('propertyChange', (name, args) => {
8624
+ if (['width', 'height'].includes(name)) {
8625
+ this.touchGraph[name] = args.newValue;
8626
+ }
8627
+ }); // 把上层canvse事件传递给绘图层对象
8621
8628
 
8622
- if (eventName) {
8623
- this.emit(eventName, args);
8624
- }
8625
- });
8629
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8630
+ const eventName = args.event.eventName || args.event.type;
8631
+
8632
+ if (eventName) {
8633
+ this.emit(eventName, args);
8634
+ args.event.stopPropagation && args.event.stopPropagation();
8635
+ }
8636
+ });
8637
+ }
8626
8638
  } // 初始化标线
8627
8639
 
8628
8640
 
@@ -233,9 +233,13 @@
233
233
 
234
234
  for(let k in source) {
235
235
  if(k === 'constructor') continue;
236
+ const v = source[k];
237
+ // 不复制页面元素和class对象
238
+ if(v && (v.tagName || v.getContext)) continue;
239
+
236
240
  // 如果不是对象和空,则采用target的属性
237
241
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
238
- target[k] = this.clone(source[k], target[k], deep, copyHandler, deepIndex);
242
+ target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
239
243
  }
240
244
  }
241
245
  return target;
@@ -5084,12 +5088,12 @@
5084
5088
  // 触发刷新事件
5085
5089
  self.emit('update');
5086
5090
 
5087
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5088
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5091
+ self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5092
+ self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
5089
5093
  if(callback) callback();
5090
5094
  }
5091
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5092
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5095
+ self.__requestAnimationFrameFunHandler && this.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5096
+ self.__requestAnimationFrameFunHandler = this.requestAnimationFrame(update);
5093
5097
  return this;
5094
5098
  }
5095
5099
 
@@ -8597,35 +8601,43 @@
8597
8601
  container = container.parentElement;
8598
8602
  }
8599
8603
 
8600
- container && (container.style.position = 'relative');
8604
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8605
+
8606
+ let cn = options.touchCanvas;
8601
8607
  options = this.utils.clone(options, {
8602
8608
  autoRefresh: true
8603
8609
  }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8604
8610
  // isWXMiniApp 非微信小程序下才能创建
8605
8611
 
8606
- if (!this.isWXMiniApp && container && options.touchGraph) {
8607
- let cn = document.createElement('canvas');
8608
- cn.width = container.offsetWidth || container.clientWidth;
8609
- cn.height = container.offsetHeight || container.clientHeight;
8610
- cn.style.position = 'absolute';
8611
- cn.style.top = 0;
8612
- cn.style.left = 0;
8613
- this.touchGraph = new jmGraph(cn, options);
8614
- container.appendChild(cn);
8615
- this.touchGraph.chartGraph = this;
8616
- this.on('propertyChange', (name, args) => {
8617
- if (['width', 'height'].includes(name)) {
8618
- this.touchGraph[name] = args.newValue;
8619
- }
8620
- }); // 把上层canvse事件传递给绘图层对象
8612
+ if (container && (options.touchGraph || cn)) {
8613
+ if (!cn && !this.isWXMiniApp) {
8614
+ cn = document.createElement('canvas');
8615
+ cn.width = container.offsetWidth || container.clientWidth;
8616
+ cn.height = container.offsetHeight || container.clientHeight;
8617
+ cn.style.position = 'absolute';
8618
+ cn.style.top = 0;
8619
+ cn.style.left = 0;
8620
+ container.appendChild(cn);
8621
+ }
8621
8622
 
8622
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8623
- const eventName = args.event.eventName || args.event.type;
8623
+ if (cn) {
8624
+ this.touchGraph = new jmGraph(cn, options);
8625
+ this.touchGraph.chartGraph = this;
8626
+ this.on('propertyChange', (name, args) => {
8627
+ if (['width', 'height'].includes(name)) {
8628
+ this.touchGraph[name] = args.newValue;
8629
+ }
8630
+ }); // 把上层canvse事件传递给绘图层对象
8624
8631
 
8625
- if (eventName) {
8626
- this.emit(eventName, args);
8627
- }
8628
- });
8632
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8633
+ const eventName = args.event.eventName || args.event.type;
8634
+
8635
+ if (eventName) {
8636
+ this.emit(eventName, args);
8637
+ args.event.stopPropagation && args.event.stopPropagation();
8638
+ }
8639
+ });
8640
+ }
8629
8641
  } // 初始化标线
8630
8642
 
8631
8643
 
@@ -235,9 +235,13 @@ System.register([], function (exports) {
235
235
 
236
236
  for(let k in source) {
237
237
  if(k === 'constructor') continue;
238
+ const v = source[k];
239
+ // 不复制页面元素和class对象
240
+ if(v && (v.tagName || v.getContext)) continue;
241
+
238
242
  // 如果不是对象和空,则采用target的属性
239
243
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
240
- target[k] = this.clone(source[k], target[k], deep, copyHandler, deepIndex);
244
+ target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
241
245
  }
242
246
  }
243
247
  return target;
@@ -5086,12 +5090,12 @@ System.register([], function (exports) {
5086
5090
  // 触发刷新事件
5087
5091
  self.emit('update');
5088
5092
 
5089
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5090
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5093
+ self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5094
+ self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
5091
5095
  if(callback) callback();
5092
5096
  }
5093
- self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
5094
- self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
5097
+ self.__requestAnimationFrameFunHandler && this.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5098
+ self.__requestAnimationFrameFunHandler = this.requestAnimationFrame(update);
5095
5099
  return this;
5096
5100
  }
5097
5101
 
@@ -8599,35 +8603,43 @@ System.register([], function (exports) {
8599
8603
  container = container.parentElement;
8600
8604
  }
8601
8605
 
8602
- container && (container.style.position = 'relative');
8606
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8607
+
8608
+ let cn = options.touchCanvas;
8603
8609
  options = this.utils.clone(options, {
8604
8610
  autoRefresh: true
8605
8611
  }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8606
8612
  // isWXMiniApp 非微信小程序下才能创建
8607
8613
 
8608
- if (!this.isWXMiniApp && container && options.touchGraph) {
8609
- let cn = document.createElement('canvas');
8610
- cn.width = container.offsetWidth || container.clientWidth;
8611
- cn.height = container.offsetHeight || container.clientHeight;
8612
- cn.style.position = 'absolute';
8613
- cn.style.top = 0;
8614
- cn.style.left = 0;
8615
- this.touchGraph = new jmGraph(cn, options);
8616
- container.appendChild(cn);
8617
- this.touchGraph.chartGraph = this;
8618
- this.on('propertyChange', (name, args) => {
8619
- if (['width', 'height'].includes(name)) {
8620
- this.touchGraph[name] = args.newValue;
8621
- }
8622
- }); // 把上层canvse事件传递给绘图层对象
8614
+ if (container && (options.touchGraph || cn)) {
8615
+ if (!cn && !this.isWXMiniApp) {
8616
+ cn = document.createElement('canvas');
8617
+ cn.width = container.offsetWidth || container.clientWidth;
8618
+ cn.height = container.offsetHeight || container.clientHeight;
8619
+ cn.style.position = 'absolute';
8620
+ cn.style.top = 0;
8621
+ cn.style.left = 0;
8622
+ container.appendChild(cn);
8623
+ }
8623
8624
 
8624
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8625
- const eventName = args.event.eventName || args.event.type;
8625
+ if (cn) {
8626
+ this.touchGraph = new jmGraph(cn, options);
8627
+ this.touchGraph.chartGraph = this;
8628
+ this.on('propertyChange', (name, args) => {
8629
+ if (['width', 'height'].includes(name)) {
8630
+ this.touchGraph[name] = args.newValue;
8631
+ }
8632
+ }); // 把上层canvse事件传递给绘图层对象
8626
8633
 
8627
- if (eventName) {
8628
- this.emit(eventName, args);
8629
- }
8630
- });
8634
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8635
+ const eventName = args.event.eventName || args.event.type;
8636
+
8637
+ if (eventName) {
8638
+ this.emit(eventName, args);
8639
+ args.event.stopPropagation && args.event.stopPropagation();
8640
+ }
8641
+ });
8642
+ }
8631
8643
  } // 初始化标线
8632
8644
 
8633
8645
 
package/example/bar.html CHANGED
@@ -12,17 +12,6 @@
12
12
  width:100%;
13
13
  height:100%;
14
14
  }
15
- #mycanvas canvas, #mycanvas div{
16
- background-color:#fff;
17
- margin:0 auto;
18
- }
19
- /*div.jm-tooltip {
20
- background-color: rgba(255,255,255,0.8);
21
- padding:4px;
22
- border:1px solid #000;
23
- box-shadow: 0 0 3px #000;
24
- border-radius: 6px;
25
- }*/
26
15
  </style>
27
16
  <script type="module">
28
17
  //window.devicePixelRatio = 1;
@@ -36,6 +25,7 @@
36
25
 
37
26
 
38
27
  function inichart(w, h) {
28
+ var touchCanvas = document.getElementById('mytouchcanvas');
39
29
  var chart = new jmChart('mycanvas', {
40
30
  width: w,
41
31
  height: h,
@@ -47,6 +37,8 @@
47
37
  //minYValue: -200,
48
38
  //maxYValue: 300,
49
39
  autoRefresh: true,
40
+ // 指定了操作层的canvas,如果不想自已指定,也可以把touchGraph设置为true也是一样的效果
41
+ touchCanvas,
50
42
  style: {
51
43
  axis: {
52
44
  x: true,
@@ -194,8 +186,12 @@
194
186
  </script>
195
187
  </head>
196
188
  <body>
197
- <div id="mycanvas">
198
- </div>
189
+ <div>
190
+ <canvas id="mycanvas">
191
+ </canvas>
192
+ <canvas id="mytouchcanvas" style="position: absolute; left:0; top: 0;">
193
+ </canvas>
194
+ </div>
199
195
  <button id="btnRedraw">重绘</button>
200
196
  </body>
201
197
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.2.3",
3
+ "version": "1.2.6",
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.98"
31
+ "jmgraph": "^3.2.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/core": "^7.10.2",
package/src/jmChart.js CHANGED
@@ -134,7 +134,9 @@ export default class jmChart extends jmGraph {
134
134
  if(container && container.tagName === 'CANVAS') {
135
135
  container = container.parentElement;
136
136
  }
137
- container && (container.style.position = 'relative');
137
+ container && container.style && (container.style.position = 'relative');
138
+ // 要先从选项中取出canvas,否则clone过滤掉
139
+ let cn = options.touchCanvas;
138
140
 
139
141
  options = this.utils.clone(options, {
140
142
  autoRefresh: true
@@ -142,32 +144,34 @@ export default class jmChart extends jmGraph {
142
144
 
143
145
  // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
144
146
  // isWXMiniApp 非微信小程序下才能创建
145
- if(!this.isWXMiniApp && container && options.touchGraph) {
146
- let cn = document.createElement('canvas');
147
- cn.width = container.offsetWidth||container.clientWidth;
148
- cn.height = container.offsetHeight||container.clientHeight;
149
- cn.style.position = 'absolute';
150
- cn.style.top = 0;
151
- cn.style.left = 0;
152
-
153
- this.touchGraph = new jmGraph(cn, options);
154
-
155
- container.appendChild(cn);
156
-
157
- this.touchGraph.chartGraph = this;
158
-
159
- this.on('propertyChange', (name, args) => {
160
- if(['width', 'height'].includes(name)) {
161
- this.touchGraph[name] = args.newValue;
162
- }
163
- });
164
- // 把上层canvse事件传递给绘图层对象
165
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', (args) => {
166
- const eventName = args.event.eventName || args.event.type;
167
- if(eventName) {
168
- this.emit(eventName, args);
169
- }
170
- });
147
+ if(container && (options.touchGraph || cn)) {
148
+ if(!cn && !this.isWXMiniApp) {
149
+ cn = document.createElement('canvas');
150
+ cn.width = container.offsetWidth||container.clientWidth;
151
+ cn.height = container.offsetHeight||container.clientHeight;
152
+ cn.style.position = 'absolute';
153
+ cn.style.top = 0;
154
+ cn.style.left = 0;
155
+ container.appendChild(cn);
156
+ }
157
+ if(cn) {
158
+ this.touchGraph = new jmGraph(cn, options);
159
+ this.touchGraph.chartGraph = this;
160
+
161
+ this.on('propertyChange', (name, args) => {
162
+ if(['width', 'height'].includes(name)) {
163
+ this.touchGraph[name] = args.newValue;
164
+ }
165
+ });
166
+ // 把上层canvse事件传递给绘图层对象
167
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', (args) => {
168
+ const eventName = args.event.eventName || args.event.type;
169
+ if(eventName) {
170
+ this.emit(eventName, args);
171
+ args.event.stopPropagation && args.event.stopPropagation();
172
+ }
173
+ });
174
+ }
171
175
  }
172
176
  // 初始化标线
173
177
  this.markLine = new jmMarkLineManager(this);