jmchart 1.1.81 → 1.1.91

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.
@@ -341,7 +341,7 @@
341
341
  let isTouch = false;
342
342
  let touches = evt.changedTouches || evt.targetTouches || evt.touches;
343
343
  let target = evt.target || evt.srcElement;
344
- if(touches) {
344
+ if(touches && touches.length) {
345
345
  evt = touches[0];//兼容touch事件
346
346
  if(!evt.target) evt.target = target;
347
347
  isTouch = true;
@@ -874,6 +874,23 @@
874
874
  }
875
875
  return r;
876
876
  }
877
+ // window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
878
+ static requestAnimationFrame(callback) {
879
+ if(typeof requestAnimationFrame === 'undefined') {
880
+ return setTimeout(callback, 20);
881
+ }
882
+ else {
883
+ return requestAnimationFrame(callback);
884
+ }
885
+ }
886
+ static cancelAnimationFrame(handler) {
887
+ if(typeof requestAnimationFrame === 'undefined') {
888
+ return clearTimeout(handler);
889
+ }
890
+ else {
891
+ return cancelAnimationFrame(handler);
892
+ }
893
+ }
877
894
  }
878
895
 
879
896
  /**
@@ -4339,6 +4356,7 @@
4339
4356
 
4340
4357
  touchStart(evt) {
4341
4358
  evt = evt || window.event;
4359
+ evt.eventName = 'touchstart';
4342
4360
  this.container.raiseEvent('touchstart',evt);
4343
4361
  let t = evt.target || evt.srcElement;
4344
4362
  if(t == this.target) {
@@ -4349,6 +4367,7 @@
4349
4367
 
4350
4368
  touchMove(evt) {
4351
4369
  evt = evt || window.event;
4370
+ evt.eventName = 'touchmove';
4352
4371
  this.container.raiseEvent('touchmove',evt);
4353
4372
  let t = evt.target || evt.srcElement;
4354
4373
  if(t == this.target) {
@@ -4359,6 +4378,7 @@
4359
4378
 
4360
4379
  touchEnd(evt) {
4361
4380
  evt = evt || window.event;
4381
+ evt.eventName = 'touchend';
4362
4382
 
4363
4383
  this.container.raiseEvent('touchend',evt);
4364
4384
  let t = evt.target || evt.srcElement;
@@ -4370,6 +4390,7 @@
4370
4390
 
4371
4391
  touchCancel(evt) {
4372
4392
  evt = evt || window.event;
4393
+ evt.eventName = 'touchcancel';
4373
4394
 
4374
4395
  this.container.raiseEvent('touchcancel',evt);
4375
4396
  let t = evt.target || evt.srcElement;
@@ -4410,6 +4431,7 @@
4410
4431
 
4411
4432
  this.eventEvents['mousedown'] = jmUtils.bindEvent(this.target,'mousedown',function(evt) {
4412
4433
  evt = evt || window.event;
4434
+ evt.eventName = 'mousedown';
4413
4435
  container.raiseEvent('mousedown',evt);
4414
4436
  //if(r === false) {
4415
4437
  //if(evt.preventDefault) evt.preventDefault();
@@ -4419,6 +4441,7 @@
4419
4441
 
4420
4442
  this.eventEvents['mousedown'] = jmUtils.bindEvent(this.target,'mousemove',function(evt) {
4421
4443
  evt = evt || window.event;
4444
+ evt.eventName = 'mousemove';
4422
4445
  let target = evt.target || evt.srcElement;
4423
4446
  if(target == canvas) {
4424
4447
  container.raiseEvent('mousemove',evt);
@@ -4430,19 +4453,23 @@
4430
4453
  });
4431
4454
 
4432
4455
  this.eventEvents['mousedown'] = jmUtils.bindEvent(this.target,'mouseover',function(evt) {
4433
- evt = evt || window.event;
4456
+ evt = evt || window.event;
4457
+ evt.eventName = 'mouseover';
4434
4458
  container.raiseEvent('mouseover',evt);
4435
4459
  });
4436
4460
  this.eventEvents['mouseleave'] = jmUtils.bindEvent(this.target,'mouseleave',function(evt) {
4437
- evt = evt || window.event;
4461
+ evt = evt || window.event;
4462
+ evt.eventName = 'mouseleave';
4438
4463
  container.raiseEvent('mouseleave',evt);
4439
4464
  });
4440
4465
  this.eventEvents['mouseout'] = jmUtils.bindEvent(this.target,'mouseout',function(evt) {
4441
- evt = evt || window.event;
4466
+ evt = evt || window.event;
4467
+ evt.eventName = 'mouseout';
4442
4468
  container.raiseEvent('mouseout',evt);
4443
4469
  });
4444
4470
  doc && (this.eventEvents['mouseup'] = jmUtils.bindEvent(doc,'mouseup',function(evt) {
4445
- evt = evt || window.event;
4471
+ evt = evt || window.event;
4472
+ evt.eventName = 'mouseup';
4446
4473
  //let target = evt.target || evt.srcElement;
4447
4474
  //if(target == canvas) {
4448
4475
  let r = container.raiseEvent('mouseup',evt);
@@ -4455,33 +4482,40 @@
4455
4482
 
4456
4483
  this.eventEvents['dblclick'] = jmUtils.bindEvent(this.target,'dblclick',function(evt) {
4457
4484
  evt = evt || window.event;
4485
+ evt.eventName = 'dblclick';
4458
4486
  container.raiseEvent('dblclick',evt);
4459
4487
  });
4460
4488
  this.eventEvents['click'] = jmUtils.bindEvent(this.target,'click',function(evt) {
4461
4489
  evt = evt || window.event;
4490
+ evt.eventName = 'click';
4462
4491
  container.raiseEvent('click',evt);
4463
4492
  });
4464
4493
 
4465
4494
  doc && (this.eventEvents['resize'] = jmUtils.bindEvent(doc,'resize',function(evt) {
4466
4495
  evt = evt || window.event;
4496
+ evt.eventName = 'resize';
4467
4497
  return container.raiseEvent('resize',evt);
4468
4498
  }));
4469
4499
 
4470
4500
  // passive: false 为了让浏览器不告警并且preventDefault有效
4471
4501
  // 另一种处理:touch-action: none; 这样任何触摸事件都不会产生默认行为,但是 touch 事件照样触发。
4472
4502
  this.eventEvents['touchstart'] = jmUtils.bindEvent(this.target,'touchstart', function(evt) {
4503
+ evt.eventName = 'touchstart';
4473
4504
  return instance.touchStart(evt);
4474
4505
  },{ passive: false });
4475
4506
 
4476
4507
  this.eventEvents['touchmove'] = jmUtils.bindEvent(this.target,'touchmove', function(evt) {
4508
+ evt.eventName = 'touchmove';
4477
4509
  return instance.touchMove(evt);
4478
4510
  },{ passive: false });
4479
4511
 
4480
4512
  doc && (this.eventEvents['touchend'] = jmUtils.bindEvent(doc,'touchend', function(evt) {
4513
+ evt.eventName = 'touchend';
4481
4514
  return instance.touchEnd(evt);
4482
4515
  },{ passive: false }));
4483
4516
 
4484
4517
  doc && (this.eventEvents['touchcancel'] = jmUtils.bindEvent(doc,'touchcancel', function(evt) {
4518
+ evt.eventName = 'touchcancel';
4485
4519
  return instance.touchCancel(evt);
4486
4520
  },{ passive: false }));
4487
4521
  }
@@ -4536,7 +4570,7 @@
4536
4570
  return true;
4537
4571
  };
4538
4572
 
4539
- doc && (this.eventEvents['touchcancel'] = jmUtils.bindEvent(doc,'keypress',function(evt) {
4573
+ doc && (this.eventEvents['keypress'] = jmUtils.bindEvent(doc,'keypress',function(evt) {
4540
4574
  evt = evt || window.event;
4541
4575
  if(!checkKeyEvent(evt)) return;//如果事件为其它输入框,则不响应
4542
4576
  let r = container.raiseEvent('keypress',evt);
@@ -4544,7 +4578,7 @@
4544
4578
  evt.preventDefault();
4545
4579
  return r;
4546
4580
  }));
4547
- doc && (this.eventEvents['touchcancel'] = jmUtils.bindEvent(doc,'keydown',function(evt) {
4581
+ doc && (this.eventEvents['keydown'] = jmUtils.bindEvent(doc,'keydown',function(evt) {
4548
4582
  evt = evt || window.event;
4549
4583
  if(!checkKeyEvent(evt)) return;//如果事件为其它输入框,则不响应
4550
4584
  let r = container.raiseEvent('keydown',evt);
@@ -4552,7 +4586,7 @@
4552
4586
  evt.preventDefault();
4553
4587
  return r;
4554
4588
  }));
4555
- doc && (this.eventEvents['touchcancel'] = jmUtils.bindEvent(doc,'keyup',function(evt) {
4589
+ doc && (this.eventEvents['keyup'] = jmUtils.bindEvent(doc,'keyup',function(evt) {
4556
4590
  evt = evt || window.event;
4557
4591
  if(!checkKeyEvent(evt)) return;//如果事件为其它输入框,则不响应
4558
4592
  let r = container.raiseEvent('keyup',evt);
@@ -4592,7 +4626,7 @@
4592
4626
  }
4593
4627
 
4594
4628
  option = option || {};
4595
-
4629
+ option.mode = option.mode || '2d'; // webgl | 2d
4596
4630
  option.interactive = true;
4597
4631
 
4598
4632
  super(option, 'jmGraph');
@@ -4632,8 +4666,7 @@
4632
4666
  }
4633
4667
  else {
4634
4668
  this.container = canvas.parentElement;
4635
- }
4636
-
4669
+ }
4637
4670
  this.context = canvas.getContext('2d');
4638
4671
  }
4639
4672
  this.canvas = canvas;
@@ -5061,26 +5094,19 @@
5061
5094
  if(this.___isAutoRefreshing) return;
5062
5095
  const self = this;
5063
5096
  this.___isAutoRefreshing = true;
5064
- let requestAnimationFrameFun = null;
5065
- if(typeof requestAnimationFrame === 'undefined') {
5066
- requestAnimationFrameFun = (fun) => {
5067
- if(this.__requestAnimationFrameFunHandler) clearTimeout(this.__requestAnimationFrameFunHandler);
5068
- this.__requestAnimationFrameFunHandler = setTimeout(fun, 20);
5069
- };
5070
- }
5071
- else {
5072
- requestAnimationFrameFun = requestAnimationFrame;
5073
- }
5097
+
5074
5098
  function update() {
5075
5099
  if(self.destoryed) {
5076
5100
  self.___isAutoRefreshing = false;
5077
5101
  return;// 已销毁
5078
5102
  }
5079
5103
  if(self.needUpdate) self.redraw();
5080
- requestAnimationFrameFun(update);
5104
+ self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5105
+ self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5081
5106
  if(callback) callback();
5082
5107
  }
5083
- requestAnimationFrameFun(update);
5108
+ self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5109
+ self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5084
5110
  return this;
5085
5111
  }
5086
5112
 
@@ -5133,12 +5159,12 @@
5133
5159
  }
5134
5160
  }
5135
5161
 
5136
- /**
5137
- * 基础样式
5138
- *
5139
- * @class jmChartStyle
5140
- * @module jmChart
5141
- * @static
5162
+ /**
5163
+ * 基础样式
5164
+ *
5165
+ * @class jmChartStyle
5166
+ * @module jmChart
5167
+ * @static
5142
5168
  */
5143
5169
  var defaultStyle = {
5144
5170
  layout: 'normal',
@@ -5274,13 +5300,13 @@
5274
5300
  // 图形样式集
5275
5301
  chartColors: ['#249FDA', '#EA3B7C', '#8EBC00', '#309B46', '#4B507E', '#D8E404', '#EB792A', '#A00DA0'],
5276
5302
 
5277
- /*tooltip: {
5278
- 'background-color': 'rgb(255,255,255)',
5279
- 'padding':'4px',
5280
- 'opacity':'0.8',
5281
- 'border':'1px solid #000',
5282
- 'box-shadow': '0 0 3px #000',
5283
- 'border-radius': '6px'
5303
+ /*tooltip: {
5304
+ 'background-color': 'rgb(255,255,255)',
5305
+ 'padding':'4px',
5306
+ 'opacity':'0.8',
5307
+ 'border':'1px solid #000',
5308
+ 'box-shadow': '0 0 3px #000',
5309
+ 'border-radius': '6px'
5284
5310
  },*/
5285
5311
  line: {
5286
5312
  normal: {
@@ -5387,18 +5413,35 @@
5387
5413
  blur: 2,
5388
5414
  color: '#ccc'
5389
5415
  }
5416
+ },
5417
+ candlestick: {
5418
+ normal: {
5419
+ lineWidth: 1,
5420
+ zIndex: 18,
5421
+ cursor: 'default'
5422
+ },
5423
+ hover: {
5424
+ //zIndex: 100,
5425
+ cursor: 'pointer'
5426
+ },
5427
+ perWidth: 0.5,
5428
+ // 阴线颜色
5429
+ negativeColor: 'green',
5430
+ // 阳线颜色
5431
+ masculineColor: 'red',
5432
+ lineWidth: 1
5390
5433
  }
5391
5434
  };
5392
5435
 
5393
- /**
5394
- * 轴
5395
- *
5396
- * @class jmAxis
5397
- * @module jmChart
5398
- * @param {jmChart} chart 当前图表
5399
- * @param {string} [type] 轴类型(x/y/radar),默认为x
5400
- * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
5401
- * @param {object} [style] 样式
5436
+ /**
5437
+ * 轴
5438
+ *
5439
+ * @class jmAxis
5440
+ * @module jmChart
5441
+ * @param {jmChart} chart 当前图表
5442
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
5443
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
5444
+ * @param {object} [style] 样式
5402
5445
  */
5403
5446
 
5404
5447
  class jmAxis extends jmArrowLine {
@@ -5445,21 +5488,21 @@
5445
5488
 
5446
5489
  if (typeof options.minXValue !== 'undefined') this.minValue = options.minXValue; // 最小值,如果指定了,则轴的最小值为它或更小的值
5447
5490
  } else {
5448
- if (typeof options.maxYValue !== 'undefined') this.maxValue = options.maxYValue; // 最大的值,如果指定了,则如果有数值比它大才会修改上限,否则以它为上限
5491
+ if (typeof options.maxYValue !== 'undefined' && (options.maxYValue > this.maxValue || typeof this.maxValue === 'undefined')) this.maxValue = options.maxYValue; // 最大的值,如果指定了,则如果有数值比它大才会修改上限,否则以它为上限
5449
5492
 
5450
- if (typeof options.minYValue !== 'undefined') this.minValue = options.minYValue; // 最小值,如果指定了,则轴的最小值为它或更小的值
5493
+ if (typeof options.minYValue !== 'undefined' && (options.minYValue < this.minValue || typeof this.minValue === 'undefined')) this.minValue = options.minYValue; // 最小值,如果指定了,则轴的最小值为它或更小的值
5451
5494
  }
5452
5495
  }
5453
- /**
5454
- * 轴类型(x/y/radar),默认为x
5455
- *
5456
- * @property type
5457
- * @type string
5496
+ /**
5497
+ * 轴类型(x/y/radar),默认为x
5498
+ *
5499
+ * @property type
5500
+ * @type string
5458
5501
  */
5459
5502
 
5460
5503
 
5461
- /**
5462
- * 关联访问的是chart的数据源
5504
+ /**
5505
+ * 关联访问的是chart的数据源
5463
5506
  */
5464
5507
  get data() {
5465
5508
  return this.graph.data;
@@ -5468,10 +5511,10 @@
5468
5511
  set data(d) {
5469
5512
  this.graph.data = d;
5470
5513
  }
5471
- /**
5472
- * 计算当前轴的位置
5473
- *
5474
- * @method reset
5514
+ /**
5515
+ * 计算当前轴的位置
5516
+ *
5517
+ * @method reset
5475
5518
  */
5476
5519
 
5477
5520
 
@@ -5529,10 +5572,10 @@
5529
5572
 
5530
5573
  super.draw();
5531
5574
  }
5532
- /**
5533
- * 生成轴标签
5534
- *
5535
- * @method createLabel
5575
+ /**
5576
+ * 生成轴标签
5577
+ *
5578
+ * @method createLabel
5536
5579
  */
5537
5580
 
5538
5581
 
@@ -5549,11 +5592,11 @@
5549
5592
  this.createYLabel();
5550
5593
  }
5551
5594
  }
5552
- /**
5553
- * 生成X轴标签
5554
- *
5555
- * @method createXLabel
5556
- * @private
5595
+ /**
5596
+ * 生成X轴标签
5597
+ *
5598
+ * @method createXLabel
5599
+ * @private
5557
5600
  */
5558
5601
 
5559
5602
 
@@ -5644,11 +5687,11 @@
5644
5687
  }
5645
5688
  }
5646
5689
  }
5647
- /**
5648
- * 生成Y轴标签
5649
- *
5650
- * @method createYLabel
5651
- * @private
5690
+ /**
5691
+ * 生成Y轴标签
5692
+ *
5693
+ * @method createYLabel
5694
+ * @private
5652
5695
  */
5653
5696
 
5654
5697
 
@@ -5661,8 +5704,8 @@
5661
5704
 
5662
5705
  let count = this.labelCount;
5663
5706
  const mm = max - min;
5664
- /*if(mm <= 10) {
5665
- count = mm;
5707
+ /*if(mm <= 10) {
5708
+ count = mm;
5666
5709
  }*/
5667
5710
  // mm 放大10000倍,这里结果也需要除于10000
5668
5711
 
@@ -5774,10 +5817,10 @@
5774
5817
  }
5775
5818
  }
5776
5819
  }
5777
- /**
5778
- * 获取当前轴所占宽
5779
- *
5780
- * @method width
5820
+ /**
5821
+ * 获取当前轴所占宽
5822
+ *
5823
+ * @method width
5781
5824
  */
5782
5825
 
5783
5826
 
@@ -5792,10 +5835,10 @@
5792
5835
  set width(w) {
5793
5836
  this._width = w;
5794
5837
  }
5795
- /**
5796
- * 获取当前轴所占高
5797
- *
5798
- * @method height
5838
+ /**
5839
+ * 获取当前轴所占高
5840
+ *
5841
+ * @method height
5799
5842
  */
5800
5843
 
5801
5844
 
@@ -5805,12 +5848,12 @@
5805
5848
 
5806
5849
 
5807
5850
  set height(h) {}
5808
- /**
5809
- * 获取或设置当前轴最大值
5810
- *
5811
- * @method max
5812
- * @param {number/date/string} 当前轴的最大值
5813
- * @return 当前轴的最大值
5851
+ /**
5852
+ * 获取或设置当前轴最大值
5853
+ *
5854
+ * @method max
5855
+ * @param {number/date/string} 当前轴的最大值
5856
+ * @return 当前轴的最大值
5814
5857
  */
5815
5858
 
5816
5859
 
@@ -5859,12 +5902,12 @@
5859
5902
 
5860
5903
  return this._max;
5861
5904
  }
5862
- /**
5863
- * 获取或设置当前轴最小值
5864
- *
5865
- * @method max
5866
- * @param {number/date/string} 当前轴的最小值
5867
- * @return 当前轴的最小值
5905
+ /**
5906
+ * 获取或设置当前轴最小值
5907
+ *
5908
+ * @method max
5909
+ * @param {number/date/string} 当前轴的最小值
5910
+ * @return 当前轴的最小值
5868
5911
  */
5869
5912
 
5870
5913
 
@@ -5911,10 +5954,10 @@
5911
5954
 
5912
5955
  return this.dataType == 'string' ? 0 : this._min;
5913
5956
  }
5914
- /**
5915
- * 清除一些属性
5916
- *
5917
- * @method clear
5957
+ /**
5958
+ * 清除一些属性
5959
+ *
5960
+ * @method clear
5918
5961
  */
5919
5962
 
5920
5963
 
@@ -5922,11 +5965,11 @@
5922
5965
  this._min = null;
5923
5966
  this._max = null;
5924
5967
  }
5925
- /**
5926
- * 计算当前轴的单位偏移量
5927
- *
5928
- * @method step
5929
- * @return {number} 单位偏移量
5968
+ /**
5969
+ * 计算当前轴的单位偏移量
5970
+ *
5971
+ * @method step
5972
+ * @return {number} 单位偏移量
5930
5973
  */
5931
5974
 
5932
5975
 
@@ -5975,12 +6018,12 @@
5975
6018
 
5976
6019
  }
5977
6020
 
5978
- /**
5979
- * 图例的容器
5980
- *
5981
- * @class jmLegend
5982
- * @module jmChart
5983
- * @param {jmChart} chart 当前图表
6021
+ /**
6022
+ * 图例的容器
6023
+ *
6024
+ * @class jmLegend
6025
+ * @module jmChart
6026
+ * @param {jmChart} chart 当前图表
5984
6027
  */
5985
6028
 
5986
6029
  class jmLegend extends jmRect {
@@ -5992,20 +6035,20 @@
5992
6035
  };
5993
6036
  super(options);
5994
6037
 
5995
- _defineProperty(this, "legendPosition", 'right');
6038
+ _defineProperty(this, "legendPosition", '');
5996
6039
  }
5997
- /**
5998
- * 图例放置位置
6040
+ /**
6041
+ * 图例放置位置
5999
6042
  */
6000
6043
 
6001
6044
 
6002
6045
  }
6003
- /**
6004
- * 添加图例
6005
- *
6006
- * @method append
6007
- * @param {jmSeries} series 当前图序列
6008
- * @param {jmControl} shape 当前图例的图形对象
6046
+ /**
6047
+ * 添加图例
6048
+ *
6049
+ * @method append
6050
+ * @param {jmSeries} series 当前图序列
6051
+ * @param {jmControl} shape 当前图例的图形对象
6009
6052
  */
6010
6053
 
6011
6054
  jmLegend.prototype.append = function (series, shape, options = {}) {
@@ -6045,24 +6088,27 @@
6045
6088
  panel.height = shape.height; //执行进入事件
6046
6089
  //触动图例后加粗显示图
6047
6090
 
6048
- /*const hover = options.hover || function() {
6049
- //应用图的动态样式
6050
- //Object.assign(series.style, series.style.hover);
6051
- //Object.assign(this.style, this.style.hover || {});
6052
- //series.graph.refresh();
6053
- };
6054
- panel.bind('mouseover', hover);
6055
- //执行离开
6056
- const leave = options.leave || function() {
6057
- //应用图的普通样式
6058
- //Object.assign(series.style, series.style.normal);
6059
- //Object.assign(this.style, this.style.normal || {});
6060
- //jmUtils.apply(this.series.style.normal,this.series.style);
6061
- //series.graph.refresh();
6062
- };
6091
+ /*const hover = options.hover || function() {
6092
+ //应用图的动态样式
6093
+ //Object.assign(series.style, series.style.hover);
6094
+
6095
+ //Object.assign(this.style, this.style.hover || {});
6096
+
6097
+ //series.graph.refresh();
6098
+ };
6099
+ panel.bind('mouseover', hover);
6100
+ //执行离开
6101
+ const leave = options.leave || function() {
6102
+ //应用图的普通样式
6103
+ //Object.assign(series.style, series.style.normal);
6104
+
6105
+ //Object.assign(this.style, this.style.normal || {});
6106
+ //jmUtils.apply(this.series.style.normal,this.series.style);
6107
+ //series.graph.refresh();
6108
+ };
6063
6109
  panel.bind('mouseleave', leave);*/
6064
6110
 
6065
- const legendPosition = this.legendPosition || this.style.legendPosition;
6111
+ const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
6066
6112
 
6067
6113
  if (legendPosition == 'top' || legendPosition == 'bottom') {
6068
6114
  //顶部和底部图例横排,每次右移位一个单位图例
@@ -6079,10 +6125,10 @@
6079
6125
 
6080
6126
  this.needUpdate = true;
6081
6127
  };
6082
- /**
6083
- * 初始化图例
6084
- *
6085
- * @method init
6128
+ /**
6129
+ * 初始化图例
6130
+ *
6131
+ * @method init
6086
6132
  */
6087
6133
 
6088
6134
 
@@ -6094,10 +6140,10 @@
6094
6140
  this.style.lineWidth = 0;
6095
6141
  this.children.clear();
6096
6142
  };
6097
- /**
6098
- * 重置图例属性,根据图例内容计算期大小并更新画图区域大小
6099
- *
6100
- * @method reset
6143
+ /**
6144
+ * 重置图例属性,根据图例内容计算期大小并更新画图区域大小
6145
+ *
6146
+ * @method reset
6101
6147
  */
6102
6148
 
6103
6149
 
@@ -6142,11 +6188,11 @@
6142
6188
  };
6143
6189
 
6144
6190
  var utils = {
6145
- /**
6146
- * 对比二个数组数据是否改变
6147
- * @param {Array} source 被对比的数、组
6148
- * @param {Array} target 对比数组
6149
- * @param {Function} compare 比较函数
6191
+ /**
6192
+ * 对比二个数组数据是否改变
6193
+ * @param {Array} source 被对比的数、组
6194
+ * @param {Array} target 对比数组
6195
+ * @param {Function} compare 比较函数
6150
6196
  */
6151
6197
  arrayIsChange(source, target, compare) {
6152
6198
  if (!source || !target) return true;
@@ -6163,14 +6209,14 @@
6163
6209
 
6164
6210
  };
6165
6211
 
6166
- /**
6167
- * 图形基类
6168
- *
6169
- * @class jmSeries
6170
- * @module jmChart
6171
- * @param {jmChart} chart 当前图表
6172
- * @param {array} mappings 图形字段映射
6173
- * @param {style} style 样式
6212
+ /**
6213
+ * 图形基类
6214
+ *
6215
+ * @class jmSeries
6216
+ * @module jmChart
6217
+ * @param {jmChart} chart 当前图表
6218
+ * @param {array} mappings 图形字段映射
6219
+ * @param {style} style 样式
6174
6220
  */
6175
6221
  //构造线图
6176
6222
 
@@ -6214,8 +6260,8 @@
6214
6260
  maxYValue: options.maxYValue
6215
6261
  });
6216
6262
  }
6217
- /**
6218
- * 关联访问的是chart的数据源
6263
+ /**
6264
+ * 关联访问的是chart的数据源
6219
6265
  */
6220
6266
 
6221
6267
 
@@ -6237,11 +6283,11 @@
6237
6283
  set enableAnimate(v) {
6238
6284
  this.option.enableAnimate = v;
6239
6285
  }
6240
- /**
6241
- * 图例名称
6242
- *
6243
- * @property legendLabel
6244
- * @type string
6286
+ /**
6287
+ * 图例名称
6288
+ *
6289
+ * @property legendLabel
6290
+ * @type string
6245
6291
  */
6246
6292
 
6247
6293
 
@@ -6271,10 +6317,10 @@
6271
6317
  points: this.dataPoints
6272
6318
  };
6273
6319
  }
6274
- /**
6275
- * 根据X轴坐标,获取它最近的数据描点
6276
- * 离点最近的一个描点
6277
- * @param {number} x X轴坐标
6320
+ /**
6321
+ * 根据X轴坐标,获取它最近的数据描点
6322
+ * 离点最近的一个描点
6323
+ * @param {number} x X轴坐标
6278
6324
  */
6279
6325
 
6280
6326
 
@@ -6302,9 +6348,9 @@
6302
6348
 
6303
6349
  return null;
6304
6350
  }
6305
- /**
6306
- * 根据X轴值获取数据点
6307
- * @param {number} xValue X轴值
6351
+ /**
6352
+ * 根据X轴值获取数据点
6353
+ * @param {number} xValue X轴值
6308
6354
  */
6309
6355
 
6310
6356
 
@@ -6318,11 +6364,11 @@
6318
6364
 
6319
6365
  return null;
6320
6366
  }
6321
- /**
6322
- * 重置属性
6323
- * 根据数据源计算轴的属性
6324
- *
6325
- * @method reset
6367
+ /**
6368
+ * 重置属性
6369
+ * 根据数据源计算轴的属性
6370
+ *
6371
+ * @method reset
6326
6372
  */
6327
6373
 
6328
6374
 
@@ -6366,10 +6412,10 @@
6366
6412
  this.xAxis.min(xv);
6367
6413
  }
6368
6414
  }
6369
- /**
6370
- * 生成序列图描点
6371
- *
6372
- * @method createPoints
6415
+ /**
6416
+ * 生成序列图描点
6417
+ *
6418
+ * @method createPoints
6373
6419
  */
6374
6420
 
6375
6421
 
@@ -6411,7 +6457,8 @@
6411
6457
  x: p.x,
6412
6458
  // 高度
6413
6459
  height: p.height,
6414
- yValue: yv
6460
+ yValue: yv,
6461
+ field: f
6415
6462
  }; //如果Y值不存在。则此点无效,不画图
6416
6463
 
6417
6464
  if (yv == null || typeof yv == 'undefined') {
@@ -6446,10 +6493,10 @@
6446
6493
  return this.style.color;
6447
6494
  }
6448
6495
  }
6449
- /**
6450
- * 生成图例
6451
- *
6452
- * @method createLegend
6496
+ /**
6497
+ * 生成图例
6498
+ *
6499
+ * @method createLegend
6453
6500
  */
6454
6501
 
6455
6502
 
@@ -6501,9 +6548,9 @@
6501
6548
  });
6502
6549
  this.addShape(label);
6503
6550
  }
6504
- /**
6505
- * 在图上加下定制图形
6506
- * @param {jmShape} shape 图形
6551
+ /**
6552
+ * 在图上加下定制图形
6553
+ * @param {jmShape} shape 图形
6507
6554
  */
6508
6555
 
6509
6556
 
@@ -6512,13 +6559,13 @@
6512
6559
  this.shapes.add(shape);
6513
6560
  return shape;
6514
6561
  }
6515
- /**
6516
- * 获取指定事件的集合
6517
- * 比如mousedown,mouseup等
6518
- *
6519
- * @method getEvent
6520
- * @param {string} name 事件名称
6521
- * @return {list} 事件委托的集合
6562
+ /**
6563
+ * 获取指定事件的集合
6564
+ * 比如mousedown,mouseup等
6565
+ *
6566
+ * @method getEvent
6567
+ * @param {string} name 事件名称
6568
+ * @return {list} 事件委托的集合
6522
6569
  */
6523
6570
 
6524
6571
 
@@ -6542,14 +6589,14 @@
6542
6589
 
6543
6590
  }
6544
6591
 
6545
- /**
6546
- * 柱图
6547
- *
6548
- * @class jmBarSeries
6549
- * @module jmChart
6550
- * @param {jmChart} chart 当前图表
6551
- * @param {array} mappings 图形字段映射
6552
- * @param {style} style 样式
6592
+ /**
6593
+ * 柱图
6594
+ *
6595
+ * @class jmBarSeries
6596
+ * @module jmChart
6597
+ * @param {jmChart} chart 当前图表
6598
+ * @param {array} mappings 图形字段映射
6599
+ * @param {style} style 样式
6553
6600
  */
6554
6601
  //构造函数
6555
6602
 
@@ -6557,11 +6604,11 @@
6557
6604
  constructor(options) {
6558
6605
  super(options);
6559
6606
  }
6560
- /**
6561
- * 绘制当前图形
6562
- *
6563
- * @method beginDraw
6564
- * @for jmBarSeries
6607
+ /**
6608
+ * 绘制当前图形
6609
+ *
6610
+ * @method beginDraw
6611
+ * @for jmBarSeries
6565
6612
  */
6566
6613
 
6567
6614
 
@@ -6668,9 +6715,9 @@
6668
6715
  this.barTotalWidth = maxWidth * this.graph.barSeriesCount;
6669
6716
  }
6670
6717
  }
6671
- /**
6672
- * 在图上加下定制图形
6673
- * @param {jmShape} shape 图形
6718
+ /**
6719
+ * 在图上加下定制图形
6720
+ * @param {jmShape} shape 图形
6674
6721
  */
6675
6722
 
6676
6723
 
@@ -6682,14 +6729,14 @@
6682
6729
 
6683
6730
  }
6684
6731
 
6685
- /**
6686
- * 柱图
6687
- *
6688
- * @class jmBarSeries
6689
- * @module jmChart
6690
- * @param {jmChart} chart 当前图表
6691
- * @param {array} mappings 图形字段映射
6692
- * @param {style} style 样式
6732
+ /**
6733
+ * 柱图
6734
+ *
6735
+ * @class jmBarSeries
6736
+ * @module jmChart
6737
+ * @param {jmChart} chart 当前图表
6738
+ * @param {array} mappings 图形字段映射
6739
+ * @param {style} style 样式
6693
6740
  */
6694
6741
  //构造函数
6695
6742
 
@@ -6697,11 +6744,11 @@
6697
6744
  constructor(options) {
6698
6745
  super(options);
6699
6746
  }
6700
- /**
6701
- * 绘制当前图形
6702
- *
6703
- * @method beginDraw
6704
- * @for jmBarSeries
6747
+ /**
6748
+ * 绘制当前图形
6749
+ *
6750
+ * @method beginDraw
6751
+ * @for jmBarSeries
6705
6752
  */
6706
6753
 
6707
6754
 
@@ -6831,14 +6878,14 @@
6831
6878
 
6832
6879
  }
6833
6880
 
6834
- /**
6835
- * 饼图
6836
- *
6837
- * @class jmPieSeries
6838
- * @module jmChart
6839
- * @param {jmChart} chart 当前图表
6840
- * @param {array} mappings 图形字段映射
6841
- * @param {style} style 样式
6881
+ /**
6882
+ * 饼图
6883
+ *
6884
+ * @class jmPieSeries
6885
+ * @module jmChart
6886
+ * @param {jmChart} chart 当前图表
6887
+ * @param {array} mappings 图形字段映射
6888
+ * @param {style} style 样式
6842
6889
  */
6843
6890
  //构造函数
6844
6891
 
@@ -6922,10 +6969,10 @@
6922
6969
  set startAngle(v) {
6923
6970
  this.option.startAngle = v;
6924
6971
  }
6925
- /**
6926
- * 生成序列图描点
6927
- *
6928
- * @method createPoints
6972
+ /**
6973
+ * 生成序列图描点
6974
+ *
6975
+ * @method createPoints
6929
6976
  */
6930
6977
 
6931
6978
 
@@ -7015,8 +7062,8 @@
7015
7062
  maxRadius: p.maxRadius,
7016
7063
  minRadius: p.minRadius
7017
7064
  });
7018
- /**
7019
- * 因为jmgraph是按图形形状来计算所占区域和大小的, 这里我们把扇形占区域改为整个图圆。这样计算大小和渐变时才好闭合。
7065
+ /**
7066
+ * 因为jmgraph是按图形形状来计算所占区域和大小的, 这里我们把扇形占区域改为整个图圆。这样计算大小和渐变时才好闭合。
7020
7067
  */
7021
7068
 
7022
7069
  p.shape.getLocation = function () {
@@ -7125,10 +7172,10 @@
7125
7172
  }
7126
7173
 
7127
7174
  }
7128
- /**
7129
- * 生成图例
7130
- *
7131
- * @method createLegend
7175
+ /**
7176
+ * 生成图例
7177
+ *
7178
+ * @method createLegend
7132
7179
  */
7133
7180
 
7134
7181
  jmPieSeries.prototype.createLegend = function () {
@@ -7170,14 +7217,14 @@
7170
7217
  }
7171
7218
  };
7172
7219
 
7173
- /**
7174
- * 图形基类
7175
- *
7176
- * @class jmLineSeries
7177
- * @module jmChart
7178
- * @param {jmChart} chart 当前图表
7179
- * @param {array} mappings 图形字段映射
7180
- * @param {style} style 样式
7220
+ /**
7221
+ * 图形基类
7222
+ *
7223
+ * @class jmLineSeries
7224
+ * @module jmChart
7225
+ * @param {jmChart} chart 当前图表
7226
+ * @param {array} mappings 图形字段映射
7227
+ * @param {style} style 样式
7181
7228
  */
7182
7229
  //构造函数
7183
7230
 
@@ -7186,11 +7233,11 @@
7186
7233
  options.style = options.style || options.graph.style.line;
7187
7234
  super(options); //this.on('beginDraw', this[PreDrawKey]);
7188
7235
  }
7189
- /**
7190
- * 绘制图形前 初始化线条
7191
- *
7192
- * @method preDraw
7193
- * @for jmLineSeries
7236
+ /**
7237
+ * 绘制图形前 初始化线条
7238
+ *
7239
+ * @method preDraw
7240
+ * @for jmLineSeries
7194
7241
  */
7195
7242
 
7196
7243
 
@@ -7325,10 +7372,10 @@
7325
7372
 
7326
7373
  return shapePoints;
7327
7374
  }
7328
- /**
7329
- * 生成图例
7330
- *
7331
- * @method createLegend
7375
+ /**
7376
+ * 生成图例
7377
+ *
7378
+ * @method createLegend
7332
7379
  */
7333
7380
 
7334
7381
 
@@ -7417,14 +7464,14 @@
7417
7464
 
7418
7465
  }
7419
7466
 
7420
- /**
7421
- * 二条线组成的区域图表
7422
- *
7423
- * @class jmStackLineSeries
7424
- * @module jmChart
7425
- * @param {jmChart} chart 当前图表
7426
- * @param {array} mappings 图形字段映射
7427
- * @param {style} style 样式
7467
+ /**
7468
+ * 二条线组成的区域图表
7469
+ *
7470
+ * @class jmStackLineSeries
7471
+ * @module jmChart
7472
+ * @param {jmChart} chart 当前图表
7473
+ * @param {array} mappings 图形字段映射
7474
+ * @param {style} style 样式
7428
7475
  */
7429
7476
  //构造函数
7430
7477
 
@@ -7433,11 +7480,11 @@
7433
7480
  options.style = options.style || options.graph.style.stackLine;
7434
7481
  super(options);
7435
7482
  }
7436
- /**
7437
- * 绘制图形前 初始化线条
7438
- *
7439
- * @method preDraw
7440
- * @for jmLineSeries
7483
+ /**
7484
+ * 绘制图形前 初始化线条
7485
+ *
7486
+ * @method preDraw
7487
+ * @for jmLineSeries
7441
7488
  */
7442
7489
 
7443
7490
 
@@ -7517,10 +7564,10 @@
7517
7564
  areaEnd.m = false;
7518
7565
  this.createArea(areaPoints, false);
7519
7566
  }
7520
- /**
7521
- * 生成图例
7522
- *
7523
- * @method createLegend
7567
+ /**
7568
+ * 生成图例
7569
+ *
7570
+ * @method createLegend
7524
7571
  */
7525
7572
 
7526
7573
 
@@ -7568,15 +7615,114 @@
7568
7615
 
7569
7616
  }
7570
7617
 
7571
- /**
7572
- * 轴
7573
- *
7574
- * @class jmAxis
7575
- * @module jmChart
7576
- * @param {jmChart} chart 当前图表
7577
- * @param {string} [type] 轴类型(x/y/radar),默认为x
7578
- * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
7579
- * @param {object} [style] 样式
7618
+ /**
7619
+ * K线图
7620
+ *
7621
+ * @class jmCandlestickSeries
7622
+ * @module jmChart
7623
+ * @param {jmChart} chart 当前图表
7624
+ * @param {array} mappings 图形字段映射
7625
+ * @param {style} style 样式
7626
+ */
7627
+ //构造函数
7628
+
7629
+ class jmCandlestickSeries extends jmSeries {
7630
+ constructor(options) {
7631
+ options.style = options.style || options.graph.style.line;
7632
+ super(options); //this.on('beginDraw', this[PreDrawKey]);
7633
+ }
7634
+ /**
7635
+ * 绘制图形前 初始化线条
7636
+ *
7637
+ * @method preDraw
7638
+ * @for jmLineSeries
7639
+ */
7640
+
7641
+
7642
+ init() {
7643
+ //生成描点位
7644
+ const {
7645
+ points
7646
+ } = this.initDataPoint(); //去除多余的线条
7647
+ //当数据源线条数比现有的少时,删除多余的线条
7648
+
7649
+ const len = points.length;
7650
+ this.initWidth(len);
7651
+ const w = this.barWidth / 2; //实心处宽度的一半
7652
+
7653
+ for (let i = 0; i < len; i++) {
7654
+ const p = points[i]; //如果当前点无效,则跳致下一点
7655
+
7656
+ if (typeof p.y === 'undefined' || p.y === null) {
7657
+ //prePoint = null;
7658
+ continue;
7659
+ }
7660
+
7661
+ const sp = this.addShape(this.graph.createPath([], p.style));
7662
+ const bl = {
7663
+ x: p.x - w,
7664
+ y: p.points[0].y
7665
+ };
7666
+ const br = {
7667
+ x: p.x + w,
7668
+ y: p.points[0].y
7669
+ };
7670
+ const tl = {
7671
+ x: p.x - w,
7672
+ y: p.points[1].y
7673
+ };
7674
+ const tr = {
7675
+ x: p.x + w,
7676
+ y: p.points[1].y
7677
+ }; // 默认认为是阳线
7678
+
7679
+ let tm = p.points[1];
7680
+ let bm = p.points[0];
7681
+ p.style.stroke = p.style.fill = p.style.masculineColor || 'red'; // 开盘大于收盘,则阴线
7682
+
7683
+ if (p.points[0].yValue > p.points[1].yValue) {
7684
+ p.style.stroke = p.style.fill = p.style.negativeColor || 'green';
7685
+ bl.y = br.y = p.points[1].y;
7686
+ tl.y = tr.y = p.points[0].y;
7687
+ tm = p.points[0];
7688
+ bm = p.points[1];
7689
+ }
7690
+
7691
+ sp.points.push(p.points[2], tm, tl, bl, bm, p.points[3], bm, br, tr, tm, p.points[2]); // 生成关健值标注
7692
+
7693
+ this.emit('onPointCreated', p);
7694
+ }
7695
+ } // 计算实心体宽度
7696
+
7697
+
7698
+ initWidth(count) {
7699
+ //计算每个柱子占宽
7700
+ //每项柱子占宽除以柱子个数,默认最大宽度为30
7701
+ const maxWidth = this.xAxis.width / count;
7702
+
7703
+ if (this.style.barWidth > 0) {
7704
+ this.barWidth = Number(this.style.barWidth);
7705
+ } else {
7706
+ this.barWidth = maxWidth * (this.style.perWidth || 0.4);
7707
+ }
7708
+
7709
+ if (this.barWidth > maxWidth) {
7710
+ this.barWidth = maxWidth;
7711
+ this.barTotalWidth = maxWidth * count;
7712
+ }
7713
+ }
7714
+
7715
+ }
7716
+
7717
+ /**
7718
+ * 轴
7719
+ *
7720
+ * @class jmAxis
7721
+ * @module jmChart
7722
+ * @param {jmChart} chart 当前图表
7723
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
7724
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
7725
+ * @param {object} [style] 样式
7580
7726
  */
7581
7727
 
7582
7728
  class jmMarkLine extends jmLine {
@@ -7585,8 +7731,8 @@
7585
7731
  this.visible = false;
7586
7732
  this.markLineType = options.type || 'x'; // 为横轴x或纵轴y
7587
7733
 
7588
- /**
7589
- * 当前图形下的所有子图
7734
+ /**
7735
+ * 当前图形下的所有子图
7590
7736
  */
7591
7737
 
7592
7738
  this.shapes = new jmList();
@@ -7649,8 +7795,8 @@
7649
7795
  serie.lastMarkPoint = point; // 记下最后一次改变的点
7650
7796
  // 同时改变下X轴标线的位置,它的Y坐标跟随最后一个命中的线点
7651
7797
 
7652
- if (graph && graph.xMarkLine) {
7653
- graph.xMarkLine.start.y = graph.xMarkLine.end.y = isTocuhGraph ? point.y + graph.chartArea.position.y : point.y;
7798
+ if (graph && graph.markLine && graph.markLine.xMarkLine) {
7799
+ graph.markLine.xMarkLine.start.y = graph.markLine.xMarkLine.end.y = isTocuhGraph ? point.y + graph.chartArea.position.y : point.y;
7654
7800
  }
7655
7801
  }
7656
7802
  } catch (e) {
@@ -7665,9 +7811,9 @@
7665
7811
  }, 10);
7666
7812
  }
7667
7813
  }
7668
- /**
7669
- * 移动标线
7670
- * @param { object } args 移动事件参数
7814
+ /**
7815
+ * 移动标线
7816
+ * @param { object } args 移动事件参数
7671
7817
  */
7672
7818
 
7673
7819
 
@@ -7731,8 +7877,8 @@
7731
7877
  this.needUpdate = true;
7732
7878
  }
7733
7879
  }
7734
- /**
7735
- * 中止
7880
+ /**
7881
+ * 中止
7736
7882
  */
7737
7883
 
7738
7884
 
@@ -7743,13 +7889,169 @@
7743
7889
 
7744
7890
  }
7745
7891
 
7746
- /**
7747
- * jm图表组件
7748
- * option参数:graph=jmgraph
7749
- *
7750
- * @class jmChart
7751
- * @module jmChart
7752
- * @param {element} container 图表容器
7892
+ /**
7893
+ * 轴
7894
+ *
7895
+ * @class jmMarkLineManager
7896
+ * @module jmChart
7897
+ * @param {jmChart} chart 当前图表
7898
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
7899
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
7900
+ * @param {object} [style] 样式
7901
+ */
7902
+
7903
+ class jmMarkLineManager {
7904
+ constructor(chart) {
7905
+ this.chart = chart;
7906
+ this.init(chart);
7907
+ } // 初始化
7908
+
7909
+
7910
+ init(chart) {
7911
+ const graph = chart.touchGraph || chart;
7912
+ graph.on('beginDraw', () => {
7913
+ // 重置标线,会处理小圆圈问题
7914
+ this.xMarkLine && this.xMarkLine.init();
7915
+ this.yMarkLine && this.yMarkLine.init();
7916
+ });
7917
+
7918
+ if (chart.style.markLine) {
7919
+ // 生成标线,可以跟随鼠标或手指滑动
7920
+ if (chart.style.markLine && chart.style.markLine.x) {
7921
+ this.xMarkLine = graph.createShape(jmMarkLine, {
7922
+ type: 'x',
7923
+ style: chart.style.markLine
7924
+ });
7925
+ const area = graph.chartArea || graph;
7926
+ area.children.add(this.xMarkLine);
7927
+ }
7928
+
7929
+ if (chart.style.markLine && chart.style.markLine.y) {
7930
+ this.yMarkLine = graph.createShape(jmMarkLine, {
7931
+ type: 'y',
7932
+ style: chart.style.markLine
7933
+ });
7934
+ const area = graph.chartArea || graph;
7935
+ area.children.add(this.yMarkLine);
7936
+ }
7937
+
7938
+ let longtap = 0; // 是否有长按, 0 未开始,1已按下,2识别为长按
7939
+
7940
+ let longtapHandler = 0;
7941
+ let touchStartPos = {
7942
+ x: 0,
7943
+ y: 0
7944
+ };
7945
+ graph.on('mousedown touchstart', args => {
7946
+ // 如果长按才启用
7947
+ if (chart.style.markLine.longtap) {
7948
+ longtap = 1;
7949
+ longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
7950
+ let tapStartTime = Date.now();
7951
+
7952
+ const reqFun = () => {
7953
+ const elapsed = Date.now() - tapStartTime;
7954
+
7955
+ if (longtap === 1 || longtap === 2) {
7956
+ // 如果还未过一定时间,则继续等待
7957
+ if (elapsed < 500) {
7958
+ longtapHandler = graph.utils.requestAnimationFrame(reqFun);
7959
+ return;
7960
+ }
7961
+
7962
+ longtap = 2;
7963
+ this.startMove(args);
7964
+ chart.emit('marklinelongtapstart', args);
7965
+ }
7966
+ }; // 如果一定时间后还没有取消,则表示长按了
7967
+
7968
+
7969
+ longtapHandler = graph.utils.requestAnimationFrame(reqFun); //args.event.stopPropagation();
7970
+ //args.event.preventDefault();// 阻止默认行为
7971
+ } else {
7972
+ this.startMove(args);
7973
+ }
7974
+
7975
+ args.longtap = longtap;
7976
+ touchStartPos = args.position;
7977
+ }); // 移动标线
7978
+
7979
+ graph.on('mousemove touchmove', args => {
7980
+ const ox = args.position.x - touchStartPos.x;
7981
+ const oy = args.position.y - touchStartPos.y;
7982
+ const offpos = Math.sqrt(ox * ox + oy * oy);
7983
+ if (longtap === 1 && offpos > 15) longtap = 0; // 如果移动了,则取消长按
7984
+
7985
+ args.longtap = longtap;
7986
+ this.move(args);
7987
+ }); // 取消移动
7988
+
7989
+ graph.on('mouseup touchend touchcancel touchleave', args => {
7990
+ longtap = 0;
7991
+ this.endMove(args);
7992
+ });
7993
+ }
7994
+ } // 开始移动标线
7995
+
7996
+
7997
+ startMove(args, markLineType = 'xy') {
7998
+ if (this.xMarkLine && markLineType.includes('x')) {
7999
+ this.xMarkLine.visible = true;
8000
+ this.xMarkLine.move(args);
8001
+ }
8002
+
8003
+ if (this.yMarkLine && markLineType.includes('y')) {
8004
+ this.yMarkLine.visible = true;
8005
+ this.yMarkLine.move(args);
8006
+ }
8007
+
8008
+ if (!args.cancel) this.chart.emit('marklinestartmove', args);
8009
+ } // 移动标线
8010
+
8011
+
8012
+ move(args) {
8013
+ let moved = false;
8014
+
8015
+ if (this.xMarkLine && this.xMarkLine.visible) {
8016
+ this.xMarkLine.move(args);
8017
+ moved = true;
8018
+ }
8019
+
8020
+ if (this.yMarkLine && this.yMarkLine.visible) {
8021
+ this.yMarkLine.move(args);
8022
+ moved = true;
8023
+ }
8024
+
8025
+ if (moved) {
8026
+ args.event.stopPropagation();
8027
+ args.event.preventDefault(); // 阻止默认行为
8028
+
8029
+ if (!args.cancel) this.chart.emit('marklinemove', args);
8030
+ }
8031
+ } // 终止动移
8032
+
8033
+
8034
+ endMove(args) {
8035
+ if (this.xMarkLine && this.xMarkLine.visible) {
8036
+ this.xMarkLine.cancel(args);
8037
+ }
8038
+
8039
+ if (this.yMarkLine && this.yMarkLine.visible) {
8040
+ this.yMarkLine.cancel(args);
8041
+ }
8042
+
8043
+ if (!args.cancel) this.chart.emit('marklineendmove', args);
8044
+ }
8045
+
8046
+ }
8047
+
8048
+ /**
8049
+ * jm图表组件
8050
+ * option参数:graph=jmgraph
8051
+ *
8052
+ * @class jmChart
8053
+ * @module jmChart
8054
+ * @param {element} container 图表容器
7753
8055
  */
7754
8056
 
7755
8057
  class jmChart extends jmGraph {
@@ -7778,13 +8080,13 @@
7778
8080
 
7779
8081
  this.createTouchGraph(this.container, options);
7780
8082
  }
7781
- /**
7782
- * 绑定的数据源
8083
+ /**
8084
+ * 绑定的数据源
7783
8085
  */
7784
8086
 
7785
8087
 
7786
- /**
7787
- * 是否启用动画
8088
+ /**
8089
+ * 是否启用动画
7788
8090
  */
7789
8091
  get enableAnimate() {
7790
8092
  if (typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;else {
@@ -7795,8 +8097,8 @@
7795
8097
  set enableAnimate(v) {
7796
8098
  this.option.enableAnimate = v;
7797
8099
  }
7798
- /**
7799
- * Y轴的基线 默认是0
8100
+ /**
8101
+ * Y轴的基线 默认是0
7800
8102
  */
7801
8103
 
7802
8104
 
@@ -7810,11 +8112,11 @@
7810
8112
 
7811
8113
 
7812
8114
  init(options) {
7813
- /**
7814
- * 绘图区域
7815
- *
7816
- * @property chartArea
7817
- * @type jmControl
8115
+ /**
8116
+ * 绘图区域
8117
+ *
8118
+ * @property chartArea
8119
+ * @type jmControl
7818
8120
  */
7819
8121
  if (!this.chartArea) {
7820
8122
  this.chartArea = this.createShape('rect', {
@@ -7826,11 +8128,11 @@
7826
8128
  });
7827
8129
  this.children.add(this.chartArea);
7828
8130
  }
7829
- /**
7830
- * 图例
7831
- *
7832
- * @property legend
7833
- * @type jmLegend
8131
+ /**
8132
+ * 图例
8133
+ *
8134
+ * @property legend
8135
+ * @type jmLegend
7834
8136
  */
7835
8137
 
7836
8138
 
@@ -7842,11 +8144,11 @@
7842
8144
  if (options.legendVisible === false) {
7843
8145
  this.legend.visible = false;
7844
8146
  }
7845
- /**
7846
- * 图表提示控件
7847
- *
7848
- * @property tooltip
7849
- * @type jmTooltip
8147
+ /**
8148
+ * 图表提示控件
8149
+ *
8150
+ * @property tooltip
8151
+ * @type jmTooltip
7850
8152
  */
7851
8153
  //this.tooltip = this.graph.createShape('tooltip',{style:this.style.tooltip});
7852
8154
  //this.chartArea.children.add(this.tooltip);
@@ -7864,84 +8166,36 @@
7864
8166
  container && (container.style.position = 'relative');
7865
8167
  options = this.utils.clone(options, {
7866
8168
  autoRefresh: true
7867
- }, true);
7868
- let graph = this.touchGraph = this; // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
8169
+ }, true); // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
7869
8170
  // isWXMiniApp 非微信小程序下才能创建
7870
8171
 
7871
- if (!graph.isWXMiniApp && container && options.touchGraph) {
8172
+ if (!this.isWXMiniApp && container && options.touchGraph) {
7872
8173
  let cn = document.createElement('canvas');
7873
8174
  cn.width = container.offsetWidth || container.clientWidth;
7874
8175
  cn.height = container.offsetHeight || container.clientHeight;
7875
8176
  cn.style.position = 'absolute';
7876
8177
  cn.style.top = 0;
7877
8178
  cn.style.left = 0;
7878
- this.touchGraph = graph = new jmGraph(cn, options);
8179
+ this.touchGraph = new jmGraph(cn, options);
7879
8180
  container.appendChild(cn);
7880
8181
  this.touchGraph.chartGraph = this;
7881
8182
  this.on('propertyChange', (name, args) => {
7882
8183
  if (['width', 'height'].includes(name)) {
7883
8184
  this.touchGraph[name] = args.newValue / this.devicePixelRatio;
7884
8185
  }
7885
- });
7886
- }
7887
-
7888
- if (this.style.markLine) {
7889
- graph.on('beginDraw', () => {
7890
- // 重置标线,会处理小圆圈问题
7891
- this.xMarkLine && this.xMarkLine.init();
7892
- this.yMarkLine && this.yMarkLine.init();
7893
- }); // 生成标线,可以跟随鼠标或手指滑动
7894
-
7895
- if (this.style.markLine && this.style.markLine.x) {
7896
- this.xMarkLine = graph.createShape(jmMarkLine, {
7897
- type: 'x',
7898
- style: this.style.markLine
7899
- });
7900
- const area = graph.chartArea || graph;
7901
- area.children.add(this.xMarkLine);
7902
- }
7903
-
7904
- if (this.style.markLine && this.style.markLine.y) {
7905
- this.yMarkLine = graph.createShape(jmMarkLine, {
7906
- type: 'y',
7907
- style: this.style.markLine
7908
- });
7909
- const area = graph.chartArea || graph;
7910
- area.children.add(this.yMarkLine);
7911
- }
7912
-
7913
- graph.on('mousedown touchstart', args => {
7914
- if (this.xMarkLine) {
7915
- this.xMarkLine.visible = true;
7916
- this.xMarkLine.move(args);
7917
- }
8186
+ }); // 把上层canvse事件传递给绘图层对象
7918
8187
 
7919
- if (this.yMarkLine) {
7920
- this.yMarkLine.visible = true;
7921
- this.yMarkLine.move(args);
7922
- }
7923
- }); // 移动标线
7924
-
7925
- graph.on('mousemove touchmove', args => {
7926
- if (this.xMarkLine && this.xMarkLine.visible) {
7927
- this.xMarkLine.move(args);
7928
- }
8188
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', args => {
8189
+ const eventName = args.event.eventName || args.event.type;
7929
8190
 
7930
- if (this.yMarkLine && this.yMarkLine.visible) {
7931
- this.yMarkLine.move(args);
8191
+ if (eventName) {
8192
+ this.emit(eventName, args);
7932
8193
  }
7933
- }); // 取消移动
8194
+ });
8195
+ } // 初始化标线
7934
8196
 
7935
- graph.on('mouseup touchend touchcancel touchleave', args => {
7936
- if (this.xMarkLine && this.xMarkLine.visible) {
7937
- this.xMarkLine.cancel(args);
7938
- }
7939
8197
 
7940
- if (this.yMarkLine && this.yMarkLine.visible) {
7941
- this.yMarkLine.cancel(args);
7942
- }
7943
- });
7944
- }
8198
+ this.markLine = new jmMarkLineManager(this);
7945
8199
  } // 重置整个图表
7946
8200
 
7947
8201
 
@@ -7974,11 +8228,11 @@
7974
8228
  delete this.yAxises;
7975
8229
  }
7976
8230
  }
7977
- /**
7978
- * 获取颜色
7979
- *
7980
- * @method getColor
7981
- * @param {int} index 颜色索引
8231
+ /**
8232
+ * 获取颜色
8233
+ *
8234
+ * @method getColor
8235
+ * @param {int} index 颜色索引
7982
8236
  */
7983
8237
 
7984
8238
 
@@ -7990,11 +8244,11 @@
7990
8244
 
7991
8245
  return this.style.chartColors[index];
7992
8246
  }
7993
- /**
7994
- * 绘制当前图表
7995
- * 先绘制轴等基础信息
7996
- *
7997
- * @method beginDraw
8247
+ /**
8248
+ * 绘制当前图表
8249
+ * 先绘制轴等基础信息
8250
+ *
8251
+ * @method beginDraw
7998
8252
  */
7999
8253
 
8000
8254
 
@@ -8059,10 +8313,10 @@
8059
8313
  serie.init && serie.init();
8060
8314
  }); //console.log('beginDraw4', Date.now() - startTime);
8061
8315
  }
8062
- /**
8063
- * 重新定位区域的位置
8064
- *
8065
- * @method resetAreaPosition
8316
+ /**
8317
+ * 重新定位区域的位置
8318
+ *
8319
+ * @method resetAreaPosition
8066
8320
  */
8067
8321
 
8068
8322
 
@@ -8074,15 +8328,15 @@
8074
8328
  this.chartArea.width = w;
8075
8329
  this.chartArea.height = h;
8076
8330
  }
8077
- /**
8078
- * 创建轴
8079
- *
8080
- * @method createAxis
8081
- * @for jmChart
8082
- * @param {string} [type] 轴类型(x/y/radar),默认为x
8083
- * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
8084
- * @param {object} [style] 样式
8085
- * @return {axis} 轴
8331
+ /**
8332
+ * 创建轴
8333
+ *
8334
+ * @method createAxis
8335
+ * @for jmChart
8336
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
8337
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
8338
+ * @param {object} [style] 样式
8339
+ * @return {axis} 轴
8086
8340
  */
8087
8341
 
8088
8342
 
@@ -8094,12 +8348,12 @@
8094
8348
  this.children.add(axis);
8095
8349
  return axis;
8096
8350
  }
8097
- /**
8098
- * 生成X轴
8099
- *
8100
- * @method createXAxis
8101
- * @param {string} x轴的数据类型(string/number/date)
8102
- * @param {bool} 是否从0开始
8351
+ /**
8352
+ * 生成X轴
8353
+ *
8354
+ * @method createXAxis
8355
+ * @param {string} x轴的数据类型(string/number/date)
8356
+ * @param {bool} 是否从0开始
8103
8357
  */
8104
8358
 
8105
8359
 
@@ -8126,13 +8380,13 @@
8126
8380
 
8127
8381
  return this.xAxis;
8128
8382
  }
8129
- /**
8130
- * 生成Y轴
8131
- *
8132
- * @method createYAxis
8133
- * @param {int} Y轴索引,可以创建多个Y轴
8134
- * @param {string} y轴的数据类型(string/number/date)
8135
- * @param {bool} 是否从0开始
8383
+ /**
8384
+ * 生成Y轴
8385
+ *
8386
+ * @method createYAxis
8387
+ * @param {int} Y轴索引,可以创建多个Y轴
8388
+ * @param {string} y轴的数据类型(string/number/date)
8389
+ * @param {bool} 是否从0开始
8136
8390
  */
8137
8391
 
8138
8392
 
@@ -8161,14 +8415,14 @@
8161
8415
  var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
8162
8416
  return yaxis;
8163
8417
  }
8164
- /**
8165
- * 创建图形
8166
- *
8167
- * @method createSeries
8168
- * @for jmChart
8169
- * @param {string} [type] 图类型,(line/bar/pie/radar)
8170
- * @param {object} [options] 生成图表选项 {xField, yField, index}
8171
- * @return {series} 图形
8418
+ /**
8419
+ * 创建图形
8420
+ *
8421
+ * @method createSeries
8422
+ * @for jmChart
8423
+ * @param {string} [type] 图类型,(line/bar/pie/radar)
8424
+ * @param {object} [options] 生成图表选项 {xField, yField, index}
8425
+ * @return {series} 图形
8172
8426
  */
8173
8427
 
8174
8428
 
@@ -8179,7 +8433,8 @@
8179
8433
  'bar': jmBarSeries,
8180
8434
  'stackBar': jmStackBarSeries,
8181
8435
  'pie': jmPieSeries,
8182
- 'stackLine': jmStackLineSeries
8436
+ 'stackLine': jmStackLineSeries,
8437
+ 'candlestick': jmCandlestickSeries
8183
8438
  };
8184
8439
  } //默认样式为类型对应的样式
8185
8440
 
@@ -8322,7 +8577,7 @@
8322
8577
  template: `<div ref="jmChartContainer" :style="{width: width, height: height}"></div>`
8323
8578
  };
8324
8579
 
8325
- exports["default"] = jmChart;
8580
+ exports['default'] = jmChart;
8326
8581
  exports.jmChart = jmChart;
8327
8582
  exports.vChart = vchart;
8328
8583
 
@@ -8330,4 +8585,4 @@
8330
8585
 
8331
8586
  return exports;
8332
8587
 
8333
- })({});
8588
+ }({}));