jmchart 1.2.5 → 1.2.7

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;
@@ -4631,6 +4635,7 @@ define(['exports'], function (exports) { 'use strict';
4631
4635
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4632
4636
  if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4633
4637
  this.isWXMiniApp = true;// 微信小程序平台
4638
+ this.container = canvas;
4634
4639
  }
4635
4640
  else {
4636
4641
  if(typeof canvas === 'string' && typeof document != 'undefined') {
@@ -8596,35 +8601,43 @@ define(['exports'], function (exports) { 'use strict';
8596
8601
  container = container.parentElement;
8597
8602
  }
8598
8603
 
8599
- container && (container.style.position = 'relative');
8600
- options = this.utils.clone(options, {
8601
- autoRefresh: true
8602
- }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8604
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8605
+
8606
+ let cn = options.touchCanvas; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8603
8607
  // isWXMiniApp 非微信小程序下才能创建
8604
8608
 
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事件传递给绘图层对象
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
+ }
8620
8619
 
8621
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8622
- const eventName = args.event.eventName || args.event.type;
8620
+ if (cn) {
8621
+ options = this.utils.clone(options, {
8622
+ autoRefresh: true
8623
+ }, true);
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事件传递给绘图层对象
8623
8631
 
8624
- if (eventName) {
8625
- this.emit(eventName, args);
8626
- }
8627
- });
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
+ }
8628
8641
  } // 初始化标线
8629
8642
 
8630
8643
 
@@ -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;
@@ -4633,6 +4637,7 @@ class jmGraph$1 extends jmControl {
4633
4637
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4634
4638
  if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4635
4639
  this.isWXMiniApp = true;// 微信小程序平台
4640
+ this.container = canvas;
4636
4641
  }
4637
4642
  else {
4638
4643
  if(typeof canvas === 'string' && typeof document != 'undefined') {
@@ -8598,35 +8603,43 @@ class jmChart extends jmGraph {
8598
8603
  container = container.parentElement;
8599
8604
  }
8600
8605
 
8601
- container && (container.style.position = 'relative');
8602
- options = this.utils.clone(options, {
8603
- autoRefresh: true
8604
- }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8606
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8607
+
8608
+ let cn = options.touchCanvas; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8605
8609
  // isWXMiniApp 非微信小程序下才能创建
8606
8610
 
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事件传递给绘图层对象
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
+ }
8622
8621
 
8623
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8624
- const eventName = args.event.eventName || args.event.type;
8622
+ if (cn) {
8623
+ options = this.utils.clone(options, {
8624
+ autoRefresh: true
8625
+ }, true);
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事件传递给绘图层对象
8625
8633
 
8626
- if (eventName) {
8627
- this.emit(eventName, args);
8628
- }
8629
- });
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
+ }
8630
8643
  } // 初始化标线
8631
8644
 
8632
8645
 
@@ -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;
@@ -4629,6 +4633,7 @@ class jmGraph$1 extends jmControl {
4629
4633
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4630
4634
  if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4631
4635
  this.isWXMiniApp = true;// 微信小程序平台
4636
+ this.container = canvas;
4632
4637
  }
4633
4638
  else {
4634
4639
  if(typeof canvas === 'string' && typeof document != 'undefined') {
@@ -8594,35 +8599,43 @@ class jmChart extends jmGraph {
8594
8599
  container = container.parentElement;
8595
8600
  }
8596
8601
 
8597
- container && (container.style.position = 'relative');
8598
- options = this.utils.clone(options, {
8599
- autoRefresh: true
8600
- }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8602
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8603
+
8604
+ let cn = options.touchCanvas; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8601
8605
  // isWXMiniApp 非微信小程序下才能创建
8602
8606
 
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事件传递给绘图层对象
8607
+ if (container && (options.touchGraph || cn)) {
8608
+ if (!cn && !this.isWXMiniApp) {
8609
+ 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
+ container.appendChild(cn);
8616
+ }
8618
8617
 
8619
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8620
- const eventName = args.event.eventName || args.event.type;
8618
+ if (cn) {
8619
+ options = this.utils.clone(options, {
8620
+ autoRefresh: true
8621
+ }, true);
8622
+ this.touchGraph = new jmGraph(cn, options);
8623
+ this.touchGraph.chartGraph = this;
8624
+ this.on('propertyChange', (name, args) => {
8625
+ if (['width', 'height'].includes(name)) {
8626
+ this.touchGraph[name] = args.newValue;
8627
+ }
8628
+ }); // 把上层canvse事件传递给绘图层对象
8621
8629
 
8622
- if (eventName) {
8623
- this.emit(eventName, args);
8624
- }
8625
- });
8630
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8631
+ const eventName = args.event.eventName || args.event.type;
8632
+
8633
+ if (eventName) {
8634
+ this.emit(eventName, args);
8635
+ args.event.stopPropagation && args.event.stopPropagation();
8636
+ }
8637
+ });
8638
+ }
8626
8639
  } // 初始化标线
8627
8640
 
8628
8641
 
@@ -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;
@@ -4632,6 +4636,7 @@
4632
4636
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4633
4637
  if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4634
4638
  this.isWXMiniApp = true;// 微信小程序平台
4639
+ this.container = canvas;
4635
4640
  }
4636
4641
  else {
4637
4642
  if(typeof canvas === 'string' && typeof document != 'undefined') {
@@ -8597,35 +8602,43 @@
8597
8602
  container = container.parentElement;
8598
8603
  }
8599
8604
 
8600
- container && (container.style.position = 'relative');
8601
- options = this.utils.clone(options, {
8602
- autoRefresh: true
8603
- }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8605
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8606
+
8607
+ let cn = options.touchCanvas; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8604
8608
  // isWXMiniApp 非微信小程序下才能创建
8605
8609
 
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事件传递给绘图层对象
8610
+ if (container && (options.touchGraph || cn)) {
8611
+ if (!cn && !this.isWXMiniApp) {
8612
+ cn = document.createElement('canvas');
8613
+ cn.width = container.offsetWidth || container.clientWidth;
8614
+ cn.height = container.offsetHeight || container.clientHeight;
8615
+ cn.style.position = 'absolute';
8616
+ cn.style.top = 0;
8617
+ cn.style.left = 0;
8618
+ container.appendChild(cn);
8619
+ }
8621
8620
 
8622
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8623
- const eventName = args.event.eventName || args.event.type;
8621
+ if (cn) {
8622
+ options = this.utils.clone(options, {
8623
+ autoRefresh: true
8624
+ }, true);
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事件传递给绘图层对象
8624
8632
 
8625
- if (eventName) {
8626
- this.emit(eventName, args);
8627
- }
8628
- });
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
+ }
8629
8642
  } // 初始化标线
8630
8643
 
8631
8644
 
@@ -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;
@@ -4634,6 +4638,7 @@ System.register([], function (exports) {
4634
4638
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4635
4639
  if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4636
4640
  this.isWXMiniApp = true;// 微信小程序平台
4641
+ this.container = canvas;
4637
4642
  }
4638
4643
  else {
4639
4644
  if(typeof canvas === 'string' && typeof document != 'undefined') {
@@ -8599,35 +8604,43 @@ System.register([], function (exports) {
8599
8604
  container = container.parentElement;
8600
8605
  }
8601
8606
 
8602
- container && (container.style.position = 'relative');
8603
- options = this.utils.clone(options, {
8604
- autoRefresh: true
8605
- }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8607
+ container && container.style && (container.style.position = 'relative'); // 要先从选项中取出canvas,否则clone过滤掉
8608
+
8609
+ let cn = options.touchCanvas; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8606
8610
  // isWXMiniApp 非微信小程序下才能创建
8607
8611
 
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事件传递给绘图层对象
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
+ }
8623
8622
 
8624
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8625
- const eventName = args.event.eventName || args.event.type;
8623
+ if (cn) {
8624
+ options = this.utils.clone(options, {
8625
+ autoRefresh: true
8626
+ }, true);
8627
+ this.touchGraph = new jmGraph(cn, options);
8628
+ this.touchGraph.chartGraph = this;
8629
+ this.on('propertyChange', (name, args) => {
8630
+ if (['width', 'height'].includes(name)) {
8631
+ this.touchGraph[name] = args.newValue;
8632
+ }
8633
+ }); // 把上层canvse事件传递给绘图层对象
8626
8634
 
8627
- if (eventName) {
8628
- this.emit(eventName, args);
8629
- }
8630
- });
8635
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8636
+ const eventName = args.event.eventName || args.event.type;
8637
+
8638
+ if (eventName) {
8639
+ this.emit(eventName, args);
8640
+ args.event.stopPropagation && args.event.stopPropagation();
8641
+ }
8642
+ });
8643
+ }
8631
8644
  } // 初始化标线
8632
8645
 
8633
8646
 
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.5",
3
+ "version": "1.2.7",
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.2.0"
31
+ "jmgraph": "^3.2.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/core": "^7.10.2",
package/src/jmChart.js CHANGED
@@ -134,40 +134,44 @@ 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');
138
-
139
- options = this.utils.clone(options, {
140
- autoRefresh: true
141
- }, true);
137
+ container && container.style && (container.style.position = 'relative');
138
+ // 要先从选项中取出canvas,否则clone过滤掉
139
+ let cn = options.touchCanvas;
142
140
 
143
141
  // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
144
142
  // 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
- });
143
+ if(container && (options.touchGraph || cn)) {
144
+ if(!cn && !this.isWXMiniApp) {
145
+ cn = document.createElement('canvas');
146
+ cn.width = container.offsetWidth||container.clientWidth;
147
+ cn.height = container.offsetHeight||container.clientHeight;
148
+ cn.style.position = 'absolute';
149
+ cn.style.top = 0;
150
+ cn.style.left = 0;
151
+ container.appendChild(cn);
152
+ }
153
+ if(cn) {
154
+ options = this.utils.clone(options, {
155
+ autoRefresh: true
156
+ }, true);
157
+
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);