@visactor/vrender-components 0.12.2 → 0.13.0-alpha.0

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.
Files changed (111) hide show
  1. package/cjs/axis/base.d.ts +2 -1
  2. package/cjs/axis/base.js +8 -6
  3. package/cjs/axis/base.js.map +1 -1
  4. package/cjs/axis/circle.d.ts +3 -2
  5. package/cjs/axis/circle.js +1 -0
  6. package/cjs/axis/circle.js.map +1 -1
  7. package/cjs/axis/line.d.ts +3 -2
  8. package/cjs/axis/line.js +26 -4
  9. package/cjs/axis/line.js.map +1 -1
  10. package/cjs/axis/overlap/auto-hide.d.ts +9 -0
  11. package/cjs/axis/overlap/auto-hide.js +62 -0
  12. package/cjs/axis/overlap/auto-hide.js.map +1 -0
  13. package/cjs/axis/overlap/auto-limit.d.ts +8 -0
  14. package/cjs/axis/overlap/auto-limit.js +21 -0
  15. package/cjs/axis/overlap/auto-limit.js.map +1 -0
  16. package/cjs/axis/overlap/auto-rotate.d.ts +7 -0
  17. package/cjs/axis/overlap/auto-rotate.js +103 -0
  18. package/cjs/axis/overlap/auto-rotate.js.map +1 -0
  19. package/cjs/axis/type.d.ts +20 -11
  20. package/cjs/axis/type.js.map +1 -1
  21. package/cjs/index.d.ts +2 -1
  22. package/cjs/index.js +10 -9
  23. package/cjs/index.js.map +1 -1
  24. package/cjs/legend/discrete/discrete.js +1 -1
  25. package/cjs/legend/discrete/discrete.js.map +1 -1
  26. package/cjs/poptip/contribution.d.ts +6 -0
  27. package/cjs/poptip/contribution.js +34 -0
  28. package/cjs/poptip/contribution.js.map +1 -0
  29. package/cjs/poptip/index.d.ts +3 -0
  30. package/cjs/poptip/index.js +22 -0
  31. package/cjs/poptip/index.js.map +1 -0
  32. package/cjs/poptip/poptip-plugin.d.ts +14 -0
  33. package/cjs/poptip/poptip-plugin.js +43 -0
  34. package/cjs/poptip/poptip-plugin.js.map +1 -0
  35. package/cjs/poptip/poptip.d.ts +13 -0
  36. package/cjs/poptip/poptip.js +201 -0
  37. package/cjs/poptip/poptip.js.map +1 -0
  38. package/cjs/poptip/register.d.ts +3 -0
  39. package/cjs/poptip/register.js +17 -0
  40. package/cjs/poptip/register.js.map +1 -0
  41. package/cjs/poptip/type.d.ts +27 -0
  42. package/cjs/poptip/type.js +6 -0
  43. package/cjs/poptip/type.js.map +1 -0
  44. package/cjs/tag/tag.d.ts +1 -1
  45. package/cjs/tag/tag.js.map +1 -1
  46. package/cjs/tooltip/tooltip.js +29 -15
  47. package/cjs/tooltip/tooltip.js.map +1 -1
  48. package/cjs/tooltip/type.d.ts +5 -2
  49. package/cjs/tooltip/type.js.map +1 -1
  50. package/cjs/tooltip/util.d.ts +3 -1
  51. package/cjs/tooltip/util.js +18 -1
  52. package/cjs/tooltip/util.js.map +1 -1
  53. package/cjs/util/text.d.ts +3 -2
  54. package/cjs/util/text.js.map +1 -1
  55. package/dist/index.js +652 -28
  56. package/dist/index.min.js +1 -1
  57. package/es/axis/base.d.ts +2 -1
  58. package/es/axis/base.js +7 -6
  59. package/es/axis/base.js.map +1 -1
  60. package/es/axis/circle.d.ts +3 -2
  61. package/es/axis/circle.js +1 -0
  62. package/es/axis/circle.js.map +1 -1
  63. package/es/axis/line.d.ts +3 -2
  64. package/es/axis/line.js +32 -4
  65. package/es/axis/line.js.map +1 -1
  66. package/es/axis/overlap/auto-hide.d.ts +9 -0
  67. package/es/axis/overlap/auto-hide.js +53 -0
  68. package/es/axis/overlap/auto-hide.js.map +1 -0
  69. package/es/axis/overlap/auto-limit.d.ts +8 -0
  70. package/es/axis/overlap/auto-limit.js +13 -0
  71. package/es/axis/overlap/auto-limit.js.map +1 -0
  72. package/es/axis/overlap/auto-rotate.d.ts +7 -0
  73. package/es/axis/overlap/auto-rotate.js +95 -0
  74. package/es/axis/overlap/auto-rotate.js.map +1 -0
  75. package/es/axis/type.d.ts +20 -11
  76. package/es/axis/type.js.map +1 -1
  77. package/es/index.d.ts +2 -1
  78. package/es/index.js +3 -1
  79. package/es/index.js.map +1 -1
  80. package/es/legend/discrete/discrete.js +1 -1
  81. package/es/legend/discrete/discrete.js.map +1 -1
  82. package/es/poptip/contribution.d.ts +6 -0
  83. package/es/poptip/contribution.js +31 -0
  84. package/es/poptip/contribution.js.map +1 -0
  85. package/es/poptip/index.d.ts +3 -0
  86. package/es/poptip/index.js +6 -0
  87. package/es/poptip/index.js.map +1 -0
  88. package/es/poptip/poptip-plugin.d.ts +14 -0
  89. package/es/poptip/poptip-plugin.js +41 -0
  90. package/es/poptip/poptip-plugin.js.map +1 -0
  91. package/es/poptip/poptip.d.ts +13 -0
  92. package/es/poptip/poptip.js +194 -0
  93. package/es/poptip/poptip.js.map +1 -0
  94. package/es/poptip/register.d.ts +3 -0
  95. package/es/poptip/register.js +17 -0
  96. package/es/poptip/register.js.map +1 -0
  97. package/es/poptip/type.d.ts +27 -0
  98. package/es/poptip/type.js +2 -0
  99. package/es/poptip/type.js.map +1 -0
  100. package/es/tag/tag.d.ts +1 -1
  101. package/es/tag/tag.js.map +1 -1
  102. package/es/tooltip/tooltip.js +30 -15
  103. package/es/tooltip/tooltip.js.map +1 -1
  104. package/es/tooltip/type.d.ts +5 -2
  105. package/es/tooltip/type.js.map +1 -1
  106. package/es/tooltip/util.d.ts +3 -1
  107. package/es/tooltip/util.js +16 -1
  108. package/es/tooltip/util.js.map +1 -1
  109. package/es/util/text.d.ts +3 -2
  110. package/es/util/text.js.map +1 -1
  111. package/package.json +7 -6
package/dist/index.js CHANGED
@@ -660,6 +660,305 @@
660
660
  }
661
661
  }
662
662
 
663
+ class PopTip extends AbstractComponent {
664
+ name = 'poptip';
665
+ static defaultAttributes = {
666
+ position: 'rt',
667
+ visible: true,
668
+ title: null,
669
+ content: null,
670
+ titleStyle: {
671
+ fontSize: 12,
672
+ fill: '#000',
673
+ textAlign: 'left',
674
+ textBaseline: 'top'
675
+ },
676
+ contentStyle: {
677
+ fontSize: 12,
678
+ fill: '#000',
679
+ textAlign: 'left',
680
+ textBaseline: 'top'
681
+ },
682
+ space: 8,
683
+ padding: 10
684
+ };
685
+ constructor(attributes) {
686
+ super(vutils.merge({}, PopTip.defaultAttributes, attributes));
687
+ }
688
+ render() {
689
+ const { title = '', titleStyle = {}, position, content = '', contentStyle = {}, panel = {}, space = 4, minWidth = 0, maxWidth = Infinity, padding = 4, visible, state } = this.attribute;
690
+ const parsedPadding = vutils.normalizePadding(padding);
691
+ const group = this.createOrUpdateChild('poptip-content', { x: 0, y: 0, zIndex: 1 }, 'group');
692
+ const maxLineWidth = maxWidth - parsedPadding[1] - parsedPadding[3];
693
+ const titleVisible = vutils.isValid(title) && visible !== false;
694
+ const titleAttrs = {
695
+ text: title,
696
+ visible: titleVisible,
697
+ ...titleStyle,
698
+ x: parsedPadding[3],
699
+ y: parsedPadding[0],
700
+ maxLineWidth,
701
+ textAlign: 'left',
702
+ textBaseline: 'top'
703
+ };
704
+ const titleShape = group.createOrUpdateChild('poptip-title', titleAttrs, 'text');
705
+ if (!vutils.isEmpty(state?.title)) {
706
+ titleShape.states = state.title;
707
+ }
708
+ const titleBounds = titleShape.AABBBounds;
709
+ const titleHeight = titleBounds.height();
710
+ const titleWidth = titleBounds.width();
711
+ let height = titleHeight + space;
712
+ if (!titleVisible) {
713
+ height = 0;
714
+ }
715
+ const contentVisible = vutils.isValid(content) && visible !== false;
716
+ const contentAttrs = {
717
+ text: content,
718
+ visible: contentVisible,
719
+ ...contentStyle,
720
+ x: parsedPadding[3],
721
+ y: parsedPadding[0] + height,
722
+ maxLineWidth,
723
+ textAlign: 'left',
724
+ textBaseline: 'top'
725
+ };
726
+ const contentShape = group.createOrUpdateChild('poptip-content', contentAttrs, 'text');
727
+ if (!vutils.isEmpty(state?.content)) {
728
+ contentShape.states = state.content;
729
+ }
730
+ const contentBounds = contentShape.AABBBounds;
731
+ const contentHeight = contentBounds.height();
732
+ const contentWidth = contentBounds.width();
733
+ if (contentVisible) {
734
+ height += contentHeight;
735
+ }
736
+ let popTipWidth = vutils.max(titleWidth + parsedPadding[1] + parsedPadding[3], contentWidth + parsedPadding[1] + parsedPadding[3]);
737
+ if (popTipWidth > maxWidth) {
738
+ popTipWidth = maxWidth;
739
+ }
740
+ else if (popTipWidth < minWidth) {
741
+ popTipWidth = minWidth;
742
+ }
743
+ const poptipHeight = parsedPadding[0] + parsedPadding[2] + height;
744
+ const { visible: bgVisible, ...backgroundStyle } = panel;
745
+ const symbolSize = backgroundStyle.size ?? 12;
746
+ const lineWidth = backgroundStyle.lineWidth ?? 1;
747
+ const { angle, offset, rectOffset } = this.getAngleAndOffset(position, popTipWidth, poptipHeight, vutils.isArray(symbolSize) ? symbolSize : [symbolSize, symbolSize - lineWidth]);
748
+ if (vutils.isBoolean(bgVisible)) {
749
+ const offsetX = (vutils.isArray(symbolSize) ? symbolSize[0] : symbolSize) / 4;
750
+ const bgSymbol = group.createOrUpdateChild('poptip-symbol-panel', {
751
+ ...backgroundStyle,
752
+ visible: bgVisible && (contentVisible || titleVisible),
753
+ x: offsetX,
754
+ y: 0,
755
+ anchor: [0, 0],
756
+ symbolType: 'arrow2Left',
757
+ angle: angle,
758
+ dx: offset[0],
759
+ dy: offset[1],
760
+ size: symbolSize,
761
+ zIndex: -9
762
+ }, 'symbol');
763
+ if (!vutils.isEmpty(state?.panel)) {
764
+ bgSymbol.states = state.panel;
765
+ }
766
+ const bgRect = group.createOrUpdateChild('poptip-rect-panel', {
767
+ ...backgroundStyle,
768
+ visible: bgVisible && (contentVisible || titleVisible),
769
+ x: 0,
770
+ y: 0,
771
+ width: popTipWidth,
772
+ height: poptipHeight,
773
+ zIndex: -10
774
+ }, 'rect');
775
+ if (!vutils.isEmpty(state?.panel)) {
776
+ bgRect.states = state.panel;
777
+ }
778
+ }
779
+ group.setAttributes({
780
+ x: -offset[0],
781
+ y: -offset[1]
782
+ });
783
+ }
784
+ getAngleAndOffset(position, width, height, size) {
785
+ const sizeH = size[1] / 2;
786
+ switch (position) {
787
+ case 'tl':
788
+ return {
789
+ angle: (vutils.pi / 2) * 3,
790
+ offset: [width / 4, height + sizeH],
791
+ rectOffset: [-width / 4, -height - size[1]]
792
+ };
793
+ case 'top':
794
+ return { angle: (vutils.pi / 2) * 3, offset: [width / 2, height + sizeH], rectOffset: [0, -height - size[1]] };
795
+ case 'tr':
796
+ return {
797
+ angle: (vutils.pi / 2) * 3,
798
+ offset: [(width / 4) * 3, height + sizeH],
799
+ rectOffset: [(width / 4) * 3, -height - size[1]]
800
+ };
801
+ case 'rt':
802
+ return { angle: 0, offset: [-sizeH, height / 5], rectOffset: [(width / 4) * 3, -height - size[1]] };
803
+ case 'right':
804
+ return { angle: 0, offset: [-sizeH, height / 2], rectOffset: [(width / 4) * 3, -height - size[1]] };
805
+ case 'rb':
806
+ return { angle: 0, offset: [-sizeH, (height / 5) * 4], rectOffset: [(width / 4) * 3, -height - size[1]] };
807
+ case 'bl':
808
+ return { angle: vutils.pi / 2, offset: [width / 4, -sizeH], rectOffset: [-width / 4, -height - size[1]] };
809
+ case 'bottom':
810
+ return { angle: vutils.pi / 2, offset: [width / 2, -sizeH], rectOffset: [0, -height - size[1]] };
811
+ case 'br':
812
+ return { angle: vutils.pi / 2, offset: [(width / 4) * 3, -sizeH], rectOffset: [(width / 4) * 3, -height - size[1]] };
813
+ case 'lt':
814
+ return { angle: vutils.pi, offset: [width + sizeH, height / 5], rectOffset: [-width / 4, -height - size[1]] };
815
+ case 'left':
816
+ return { angle: vutils.pi, offset: [width + sizeH, height / 2], rectOffset: [0, -height - size[1]] };
817
+ case 'lb':
818
+ return {
819
+ angle: vutils.pi,
820
+ offset: [width + sizeH, (height / 5) * 4],
821
+ rectOffset: [(width / 4) * 3, -height - size[1]]
822
+ };
823
+ }
824
+ }
825
+ }
826
+
827
+ var PARAM_TYPES = "inversify:paramtypes";
828
+ var DESIGN_PARAM_TYPES = "design:paramtypes";
829
+
830
+ function _typeof(obj) {
831
+ "@babel/helpers - typeof";
832
+
833
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
834
+ return typeof obj;
835
+ } : function (obj) {
836
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
837
+ }, _typeof(obj);
838
+ }
839
+
840
+ var idCounter = 0;
841
+ function id() {
842
+ return idCounter++;
843
+ }
844
+
845
+ var DUPLICATED_INJECTABLE_DECORATOR = "Cannot apply @injectable decorator multiple times.";
846
+
847
+ var ContainerModule = function () {
848
+ function ContainerModule(registry) {
849
+ this.id = id();
850
+ this.registry = registry;
851
+ }
852
+ return ContainerModule;
853
+ }();
854
+
855
+ function injectable() {
856
+ return function (target) {
857
+ if (Reflect.hasOwnMetadata(PARAM_TYPES, target)) {
858
+ throw new Error(DUPLICATED_INJECTABLE_DECORATOR);
859
+ }
860
+ var types = Reflect.getMetadata(DESIGN_PARAM_TYPES, target) || [];
861
+ Reflect.defineMetadata(PARAM_TYPES, types, target);
862
+ return target;
863
+ };
864
+ }
865
+
866
+ function __decorate(decorators, target, key, desc) {
867
+ var c = arguments.length,
868
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
869
+ d;
870
+ if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
871
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
872
+ }
873
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
874
+ var e = new Error(message);
875
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
876
+ };
877
+
878
+ let PopTipRenderContribution = class PopTipRenderContribution {
879
+ render(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, options) {
880
+ if (graphic._showPoptip) {
881
+ const { visible, visibleCb } = graphic.attribute.poptip;
882
+ if (visible === false || (visibleCb && visibleCb(graphic) === false)) {
883
+ return;
884
+ }
885
+ if (!this.poptipComponent) {
886
+ this.poptipComponent = new PopTip(graphic.attribute.poptip);
887
+ }
888
+ this.poptipComponent.setAttributes({
889
+ ...graphic.attribute.poptip,
890
+ x: 0,
891
+ y: 0,
892
+ postMatrix: graphic.globalTransMatrix
893
+ });
894
+ const interactiveLayer = drawContext.stage.getLayer('_builtin_interactive');
895
+ if (interactiveLayer) {
896
+ interactiveLayer.add(this.poptipComponent);
897
+ }
898
+ }
899
+ }
900
+ };
901
+ PopTipRenderContribution = __decorate([
902
+ injectable()
903
+ ], PopTipRenderContribution);
904
+
905
+ let PopTipPlugin = class PopTipPlugin {
906
+ name = 'PopTipPlugin';
907
+ activeEvent = 'onRegister';
908
+ pluginService;
909
+ _uid = vrender.Generator.GenAutoIncrementId();
910
+ key = this.name + this._uid;
911
+ activeGraphic;
912
+ activate(context) {
913
+ this.pluginService = context;
914
+ const { stage } = this.pluginService;
915
+ stage.addEventListener('pointerover', this.poptip);
916
+ }
917
+ poptip = (e) => {
918
+ const graphic = e.target;
919
+ if (graphic.isContainer || !graphic.attribute || graphic === this.activeGraphic) {
920
+ this.unpoptip(e);
921
+ return;
922
+ }
923
+ const { poptip } = graphic.attribute;
924
+ if (poptip) {
925
+ graphic._showPoptip = true;
926
+ }
927
+ if (this.activeGraphic) {
928
+ this.activeGraphic._showPoptip = false;
929
+ }
930
+ this.setActiveGraphic(graphic, true);
931
+ };
932
+ unpoptip = (e) => {
933
+ if (!this.activeGraphic) {
934
+ return;
935
+ }
936
+ this.activeGraphic._showPoptip = false;
937
+ this.setActiveGraphic(null, true);
938
+ };
939
+ setActiveGraphic(graphic, rerender) {
940
+ this.activeGraphic = graphic;
941
+ this.pluginService.stage.renderNextFrame();
942
+ }
943
+ deactivate(context) {
944
+ const { stage } = this.pluginService;
945
+ stage.removeEventListener('pointerover', this.poptip);
946
+ }
947
+ };
948
+ PopTipPlugin = __decorate([
949
+ injectable()
950
+ ], PopTipPlugin);
951
+
952
+ const module = new ContainerModule(bind => {
953
+ bind(PopTipRenderContribution).toSelf().inSingletonScope();
954
+ bind(vrender.InteractiveSubRenderContribution).toService(PopTipRenderContribution);
955
+ bind(PopTipPlugin).toSelf().inSingletonScope();
956
+ bind(vrender.AutoEnablePlugins).toService(PopTipPlugin);
957
+ });
958
+ function enablePoptip() {
959
+ vrender.container.load(module);
960
+ }
961
+
663
962
  class CrosshairBase extends AbstractComponent {
664
963
  name = 'crosshair';
665
964
  render() {
@@ -2292,7 +2591,9 @@
2292
2591
  this.axisLabelsContainer = labelGroup;
2293
2592
  axisContainer.add(labelGroup);
2294
2593
  items.forEach((axisItems, layer) => {
2295
- this.renderLabels(labelGroup, axisItems, layer);
2594
+ const layerLabelGroup = this.renderLabels(labelGroup, axisItems, layer);
2595
+ const labels = layerLabelGroup.getChildren();
2596
+ this.handleLabelsOverlap(labels, axisItems, layer, items.length);
2296
2597
  });
2297
2598
  }
2298
2599
  if (grid?.visible) {
@@ -2357,13 +2658,11 @@
2357
2658
  }
2358
2659
  }
2359
2660
  renderLabels(container, items, layer) {
2360
- let data;
2361
- if (layer === 0) {
2362
- data = this.data;
2363
- }
2364
- else {
2365
- data = this._transformItems(items);
2661
+ const { dataFilter } = this.attribute.label;
2662
+ if (dataFilter && vutils.isFunction(dataFilter)) {
2663
+ items = dataFilter(items, layer);
2366
2664
  }
2665
+ const data = this._transformItems(items);
2367
2666
  const labelGroup = vrender.createGroup({ x: 0, y: 0, pickable: false });
2368
2667
  labelGroup.name = `${exports.AXIS_ELEMENT_NAME.labelContainer}-layer-${layer}`;
2369
2668
  labelGroup.id = this._getNodeId(`label-container-layer-${layer}`);
@@ -2440,13 +2739,13 @@
2440
2739
  const { tick } = this.attribute;
2441
2740
  const data = this.data;
2442
2741
  const tickLineItems = [];
2443
- const { alignWithLabel, inside = false, length } = tick;
2742
+ const { alignWithLabel, inside = false, length, dataFilter } = tick;
2444
2743
  let tickSegment = 1;
2445
2744
  const count = data.length;
2446
2745
  if (count >= 2) {
2447
2746
  tickSegment = data[1].value - data[0].value;
2448
2747
  }
2449
- data.forEach((item) => {
2748
+ (dataFilter && vutils.isFunction(dataFilter) ? dataFilter(data) : data).forEach((item) => {
2450
2749
  let point = item.point;
2451
2750
  let tickValue = item.value;
2452
2751
  if (!alignWithLabel) {
@@ -2602,6 +2901,231 @@
2602
2901
  }
2603
2902
  }
2604
2903
 
2904
+ const methods = {
2905
+ parity: function (items) {
2906
+ return items.filter((item, i) => (i % 2 ? item.setAttribute('opacity', 0) : 1));
2907
+ },
2908
+ greedy: function (items, sep) {
2909
+ let a;
2910
+ return items.filter((b, i) => {
2911
+ if (!i || !intersect(a.AABBBounds, b.AABBBounds, sep)) {
2912
+ a = b;
2913
+ return 1;
2914
+ }
2915
+ return b.setAttribute('opacity', 0);
2916
+ });
2917
+ }
2918
+ };
2919
+ function intersect(a, b, sep) {
2920
+ return sep > Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2);
2921
+ }
2922
+ function hasOverlap(items, pad) {
2923
+ for (let i = 1, n = items.length, a = items[0].AABBBounds, b; i < n; a = b, ++i) {
2924
+ if (intersect(a, (b = items[i].AABBBounds), pad)) {
2925
+ return true;
2926
+ }
2927
+ }
2928
+ }
2929
+ function hasBounds(item) {
2930
+ const b = item.AABBBounds;
2931
+ return b.width() > 1 && b.height() > 1;
2932
+ }
2933
+ function reset(items) {
2934
+ items.forEach(item => item.setAttribute('opacity', 1));
2935
+ return items;
2936
+ }
2937
+ function autoHide(labels, config) {
2938
+ if (vutils.isEmpty(labels)) {
2939
+ return;
2940
+ }
2941
+ const source = labels.filter(hasBounds);
2942
+ if (vutils.isEmpty(source)) {
2943
+ return;
2944
+ }
2945
+ let items;
2946
+ items = reset(source);
2947
+ const { method = 'parity', separation: sep = 0 } = config;
2948
+ const reduce = vutils.isFunction(method) ? method : methods[method] || methods.parity;
2949
+ if (items.length >= 3 && hasOverlap(items, sep)) {
2950
+ do {
2951
+ items = reduce(items, sep);
2952
+ } while (items.length >= 3 && hasOverlap(items, sep));
2953
+ if (items.length < 3 && !vutils.last(source).attribute.opacity) {
2954
+ if (items.length > 1) {
2955
+ vutils.last(items).setAttribute('opacity', 0);
2956
+ }
2957
+ vutils.last(source).setAttribute('opacity', 1);
2958
+ }
2959
+ }
2960
+ source.forEach(item => {
2961
+ item.setAttribute('visible', !!item.attribute.opacity);
2962
+ });
2963
+ }
2964
+
2965
+ function autoRotate(items, rotateConfig) {
2966
+ if (vutils.isEmpty(items)) {
2967
+ return;
2968
+ }
2969
+ const { orient, labelRotateAngle = [0, 45, 90] } = rotateConfig;
2970
+ if (labelRotateAngle.length === 0 || items.some(item => !!item.attribute.angle)) {
2971
+ return;
2972
+ }
2973
+ let i = 0;
2974
+ let n = 0;
2975
+ if (labelRotateAngle && labelRotateAngle.length > 0) {
2976
+ n = labelRotateAngle.length;
2977
+ }
2978
+ while (i < n) {
2979
+ const angle = labelRotateAngle[i++];
2980
+ items.forEach(item => {
2981
+ item.attribute.angle = vutils.degreeToRadian(angle);
2982
+ });
2983
+ tryRotate(orient, items);
2984
+ if (!hasIntersect(items)) {
2985
+ break;
2986
+ }
2987
+ }
2988
+ }
2989
+ function hasIntersect(items) {
2990
+ for (let i = 1; i < items.length; i++) {
2991
+ if (itemIntersect(items[i - 1], items[i])) {
2992
+ return true;
2993
+ }
2994
+ }
2995
+ return false;
2996
+ }
2997
+ function itemIntersect(item1, item2) {
2998
+ return vutils.isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true);
2999
+ }
3000
+ function tryRotate(orient, items) {
3001
+ if (orient === 'bottom' || orient === 'top') {
3002
+ rotateXAxis(orient, items);
3003
+ }
3004
+ if (orient === 'left' || orient === 'right') {
3005
+ rotateYAxis(orient, items);
3006
+ }
3007
+ genRotateBounds(items);
3008
+ }
3009
+ function rotate(x, y, deg, originX, originY) {
3010
+ return {
3011
+ x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,
3012
+ y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY
3013
+ };
3014
+ }
3015
+ function genNormalBounds(item) {
3016
+ const bounds = item.AABBBounds;
3017
+ return {
3018
+ x1: bounds.x1,
3019
+ x2: bounds.x2,
3020
+ y1: bounds.y1,
3021
+ y2: bounds.y2,
3022
+ centerX: item.attribute.x,
3023
+ centerY: item.attribute.y,
3024
+ angle: item.attribute.angle
3025
+ };
3026
+ }
3027
+ function genRotateBounds(items) {
3028
+ items.forEach(item => {
3029
+ const bounds = genNormalBounds(item);
3030
+ const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);
3031
+ const deltaX = rotatedCenter.x - bounds.centerX;
3032
+ const deltaY = rotatedCenter.y - bounds.centerY;
3033
+ bounds.x1 += deltaX;
3034
+ bounds.x2 += deltaX;
3035
+ bounds.y1 += deltaY;
3036
+ bounds.y2 += deltaY;
3037
+ bounds.centerX += deltaX;
3038
+ bounds.centerY += deltaY;
3039
+ item.rotatedBounds = bounds;
3040
+ });
3041
+ }
3042
+ function rotateYAxis(orient, items) {
3043
+ let align = ['right', 'right', 'center', 'left', 'center', 'left', 'center', 'right', 'right'];
3044
+ let baseline = ['middle', 'middle', 'top', 'top', 'middle', 'middle', 'bottom', 'bottom', 'middle'];
3045
+ if (orient === 'right') {
3046
+ align = ['left', 'right', 'right', 'right', 'left', 'left', 'left', 'left', 'right'];
3047
+ baseline = ['middle', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];
3048
+ }
3049
+ items.forEach((item, i) => {
3050
+ let angle = item.attribute.angle || 0;
3051
+ if (angle < 0) {
3052
+ while (angle < 0) {
3053
+ angle += Math.PI * 2;
3054
+ }
3055
+ }
3056
+ if (angle > 0) {
3057
+ while (angle >= Math.PI * 2) {
3058
+ angle -= Math.PI * 2;
3059
+ }
3060
+ }
3061
+ const step = angle / (Math.PI * 0.5);
3062
+ let index;
3063
+ if (step === Math.floor(step)) {
3064
+ index = Math.floor(step) * 2;
3065
+ }
3066
+ else {
3067
+ index = Math.floor(step) * 2 + 1;
3068
+ }
3069
+ item.setAttributes({
3070
+ textAlign: align[index],
3071
+ textBaseline: baseline[index],
3072
+ angle: angle
3073
+ });
3074
+ });
3075
+ }
3076
+ function rotateXAxis(orient, items) {
3077
+ let align = ['center', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'left'];
3078
+ let baseline = ['top', 'top', 'middle', 'bottom', 'bottom', 'bottom', 'middle', 'top', 'top'];
3079
+ if (orient === 'top') {
3080
+ align = ['center', 'right', 'right', 'right', 'center', 'left', 'left', 'left', 'right'];
3081
+ baseline = ['bottom', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];
3082
+ }
3083
+ items.forEach(item => {
3084
+ let angle = item.attribute.angle || 0;
3085
+ if (angle < 0) {
3086
+ while (angle < 0) {
3087
+ angle += Math.PI * 2;
3088
+ }
3089
+ }
3090
+ if (angle > 0) {
3091
+ while (angle >= Math.PI * 2) {
3092
+ angle -= Math.PI * 2;
3093
+ }
3094
+ }
3095
+ const step = angle / (Math.PI * 0.5);
3096
+ let index;
3097
+ if (step === Math.floor(step)) {
3098
+ index = Math.floor(step) * 2;
3099
+ }
3100
+ else {
3101
+ index = Math.floor(step) * 2 + 1;
3102
+ }
3103
+ item.setAttributes({
3104
+ textAlign: align[index],
3105
+ textBaseline: baseline[index],
3106
+ angle
3107
+ });
3108
+ });
3109
+ }
3110
+
3111
+ function autoLimit(labels, config) {
3112
+ const { limitLength, ellipsis = '...', orient } = config;
3113
+ if (vutils.isEmpty(labels) || !vutils.isValidNumber(limitLength)) {
3114
+ return;
3115
+ }
3116
+ labels.forEach(label => {
3117
+ const limitLabelLength = label.attribute.angle === 0 || vutils.isNil(label.attribute.angle)
3118
+ ? orient === 'top' || orient === 'bottom'
3119
+ ? null
3120
+ : limitLength
3121
+ : limitLength / Math.sin(label.attribute.angle);
3122
+ label.setAttributes({
3123
+ maxLineWidth: limitLabelLength,
3124
+ ellipsis
3125
+ });
3126
+ });
3127
+ }
3128
+
2605
3129
  function getCirclePoints(center, count, radius, startAngle, endAngle) {
2606
3130
  const points = [];
2607
3131
  const range = endAngle - startAngle;
@@ -2680,9 +3204,10 @@
2680
3204
  const space = +vutils.get(this.attribute, 'label.space', 4);
2681
3205
  labelLength += space;
2682
3206
  if (axisVector[1] === 0) {
2683
- Object.keys(this.axisLabelLayerSize).forEach((layer, index) => {
2684
- labelLength += this.axisLabelLayerSize[layer].height + (index > 0 ? space : 0);
2685
- });
3207
+ labelLength = this.axisLabelsContainer.AABBBounds.height();
3208
+ }
3209
+ else if (axisVector[0] === 0) {
3210
+ labelLength = this.axisLabelsContainer.AABBBounds.width();
2686
3211
  }
2687
3212
  else {
2688
3213
  Object.keys(this.axisLabelLayerSize).forEach((layer, index) => {
@@ -2910,6 +3435,51 @@
2910
3435
  }
2911
3436
  return base;
2912
3437
  }
3438
+ handleLabelsOverlap(labelShapes, labelData, layer, layerCount) {
3439
+ if (vutils.isEmpty(labelShapes)) {
3440
+ return;
3441
+ }
3442
+ const { verticalLimitSize, label, title, line, tick, orient } = this.attribute;
3443
+ const labelSpace = label.space ?? 4;
3444
+ let limitLength = verticalLimitSize;
3445
+ let titleHeight = 0;
3446
+ let titleSpacing = 0;
3447
+ const axisLineWidth = line?.visible ? line.style.lineWidth ?? 1 : 0;
3448
+ const tickLength = tick?.visible ? tick.length ?? 4 : 0;
3449
+ if (title?.visible) {
3450
+ titleHeight = measureTextSize(title.text, title.textStyle).height;
3451
+ titleSpacing = title.space;
3452
+ }
3453
+ if (limitLength) {
3454
+ limitLength = (limitLength - labelSpace - titleSpacing - titleHeight - axisLineWidth - tickLength) / layerCount;
3455
+ }
3456
+ const { layoutFunc, autoRotate: autoRotate$1, autoRotateAngle, autoLimit: autoLimit$1, limitEllipsis, autoHide: autoHide$1, autoHideMethod, autoHideSeparation } = label;
3457
+ if (vutils.isFunction(layoutFunc)) {
3458
+ layoutFunc(labelShapes, labelData, layer, this);
3459
+ }
3460
+ else {
3461
+ if (autoRotate$1) {
3462
+ autoRotate(labelShapes, {
3463
+ labelRotateAngle: autoRotateAngle,
3464
+ orient
3465
+ });
3466
+ }
3467
+ if (autoLimit$1 && vutils.isValidNumber(limitLength) && limitLength > 0) {
3468
+ autoLimit(labelShapes, {
3469
+ limitLength,
3470
+ ellipsis: limitEllipsis,
3471
+ orient
3472
+ });
3473
+ }
3474
+ if (autoHide$1) {
3475
+ autoHide(labelShapes, {
3476
+ orient,
3477
+ method: autoHideMethod,
3478
+ separation: autoHideSeparation
3479
+ });
3480
+ }
3481
+ }
3482
+ }
2913
3483
  }
2914
3484
 
2915
3485
  class CircleAxis extends AxisBase {
@@ -3164,6 +3734,9 @@
3164
3734
  }
3165
3735
  return base;
3166
3736
  }
3737
+ handleLabelsOverlap(labelShapes, labelData, layer, layerCount) {
3738
+ return;
3739
+ }
3167
3740
  }
3168
3741
 
3169
3742
  function getElMap(g) {
@@ -5333,7 +5906,7 @@
5333
5906
  ...shape,
5334
5907
  ...shapeAttr.style
5335
5908
  });
5336
- Object.keys(shapeAttr.state).forEach(key => {
5909
+ Object.keys(shapeAttr.state || {}).forEach(key => {
5337
5910
  const color = shapeAttr.state[key].fill || shapeAttr.state[key].stroke;
5338
5911
  if (shape.fill && vutils.isNil(shapeAttr.state[key].fill) && color) {
5339
5912
  shapeAttr.state[key].fill = color;
@@ -8263,6 +8836,21 @@
8263
8836
  value: valueList.every(vutils.isNil) ? undefined : vutils.merge({}, ...valueList)
8264
8837
  });
8265
8838
  };
8839
+ const getRichTextAttribute = (attr) => {
8840
+ const { width, height, wordBreak = 'break-word', textAlign, textBaseline, text } = attr;
8841
+ return {
8842
+ width,
8843
+ height,
8844
+ wordBreak: wordBreak,
8845
+ textAlign: textAlign,
8846
+ textBaseline: textBaseline,
8847
+ singleLine: false,
8848
+ textConfig: vutils.array(text).map(text => ({
8849
+ ...attr,
8850
+ text
8851
+ }))
8852
+ };
8853
+ };
8266
8854
 
8267
8855
  const defaultAttributes = {
8268
8856
  panel: {
@@ -8376,10 +8964,20 @@
8376
8964
  this._tooltipTitleSymbol = this._tooltipTitleContainer.createOrUpdateChild(`${TOOLTIP_TITLE_NAME}-${TOOLTIP_SHAPE_NAME_SUFFIX}`, vutils.merge({ symbolType: 'circle' }, titleAttr.shape, {
8377
8965
  visible: isVisible(titleAttr) && isVisible(titleAttr.shape)
8378
8966
  }), 'symbol');
8967
+ if (titleAttr.value.multiLine) {
8968
+ this._tooltipTitle = this._tooltipTitleContainer.createOrUpdateChild(`${TOOLTIP_TITLE_NAME}-${TOOLTIP_VALUE_NAME_SUFFIX}`, {
8969
+ visible: isVisible(titleAttr) && isVisible(titleAttr.value),
8970
+ ...getRichTextAttribute(titleAttr.value)
8971
+ }, 'richtext');
8972
+ }
8973
+ else {
8974
+ this._tooltipTitle = this._tooltipTitleContainer.createOrUpdateChild(`${TOOLTIP_TITLE_NAME}-${TOOLTIP_VALUE_NAME_SUFFIX}`, {
8975
+ text: '',
8976
+ visible: isVisible(titleAttr) && isVisible(titleAttr.value),
8977
+ ...titleAttr.value
8978
+ }, 'text');
8979
+ }
8379
8980
  const titlePaddingLeft = isVisible(titleAttr.shape) ? titleAttr.shape.size + titleAttr.shape.spacing : 0;
8380
- this._tooltipTitle = this._tooltipTitleContainer.createOrUpdateChild(`${TOOLTIP_TITLE_NAME}-${TOOLTIP_VALUE_NAME_SUFFIX}`, vutils.merge({ text: '' }, titleAttr.value, {
8381
- visible: isVisible(titleAttr) && isVisible(titleAttr.value)
8382
- }), 'text');
8383
8981
  const { textAlign, textBaseline } = titleAttr.value;
8384
8982
  const contentWidth = panel.width - padding[3] - padding[0] - titlePaddingLeft;
8385
8983
  if (textAlign === 'center') {
@@ -8419,7 +9017,8 @@
8419
9017
  itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_SHAPE_NAME_SUFFIX}`, {
8420
9018
  visible: true,
8421
9019
  x: itemAttr.shape.size / 2,
8422
- y: itemAttr.height / 2,
9020
+ y: itemAttr.shape.size / 2 +
9021
+ ((itemAttr.key.lineHeight ?? itemAttr.key.fontSize) - itemAttr.shape.size) / 2,
8423
9022
  ...itemAttr.shape
8424
9023
  }, 'symbol');
8425
9024
  }
@@ -8427,10 +9026,21 @@
8427
9026
  x += itemAttr.shape.size + itemAttr.shape.spacing;
8428
9027
  }
8429
9028
  if (isVisible(itemAttr.key)) {
8430
- const element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_KEY_NAME_SUFFIX}`, {
8431
- visible: true,
8432
- ...itemAttr.key
8433
- }, 'text');
9029
+ let element;
9030
+ if (itemAttr.key.multiLine) {
9031
+ element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_KEY_NAME_SUFFIX}`, {
9032
+ visible: true,
9033
+ ...getRichTextAttribute(itemAttr.key),
9034
+ textBaseline: 'top'
9035
+ }, 'richtext');
9036
+ }
9037
+ else {
9038
+ element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_KEY_NAME_SUFFIX}`, {
9039
+ visible: true,
9040
+ ...itemAttr.key,
9041
+ textBaseline: 'top'
9042
+ }, 'text');
9043
+ }
8434
9044
  const { textAlign } = itemAttr.key;
8435
9045
  if (textAlign === 'center') {
8436
9046
  element.setAttribute('x', x + keyWidth / 2);
@@ -8441,14 +9051,25 @@
8441
9051
  else {
8442
9052
  element.setAttribute('x', x);
8443
9053
  }
8444
- element.setAttribute('y', itemAttr.height / 2);
9054
+ element.setAttribute('y', 0);
8445
9055
  x += keyWidth + itemAttr.key.spacing;
8446
9056
  }
8447
9057
  if (isVisible(itemAttr.value)) {
8448
- const element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_VALUE_NAME_SUFFIX}`, {
8449
- visible: true,
8450
- ...itemAttr.value
8451
- }, 'text');
9058
+ let element;
9059
+ if (itemAttr.value.multiLine) {
9060
+ element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_VALUE_NAME_SUFFIX}`, {
9061
+ visible: true,
9062
+ ...getRichTextAttribute(itemAttr.value),
9063
+ textBaseline: 'top'
9064
+ }, 'richtext');
9065
+ }
9066
+ else {
9067
+ element = itemGroup.createOrUpdateChild(`${itemGroupName}-${TOOLTIP_VALUE_NAME_SUFFIX}`, {
9068
+ visible: true,
9069
+ ...itemAttr.value,
9070
+ textBaseline: 'top'
9071
+ }, 'text');
9072
+ }
8452
9073
  let textAlign = 'right';
8453
9074
  if (vutils.isValid(itemAttr.value.textAlign)) {
8454
9075
  textAlign = itemAttr.value.textAlign;
@@ -8467,7 +9088,7 @@
8467
9088
  element.setAttribute('x', x);
8468
9089
  }
8469
9090
  x += valueWidth;
8470
- element.setAttribute('y', itemAttr.height / 2);
9091
+ element.setAttribute('y', 0);
8471
9092
  itemGroup.add(element);
8472
9093
  }
8473
9094
  lastYPos += itemAttr.height + itemAttr.spaceRow;
@@ -8624,7 +9245,7 @@
8624
9245
  }
8625
9246
  }
8626
9247
 
8627
- const version = "0.12.2";
9248
+ const version = "0.13.0-alpha.0";
8628
9249
 
8629
9250
  exports.AbstractComponent = AbstractComponent;
8630
9251
  exports.BasePlayer = BasePlayer;
@@ -8661,6 +9282,7 @@
8661
9282
  exports.MarkPoint = MarkPoint;
8662
9283
  exports.Pager = Pager;
8663
9284
  exports.PolygonCrosshair = PolygonCrosshair;
9285
+ exports.PopTip = PopTip;
8664
9286
  exports.RectCrosshair = RectCrosshair;
8665
9287
  exports.RectLabel = RectLabel;
8666
9288
  exports.ScrollBar = ScrollBar;
@@ -8672,9 +9294,11 @@
8672
9294
  exports.Tag = Tag;
8673
9295
  exports.Title = Title;
8674
9296
  exports.Tooltip = Tooltip;
9297
+ exports.enablePoptip = enablePoptip;
8675
9298
  exports.getHorizontalPath = getHorizontalPath;
8676
9299
  exports.getSizeHandlerPath = getSizeHandlerPath;
8677
9300
  exports.getVerticalPath = getVerticalPath;
9301
+ exports.module = module;
8678
9302
  exports.version = version;
8679
9303
 
8680
9304
  }));