@antv/g2 5.1.0 → 5.1.2

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 (152) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -3
  3. package/README.zh-CN.md +2 -2
  4. package/dist/g2-lite.min.js +1 -10
  5. package/dist/g2.min.js +1 -10
  6. package/esm/api/chart.d.ts +7 -1
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/extend.d.ts +2 -1
  9. package/esm/api/index.d.ts +1 -3
  10. package/esm/api/index.js +1 -3
  11. package/esm/api/index.js.map +1 -1
  12. package/esm/api/library.d.ts +1 -0
  13. package/esm/api/runtime.js +1 -0
  14. package/esm/api/runtime.js.map +1 -1
  15. package/esm/component/axis.js +1 -1
  16. package/esm/component/axis.js.map +1 -1
  17. package/esm/index.d.ts +2 -2
  18. package/esm/index.js +2 -2
  19. package/esm/index.js.map +1 -1
  20. package/esm/interaction/brushHighlight.d.ts +1 -1
  21. package/esm/interaction/brushHighlight.js +15 -5
  22. package/esm/interaction/brushHighlight.js.map +1 -1
  23. package/esm/interaction/tooltip.d.ts +1 -1
  24. package/esm/interaction/tooltip.js +88 -42
  25. package/esm/interaction/tooltip.js.map +1 -1
  26. package/esm/lib/plot.d.ts +1 -0
  27. package/esm/lib/plot.js +2 -1
  28. package/esm/lib/plot.js.map +1 -1
  29. package/esm/lib/std.d.ts +1 -0
  30. package/esm/mark/area.js +1 -1
  31. package/esm/mark/area.js.map +1 -1
  32. package/esm/mark/gauge.d.ts +1 -1
  33. package/esm/mark/gauge.js +14 -2
  34. package/esm/mark/gauge.js.map +1 -1
  35. package/esm/mark/index.d.ts +2 -0
  36. package/esm/mark/index.js +1 -0
  37. package/esm/mark/index.js.map +1 -1
  38. package/esm/mark/line.js +1 -1
  39. package/esm/mark/line.js.map +1 -1
  40. package/esm/mark/liquid.d.ts +7 -0
  41. package/esm/mark/liquid.js +83 -0
  42. package/esm/mark/liquid.js.map +1 -0
  43. package/esm/runtime/constant.d.ts +1 -0
  44. package/esm/runtime/constant.js +1 -0
  45. package/esm/runtime/constant.js.map +1 -1
  46. package/esm/runtime/plot.js +7 -1
  47. package/esm/runtime/plot.js.map +1 -1
  48. package/esm/runtime/transform.js +4 -1
  49. package/esm/runtime/transform.js.map +1 -1
  50. package/esm/shape/index.d.ts +2 -0
  51. package/esm/shape/index.js +1 -0
  52. package/esm/shape/index.js.map +1 -1
  53. package/esm/shape/liquid/liquid.d.ts +3 -0
  54. package/esm/shape/liquid/liquid.js +79 -0
  55. package/esm/shape/liquid/liquid.js.map +1 -0
  56. package/esm/shape/liquid/shapes.d.ts +38 -0
  57. package/esm/shape/liquid/shapes.js +93 -0
  58. package/esm/shape/liquid/shapes.js.map +1 -0
  59. package/esm/shape/liquid/wave.d.ts +16 -0
  60. package/esm/shape/liquid/wave.js +192 -0
  61. package/esm/shape/liquid/wave.js.map +1 -0
  62. package/esm/spec/mark.d.ts +2 -1
  63. package/esm/theme/light.js +2 -1
  64. package/esm/theme/light.js.map +1 -1
  65. package/esm/utils/helper.js +10 -2
  66. package/esm/utils/helper.js.map +1 -1
  67. package/lib/api/chart.d.ts +7 -1
  68. package/lib/api/chart.js.map +1 -1
  69. package/lib/api/extend.d.ts +2 -1
  70. package/lib/api/index.d.ts +1 -3
  71. package/lib/api/index.js +1 -5
  72. package/lib/api/index.js.map +1 -1
  73. package/lib/api/library.d.ts +1 -0
  74. package/lib/api/runtime.js +1 -0
  75. package/lib/api/runtime.js.map +1 -1
  76. package/lib/component/axis.js +1 -1
  77. package/lib/component/axis.js.map +1 -1
  78. package/lib/index.d.ts +2 -2
  79. package/lib/index.js +2 -3
  80. package/lib/index.js.map +1 -1
  81. package/lib/interaction/brushHighlight.d.ts +1 -1
  82. package/lib/interaction/brushHighlight.js +15 -5
  83. package/lib/interaction/brushHighlight.js.map +1 -1
  84. package/lib/interaction/tooltip.d.ts +1 -1
  85. package/lib/interaction/tooltip.js +87 -41
  86. package/lib/interaction/tooltip.js.map +1 -1
  87. package/lib/lib/plot.d.ts +1 -0
  88. package/lib/lib/plot.js +1 -0
  89. package/lib/lib/plot.js.map +1 -1
  90. package/lib/lib/std.d.ts +1 -0
  91. package/lib/mark/area.js +1 -1
  92. package/lib/mark/area.js.map +1 -1
  93. package/lib/mark/gauge.d.ts +1 -1
  94. package/lib/mark/gauge.js +13 -1
  95. package/lib/mark/gauge.js.map +1 -1
  96. package/lib/mark/index.d.ts +2 -0
  97. package/lib/mark/index.js +3 -1
  98. package/lib/mark/index.js.map +1 -1
  99. package/lib/mark/line.js +1 -1
  100. package/lib/mark/line.js.map +1 -1
  101. package/lib/mark/liquid.d.ts +7 -0
  102. package/lib/mark/liquid.js +87 -0
  103. package/lib/mark/liquid.js.map +1 -0
  104. package/lib/runtime/constant.d.ts +1 -0
  105. package/lib/runtime/constant.js +2 -1
  106. package/lib/runtime/constant.js.map +1 -1
  107. package/lib/runtime/plot.js +7 -1
  108. package/lib/runtime/plot.js.map +1 -1
  109. package/lib/runtime/transform.js +3 -0
  110. package/lib/runtime/transform.js.map +1 -1
  111. package/lib/shape/index.d.ts +2 -0
  112. package/lib/shape/index.js +3 -1
  113. package/lib/shape/index.js.map +1 -1
  114. package/lib/shape/liquid/liquid.d.ts +3 -0
  115. package/lib/shape/liquid/liquid.js +83 -0
  116. package/lib/shape/liquid/liquid.js.map +1 -0
  117. package/lib/shape/liquid/shapes.d.ts +38 -0
  118. package/lib/shape/liquid/shapes.js +96 -0
  119. package/lib/shape/liquid/shapes.js.map +1 -0
  120. package/lib/shape/liquid/wave.d.ts +16 -0
  121. package/lib/shape/liquid/wave.js +196 -0
  122. package/lib/shape/liquid/wave.js.map +1 -0
  123. package/lib/spec/mark.d.ts +2 -1
  124. package/lib/theme/light.js +2 -1
  125. package/lib/theme/light.js.map +1 -1
  126. package/lib/utils/helper.js +10 -2
  127. package/lib/utils/helper.js.map +1 -1
  128. package/package.json +5 -5
  129. package/src/api/chart.ts +6 -1
  130. package/src/api/extend.ts +11 -11
  131. package/src/api/index.ts +6 -3
  132. package/src/api/runtime.ts +1 -0
  133. package/src/component/axis.ts +1 -1
  134. package/src/index.ts +3 -2
  135. package/src/interaction/brushHighlight.ts +26 -3
  136. package/src/interaction/tooltip.ts +95 -38
  137. package/src/lib/plot.ts +2 -1
  138. package/src/mark/area.ts +1 -1
  139. package/src/mark/gauge.ts +30 -9
  140. package/src/mark/index.ts +2 -0
  141. package/src/mark/line.ts +1 -1
  142. package/src/mark/liquid.ts +100 -0
  143. package/src/runtime/constant.ts +1 -0
  144. package/src/runtime/plot.ts +10 -2
  145. package/src/runtime/transform.ts +3 -1
  146. package/src/shape/index.ts +2 -0
  147. package/src/shape/liquid/liquid.ts +116 -0
  148. package/src/shape/liquid/shapes.ts +101 -0
  149. package/src/shape/liquid/wave.ts +245 -0
  150. package/src/spec/mark.ts +2 -0
  151. package/src/theme/light.ts +2 -1
  152. package/src/utils/helper.ts +9 -1
@@ -2,7 +2,7 @@ import { Circle, DisplayObject, IElement, Line } from '@antv/g';
2
2
  import { sort, group, mean, bisector, minIndex } from 'd3-array';
3
3
  import { deepMix, lowerFirst, throttle } from '@antv/util';
4
4
  import { Tooltip as TooltipComponent } from '@antv/gui';
5
- import { Constant, Identity } from '@antv/scale';
5
+ import { Constant, Identity, Band } from '@antv/scale';
6
6
  import { defined, subObject } from '../utils/helper';
7
7
  import { isTranspose, isPolar } from '../utils/coordinate';
8
8
  import { angle, sub } from '../utils/vector';
@@ -140,7 +140,7 @@ function showTooltip({
140
140
  parent.tooltipElement = tooltipElement;
141
141
  }
142
142
 
143
- function hideTooltip({ root, single, emitter, nativeEvent = true, mount }) {
143
+ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
144
144
  if (nativeEvent) {
145
145
  emitter.emit('tooltip:hide', { nativeEvent });
146
146
  }
@@ -152,11 +152,14 @@ function hideTooltip({ root, single, emitter, nativeEvent = true, mount }) {
152
152
  }
153
153
  }
154
154
 
155
- function destroyTooltip(root) {
156
- const { tooltipElement } = root;
155
+ function destroyTooltip({ root, single }) {
156
+ const canvasContainer = root.getRootNode().defaultView.getConfig().container;
157
+ const parent = single ? canvasContainer : root;
158
+ if (!parent) return;
159
+ const { tooltipElement } = parent;
157
160
  if (tooltipElement) {
158
161
  tooltipElement.destroy();
159
- root.tooltipElement = undefined;
162
+ parent.tooltipElement = undefined;
160
163
  }
161
164
  }
162
165
 
@@ -182,19 +185,26 @@ function singleItem(element) {
182
185
  }
183
186
 
184
187
  function groupNameOf(scale, datum) {
185
- const { color: scaleColor, series: scaleSeries } = scale;
188
+ const { color: scaleColor, series: scaleSeries, facet = false } = scale;
186
189
  const { color, series } = datum;
187
190
  const invertAble = (scale) => {
188
191
  return (
189
192
  scale &&
190
193
  scale.invert &&
191
- !(scale instanceof Identity) &&
194
+ !(scale instanceof Band) &&
192
195
  !(scale instanceof Constant)
193
196
  );
194
197
  };
195
198
  // For non constant color channel.
196
199
  if (invertAble(scaleSeries)) return scaleSeries.invert(series);
197
- if (series && series !== color) return series;
200
+ if (
201
+ series &&
202
+ scaleSeries instanceof Band &&
203
+ scaleSeries.invert(series) !== color &&
204
+ !facet
205
+ ) {
206
+ return scaleSeries.invert(series);
207
+ }
198
208
  if (invertAble(scaleColor)) {
199
209
  const name = scaleColor.invert(color);
200
210
  // For threshold scale.
@@ -627,7 +637,13 @@ export function seriesTooltip(
627
637
  ) as (...args: any[]) => void;
628
638
 
629
639
  const hide = () => {
630
- hideTooltip({ root, single, emitter, mount });
640
+ hideTooltip({ root, single, emitter });
641
+ if (crosshairs) hideRuleY(root);
642
+ if (marker) hideMarker(root);
643
+ };
644
+
645
+ const destroy = () => {
646
+ destroyTooltip({ root, single });
631
647
  if (crosshairs) hideRuleY(root);
632
648
  if (marker) hideMarker(root);
633
649
  };
@@ -645,29 +661,48 @@ export function seriesTooltip(
645
661
  };
646
662
 
647
663
  const onTooltipHide = () => {
648
- hideTooltip({ root, single, emitter, nativeEvent: false, mount });
664
+ hideTooltip({ root, single, emitter, nativeEvent: false });
649
665
  };
650
666
 
651
- emitter.on('tooltip:show', onTooltipShow);
652
- emitter.on('tooltip:hide', onTooltipHide);
667
+ const onTooltipDisable = () => {
668
+ removeEventListeners();
669
+ destroy();
670
+ };
653
671
 
654
- if (!disableNative) {
655
- root.addEventListener('pointerenter', update);
656
- root.addEventListener('pointermove', update);
657
- root.addEventListener('pointerleave', hide);
658
- }
672
+ const onTooltipEnable = () => {
673
+ addEventListeners();
674
+ };
659
675
 
660
- return () => {
676
+ const addEventListeners = () => {
677
+ if (!disableNative) {
678
+ root.addEventListener('pointerenter', update);
679
+ root.addEventListener('pointermove', update);
680
+ root.addEventListener('pointerleave', hide);
681
+ }
682
+ };
683
+
684
+ const removeEventListeners = () => {
661
685
  if (!disableNative) {
662
686
  root.removeEventListener('pointerenter', update);
663
687
  root.removeEventListener('pointermove', update);
664
688
  root.removeEventListener('pointerleave', hide);
665
689
  }
690
+ };
691
+
692
+ addEventListeners();
693
+
694
+ emitter.on('tooltip:show', onTooltipShow);
695
+ emitter.on('tooltip:hide', onTooltipHide);
696
+ emitter.on('tooltip:disable', onTooltipDisable);
697
+ emitter.on('tooltip:enable', onTooltipEnable);
698
+
699
+ return () => {
700
+ removeEventListeners();
666
701
  emitter.off('tooltip:show', onTooltipShow);
667
702
  emitter.off('tooltip:hide', onTooltipHide);
668
- destroyTooltip(root);
669
- if (crosshairs) hideRuleY(root);
670
- if (marker) hideMarker(root);
703
+ emitter.off('tooltip:disable', onTooltipDisable);
704
+ emitter.off('tooltip:enable', onTooltipEnable);
705
+ destroy();
671
706
  };
672
707
  }
673
708
 
@@ -695,6 +730,7 @@ export function tooltip(
695
730
  view,
696
731
  mount,
697
732
  bounding,
733
+ shared = false,
698
734
  body = true,
699
735
  disableNative = false,
700
736
  }: Record<string, any>,
@@ -707,13 +743,13 @@ export function tooltip(
707
743
  (event) => {
708
744
  const { target: element } = event;
709
745
  if (!elementSet.has(element)) {
710
- hideTooltip({ root, single, emitter, mount });
746
+ hideTooltip({ root, single, emitter });
711
747
  return;
712
748
  }
713
749
  const k = groupKey(element);
714
750
  const group = keyGroup.get(k);
715
751
  const data =
716
- group.length === 1
752
+ group.length === 1 && !shared
717
753
  ? singleItem(group[0])
718
754
  : groupItems(group, scale, groupName);
719
755
 
@@ -726,7 +762,7 @@ export function tooltip(
726
762
  }
727
763
 
728
764
  if (isEmptyTooltipData(data)) {
729
- hideTooltip({ root, single, emitter, mount });
765
+ hideTooltip({ root, single, emitter });
730
766
  return;
731
767
  }
732
768
 
@@ -762,7 +798,24 @@ export function tooltip(
762
798
  const pointerout = (event) => {
763
799
  const { target: element } = event;
764
800
  if (!elementSet.has(element)) return;
765
- hideTooltip({ root, single, emitter, mount });
801
+ hideTooltip({ root, single, emitter });
802
+ };
803
+
804
+ const addEventListeners = () => {
805
+ if (!disableNative) {
806
+ root.addEventListener('pointerover', pointerover);
807
+ root.addEventListener('pointermove', pointerover);
808
+ root.addEventListener('pointerout', pointerout);
809
+ }
810
+ };
811
+
812
+ const removeEventListeners = () => {
813
+ if (!disableNative) {
814
+ root.removeEventListener('pointerover', pointerover);
815
+ root.removeEventListener('pointermove', pointerover);
816
+ root.removeEventListener('pointerout', pointerout);
817
+ }
818
+ destroyTooltip({ root, single });
766
819
  };
767
820
 
768
821
  const onTooltipShow = ({ nativeEvent, data }) => {
@@ -780,28 +833,30 @@ export function tooltip(
780
833
 
781
834
  const onTooltipHide = ({ nativeEvent }: any = {}) => {
782
835
  if (nativeEvent) return;
783
- hideTooltip({ root, single, emitter, nativeEvent: false, mount });
836
+ hideTooltip({ root, single, emitter, nativeEvent: false });
837
+ };
838
+
839
+ const onTooltipDisable = () => {
840
+ removeEventListeners();
841
+ destroyTooltip({ root, single });
842
+ };
843
+
844
+ const onTooltipEnable = () => {
845
+ addEventListeners();
784
846
  };
785
847
 
786
848
  emitter.on('tooltip:show', onTooltipShow);
787
849
  emitter.on('tooltip:hide', onTooltipHide);
850
+ emitter.on('tooltip:enable', onTooltipEnable);
851
+ emitter.on('tooltip:disable', onTooltipDisable);
788
852
 
789
- if (!disableNative) {
790
- root.addEventListener('pointerover', pointerover);
791
- root.addEventListener('pointermove', pointerover);
792
- root.addEventListener('pointerout', pointerout);
793
- }
853
+ addEventListeners();
794
854
 
795
855
  return () => {
796
- if (!disableNative) {
797
- root.removeEventListener('pointerover', pointerover);
798
- root.removeEventListener('pointermove', pointerover);
799
- root.removeEventListener('pointerout', pointerout);
800
- }
801
-
856
+ removeEventListeners();
802
857
  emitter.off('tooltip:show', onTooltipShow);
803
858
  emitter.off('tooltip:hide', onTooltipHide);
804
- destroyTooltip(root);
859
+ destroyTooltip({ root, single });
805
860
  };
806
861
  }
807
862
 
@@ -849,6 +904,7 @@ export function Tooltip(options) {
849
904
  const bbox = plotArea.getBounds();
850
905
  const startX = bbox.min[0];
851
906
  const startY = bbox.min[1];
907
+ Object.assign(scale, { facet: true });
852
908
 
853
909
  // @todo Nested structure rather than flat structure for facet?
854
910
  // Add listener to the root area.
@@ -876,6 +932,7 @@ export function Tooltip(options) {
876
932
  item,
877
933
  emitter,
878
934
  view,
935
+ shared,
879
936
  });
880
937
  };
881
938
  }
package/src/lib/plot.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Boxplot, WordCloud, Gauge } from '../mark';
1
+ import { Boxplot, WordCloud, Gauge, Liquid } from '../mark';
2
2
  import { Venn } from '../data';
3
3
 
4
4
  export function plotlib() {
@@ -7,5 +7,6 @@ export function plotlib() {
7
7
  'mark.boxplot': Boxplot,
8
8
  'mark.gauge': Gauge,
9
9
  'mark.wordCloud': WordCloud,
10
+ 'mark.liquid': Liquid,
10
11
  } as const;
11
12
  }
package/src/mark/area.ts CHANGED
@@ -85,7 +85,7 @@ Area.props = {
85
85
  { name: 'x', required: true },
86
86
  { name: 'y', required: true },
87
87
  { name: 'size' },
88
- { name: 'series', scale: 'identity' },
88
+ { name: 'series', scale: 'band' },
89
89
  ],
90
90
  preInference: [
91
91
  ...basePreInference(),
package/src/mark/gauge.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { deepMix } from '@antv/util';
1
+ import { deepMix, isNumber } from '@antv/util';
2
2
  import { Vector2 } from '@antv/coord';
3
3
  import { Group } from '@antv/g';
4
4
  import { filterPrefixObject, isUnset, subObject } from '../utils/helper';
@@ -124,16 +124,37 @@ const DEFAULT_TEXT_OPTIONS = {
124
124
  },
125
125
  };
126
126
 
127
- export type GaugeData = {
128
- target?: number;
129
- total?: number;
130
- percent?: number;
131
- name?: string;
132
- thresholds?: number[];
133
- };
127
+ export type GaugeData =
128
+ | {
129
+ target?: number;
130
+ total?: number;
131
+ percent?: number;
132
+ name?: string;
133
+ thresholds?: number[];
134
+ }
135
+ | number;
136
+
137
+ function getGaugeData(data: GaugeData) {
138
+ if (isNumber(data)) {
139
+ // Percent range [0, 1].
140
+ const percent = Math.max(0, Math.min(data, 1));
141
+ return {
142
+ percent,
143
+ target: percent,
144
+ total: 1,
145
+ };
146
+ }
147
+ return data;
148
+ }
134
149
 
135
150
  function dataTransform(data: GaugeData, scale) {
136
- const { name = 'score', target, total, percent, thresholds = [] } = data;
151
+ const {
152
+ name = 'score',
153
+ target,
154
+ total,
155
+ percent,
156
+ thresholds = [],
157
+ } = getGaugeData(data);
137
158
  const _target = percent || target;
138
159
  const _total = percent ? 1 : total;
139
160
  const newScale = {
package/src/mark/index.ts CHANGED
@@ -30,6 +30,7 @@ export { WordCloud } from './wordCloud';
30
30
  export { Gauge } from './gauge';
31
31
  export { Density } from './density';
32
32
  export { Heatmap } from './heatmap';
33
+ export { Liquid } from './liquid';
33
34
 
34
35
  export type { IntervalOptions } from './interval';
35
36
  export type { RectOptions } from './rect';
@@ -59,3 +60,4 @@ export type { WordCloudOptions } from './wordCloud';
59
60
  export type { GaugeOptions } from './gauge';
60
61
  export type { DensityOptions } from './density';
61
62
  export type { HeatmapOptions } from './heatmap';
63
+ export type { LiquidOptions } from './liquid';
package/src/mark/line.ts CHANGED
@@ -108,7 +108,7 @@ Line.props = {
108
108
  { name: 'y' },
109
109
  { name: 'position', independent: true },
110
110
  { name: 'size' },
111
- { name: 'series', scale: 'identity' },
111
+ { name: 'series', scale: 'band' },
112
112
  ],
113
113
  preInference: [
114
114
  ...basePreInference(),
@@ -0,0 +1,100 @@
1
+ import { deepMix, isNumber } from '@antv/util';
2
+ import { subObject } from '../utils/helper';
3
+ import { CompositeMarkComponent as CC } from '../runtime';
4
+ import { LiquidMark } from '../spec';
5
+ import { LiquidShape } from '../shape';
6
+
7
+ const DEFAULT_OPTIONS = {
8
+ axis: {
9
+ x: false,
10
+ y: false,
11
+ },
12
+ legend: false,
13
+ tooltip: false,
14
+ encode: {
15
+ x: 'type',
16
+ y: 'percent',
17
+ },
18
+ scale: {
19
+ y: {
20
+ domain: [0, 1],
21
+ },
22
+ },
23
+ style: {
24
+ shape: LiquidShape,
25
+ },
26
+ animate: {
27
+ enter: {
28
+ type: 'fadeIn',
29
+ },
30
+ },
31
+ };
32
+
33
+ const DEFAULT_TEXT_OPTIONS = {
34
+ type: 'text',
35
+ style: {
36
+ x: '50%',
37
+ y: '50%',
38
+ textAlign: 'center',
39
+ textBaseline: 'middle',
40
+ fontSize: 20,
41
+ fontWeight: 800,
42
+ fill: '#888',
43
+ },
44
+ animate: {
45
+ enter: {
46
+ type: 'fadeIn',
47
+ },
48
+ },
49
+ };
50
+
51
+ export type LiquidData =
52
+ | {
53
+ percent?: number;
54
+ }
55
+ | number;
56
+
57
+ export type LiquidOptions = Omit<LiquidMark, 'type'>;
58
+
59
+ export const Liquid: CC<LiquidOptions> = (options) => {
60
+ const { data = {}, style = {}, animate, ...resOptions } = options;
61
+ // Compatible with old data structures: { percent: number } and percent >= 0.
62
+ const percent = Math.max(0, isNumber(data) ? data : data?.percent);
63
+
64
+ const newData = [{ percent, type: 'liquid' }];
65
+
66
+ const textStyle = subObject(style, 'text');
67
+ const outline = subObject(style, 'outline');
68
+ const wave = subObject(style, 'wave');
69
+ const background = subObject(style, 'background');
70
+
71
+ return [
72
+ deepMix({}, DEFAULT_OPTIONS, {
73
+ type: 'interval',
74
+ data: newData,
75
+ style: {
76
+ liquidOptions: {
77
+ percent,
78
+ liquidShape: style?.shape,
79
+ },
80
+ styleOptions: {
81
+ ...style,
82
+ outline,
83
+ wave,
84
+ background,
85
+ },
86
+ },
87
+ animate,
88
+ ...resOptions,
89
+ }),
90
+ deepMix({}, DEFAULT_TEXT_OPTIONS, {
91
+ style: {
92
+ text: `${percent * 100} %`,
93
+ ...textStyle,
94
+ },
95
+ animate,
96
+ }),
97
+ ];
98
+ };
99
+
100
+ Liquid.props = {};
@@ -6,3 +6,4 @@ export const PLOT_CLASS_NAME = 'plot';
6
6
  export const COMPONENT_CLASS_NAME = 'component';
7
7
  export const LABEL_CLASS_NAME = 'label';
8
8
  export const AREA_CLASS_NAME = 'area';
9
+ export const MASK_CLASS_NAME = 'mask';
@@ -422,11 +422,14 @@ async function initializeView(
422
422
  const flattenOptions = await transformMarks(options, library);
423
423
 
424
424
  const mergedOptions = bubbleOptions(flattenOptions);
425
+
425
426
  // @todo Remove this.
426
427
  // !!! NOTE: Mute original view options.
427
428
  // Update interaction and coordinate for this view.
428
429
  options.interaction = mergedOptions.interaction;
429
430
  options.coordinate = mergedOptions.coordinate;
431
+ // @ts-ignore
432
+ options.marks = [...mergedOptions.marks, ...mergedOptions.components];
430
433
 
431
434
  const transformedOptions = coordinate2Transform(mergedOptions, library);
432
435
  const state = await initializeMarks(transformedOptions, library);
@@ -961,13 +964,18 @@ async function plotView(
961
964
  const node = shapeFunction(data, index);
962
965
  const animation = updateFunction(data, [element], [node]);
963
966
  if (animation !== null) return animation;
964
- if (element.nodeName === node.nodeName)
967
+ if (
968
+ element.nodeName === node.nodeName &&
969
+ node.nodeName !== 'g'
970
+ ) {
965
971
  copyAttributes(element, node);
966
- else {
972
+ } else {
967
973
  element.parentNode.replaceChild(node, element);
968
974
  node.className = ELEMENT_CLASS_NAME;
969
975
  // @ts-ignore
970
976
  node.markType = type;
977
+ // @ts-ignore
978
+ node.__data__ = element.__data__;
971
979
  }
972
980
  return animation;
973
981
  })
@@ -1,5 +1,5 @@
1
1
  import { Primitive } from 'd3-array';
2
- import { deepMix } from '@antv/util';
2
+ import { deepMix, isNumber } from '@antv/util';
3
3
  import { format } from 'd3-format';
4
4
  import { indexOf, mapObject } from '../utils/array';
5
5
  import {
@@ -336,6 +336,8 @@ function isField(data: Record<string, Primitive>[], value: string): boolean {
336
336
  }
337
337
 
338
338
  function normalizedDataSource(data) {
339
+ // Liquid、Gauge need number data.
340
+ if (isNumber(data)) return { type: 'inline', value: data };
339
341
  // Return null as a placeholder.
340
342
  if (!data) return { type: 'inline', value: null };
341
343
  if (Array.isArray(data)) return { type: 'inline', value: data };
@@ -60,6 +60,7 @@ export { Rect as RangeShape } from './interval/rect';
60
60
  export { Rect as RectShape } from './interval/rect';
61
61
  export { Hollow as RectHollow } from './interval/hollow';
62
62
  export { Shape as ShapeShape } from './shape/shape';
63
+ export { Liquid as LiquidShape } from './liquid/liquid';
63
64
 
64
65
  export type { RectOptions as IntervalShapeOptions } from './interval/rect';
65
66
  export type { HollowOptions as IntervalHollowOptions } from './interval/hollow';
@@ -109,3 +110,4 @@ export type { ConnectorOptions as ConnectorShapeOptions } from './connector/conn
109
110
  export type { LabelOptions as LabelShapeOptions } from './label/label';
110
111
  export type { DensityOptions as DensityShapeOptions } from './density/density';
111
112
  export type { ShapeOptions as ShapeShapeOptions } from './shape/shape';
113
+ export type { LiquidOptions } from './liquid/liquid';
@@ -0,0 +1,116 @@
1
+ import { isFunction } from '@antv/util';
2
+ import type { PathStyleProps } from '@antv/g';
3
+ import type { ShapeComponent as SC } from '../../runtime';
4
+ import { addWave } from './wave';
5
+ import { LiquidShapesPath } from './shapes';
6
+
7
+ const getLiquidShape = (shape = 'circle') =>
8
+ LiquidShapesPath[shape] || LiquidShapesPath.circle;
9
+
10
+ export type LiquidOptions = Record<string, any>;
11
+
12
+ export const Liquid: SC<LiquidOptions> = (options, context) => {
13
+ if (!context) return;
14
+ const { coordinate } = context;
15
+ const { liquidOptions, styleOptions } = options;
16
+ const { liquidShape, percent } = liquidOptions;
17
+ const {
18
+ background: backgroundStyle,
19
+ outline = {},
20
+ wave = {},
21
+ ...attr
22
+ } = styleOptions;
23
+ const { border = 2, distance = 0, ...outlineStyle } = outline;
24
+ const { length = 192, count = 3 } = wave;
25
+
26
+ return (points, cfg, defaultAttr) => {
27
+ const { document } = context.canvas;
28
+ const { color, fillOpacity } = defaultAttr;
29
+ const attrs = { fill: color, ...defaultAttr, ...attr } as PathStyleProps;
30
+
31
+ const g = document.createElement('g', {});
32
+
33
+ // Center x/y.
34
+ const [centerX, centerY] = coordinate.getCenter();
35
+ // [width,height].
36
+ const size = coordinate.getSize();
37
+ const radius = Math.min(...size) / 2;
38
+
39
+ // 1、Gets the path of the overall shape.
40
+ const buildPath = isFunction(liquidShape)
41
+ ? liquidShape
42
+ : getLiquidShape(liquidShape);
43
+ const shapePath = buildPath(centerX, centerY, radius, ...size);
44
+
45
+ // 2、Background create.
46
+ if (Object.keys(backgroundStyle).length) {
47
+ const backgroundShape = document.createElement('path', {
48
+ style: {
49
+ path: shapePath,
50
+ fill: '#fff',
51
+ ...backgroundStyle,
52
+ },
53
+ });
54
+
55
+ g.appendChild(backgroundShape);
56
+ }
57
+
58
+ // Percent > 0 Mapping water waves.
59
+ if (percent > 0) {
60
+ // 3. Clip create.
61
+ const clipShape = document.createElement('path', {
62
+ style: {
63
+ path: shapePath,
64
+ },
65
+ });
66
+
67
+ g.appendChild(clipShape);
68
+ g.style.clipPath = clipShape;
69
+
70
+ // 4. Wave create.
71
+ addWave(
72
+ centerX,
73
+ centerY,
74
+ 1 - percent,
75
+ count,
76
+ attrs,
77
+ g,
78
+ clipShape.getBBox().y,
79
+ radius * 2,
80
+ length,
81
+ true,
82
+ document,
83
+ );
84
+ }
85
+
86
+ // 5. Draw distance.
87
+ const distanceShape = document.createElement('path', {
88
+ style: {
89
+ path: shapePath,
90
+ fill: 'transparent',
91
+ lineWidth: border + 2 * distance,
92
+ stroke: '#fff',
93
+ },
94
+ });
95
+
96
+ // 6. Draw border.
97
+ const borderShape = document.createElement('path', {
98
+ style: {
99
+ path: shapePath,
100
+ stroke: color,
101
+ strokeOpacity: fillOpacity,
102
+ lineWidth: border,
103
+ ...attrs,
104
+ ...outlineStyle,
105
+ fill: 'transparent',
106
+ },
107
+ });
108
+
109
+ g.appendChild(distanceShape);
110
+ g.appendChild(borderShape);
111
+
112
+ return g;
113
+ };
114
+ };
115
+
116
+ Liquid.props = {};