@antv/g2 5.3.4-beta.3 → 5.3.5-beta.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 (104) hide show
  1. package/dist/g2.lite.min.js +9 -9
  2. package/dist/g2.min.js +9 -9
  3. package/esm/api/runtime.js +3 -0
  4. package/esm/api/runtime.js.map +1 -1
  5. package/esm/component/legendCategory.js +42 -0
  6. package/esm/component/legendCategory.js.map +1 -1
  7. package/esm/composition/geoPath.js +2 -1
  8. package/esm/composition/geoPath.js.map +1 -1
  9. package/esm/composition/geoView.js +6 -1
  10. package/esm/composition/geoView.js.map +1 -1
  11. package/esm/index.d.ts +2 -0
  12. package/esm/interaction/tooltip.d.ts +1 -1
  13. package/esm/interaction/tooltip.js +44 -5
  14. package/esm/interaction/tooltip.js.map +1 -1
  15. package/esm/label-transform/contrastReverse.js +5 -98
  16. package/esm/label-transform/contrastReverse.js.map +1 -1
  17. package/esm/label-transform/exceedAdjust.d.ts +7 -2
  18. package/esm/label-transform/exceedAdjust.js +31 -7
  19. package/esm/label-transform/exceedAdjust.js.map +1 -1
  20. package/esm/label-transform/index.d.ts +2 -0
  21. package/esm/label-transform/index.js +1 -0
  22. package/esm/label-transform/index.js.map +1 -1
  23. package/esm/label-transform/overflowStroke.d.ts +8 -0
  24. package/esm/label-transform/overflowStroke.js +57 -0
  25. package/esm/label-transform/overflowStroke.js.map +1 -0
  26. package/esm/label-transform/utils.d.ts +10 -0
  27. package/esm/label-transform/utils.js +32 -0
  28. package/esm/label-transform/utils.js.map +1 -0
  29. package/esm/lib/core.d.ts +1 -0
  30. package/esm/lib/core.js +2 -1
  31. package/esm/lib/core.js.map +1 -1
  32. package/esm/lib/std.d.ts +1 -0
  33. package/esm/mark/sankey.js +13 -2
  34. package/esm/mark/sankey.js.map +1 -1
  35. package/esm/mark/treemap.js +2 -4
  36. package/esm/mark/treemap.js.map +1 -1
  37. package/esm/shape/gauge/round.js +23 -2
  38. package/esm/shape/gauge/round.js.map +1 -1
  39. package/esm/shape/liquid/liquid.js +2 -1
  40. package/esm/shape/liquid/liquid.js.map +1 -1
  41. package/esm/spec/labelTransform.d.ts +25 -5
  42. package/esm/utils/helper.d.ts +6 -0
  43. package/esm/utils/helper.js +13 -2
  44. package/esm/utils/helper.js.map +1 -1
  45. package/lib/api/runtime.js +3 -0
  46. package/lib/api/runtime.js.map +1 -1
  47. package/lib/component/legendCategory.js +42 -0
  48. package/lib/component/legendCategory.js.map +1 -1
  49. package/lib/composition/geoPath.js +2 -1
  50. package/lib/composition/geoPath.js.map +1 -1
  51. package/lib/composition/geoView.js +6 -1
  52. package/lib/composition/geoView.js.map +1 -1
  53. package/lib/index.d.ts +2 -0
  54. package/lib/interaction/tooltip.d.ts +1 -1
  55. package/lib/interaction/tooltip.js +42 -3
  56. package/lib/interaction/tooltip.js.map +1 -1
  57. package/lib/label-transform/contrastReverse.js +6 -99
  58. package/lib/label-transform/contrastReverse.js.map +1 -1
  59. package/lib/label-transform/exceedAdjust.d.ts +7 -2
  60. package/lib/label-transform/exceedAdjust.js +31 -7
  61. package/lib/label-transform/exceedAdjust.js.map +1 -1
  62. package/lib/label-transform/index.d.ts +2 -0
  63. package/lib/label-transform/index.js +3 -1
  64. package/lib/label-transform/index.js.map +1 -1
  65. package/lib/label-transform/overflowStroke.d.ts +8 -0
  66. package/lib/label-transform/overflowStroke.js +61 -0
  67. package/lib/label-transform/overflowStroke.js.map +1 -0
  68. package/lib/label-transform/utils.d.ts +10 -0
  69. package/lib/label-transform/utils.js +37 -0
  70. package/lib/label-transform/utils.js.map +1 -0
  71. package/lib/lib/core.d.ts +1 -0
  72. package/lib/lib/core.js +1 -0
  73. package/lib/lib/core.js.map +1 -1
  74. package/lib/lib/std.d.ts +1 -0
  75. package/lib/mark/sankey.js +12 -1
  76. package/lib/mark/sankey.js.map +1 -1
  77. package/lib/mark/treemap.js +2 -4
  78. package/lib/mark/treemap.js.map +1 -1
  79. package/lib/shape/gauge/round.js +23 -2
  80. package/lib/shape/gauge/round.js.map +1 -1
  81. package/lib/shape/liquid/liquid.js +2 -1
  82. package/lib/shape/liquid/liquid.js.map +1 -1
  83. package/lib/spec/labelTransform.d.ts +25 -5
  84. package/lib/utils/helper.d.ts +6 -0
  85. package/lib/utils/helper.js +15 -3
  86. package/lib/utils/helper.js.map +1 -1
  87. package/package.json +2 -1
  88. package/src/api/runtime.ts +2 -0
  89. package/src/component/legendCategory.ts +49 -0
  90. package/src/composition/geoPath.ts +13 -2
  91. package/src/composition/geoView.ts +6 -1
  92. package/src/interaction/tooltip.ts +65 -6
  93. package/src/label-transform/contrastReverse.ts +4 -123
  94. package/src/label-transform/exceedAdjust.ts +53 -8
  95. package/src/label-transform/index.ts +2 -0
  96. package/src/label-transform/overflowStroke.ts +69 -0
  97. package/src/label-transform/utils.ts +34 -0
  98. package/src/lib/core.ts +2 -0
  99. package/src/mark/sankey.ts +16 -2
  100. package/src/mark/treemap.ts +3 -4
  101. package/src/shape/gauge/round.ts +24 -2
  102. package/src/shape/liquid/liquid.ts +7 -1
  103. package/src/spec/labelTransform.ts +26 -2
  104. package/src/utils/helper.ts +14 -2
@@ -1,145 +1,26 @@
1
1
  import { DisplayObject } from '@antv/g';
2
- import { maxIndex } from '@antv/vendor/d3-array';
3
- import { isUndefined } from '@antv/util';
4
2
  import { ContrastReverseLabelTransform } from '../spec';
5
3
  import { LabelTransformComponent as LLC } from '../runtime';
6
- import { parseToRGB } from '../utils/color';
7
- import { isOverflow, parseAABB } from '../utils/bounds';
8
- import { bboxOf } from '../interaction/utils';
4
+ import { contrast, mostContrast } from './utils';
9
5
 
10
6
  export type ContrastReverseOptions = Omit<
11
7
  ContrastReverseLabelTransform,
12
8
  'type'
13
9
  >;
14
10
 
15
- function getsRGB(s: number) {
16
- let c = s / 255;
17
- c = c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
18
- return c;
19
- }
20
-
21
- function getL(r: number, g: number, b: number) {
22
- return 0.2126 * getsRGB(r) + 0.7152 * getsRGB(g) + 0.0722 * getsRGB(b);
23
- }
24
-
25
- /**
26
- * Calculate the contrast. see https://webaim.org/resources/contrastchecker/
27
- * @param foreground
28
- * @param background
29
- */
30
- function contrast(foreground, background): number {
31
- if (!foreground || !background || foreground === background) return 1;
32
- const { r, g, b } = foreground;
33
- const { r: rb, g: gb, b: bb } = background;
34
- const L1 = getL(r, g, b);
35
- const L2 = getL(rb, gb, bb);
36
- return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
37
- }
38
-
39
- /**
40
- * Reverse color for max contrast.
41
- */
42
- function mostContrast(color, palette: string[]): string {
43
- const i = maxIndex(palette, (c) => contrast(color, parseToRGB(c)));
44
- return palette[i];
45
- }
46
-
47
- /**
48
- * Get bounds of element considering animation state.
49
- * If element has animations, get the final state bounds.
50
- */
51
- function getBoundsWithAnimation(element: DisplayObject) {
52
- const animations = element.getAnimations();
53
-
54
- // If no animations, use regular bboxOf.
55
- if (!animations || animations.length === 0) {
56
- return bboxOf(element);
57
- }
58
-
59
- // Clone element and apply final animation state.
60
- const cloneElement = element.cloneNode(true) as DisplayObject;
61
- cloneElement.style.visibility = 'hidden';
62
-
63
- animations.forEach((animation) => {
64
- const keyframes = animation.effect.getKeyframes();
65
- if (keyframes && keyframes.length > 0) {
66
- cloneElement.attr(keyframes[keyframes.length - 1]);
67
- }
68
- });
69
-
70
- element.parentNode?.appendChild(cloneElement);
71
- const bounds = bboxOf(cloneElement);
72
- cloneElement.destroy();
73
-
74
- return bounds;
75
- }
76
-
77
11
  /**
78
12
  * Reverse the label color when the contrast is lower then `threshold`.
79
13
  * The default value of `threshold` is 4.5.
80
14
  * More about contract, see https://webaim.org/resources/contrastchecker/
81
15
  */
82
16
  export const ContrastReverse: LLC<ContrastReverseOptions> = (options) => {
83
- const {
84
- autoStroke = false,
85
- threshold = 4.5,
86
- palette = ['#000', '#fff'],
87
- } = options;
88
-
17
+ const { threshold = 4.5, palette = ['#000', '#fff'] } = options;
89
18
  return (labels: DisplayObject[]) => {
90
19
  labels.forEach((l) => {
91
- const dependentElement = l.attr('dependentElement');
92
- const background = dependentElement.parsedStyle.fill;
20
+ const background = l.attr('dependentElement').parsedStyle.fill;
93
21
  const foreground = l.parsedStyle.fill;
94
22
  const c = contrast(foreground, background);
95
-
96
- // Apply contrast reverse if needed.
97
- if (c < threshold) {
98
- const reversedColor = mostContrast(background, palette);
99
- l.attr('fill', reversedColor);
100
-
101
- // Check if text bbox overflows the dependent element.
102
- if (autoStroke) {
103
- // Save original stroke properties only if not already saved.
104
- if (!l.attr('_originalStyleSaved')) {
105
- l.attr('_originalStroke', l.attr('stroke'));
106
- l.attr('_originalLineWidth', l.attr('lineWidth'));
107
- l.attr('_originalStyleSaved', true);
108
- }
109
-
110
- const textBounds = parseAABB(getBoundsWithAnimation(l));
111
- const elementBounds = parseAABB(
112
- getBoundsWithAnimation(dependentElement),
113
- );
114
-
115
- if (isOverflow(textBounds, elementBounds)) {
116
- // Add stroke to make overflowing text more visible.
117
- // Use the opposite color from palette for stroke.
118
- const strokeColor = mostContrast(
119
- parseToRGB(reversedColor),
120
- palette,
121
- );
122
-
123
- l.attr('stroke', strokeColor);
124
- l.attr(
125
- 'lineWidth',
126
- (autoStroke as { lineWidth: number })?.lineWidth ?? 1.6,
127
- );
128
- } else {
129
- // Restore original stroke properties if not overflowing.
130
- l.attr({
131
- stroke: l.attr('_originalStroke'),
132
- lineWidth: l.attr('_originalLineWidth'),
133
- });
134
-
135
- // Undefined can't set to attrs, have to remove.
136
- if (isUndefined(l.attr('_originalStroke')))
137
- l.removeAttribute('stroke');
138
- if (isUndefined(l.attr('_originalLineWidth')))
139
- l.removeAttribute('lineWidth');
140
- }
141
- }
142
- }
23
+ if (c < threshold) l.attr('fill', mostContrast(background, palette));
143
24
  });
144
25
  return labels;
145
26
  };
@@ -28,13 +28,61 @@ const adjustPosition = (target: Bounds, edge: Bounds) => {
28
28
  return [changeX, changeY];
29
29
  };
30
30
 
31
- export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'>;
31
+ export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'> & {
32
+ /** X-axis offset default is 0 */
33
+ offsetX?: number;
34
+ /** Y-axis offset default is 0 */
35
+ offsetY?: number;
36
+ };
32
37
 
33
38
  /**
34
- * adjust the label when exceed the plot
39
+ * adjust the label when exceed the specific area
35
40
  */
36
- export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
41
+ export const ExceedAdjust: LLC<ExceedAdjustOptions> = (options = {}) => {
37
42
  return (labels: DisplayObject[], { canvas, layout }) => {
43
+ const { bounds = 'view', offsetX = 0, offsetY = 0 } = options;
44
+
45
+ // Calculate boundary area based on bounds option
46
+ const getBoundaryArea = () => {
47
+ if (bounds === 'main') {
48
+ // Main area: exclude margins and paddings from view area
49
+ const {
50
+ x = 0,
51
+ y = 0,
52
+ width = 0,
53
+ height = 0,
54
+ marginLeft = 0,
55
+ marginRight = 0,
56
+ marginTop = 0,
57
+ marginBottom = 0,
58
+ paddingLeft = 0,
59
+ paddingRight = 0,
60
+ paddingTop = 0,
61
+ paddingBottom = 0,
62
+ } = layout;
63
+
64
+ return [
65
+ [
66
+ x + marginLeft + paddingLeft + offsetX,
67
+ y + marginTop + paddingTop + offsetY,
68
+ ],
69
+ [
70
+ x + width - marginRight - paddingRight - offsetX,
71
+ y + height - marginBottom - paddingBottom - offsetY,
72
+ ],
73
+ ] as Bounds;
74
+ } else {
75
+ // View area (default): entire layout area
76
+ const { x = 0, y = 0, width = 0, height = 0 } = layout;
77
+ return [
78
+ [x + offsetX, y + offsetY],
79
+ [x + width - offsetX, y + height - offsetY],
80
+ ] as Bounds;
81
+ }
82
+ };
83
+
84
+ const boundaryArea = getBoundaryArea();
85
+
38
86
  labels.forEach((l) => {
39
87
  show(l);
40
88
  const { max, min } = l.getRenderBounds();
@@ -45,11 +93,8 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
45
93
  [xMin, yMin],
46
94
  [xMax, yMax],
47
95
  ],
48
- // Prevent label overlap in multiple charts by calculating layouts separately to avoid collisions.
49
- [
50
- [layout.x, layout.y],
51
- [layout.x + layout.width, layout.y + layout.height],
52
- ],
96
+ // Use the calculated boundary area based on bounds configuration
97
+ boundaryArea,
53
98
  );
54
99
  // For label with connectorPoints
55
100
  if (l.style.connector && l.style.connectorPoints) {
@@ -3,9 +3,11 @@ export { OverlapDodgeY } from './overlapDodgeY';
3
3
  export { ContrastReverse } from './contrastReverse';
4
4
  export { OverflowHide } from './overflowHide';
5
5
  export { ExceedAdjust } from './exceedAdjust';
6
+ export { OverflowStroke } from './overflowStroke';
6
7
 
7
8
  export type { OverlapHideOptions } from './overlapHide';
8
9
  export type { OverlapDodgeYOptions } from './overlapDodgeY';
9
10
  export type { ContrastReverseOptions } from './contrastReverse';
11
+ export type { OverflowStrokeOptions } from './overflowStroke';
10
12
  export type { OverflowHideOptions } from './overflowHide';
11
13
  export type { ExceedAdjustOptions } from './exceedAdjust';
@@ -0,0 +1,69 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { OverflowStrokeTransform } from '../spec';
3
+ import { LabelTransformComponent as LLC } from '../runtime';
4
+ import { parseToRGB } from '../utils/color';
5
+ import { isOverflow, parseAABB } from '../utils/bounds';
6
+ import { bboxOf } from '../interaction/utils';
7
+ import { mostContrast } from './utils';
8
+
9
+ export type OverflowStrokeOptions = Omit<OverflowStrokeTransform, 'type'>;
10
+
11
+ /**
12
+ * Get bounds of element considering animation state.
13
+ * If element has animations, get the final state bounds.
14
+ */
15
+ function getBoundsWithAnimation(element: DisplayObject) {
16
+ const animations = element.getAnimations();
17
+
18
+ // If no animations, use regular bboxOf.
19
+ if (!animations || animations.length === 0) {
20
+ return bboxOf(element);
21
+ }
22
+
23
+ // Clone element and apply final animation state.
24
+ const cloneElement = element.cloneNode(true) as DisplayObject;
25
+ cloneElement.style.visibility = 'hidden';
26
+
27
+ animations.forEach((animation) => {
28
+ const keyframes = animation.effect.getKeyframes();
29
+ if (keyframes && keyframes.length > 0) {
30
+ cloneElement.attr(keyframes[keyframes.length - 1]);
31
+ }
32
+ });
33
+
34
+ element.parentNode?.appendChild(cloneElement);
35
+ const bounds = bboxOf(cloneElement);
36
+ cloneElement.destroy();
37
+
38
+ return bounds;
39
+ }
40
+
41
+ /**
42
+ * Reverse label stroke against label color.
43
+ * More about contract, see https://webaim.org/resources/contrastchecker/
44
+ */
45
+ export const OverflowStroke: LLC<OverflowStrokeOptions> = (options) => {
46
+ const { palette = ['#000', '#fff'], threshold = 2 } = options;
47
+
48
+ return (labels: DisplayObject[]) => {
49
+ labels.forEach((l) => {
50
+ const dependentElement = l.attr('dependentElement');
51
+ const labelFill = l.attributes.fill ?? l.parsedStyle.fill ?? '#fff';
52
+
53
+ const textBounds = parseAABB(getBoundsWithAnimation(l));
54
+ const elementBounds = parseAABB(getBoundsWithAnimation(dependentElement));
55
+
56
+ if (isOverflow(textBounds, elementBounds, threshold)) {
57
+ // Add stroke to make overflowing text more visible.
58
+ // Use the opposite color from palette for stroke.
59
+ const strokeColor = mostContrast(parseToRGB(labelFill), palette);
60
+
61
+ l.attr('stroke', strokeColor);
62
+ } else {
63
+ // Undefined can't set to attrs, have to remove.
64
+ l.removeAttribute('stroke');
65
+ }
66
+ });
67
+ return labels;
68
+ };
69
+ };
@@ -0,0 +1,34 @@
1
+ import { maxIndex } from '@antv/vendor/d3-array';
2
+ import { parseToRGB } from '../utils/color';
3
+
4
+ function getsRGB(s: number) {
5
+ let c = s / 255;
6
+ c = c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
7
+ return c;
8
+ }
9
+
10
+ function getL(r: number, g: number, b: number) {
11
+ return 0.2126 * getsRGB(r) + 0.7152 * getsRGB(g) + 0.0722 * getsRGB(b);
12
+ }
13
+
14
+ /**
15
+ * Calculate the contrast. see https://webaim.org/resources/contrastchecker/
16
+ * @param foreground
17
+ * @param background
18
+ */
19
+ export function contrast(foreground, background): number {
20
+ if (!foreground || !background || foreground === background) return 1;
21
+ const { r, g, b } = foreground;
22
+ const { r: rb, g: gb, b: bb } = background;
23
+ const L1 = getL(r, g, b);
24
+ const L2 = getL(rb, gb, bb);
25
+ return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
26
+ }
27
+
28
+ /**
29
+ * Reverse color for max contrast.
30
+ */
31
+ export function mostContrast(color, palette: string[]): string {
32
+ const i = maxIndex(palette, (c) => contrast(color, parseToRGB(c)));
33
+ return palette[i];
34
+ }
package/src/lib/core.ts CHANGED
@@ -164,6 +164,7 @@ import {
164
164
  ContrastReverse,
165
165
  OverlapHide,
166
166
  ExceedAdjust,
167
+ OverflowStroke,
167
168
  } from '../label-transform';
168
169
 
169
170
  export function corelib() {
@@ -322,6 +323,7 @@ export function corelib() {
322
323
  'labelTransform.overlapDodgeY': OverlapDodgeY,
323
324
  'labelTransform.overflowHide': OverflowHide,
324
325
  'labelTransform.contrastReverse': ContrastReverse,
326
+ 'labelTransform.overflowStroke': OverflowStroke,
325
327
  'labelTransform.exceedAdjust': ExceedAdjust,
326
328
  } as const;
327
329
  }
@@ -2,7 +2,7 @@ import { deepMix } from '@antv/util';
2
2
  import { CompositeMarkComponent as CC } from '../runtime';
3
3
  import { SankeyMark } from '../spec';
4
4
  import { Sankey as SankeyTransform } from '../data/sankey';
5
- import { subObject } from '../utils/helper';
5
+ import { omitPrefixObject, subObject } from '../utils/helper';
6
6
  import { subTooltip, maybeAnimation } from '../utils/mark';
7
7
  import { field, initializeData } from './utils';
8
8
 
@@ -69,6 +69,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
69
69
  animate = {},
70
70
  tooltip = {},
71
71
  interaction,
72
+ state = {},
72
73
  } = options;
73
74
 
74
75
  // Initialize data, generating nodes by link if is not specified.
@@ -111,7 +112,18 @@ export const Sankey: CC<SankeyOptions> = (options) => {
111
112
  (d) => ({ name: 'target', value: key1(d.target) }),
112
113
  ],
113
114
  });
114
-
115
+ // Extract node and link state.
116
+ const [nodeState, linkState] = Object.entries(state).reduce(
117
+ (acc, [stateName, styleObj]) => {
118
+ const commonState = omitPrefixObject(styleObj, 'node', 'link');
119
+ const nodeState = subObject(styleObj, 'node');
120
+ acc[0][stateName] = { ...commonState, ...nodeState };
121
+ const linkState = subObject(styleObj, 'link');
122
+ acc[1][stateName] = { ...commonState, ...linkState };
123
+ return acc;
124
+ },
125
+ [{}, {}],
126
+ );
115
127
  return [
116
128
  deepMix({}, DEFAULT_NODE_OPTIONS, {
117
129
  data: nodeData,
@@ -131,6 +143,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
131
143
  animate: maybeAnimation(animate, 'node'),
132
144
  axis: false,
133
145
  interaction,
146
+ state: nodeState,
134
147
  }),
135
148
  deepMix({}, DEFAULT_LINK_OPTIONS, {
136
149
  data: linkData,
@@ -144,6 +157,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
144
157
  tooltip: linkTooltip,
145
158
  animate: maybeAnimation(animate, 'link'),
146
159
  interaction,
160
+ state: linkState,
147
161
  }),
148
162
  ];
149
163
  };
@@ -83,10 +83,9 @@ export const Treemap: CC<TreemapOptions> = (options, context) => {
83
83
  ...resOptions
84
84
  } = options;
85
85
 
86
- const treemapDrillDown = get(markOptions, [
87
- 'interaction',
88
- 'treemapDrillDown',
89
- ]);
86
+ const treemapDrillDown =
87
+ get(markOptions, ['interaction', 'treemapDrillDown']) ||
88
+ get(markOptions, ['marks', 0, 'interaction', 'treemapDrillDown']);
90
89
 
91
90
  // Layout
92
91
  const layoutOptions = deepMix(
@@ -12,6 +12,16 @@ const getR = (point1, point2) => {
12
12
  );
13
13
  };
14
14
 
15
+ // 计算两点之间的角度
16
+ const getAngle = (start, end, center) => {
17
+ const startAngle = Math.atan2(start[1] - center[1], start[0] - center[0]);
18
+ const endAngle = Math.atan2(end[1] - center[1], end[0] - center[0]);
19
+ let angle = endAngle - startAngle;
20
+ // 确保角度在 0-2π 之间
21
+ if (angle < 0) angle += Math.PI * 2;
22
+ return angle;
23
+ };
24
+
15
25
  // Gauge round.
16
26
  export const Round: SC<RoundOptions> = (options, context) => {
17
27
  if (!context) return;
@@ -29,6 +39,10 @@ export const Round: SC<RoundOptions> = (options, context) => {
29
39
  const minR = getR(points[0], points[1]);
30
40
  const maxR = getR(points[0], center) * 2;
31
41
 
42
+ // 计算每个弧段的角度
43
+ // 判断是否需要使用大弧度(角度大于180度)
44
+ const isHalf = getAngle(points[3], points[0], center) > Math.PI;
45
+
32
46
  /**
33
47
  * MinR small circle radius, maxR big circle radius.
34
48
  * Draw four arcs.
@@ -39,9 +53,17 @@ export const Round: SC<RoundOptions> = (options, context) => {
39
53
  d: [
40
54
  ['M', ...points[0]],
41
55
  ['A', minR, minR, 0, 1, 0, ...points[1]],
42
- ['A', maxR + minR * 2, maxR + minR * 2, 0, 0, 0, ...points[2]],
56
+ [
57
+ 'A',
58
+ maxR + minR * 2,
59
+ maxR + minR * 2,
60
+ 0,
61
+ isHalf ? 1 : 0,
62
+ 0,
63
+ ...points[2],
64
+ ],
43
65
  ['A', minR, minR, 0, 1, index === 0 ? 0 : 1, ...points[3]],
44
- ['A', maxR, maxR, 0, 0, 1, ...points[0]],
66
+ ['A', maxR, maxR, 0, isHalf ? 1 : 0, 1, ...points[0]],
45
67
  ['Z'],
46
68
  ],
47
69
  ...defaultCfg,
@@ -41,6 +41,12 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
41
41
  ? liquidShape
42
42
  : getLiquidShape(liquidShape);
43
43
  const shapePath = buildPath(centerX, centerY, radius, ...size);
44
+ const shapeClipPath = buildPath(
45
+ centerX,
46
+ centerY,
47
+ radius + border / 2,
48
+ ...size,
49
+ );
44
50
 
45
51
  // 2、Background create.
46
52
  if (Object.keys(backgroundStyle).length) {
@@ -60,7 +66,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
60
66
  // 3. Clip create.
61
67
  const clipShape = document.createElement('path', {
62
68
  style: {
63
- d: shapePath,
69
+ d: shapeClipPath,
64
70
  },
65
71
  });
66
72
 
@@ -4,6 +4,7 @@ export type LabelTransform =
4
4
  | OverlapHideLabelTransform
5
5
  | OverlapDodgeYLabelTransform
6
6
  | ContrastReverseLabelTransform
7
+ | OverflowStrokeTransform
7
8
  | OverflowHideLabelTransform;
8
9
 
9
10
  export type OverlapHideLabelTransform = {
@@ -32,10 +33,19 @@ export type ContrastReverseLabelTransform = {
32
33
  * The optional color palette, default is [#000, #fff].
33
34
  */
34
35
  palette?: string[];
36
+ };
37
+
38
+ export type OverflowStrokeTransform = {
39
+ type?: 'overlapStroke';
35
40
  /**
36
- * Auto add stroke to make overflowing text more visible.
41
+ * Stroke when label overflow more than threshold.
42
+ * Default is `2`.
37
43
  */
38
- autoStroke?: boolean | { lineWidth: number };
44
+ threshold?: number;
45
+ /**
46
+ * The optional color palette, default is [#000, #fff].
47
+ */
48
+ palette?: string[];
39
49
  };
40
50
 
41
51
  export type OverflowHideLabelTransform = {
@@ -44,4 +54,18 @@ export type OverflowHideLabelTransform = {
44
54
 
45
55
  export type ExceedAdjustLabel = {
46
56
  type: 'exceedAdjust';
57
+ /**
58
+ * The boundary area to check for label overflow.
59
+ * - 'view': Check against the entire view area (default)
60
+ * - 'main': Check against the main area (excluding margins and paddings)
61
+ */
62
+ bounds?: 'view' | 'main';
63
+ /**
64
+ * The X-axis offset, default is 0
65
+ */
66
+ offsetX?: number;
67
+ /**
68
+ * The Y-axis offset, default is 0
69
+ */
70
+ offsetY?: number;
47
71
  };
@@ -17,6 +17,16 @@ export function getViewFromElement(element: G2Element) {
17
17
  return null;
18
18
  }
19
19
 
20
+ /**
21
+ * @description Check if the element is a heatmap.
22
+ * @param element G2 element.
23
+ * @returns True if the element is a heatmap, otherwise false.
24
+ */
25
+ export function isHeatmap(element) {
26
+ const { markType, nodeName } = element;
27
+ return markType === 'heatmap' && nodeName === 'image';
28
+ }
29
+
20
30
  /**
21
31
  * @description Get element's original data.
22
32
  * @param elemenet G2 element.
@@ -26,7 +36,7 @@ export function getViewFromElement(element: G2Element) {
26
36
  export function dataOf(element: G2Element, viewData?: any) {
27
37
  const view = viewData ?? getViewFromElement(element).__data__;
28
38
  const datum = element.__data__;
29
- const { markKey, index, seriesIndex } = datum;
39
+ const { markKey, index, seriesIndex, normalized = { x: 0 } } = datum;
30
40
  const { markState } = view;
31
41
  const selectedMark: any = Array.from(markState.keys()).find(
32
42
  (mark) => (mark as any).key === markKey,
@@ -35,7 +45,9 @@ export function dataOf(element: G2Element, viewData?: any) {
35
45
  if (seriesIndex) {
36
46
  return seriesIndex.map((i) => selectedMark.data[i]);
37
47
  }
38
- return selectedMark.data[index];
48
+ return isHeatmap(element)
49
+ ? selectedMark.data[Math.round(selectedMark.data.length * normalized.x)]
50
+ : selectedMark.data[index];
39
51
  }
40
52
 
41
53
  /**