@antv/g2 4.1.37 → 4.1.38

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.
@@ -73,7 +73,7 @@ export default class Annotation extends Controller<BaseOption[]> {
73
73
  return 'annotation';
74
74
  }
75
75
 
76
- public init() {}
76
+ public init() { }
77
77
 
78
78
  /**
79
79
  * 因为 annotation 需要依赖坐标系信息,所以 render 阶段为空方法,实际的创建逻辑都在 layout 中
@@ -83,7 +83,7 @@ export default class Annotation extends Controller<BaseOption[]> {
83
83
  }
84
84
 
85
85
  // 因为 Annotation 不参与布局,但是渲染的位置依赖于坐标系,所以可以将绘制阶段延迟到 layout() 进行
86
- public render() {}
86
+ public render() { }
87
87
 
88
88
  /**
89
89
  * 更新
@@ -391,6 +391,10 @@ export default class Annotation extends Controller<BaseOption[]> {
391
391
  }
392
392
  }
393
393
 
394
+ if (isNaN(x) || isNaN(y)) {
395
+ return null;
396
+ }
397
+
394
398
  return this.view.getCoordinate().convert({ x, y });
395
399
  }
396
400
 
@@ -480,7 +484,7 @@ export default class Annotation extends Controller<BaseOption[]> {
480
484
  * @param option 用户的配置
481
485
  * @param theme
482
486
  */
483
- private getAnnotationCfg(type: string, option: any, theme: object): object {
487
+ private getAnnotationCfg(type: string, option: any, theme: object): object | null {
484
488
  const coordinate = this.view.getCoordinate();
485
489
  const canvas = this.view.getCanvas();
486
490
  let o = {};
@@ -488,11 +492,18 @@ export default class Annotation extends Controller<BaseOption[]> {
488
492
  if (isNil(option)) {
489
493
  return null;
490
494
  }
495
+ const { start, end, position } = option;;
496
+ const sp = this.parsePosition(start);
497
+ const ep = this.parsePosition(end);
498
+ const textPoint = this.parsePosition(position);
499
+ if (['arc', 'image', 'line', 'region', 'regionFilter'].includes(type) && (!sp || !ep)) {
500
+ return null;
501
+ } else if (['text', 'dataMarker', 'html'].includes(type) && !textPoint) {
502
+ return null;
503
+ }
491
504
 
492
505
  if (type === 'arc') {
493
506
  const { start, end, ...rest } = option as ArcOption;
494
- const sp = this.parsePosition(start);
495
- const ep = this.parsePosition(end);
496
507
  const startAngle = getAngleByPoint(coordinate, sp);
497
508
  let endAngle = getAngleByPoint(coordinate, ep);
498
509
  if (startAngle > endAngle) {
@@ -510,24 +521,24 @@ export default class Annotation extends Controller<BaseOption[]> {
510
521
  const { start, end, ...rest } = option as ImageOption;
511
522
  o = {
512
523
  ...rest,
513
- start: this.parsePosition(start),
514
- end: this.parsePosition(end),
524
+ start: sp,
525
+ end: ep,
515
526
  src: option.src,
516
527
  };
517
528
  } else if (type === 'line') {
518
529
  const { start, end, ...rest } = option as LineOption;
519
530
  o = {
520
531
  ...rest,
521
- start: this.parsePosition(start),
522
- end: this.parsePosition(end),
532
+ start: sp,
533
+ end: ep,
523
534
  text: get(option, 'text', null),
524
535
  };
525
536
  } else if (type === 'region') {
526
537
  const { start, end, ...rest } = option as RegionPositionBaseOption;
527
538
  o = {
528
539
  ...rest,
529
- start: this.parsePosition(start),
530
- end: this.parsePosition(end),
540
+ start: sp,
541
+ end: ep,
531
542
  };
532
543
  } else if (type === 'text') {
533
544
  const filteredData = this.view.getData();
@@ -537,7 +548,7 @@ export default class Annotation extends Controller<BaseOption[]> {
537
548
  textContent = content(filteredData);
538
549
  }
539
550
  o = {
540
- ...this.parsePosition(position),
551
+ ...textPoint,
541
552
  ...rest,
542
553
  content: textContent,
543
554
  };
@@ -545,7 +556,7 @@ export default class Annotation extends Controller<BaseOption[]> {
545
556
  const { position, point, line, text, autoAdjust, direction, ...rest } = option as DataMarkerOption;
546
557
  o = {
547
558
  ...rest,
548
- ...this.parsePosition(position),
559
+ ...textPoint,
549
560
  coordinateBBox: this.getCoordinateBBox(),
550
561
  point,
551
562
  line,
@@ -593,8 +604,8 @@ export default class Annotation extends Controller<BaseOption[]> {
593
604
  ...rest,
594
605
  color,
595
606
  shapes,
596
- start: this.parsePosition(start),
597
- end: this.parsePosition(end),
607
+ start: sp,
608
+ end: ep,
598
609
  };
599
610
  } else if (type === 'shape') {
600
611
  const { render, ...restOptions } = option as ShapeAnnotationOption;
@@ -617,7 +628,7 @@ export default class Annotation extends Controller<BaseOption[]> {
617
628
  };
618
629
  o = {
619
630
  ...restOptions,
620
- ...this.parsePosition(position),
631
+ ...textPoint,
621
632
  // html 组件需要指定 parent
622
633
  parent: canvas.get('el').parentNode,
623
634
  html: wrappedHtml,
@@ -679,8 +690,10 @@ export default class Annotation extends Controller<BaseOption[]> {
679
690
  const cfg = this.getAnnotationCfg(type, option, theme);
680
691
 
681
692
  // 忽略掉一些配置
682
- omit(cfg, ['container']);
683
- co.component.update(cfg);
693
+ if (cfg) {
694
+ omit(cfg, ['container']);
695
+ }
696
+ co.component.update({ ...(cfg || {}), visible: !!cfg });
684
697
  // 对于 regionFilter/shape,因为生命周期的原因,需要额外 render
685
698
  if (includes(ANNOTATIONS_AFTER_RENDER, option.type)) {
686
699
  co.component.render();
@@ -242,7 +242,7 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
242
242
  const values = valuesOfKey(this.data, this.xScaleCfg.field);
243
243
 
244
244
  // 如果是 xScale 数值类型,则进行排序
245
- const xScaleValues = this.view.getXScale().isLinear ? values.sort() : values;
245
+ const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
246
246
 
247
247
  const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
248
248
  this.yScalesCfg.forEach((cfg) => {
@@ -273,7 +273,7 @@ export default class Slider extends Controller<SliderOption> {
273
273
  const xScale = this.view.getXScale();
274
274
  const isHorizontal = true;
275
275
  let values = valuesOfKey(data, xScale.field);
276
-
276
+
277
277
  // 如果是 xScale 数值类型,则进行排序
278
278
  if (xScale.isLinear) {
279
279
  values = values.sort();
@@ -322,8 +322,8 @@ export default class Slider extends Controller<SliderOption> {
322
322
  const values = valuesOfKey(data, xScale.field);
323
323
 
324
324
  // 如果是 xScale 数值类型,则进行排序
325
- const xScaleValues = this.view.getXScale().isLinear ? values.sort() : values;
326
-
325
+ const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
326
+
327
327
  const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
328
328
  const xTickCount = size(xValues);
329
329
 
package/src/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* G2 的一个壳子,不包含 Geometry,由开发者自己定义和引入 */
2
2
 
3
- export const VERSION = '4.1.37';
3
+ export const VERSION = '4.1.38';
4
4
 
5
5
  // 核心基类导出
6
6
  export { Chart, View, Event } from './chart'; // Chart, View 类