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