@antv/g2 5.4.4 → 5.4.6

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 (94) hide show
  1. package/dist/g2.lite.min.js +18 -10
  2. package/dist/g2.min.js +18 -10
  3. package/esm/api/runtime.js +4 -0
  4. package/esm/api/runtime.js.map +1 -1
  5. package/esm/component/legendCategory.js +2 -0
  6. package/esm/component/legendCategory.js.map +1 -1
  7. package/esm/index.d.ts +4 -0
  8. package/esm/interaction/drillDown.d.ts +6 -0
  9. package/esm/interaction/drillDown.js +210 -0
  10. package/esm/interaction/drillDown.js.map +1 -0
  11. package/esm/interaction/index.d.ts +1 -0
  12. package/esm/interaction/index.js +1 -0
  13. package/esm/interaction/index.js.map +1 -1
  14. package/esm/interaction/legendFilter.d.ts +1 -1
  15. package/esm/interaction/legendFilter.js +3 -3
  16. package/esm/interaction/legendFilter.js.map +1 -1
  17. package/esm/interaction/tooltip.js +1 -1
  18. package/esm/interaction/tooltip.js.map +1 -1
  19. package/esm/interaction/utils.d.ts +14 -0
  20. package/esm/interaction/utils.js +57 -9
  21. package/esm/interaction/utils.js.map +1 -1
  22. package/esm/label-transform/exceedAdjust.js +17 -0
  23. package/esm/label-transform/exceedAdjust.js.map +1 -1
  24. package/esm/lib/core.d.ts +2 -1
  25. package/esm/lib/core.js +2 -1
  26. package/esm/lib/core.js.map +1 -1
  27. package/esm/lib/graph.d.ts +1 -0
  28. package/esm/lib/graph.js +2 -1
  29. package/esm/lib/graph.js.map +1 -1
  30. package/esm/lib/std.d.ts +2 -0
  31. package/esm/mark/index.d.ts +1 -0
  32. package/esm/mark/index.js +1 -0
  33. package/esm/mark/index.js.map +1 -1
  34. package/esm/mark/partition.d.ts +42 -0
  35. package/esm/mark/partition.js +217 -0
  36. package/esm/mark/partition.js.map +1 -0
  37. package/esm/runtime/plot.js +11 -1
  38. package/esm/runtime/plot.js.map +1 -1
  39. package/esm/spec/interaction.d.ts +11 -2
  40. package/esm/spec/mark.d.ts +13 -2
  41. package/lib/api/runtime.js +4 -0
  42. package/lib/api/runtime.js.map +1 -1
  43. package/lib/component/legendCategory.js +2 -0
  44. package/lib/component/legendCategory.js.map +1 -1
  45. package/lib/index.d.ts +4 -0
  46. package/lib/interaction/drillDown.d.ts +6 -0
  47. package/lib/interaction/drillDown.js +213 -0
  48. package/lib/interaction/drillDown.js.map +1 -0
  49. package/lib/interaction/index.d.ts +1 -0
  50. package/lib/interaction/index.js +3 -1
  51. package/lib/interaction/index.js.map +1 -1
  52. package/lib/interaction/legendFilter.d.ts +1 -1
  53. package/lib/interaction/legendFilter.js +4 -4
  54. package/lib/interaction/legendFilter.js.map +1 -1
  55. package/lib/interaction/tooltip.js +1 -1
  56. package/lib/interaction/tooltip.js.map +1 -1
  57. package/lib/interaction/utils.d.ts +14 -0
  58. package/lib/interaction/utils.js +57 -9
  59. package/lib/interaction/utils.js.map +1 -1
  60. package/lib/label-transform/exceedAdjust.js +17 -0
  61. package/lib/label-transform/exceedAdjust.js.map +1 -1
  62. package/lib/lib/core.d.ts +2 -1
  63. package/lib/lib/core.js +1 -0
  64. package/lib/lib/core.js.map +1 -1
  65. package/lib/lib/graph.d.ts +1 -0
  66. package/lib/lib/graph.js +1 -0
  67. package/lib/lib/graph.js.map +1 -1
  68. package/lib/lib/std.d.ts +2 -0
  69. package/lib/mark/index.d.ts +1 -0
  70. package/lib/mark/index.js +3 -1
  71. package/lib/mark/index.js.map +1 -1
  72. package/lib/mark/partition.d.ts +42 -0
  73. package/lib/mark/partition.js +223 -0
  74. package/lib/mark/partition.js.map +1 -0
  75. package/lib/runtime/plot.js +11 -1
  76. package/lib/runtime/plot.js.map +1 -1
  77. package/lib/spec/interaction.d.ts +11 -2
  78. package/lib/spec/mark.d.ts +13 -2
  79. package/package.json +2 -2
  80. package/src/api/runtime.ts +5 -0
  81. package/src/component/legendCategory.ts +2 -0
  82. package/src/interaction/drillDown.ts +258 -0
  83. package/src/interaction/index.ts +1 -0
  84. package/src/interaction/legendFilter.ts +3 -3
  85. package/src/interaction/tooltip.ts +1 -1
  86. package/src/interaction/utils.ts +65 -8
  87. package/src/label-transform/exceedAdjust.ts +22 -0
  88. package/src/lib/core.ts +2 -0
  89. package/src/lib/graph.ts +10 -1
  90. package/src/mark/index.ts +1 -0
  91. package/src/mark/partition.ts +312 -0
  92. package/src/runtime/plot.ts +10 -1
  93. package/src/spec/interaction.ts +13 -1
  94. package/src/spec/mark.ts +18 -0
@@ -6,7 +6,7 @@ import { ANNOTATION_MARKS } from '../component/constant';
6
6
  import { useState, setCursor, restoreCursor } from './utils';
7
7
 
8
8
  export const CATEGORY_LEGEND_CLASS_NAME = 'legend-category';
9
- export const CATEGORY_LEGEND_CLASS_NAME_HTML = 'legend-html';
9
+ export const CATEGORY_LEGEND_HTML_CLASS_NAME = 'legend-html-category';
10
10
 
11
11
  export const CONTINUOUS_LEGEND_CLASS_NAME = 'legend-continuous';
12
12
 
@@ -38,7 +38,7 @@ export function legendsOf(root) {
38
38
  return root.getElementsByClassName(CATEGORY_LEGEND_CLASS_NAME);
39
39
  }
40
40
  export function legendsHtmlOf(root) {
41
- return root.getElementsByClassName(CATEGORY_LEGEND_CLASS_NAME_HTML);
41
+ return root.getElementsByClassName(CATEGORY_LEGEND_HTML_CLASS_NAME);
42
42
  }
43
43
 
44
44
  export function legendsContinuousOf(root) {
@@ -624,7 +624,7 @@ export function LegendFilter() {
624
624
  channel,
625
625
  emitter,
626
626
  });
627
- } else if (legend.className === CATEGORY_LEGEND_CLASS_NAME_HTML) {
627
+ } else if (legend.className === CATEGORY_LEGEND_HTML_CLASS_NAME) {
628
628
  return legendFilterOrdinalHtml(container, {
629
629
  domain,
630
630
  filter: (value) => {
@@ -1112,7 +1112,7 @@ export function seriesTooltip(
1112
1112
  const scaleX = scale.x;
1113
1113
  const x1 = scaleX.map(x);
1114
1114
  const [x2, y2] = coordinate.map([x1, 0.5]);
1115
- const rootBounds = root.getRenderBounds();
1115
+ const rootBounds = bboxOf(root);
1116
1116
  const minX = rootBounds.min[0];
1117
1117
  const minY = rootBounds.min[1];
1118
1118
  update({
@@ -830,17 +830,47 @@ export function extractChannelValues(view: G2ViewDescriptor): {
830
830
  };
831
831
  }
832
832
 
833
+ /**
834
+ * Check if there are multiple independent axis for a given channel.
835
+ * Multi-axis can be defined by:
836
+ * 1. Explicit `independent: true` in scale configuration
837
+ * 2. Different `scale.key` values for the same channel name
838
+ *
839
+ * @param channel1 - Channel name (x or y)
840
+ * @param marks - Array of marks to check
841
+ * @returns true if multiple independent axis exist
842
+ */
833
843
  export function hasIndependentXYScale(
834
844
  channel1: string,
835
845
  marks: readonly unknown[],
836
846
  ): boolean {
837
- return marks.some((mark) => {
847
+ const scaleKeys = new Set<string>();
848
+
849
+ for (const mark of marks) {
838
850
  const { scale: markScale } = mark as Record<string, unknown>;
839
851
  const channelScale = (markScale as Record<string, unknown>)?.[channel1] as
840
852
  | Record<string, unknown>
841
853
  | undefined;
842
- return !!channelScale?.independent;
843
- });
854
+
855
+ if (!channelScale) continue;
856
+
857
+ // Early return if explicit independent flag is found
858
+ if (channelScale.independent) {
859
+ return true;
860
+ }
861
+
862
+ // Collect scale keys, treating undefined/missing key as 'default'
863
+ const key = (channelScale.key as string | undefined) || 'default';
864
+ scaleKeys.add(key);
865
+
866
+ // Early return if multiple different keys are detected
867
+ if (scaleKeys.size > 1) {
868
+ return true;
869
+ }
870
+ }
871
+
872
+ // No multiple axes detected
873
+ return false;
844
874
  }
845
875
 
846
876
  /**
@@ -928,6 +958,10 @@ export interface IndependentScaleInfo {
928
958
  * This function performs a single traversal to compute all independent scale related information,
929
959
  * avoiding repeated calculations throughout the codebase.
930
960
  *
961
+ * Multi-axis detection logic:
962
+ * 1. Explicit independent: scale.y.independent = true
963
+ * 2. Different scale keys: scale.y.key = 'left' vs scale.y.key = 'right'
964
+ *
931
965
  * @param view The view object containing markState
932
966
  * @returns Complete independent scale information
933
967
  */
@@ -946,26 +980,49 @@ export function calculateAllIndependentScaleInfo(
946
980
  const markToXScaleMap = new Map<string, string>();
947
981
  const markToYScaleMap = new Map<string, string>();
948
982
 
949
- // Single traversal to compute all classifications and mappings
983
+ // Track scale key assignments
984
+ const xScaleKeyMap = new Map<string, number>(); // key -> index
985
+ const yScaleKeyMap = new Map<string, number>(); // key -> index
950
986
  let xIndex = 1;
951
987
  let yIndex = 1;
952
988
 
989
+ // Single traversal to compute all classifications and mappings
953
990
  for (const [mark] of view.markState.entries()) {
954
991
  const markKey = mark.key;
955
992
 
956
993
  // X axis processing
957
- if (mark?.scale?.x?.independent) {
994
+ const xScaleKey = (mark?.scale?.x?.key as string) || 'x';
995
+ const hasExplicitIndependentX = !!mark?.scale?.x?.independent;
996
+
997
+ if (hasExplicitIndependentX || (hasIndependentX && xScaleKey !== 'x')) {
958
998
  marksWithIndependentX.push(markKey);
959
- markToXScaleMap.set(markKey, `x${xIndex++}`);
999
+
1000
+ // Assign scale name based on key
1001
+ // Always use indexed names (x1, x2, ...) to avoid collision with shared 'x'
1002
+ if (!xScaleKeyMap.has(xScaleKey)) {
1003
+ xScaleKeyMap.set(xScaleKey, xIndex++);
1004
+ }
1005
+ const scaleIndex = xScaleKeyMap.get(xScaleKey);
1006
+ markToXScaleMap.set(markKey, `x${scaleIndex}`);
960
1007
  } else {
961
1008
  marksWithSharedX.push(markKey);
962
1009
  markToXScaleMap.set(markKey, 'x');
963
1010
  }
964
1011
 
965
1012
  // Y axis processing
966
- if (mark?.scale?.y?.independent) {
1013
+ const yScaleKey = (mark?.scale?.y?.key as string) || 'y';
1014
+ const hasExplicitIndependentY = !!mark?.scale?.y?.independent;
1015
+
1016
+ if (hasExplicitIndependentY || (hasIndependentY && yScaleKey !== 'y')) {
967
1017
  marksWithIndependentY.push(markKey);
968
- markToYScaleMap.set(markKey, `y${yIndex++}`);
1018
+
1019
+ // Assign scale name based on key
1020
+ // Always use indexed names (y1, y2, ...) to avoid collision with shared 'y'
1021
+ if (!yScaleKeyMap.has(yScaleKey)) {
1022
+ yScaleKeyMap.set(yScaleKey, yIndex++);
1023
+ }
1024
+ const scaleIndex = yScaleKeyMap.get(yScaleKey);
1025
+ markToYScaleMap.set(markKey, `y${scaleIndex}`);
969
1026
  } else {
970
1027
  marksWithSharedY.push(markKey);
971
1028
  markToYScaleMap.set(markKey, 'y');
@@ -29,6 +29,17 @@ const adjustPosition = (target: Bounds, edge: Bounds) => {
29
29
  };
30
30
 
31
31
  const union = (a: AABB, b: AABB) => {
32
+ // Handle null bounds by returning the non-null one, or a default AABB
33
+ if (!a || !a.min || !a.max) {
34
+ if (!b || !b.min || !b.max) {
35
+ return { min: [0, 0], max: [0, 0] };
36
+ }
37
+ return b;
38
+ }
39
+ if (!b || !b.min || !b.max) {
40
+ return a;
41
+ }
42
+
32
43
  return {
33
44
  min: [Math.min(a.min[0], b.min[0]), Math.min(a.min[1], b.min[1])],
34
45
  max: [Math.max(a.max[0], b.max[0]), Math.max(a.max[1], b.max[1])],
@@ -93,6 +104,17 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = (options = {}) => {
93
104
  labels.forEach((l) => {
94
105
  show(l);
95
106
  const { max, min } = union(l.getRenderBounds(), l.getBounds());
107
+
108
+ // Skip labels with invalid bounds (filtered out data points)
109
+ // When bounds are all zeros or invalid, it means the label shouldn't be displayed
110
+ if (
111
+ !max ||
112
+ !min ||
113
+ (max[0] === 0 && max[1] === 0 && min[0] === 0 && min[1] === 0)
114
+ ) {
115
+ return;
116
+ }
117
+
96
118
  const [xMax, yMax] = max,
97
119
  [xMin, yMin] = min;
98
120
  const changeValue = adjustPosition(
package/src/lib/core.ts CHANGED
@@ -106,6 +106,7 @@ import {
106
106
  Poptip,
107
107
  ScrollbarFilter,
108
108
  TreemapDrillDown,
109
+ DrillDown,
109
110
  ElementPointMove,
110
111
  } from '../interaction';
111
112
  import {
@@ -318,6 +319,7 @@ export function corelib() {
318
319
  'interaction.scrollbarFilter': ScrollbarFilter,
319
320
  'interaction.poptip': Poptip,
320
321
  'interaction.treemapDrillDown': TreemapDrillDown,
322
+ 'interaction.drillDown': DrillDown,
321
323
  'interaction.elementPointMove': ElementPointMove,
322
324
  'composition.spaceLayer': SpaceLayer,
323
325
  'composition.spaceFlex': SpaceFlex,
package/src/lib/graph.ts CHANGED
@@ -1,4 +1,12 @@
1
- import { Sankey, Treemap, Pack, ForceGraph, Tree, Chord } from '../mark';
1
+ import {
2
+ Sankey,
3
+ Treemap,
4
+ Pack,
5
+ ForceGraph,
6
+ Tree,
7
+ Chord,
8
+ Partition,
9
+ } from '../mark';
2
10
  import { Arc, Cluster } from '../data';
3
11
 
4
12
  export function graphlib() {
@@ -11,5 +19,6 @@ export function graphlib() {
11
19
  'mark.sankey': Sankey,
12
20
  'mark.chord': Chord,
13
21
  'mark.treemap': Treemap,
22
+ 'mark.partition': Partition,
14
23
  } as const;
15
24
  }
package/src/mark/index.ts CHANGED
@@ -31,6 +31,7 @@ export { Density } from './density';
31
31
  export { Heatmap } from './heatmap';
32
32
  export { Liquid } from './liquid';
33
33
  export { Beeswarm } from './beeswarm';
34
+ export { Partition } from './partition';
34
35
 
35
36
  export type { IntervalOptions } from './interval';
36
37
  export type { RectOptions } from './rect';
@@ -0,0 +1,312 @@
1
+ import { deepMix, pick } from '@antv/util';
2
+ import { CompositeMarkComponent } from '../runtime';
3
+ import { BaseMark, ChannelTypes, PartitionNode } from '../spec';
4
+ export type PartitionMark = BaseMark<'rect', 'value' | ChannelTypes>;
5
+
6
+ export interface PartitionDataNode {
7
+ data: PartitionNode;
8
+ depth: number;
9
+ parent: PartitionDataNode | null;
10
+ children: PartitionDataNode[];
11
+ x0: number;
12
+ x1: number;
13
+ value: number;
14
+ }
15
+
16
+ export interface LayoutOptions {
17
+ valueField?: string;
18
+ sort?: (a: PartitionNode, b: PartitionNode) => number;
19
+ fillParent?: boolean; // Whether child nodes fill parent width.
20
+ nameField?: string;
21
+ }
22
+
23
+ /**
24
+ * Partition layout algorithm.
25
+ * Child nodes start layout from the parent's starting position to show parent-child relationships.
26
+ *
27
+ * @param data Hierarchical data
28
+ * @param options Configuration options
29
+ */
30
+ export function partitionLayout(
31
+ data: PartitionNode[],
32
+ options: LayoutOptions = {},
33
+ ) {
34
+ const {
35
+ valueField = 'value',
36
+ sort,
37
+ fillParent = true,
38
+ nameField = 'name',
39
+ } = options;
40
+
41
+ if (!data || data.length === 0) return [];
42
+
43
+ // Build hierarchical structure
44
+ const buildPartition = (
45
+ node: PartitionNode,
46
+ parent: PartitionDataNode | null = null,
47
+ depth = 0,
48
+ ): PartitionDataNode => {
49
+ const partitionNode: PartitionDataNode = {
50
+ data: node,
51
+ depth,
52
+ parent,
53
+ children: [],
54
+ x0: 0,
55
+ x1: 0,
56
+ value: node[valueField] || 0,
57
+ };
58
+
59
+ if (node.children && node.children.length > 0) {
60
+ partitionNode.children = node.children.map((child: PartitionNode) =>
61
+ buildPartition(child, partitionNode, depth + 1),
62
+ );
63
+ }
64
+
65
+ return partitionNode;
66
+ };
67
+
68
+ // Process each root node
69
+ const result: Array<Record<string, any>> = [];
70
+ let currentRootStartX = 0; // Track the starting position for the next root node
71
+
72
+ data.forEach((rootData: PartitionNode) => {
73
+ const root = buildPartition(rootData);
74
+
75
+ // Calculate position for each node - key point: child nodes start layout from parent's starting position
76
+ const calculateLayout = (
77
+ node: PartitionDataNode,
78
+ parentStartX = 0,
79
+ isRootNode = false,
80
+ parentWidth = 0, // Parent node actual width.
81
+ ): void => {
82
+ if (isRootNode || node.depth === 0) {
83
+ // Root node: start from current root position
84
+ node.x0 = isRootNode ? parentStartX : 0;
85
+ node.x1 = node.x0 + node.value;
86
+ } else {
87
+ // Child node: start layout from parent's starting position
88
+ node.x0 = parentStartX;
89
+ if (fillParent && parentWidth > 0) {
90
+ // If fillParent is true, calculate width based on parent width and value ratio.
91
+ const siblingsTotalValue = node.parent
92
+ ? node.parent.children.reduce((acc, child) => acc + child.value, 0)
93
+ : node.value;
94
+ const siblingsCount = node.parent ? node.parent.children.length : 1;
95
+ const ratio =
96
+ siblingsTotalValue > 0
97
+ ? node.value / siblingsTotalValue
98
+ : 1 / siblingsCount;
99
+ node.x1 = parentStartX + parentWidth * ratio;
100
+ } else {
101
+ // If fillParent is false, use node own value as width.
102
+ node.x1 = parentStartX + node.value;
103
+ }
104
+ }
105
+
106
+ // Calculate position for child nodes - start from current node's starting position
107
+ let childStartX = node.x0;
108
+ const nodeWidth = node.x1 - node.x0;
109
+
110
+ const sortedChildren = sort
111
+ ? [...node.children].sort(
112
+ (a: PartitionDataNode, b: PartitionDataNode) =>
113
+ sort(a.data, b.data),
114
+ )
115
+ : node.children;
116
+
117
+ if (fillParent && sortedChildren.length > 0) {
118
+ // fillParent mode: child nodes fill parent width proportionally.
119
+ const childrenTotalValue = node.children.reduce(
120
+ (sum, c) => sum + c.value,
121
+ 0,
122
+ );
123
+ sortedChildren.forEach((child: PartitionDataNode) => {
124
+ calculateLayout(child, childStartX, false, nodeWidth);
125
+ const ratio =
126
+ childrenTotalValue > 0
127
+ ? child.value / childrenTotalValue
128
+ : 1 / sortedChildren.length;
129
+ childStartX += nodeWidth * ratio;
130
+ });
131
+ } else {
132
+ // Non-fillParent mode: child nodes layout independently based on own value.
133
+ sortedChildren.forEach((child: PartitionDataNode) => {
134
+ calculateLayout(child, childStartX, false, 0);
135
+ // Next child node starts from current child node's end position.
136
+ childStartX += child.x1 - child.x0;
137
+ });
138
+ }
139
+ };
140
+
141
+ // Start layout calculation from root node, using current root start position.
142
+ calculateLayout(root, currentRootStartX, true);
143
+
144
+ // Update the starting position for the next root node.
145
+ currentRootStartX += root.value;
146
+
147
+ // Convert to final format.
148
+ const processNode = (node: PartitionDataNode): Record<string, any> => {
149
+ const getName = (d: PartitionNode) => d[nameField] ?? d.name;
150
+ const path = [getName(node.data)];
151
+ let ancestorNode = node;
152
+ while (ancestorNode.parent) {
153
+ path.unshift(getName(ancestorNode.parent.data));
154
+ ancestorNode = ancestorNode.parent;
155
+ }
156
+
157
+ return {
158
+ ...pick(node.data, [valueField]),
159
+ [PARTITION_PATH_FIELD]: path,
160
+ [PARTITION_ANCESTOR_FIELD]:
161
+ ancestorNode.parent?.data?.[nameField] ?? node.data[nameField],
162
+ name: node.data[nameField],
163
+ depth: node.depth,
164
+ value: node.value,
165
+ x: [node.x0, node.x1],
166
+ y: [node.depth, node.depth + 1],
167
+ // Add child node count attribute for drill-down interaction judgment.
168
+ [CHILD_NODE_COUNT]: node.children.length,
169
+ };
170
+ };
171
+
172
+ // Collect all nodes.
173
+ const collectResultNodes = (node: PartitionDataNode): void => {
174
+ result.push(processNode(node));
175
+ node.children.forEach(collectResultNodes);
176
+ };
177
+
178
+ collectResultNodes(root);
179
+ });
180
+
181
+ return result;
182
+ }
183
+
184
+ export type PartitionData = PartitionNode[];
185
+
186
+ export type PartitionOptions = Omit<PartitionMark, 'type'> & {
187
+ fillParent?: boolean; // Whether child nodes fill parent width.
188
+ };
189
+
190
+ export const PARTITION_TYPE = 'partition';
191
+ export const PARTITION_TYPE_FIELD = 'markType';
192
+ export const PARTITION_PATH_FIELD = 'path';
193
+ export const PARTITION_ANCESTOR_FIELD = 'ancestor-node';
194
+ export const CHILD_NODE_COUNT = 'childNodeCount';
195
+
196
+ export function transformData(
197
+ options: Pick<PartitionOptions, 'data' | 'encode'> & {
198
+ fillParent?: boolean;
199
+ sort?: (a: PartitionNode, b: PartitionNode) => number;
200
+ },
201
+ ) {
202
+ const { data, encode, fillParent, sort } = options;
203
+ const { color, value, name } = encode as any;
204
+
205
+ const nodes = partitionLayout(data, {
206
+ valueField: value,
207
+ fillParent,
208
+ nameField: name,
209
+ sort,
210
+ });
211
+
212
+ return nodes.map((node: Record<string, any>) => {
213
+ // Handle color mapping.
214
+ const nodeInfo = { ...node };
215
+ if (color && color !== PARTITION_ANCESTOR_FIELD) {
216
+ nodeInfo[color] = node[color];
217
+ }
218
+ return nodeInfo;
219
+ });
220
+ }
221
+
222
+ const DEFAULT_OPTIONS = {
223
+ id: PARTITION_TYPE,
224
+ encode: {
225
+ x: 'x',
226
+ y: 'y',
227
+ key: PARTITION_PATH_FIELD,
228
+ color: PARTITION_ANCESTOR_FIELD,
229
+ value: 'value',
230
+ name: 'name',
231
+ },
232
+ labels: [
233
+ {
234
+ style: {
235
+ pointerEvents: 'none',
236
+ },
237
+ text: 'value',
238
+ position: 'inside',
239
+ transform: [
240
+ {
241
+ type: 'overflowHide',
242
+ },
243
+ ],
244
+ },
245
+ ],
246
+ axis: {
247
+ x: { title: 'Time/Order', label: true },
248
+ y: false,
249
+ },
250
+ style: {
251
+ [PARTITION_TYPE_FIELD]: PARTITION_TYPE,
252
+ [CHILD_NODE_COUNT]: 'childNodeCount', // Add child node count attribute for drill-down interaction.
253
+ },
254
+ state: {
255
+ active: { zIndex: 2 },
256
+ inactive: { zIndex: 1 },
257
+ },
258
+ legend: false,
259
+ coordinate: {
260
+ type: 'cartesian',
261
+ grid: false, // Remove grid lines.
262
+ },
263
+ interaction: {
264
+ drillDown: true,
265
+ },
266
+ };
267
+
268
+ export const Partition: CompositeMarkComponent<PartitionOptions> = (
269
+ options,
270
+ ) => {
271
+ const {
272
+ encode: encodeOption,
273
+ data = [],
274
+ layout = {},
275
+ ...resOptions
276
+ } = options;
277
+
278
+ const { fillParent = true, sort } = layout as {
279
+ fillParent?: boolean;
280
+ sort?: (a: PartitionNode, b: PartitionNode) => number;
281
+ };
282
+
283
+ const encode = { ...DEFAULT_OPTIONS.encode, ...encodeOption };
284
+ const { value } = encode;
285
+ const rectData = transformData({ encode, data, fillParent, sort });
286
+
287
+ return [
288
+ deepMix({}, DEFAULT_OPTIONS, {
289
+ type: 'rect',
290
+ data: rectData,
291
+ encode,
292
+ tooltip: {
293
+ title: 'path',
294
+ items: [
295
+ (d: Record<string, any>) => {
296
+ return {
297
+ name: value as string,
298
+ value: d[value],
299
+ };
300
+ },
301
+ ],
302
+ },
303
+ // Add basic interaction.
304
+ interaction: {
305
+ elementHighlight: true,
306
+ },
307
+ ...resOptions,
308
+ }),
309
+ ];
310
+ };
311
+
312
+ Partition.props = {};
@@ -1209,7 +1209,16 @@ function plotLabel(
1209
1209
  .selectAll(className(ELEMENT_CLASS_NAME))
1210
1210
  .nodes()
1211
1211
  // Only select the valid element.
1212
- .filter((n) => !n.__removed__);
1212
+ .filter((n) => {
1213
+ if (n.__removed__) return false;
1214
+ // Filter out elements that are hidden (e.g., by slider filtering)
1215
+ // Check if element or its children have visibility: hidden
1216
+ const isHidden =
1217
+ n.style?.visibility === 'hidden' ||
1218
+ (n.children &&
1219
+ n.children.some((child) => child.style?.visibility === 'hidden'));
1220
+ return !isHidden;
1221
+ });
1213
1222
  return labelOptions.flatMap((labelOption, i) => {
1214
1223
  const { transform = [], ...options } = labelOption;
1215
1224
  return elements.flatMap((e) => {
@@ -1,4 +1,5 @@
1
1
  import type { TooltipStyleProps } from '@antv/component';
2
+ import { TextStyleProps } from '@antv/g';
2
3
  import { BBox, InteractionComponent } from '../runtime';
3
4
  import { FisheyeCoordinate } from './coordinateTransform';
4
5
  import { TooltipItemValue } from './component';
@@ -25,7 +26,8 @@ export type Interaction =
25
26
  | BrushYFilterInteraction
26
27
  | BrushXFilterInteraction
27
28
  | SliderFilterInteraction
28
- | PoptipInteraction;
29
+ | PoptipInteraction
30
+ | DrillDownInteraction;
29
31
 
30
32
  export type InteractionTypes =
31
33
  | 'elementHighlight'
@@ -49,6 +51,7 @@ export type InteractionTypes =
49
51
  | 'brushYFilter'
50
52
  | 'sliderFilter'
51
53
  | 'poptip'
54
+ | 'drillDown'
52
55
  | InteractionComponent;
53
56
 
54
57
  export type BrushHighlightInteraction = {
@@ -231,3 +234,12 @@ export type CustomInteraction = {
231
234
  type?: InteractionComponent;
232
235
  [key: string]: any;
233
236
  };
237
+
238
+ export type DrillDownInteraction = {
239
+ type?: 'drillDown';
240
+ breadCrumb?: {
241
+ rootText?: string;
242
+ style?: TextStyleProps;
243
+ active?: TextStyleProps;
244
+ };
245
+ } & Record<string, any>;
package/src/spec/mark.ts CHANGED
@@ -48,6 +48,7 @@ export type Mark =
48
48
  | TreeMark
49
49
  | WordCloudMark
50
50
  | DensityMark
51
+ | PartitionMark
51
52
  | CustomMark
52
53
  | CompositeMark;
53
54
 
@@ -87,6 +88,7 @@ export type MarkTypes =
87
88
  | 'density'
88
89
  | 'heatmap'
89
90
  | 'liquid'
91
+ | 'partition'
90
92
  | MarkComponent
91
93
  | CompositeMarkType;
92
94
 
@@ -422,4 +424,20 @@ export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
422
424
  export type HeatmapMark = BaseMark<'heatmap'>;
423
425
  export type LiquidMark = BaseMark<'liquid'>;
424
426
 
427
+ export type PartitionMark = BaseMark<
428
+ 'partition',
429
+ 'value' | 'name' | ChannelTypes
430
+ > & {
431
+ layout?: {
432
+ fillParent?: boolean; // If true, child nodes will fill the parent width proportionally.
433
+ sort?: (a: PartitionNode, b: PartitionNode) => number;
434
+ };
435
+ };
436
+
437
+ export interface PartitionNode {
438
+ name: string;
439
+ value: number;
440
+ children?: PartitionNode[];
441
+ }
442
+
425
443
  export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;