jmchart 1.1.81 → 1.1.90

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