@antv/g2 5.0.22 → 5.0.23

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 (153) hide show
  1. package/CHANGELOG.md +308 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/api/chart.d.ts +4 -1
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/index.d.ts +1 -1
  7. package/esm/api/index.js.map +1 -1
  8. package/esm/api/library.d.ts +1 -0
  9. package/esm/component/axis.js +15 -10
  10. package/esm/component/axis.js.map +1 -1
  11. package/esm/component/legendCategory.js +2 -2
  12. package/esm/component/legendCategory.js.map +1 -1
  13. package/esm/component/legendContinuous.js +4 -5
  14. package/esm/component/legendContinuous.js.map +1 -1
  15. package/esm/component/scrollbar.js +2 -0
  16. package/esm/component/scrollbar.js.map +1 -1
  17. package/esm/component/slider.js +2 -0
  18. package/esm/component/slider.js.map +1 -1
  19. package/esm/component/title.js +4 -2
  20. package/esm/component/title.js.map +1 -1
  21. package/esm/component/utils.d.ts +1 -1
  22. package/esm/component/utils.js +2 -3
  23. package/esm/component/utils.js.map +1 -1
  24. package/esm/composition/facetRect.js +2 -2
  25. package/esm/composition/facetRect.js.map +1 -1
  26. package/esm/composition/repeatMatrix.js +3 -3
  27. package/esm/composition/repeatMatrix.js.map +1 -1
  28. package/esm/index.d.ts +2 -2
  29. package/esm/index.js +1 -1
  30. package/esm/index.js.map +1 -1
  31. package/esm/interaction/brushHighlight.js.map +1 -1
  32. package/esm/interaction/tooltip.js +4 -3
  33. package/esm/interaction/tooltip.js.map +1 -1
  34. package/esm/lib/core.d.ts +1 -0
  35. package/esm/lib/core.js +4 -3
  36. package/esm/lib/core.js.map +1 -1
  37. package/esm/lib/std.d.ts +1 -0
  38. package/esm/runtime/component.js +33 -30
  39. package/esm/runtime/component.js.map +1 -1
  40. package/esm/runtime/layout.js +78 -28
  41. package/esm/runtime/layout.js.map +1 -1
  42. package/esm/runtime/plot.js +42 -42
  43. package/esm/runtime/plot.js.map +1 -1
  44. package/esm/runtime/render.js +0 -3
  45. package/esm/runtime/render.js.map +1 -1
  46. package/esm/runtime/scale.js +2 -0
  47. package/esm/runtime/scale.js.map +1 -1
  48. package/esm/runtime/types/common.d.ts +3 -1
  49. package/esm/runtime/types/theme.d.ts +8 -2
  50. package/esm/shape/connector/connector.js +19 -30
  51. package/esm/shape/connector/connector.js.map +1 -1
  52. package/esm/theme/classic.js +52 -37
  53. package/esm/theme/classic.js.map +1 -1
  54. package/esm/theme/index.d.ts +1 -0
  55. package/esm/theme/index.js +1 -0
  56. package/esm/theme/index.js.map +1 -1
  57. package/esm/theme/light.d.ts +6 -0
  58. package/esm/theme/light.js +476 -0
  59. package/esm/theme/light.js.map +1 -0
  60. package/esm/utils/selection.d.ts +1 -1
  61. package/esm/utils/selection.js +10 -10
  62. package/esm/utils/selection.js.map +1 -1
  63. package/esm/utils/size.js +1 -1
  64. package/lib/api/chart.d.ts +4 -1
  65. package/lib/api/chart.js.map +1 -1
  66. package/lib/api/index.d.ts +1 -1
  67. package/lib/api/index.js.map +1 -1
  68. package/lib/api/library.d.ts +1 -0
  69. package/lib/component/axis.js +14 -9
  70. package/lib/component/axis.js.map +1 -1
  71. package/lib/component/legendCategory.js +2 -2
  72. package/lib/component/legendCategory.js.map +1 -1
  73. package/lib/component/legendContinuous.js +4 -5
  74. package/lib/component/legendContinuous.js.map +1 -1
  75. package/lib/component/scrollbar.js +2 -0
  76. package/lib/component/scrollbar.js.map +1 -1
  77. package/lib/component/slider.js +2 -0
  78. package/lib/component/slider.js.map +1 -1
  79. package/lib/component/title.js +4 -2
  80. package/lib/component/title.js.map +1 -1
  81. package/lib/component/utils.d.ts +1 -1
  82. package/lib/component/utils.js +2 -3
  83. package/lib/component/utils.js.map +1 -1
  84. package/lib/composition/facetRect.js +2 -2
  85. package/lib/composition/facetRect.js.map +1 -1
  86. package/lib/composition/repeatMatrix.js +3 -3
  87. package/lib/composition/repeatMatrix.js.map +1 -1
  88. package/lib/index.d.ts +2 -2
  89. package/lib/index.js +4 -1
  90. package/lib/index.js.map +1 -1
  91. package/lib/interaction/brushHighlight.js.map +1 -1
  92. package/lib/interaction/tooltip.js +4 -3
  93. package/lib/interaction/tooltip.js.map +1 -1
  94. package/lib/lib/core.d.ts +1 -0
  95. package/lib/lib/core.js +1 -0
  96. package/lib/lib/core.js.map +1 -1
  97. package/lib/lib/std.d.ts +1 -0
  98. package/lib/runtime/component.js +33 -30
  99. package/lib/runtime/component.js.map +1 -1
  100. package/lib/runtime/layout.js +76 -26
  101. package/lib/runtime/layout.js.map +1 -1
  102. package/lib/runtime/plot.js +42 -42
  103. package/lib/runtime/plot.js.map +1 -1
  104. package/lib/runtime/render.js +0 -3
  105. package/lib/runtime/render.js.map +1 -1
  106. package/lib/runtime/scale.js +2 -0
  107. package/lib/runtime/scale.js.map +1 -1
  108. package/lib/runtime/types/common.d.ts +3 -1
  109. package/lib/runtime/types/theme.d.ts +8 -2
  110. package/lib/shape/connector/connector.js +19 -30
  111. package/lib/shape/connector/connector.js.map +1 -1
  112. package/lib/theme/classic.js +52 -37
  113. package/lib/theme/classic.js.map +1 -1
  114. package/lib/theme/index.d.ts +1 -0
  115. package/lib/theme/index.js +3 -1
  116. package/lib/theme/index.js.map +1 -1
  117. package/lib/theme/light.d.ts +6 -0
  118. package/lib/theme/light.js +480 -0
  119. package/lib/theme/light.js.map +1 -0
  120. package/lib/utils/selection.d.ts +1 -1
  121. package/lib/utils/selection.js +10 -10
  122. package/lib/utils/selection.js.map +1 -1
  123. package/lib/utils/size.js +1 -1
  124. package/package.json +3 -3
  125. package/src/api/chart.ts +3 -0
  126. package/src/api/index.ts +1 -1
  127. package/src/component/axis.ts +17 -13
  128. package/src/component/legendCategory.ts +3 -5
  129. package/src/component/legendContinuous.ts +4 -5
  130. package/src/component/scrollbar.ts +4 -1
  131. package/src/component/slider.ts +4 -1
  132. package/src/component/title.ts +3 -3
  133. package/src/component/utils.ts +1 -3
  134. package/src/composition/facetRect.ts +4 -3
  135. package/src/composition/repeatMatrix.ts +4 -3
  136. package/src/index.ts +10 -1
  137. package/src/interaction/brushHighlight.ts +1 -1
  138. package/src/interaction/tooltip.ts +5 -3
  139. package/src/lib/core.ts +4 -3
  140. package/src/runtime/component.ts +57 -30
  141. package/src/runtime/layout.ts +90 -31
  142. package/src/runtime/plot.ts +62 -40
  143. package/src/runtime/render.ts +0 -5
  144. package/src/runtime/scale.ts +1 -0
  145. package/src/runtime/types/common.ts +2 -0
  146. package/src/runtime/types/theme.ts +8 -2
  147. package/src/shape/connector/connector.ts +41 -47
  148. package/src/shape/utils.ts +2 -2
  149. package/src/theme/classic.ts +52 -37
  150. package/src/theme/index.ts +1 -0
  151. package/src/theme/light.ts +483 -0
  152. package/src/utils/selection.ts +11 -11
  153. package/src/utils/size.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  import { Coordinate } from '@antv/coord';
2
- import { ascending, group, max, sum } from 'd3-array';
2
+ import { ascending, group, max, min, sum } from 'd3-array';
3
3
  import { deepMix } from '@antv/util';
4
4
  import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
5
5
  import { capitalizeFirst, defined } from '../utils/helper';
@@ -23,7 +23,10 @@ import {
23
23
  styleOf,
24
24
  } from './component';
25
25
  import { G2GuideComponentOptions, G2Library, G2View } from './types/options';
26
- import { isPolar as isPolarOptions } from './coordinate';
26
+ import {
27
+ isPolar as isPolarOptions,
28
+ isRadial as isRadarOptions,
29
+ } from './coordinate';
27
30
 
28
31
  export function processAxisZ(components: G2GuideComponentOptions[]) {
29
32
  const axisZ = components.find(({ type }) => type === 'axisZ');
@@ -77,17 +80,17 @@ export function computeLayout(
77
80
  x = 0,
78
81
  y = 0,
79
82
  z = 0,
80
- inset = 0,
83
+ inset = theme.inset ?? 0,
81
84
  insetLeft = inset,
82
85
  insetTop = inset,
83
86
  insetBottom = inset,
84
87
  insetRight = inset,
85
- margin = 0,
88
+ margin = theme.margin ?? 0,
86
89
  marginLeft = margin,
87
90
  marginBottom = margin,
88
91
  marginTop = margin,
89
92
  marginRight = margin,
90
- padding,
93
+ padding = theme.padding,
91
94
  paddingBottom = padding,
92
95
  paddingLeft = padding,
93
96
  paddingRight = padding,
@@ -107,14 +110,14 @@ export function computeLayout(
107
110
  if (diff > 0) return [pl0, pr0];
108
111
 
109
112
  // Shrink start and end size equally.
110
- const half = (viewWidth * (1 - MIN_CONTENT_RATIO)) / 2;
113
+ const shrinkSize = viewWidth * (1 - MIN_CONTENT_RATIO);
111
114
  return [
112
- paddingLeft === 'auto' ? half : pl0,
113
- paddingRight === 'auto' ? half : pr0,
115
+ paddingLeft === 'auto' ? (shrinkSize * pl0) / (pl0 + pr0) : pl0,
116
+ paddingRight === 'auto' ? (shrinkSize * pr0) / (pl0 + pr0) : pr0,
114
117
  ];
115
118
  };
116
119
 
117
- const roughPadding = (padding) => (padding === 'auto' ? 30 : padding ?? 30);
120
+ const roughPadding = (padding) => (padding === 'auto' ? 20 : padding ?? 20);
118
121
  const rpt = roughPadding(paddingTop);
119
122
  const rpb = roughPadding(paddingBottom);
120
123
 
@@ -122,7 +125,7 @@ export function computeLayout(
122
125
  const horizontalPadding = computePadding(
123
126
  components,
124
127
  height - rpt - rpb,
125
- [rpt, rpb],
128
+ [rpt + marginTop, rpb + marginBottom],
126
129
  ['left', 'right'],
127
130
  options,
128
131
  theme,
@@ -137,7 +140,7 @@ export function computeLayout(
137
140
  const verticalPadding = computePadding(
138
141
  components,
139
142
  iw,
140
- [pl, pr],
143
+ [pl + marginLeft, pr + marginRight],
141
144
  ['bottom', 'top'],
142
145
  options,
143
146
  theme,
@@ -172,6 +175,8 @@ export function computeLayout(
172
175
  };
173
176
  }
174
177
 
178
+ // For composite mark with a layout algorithm and without axis,
179
+ // such as worldcloud, circlepack.
175
180
  export function computeRoughPlotSize(options: G2View) {
176
181
  const {
177
182
  height,
@@ -181,7 +186,7 @@ export function computeRoughPlotSize(options: G2View) {
181
186
  paddingRight = padding,
182
187
  paddingTop = padding,
183
188
  paddingBottom = padding,
184
- margin = 0,
189
+ margin = 16,
185
190
  marginLeft = margin,
186
191
  marginRight = margin,
187
192
  marginTop = margin,
@@ -195,7 +200,7 @@ export function computeRoughPlotSize(options: G2View) {
195
200
 
196
201
  // @todo Add this padding to theme.
197
202
  // 30 is default size for padding, which defined in runtime.
198
- const maybeAuto = (padding) => (padding === 'auto' ? 30 : padding);
203
+ const maybeAuto = (padding) => (padding === 'auto' ? 20 : padding);
199
204
 
200
205
  const finalWidth =
201
206
  width -
@@ -225,7 +230,9 @@ function computeInset(
225
230
  library: G2Library,
226
231
  ) {
227
232
  const { coordinates } = options;
228
- if (!isPolarOptions(coordinates)) return options;
233
+ if (!isPolarOptions(coordinates) && !isRadarOptions(coordinates)) {
234
+ return options;
235
+ }
229
236
 
230
237
  // Filter axis.
231
238
  const axes = components.filter(
@@ -289,7 +296,7 @@ function computePadding(
289
296
  ) {
290
297
  const positionComponents = group(components, (d) => d.position);
291
298
  const {
292
- padding,
299
+ padding = theme.padding,
293
300
  paddingLeft = padding,
294
301
  paddingRight = padding,
295
302
  paddingBottom = padding,
@@ -334,17 +341,34 @@ function computePadding(
334
341
  }
335
342
  };
336
343
 
344
+ const isHorizontal = position === 'bottom' || position === 'top';
345
+
346
+ // !!!Note
347
+ // Mute axis component padding.
348
+ // The first axis do not has padding.
349
+ const minOrder = min(components, (d) => d.order);
350
+ const axes = components.filter(
351
+ (d) => (d.type as string).startsWith('axis') && d.order == minOrder,
352
+ );
353
+ if (axes.length) axes[0].crossPadding = 0;
354
+
337
355
  // Specified padding.
338
356
  if (typeof value === 'number') {
339
357
  components.forEach(defaultSizeOf);
340
358
  } else {
341
359
  // Compute padding dynamically.
342
360
  if (components.length === 0) {
343
- layout[key] = 30;
361
+ layout[key] = 0;
344
362
  } else {
345
- const grouped = groupComponents(components, crossSize);
363
+ const size = isHorizontal
364
+ ? crossSize + crossPadding[0] + crossPadding[1]
365
+ : crossSize;
366
+ const grouped = groupComponents(components, size);
346
367
  grouped.forEach(autoSizeOf);
347
- const totalSize = grouped.reduce((sum, { size }) => sum + size, 0);
368
+ const totalSize = grouped.reduce(
369
+ (sum, { size, crossPadding = 12 }) => sum + size + crossPadding,
370
+ 0,
371
+ );
348
372
  layout[key] = totalSize;
349
373
  }
350
374
  }
@@ -513,6 +537,7 @@ function createSection({
513
537
  const pt = paddingTop + marginTop;
514
538
  const pr = paddingRight + marginRight;
515
539
  const pb = paddingBottom + marginBottom;
540
+ const plotWidth = width - marginLeft - marginRight;
516
541
 
517
542
  const centerSection: SectionArea = [
518
543
  pl + insetLeft,
@@ -525,9 +550,29 @@ function createSection({
525
550
  ];
526
551
 
527
552
  const xySection: Section = {
528
- top: [pl, 0, innerWidth, pt, 'vertical', true, ascending],
553
+ top: [
554
+ pl,
555
+ 0,
556
+ innerWidth,
557
+ pt,
558
+ 'vertical',
559
+ true,
560
+ ascending,
561
+ marginLeft,
562
+ plotWidth,
563
+ ],
529
564
  right: [width - pr, pt, pr, innerHeight, 'horizontal', false, ascending],
530
- bottom: [pl, height - pb, innerWidth, pb, 'vertical', false, ascending],
565
+ bottom: [
566
+ pl,
567
+ height - pb,
568
+ innerWidth,
569
+ pb,
570
+ 'vertical',
571
+ false,
572
+ ascending,
573
+ marginLeft,
574
+ plotWidth,
575
+ ],
531
576
  left: [0, pt, pl, innerHeight, 'horizontal', true, ascending],
532
577
  'top-left': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
533
578
  'top-right': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
@@ -677,7 +722,7 @@ function placeAxisParallelVertical(
677
722
 
678
723
  // Create a high dimension vector and map to a list of two-dimension points.
679
724
  // [0, 0, 0] -> [x0, 0, x1, 0, x2, 0]
680
- const vector = new Array(components.length + 1).fill(0);
725
+ const vector = new Array(components.length).fill(0);
681
726
  const points = coordinate.map(vector);
682
727
 
683
728
  // Extract x of each points.
@@ -702,7 +747,7 @@ function placeAxisParallelHorizontal(
702
747
 
703
748
  // Create a high dimension vector and map to a list of two-dimension points.
704
749
  // [0, 0, 0] -> [height, y0, height, y1, height, y2]
705
- const vector = new Array(components.length + 1).fill(0);
750
+ const vector = new Array(components.length).fill(0);
706
751
  const points = coordinate.map(vector);
707
752
 
708
753
  // Extract y of each points.
@@ -716,8 +761,6 @@ function placeAxisParallelHorizontal(
716
761
  const height = Y[i + 1] - y;
717
762
  component.bbox = { x, y, width, height };
718
763
  }
719
-
720
- // override style
721
764
  }
722
765
 
723
766
  function placeAxisRadar(
@@ -741,7 +784,8 @@ function placePaddingArea(
741
784
  coordinate: Coordinate,
742
785
  area: SectionArea,
743
786
  ) {
744
- const [x, y, width, height, direction, reverse, comparator] = area;
787
+ const [x, y, width, height, direction, reverse, comparator, minX, totalSize] =
788
+ area;
745
789
  const [
746
790
  mainStartKey,
747
791
  mainStartValue,
@@ -760,20 +804,35 @@ function placePaddingArea(
760
804
  // The smaller the order, the closer to center.
761
805
  components.sort((a, b) => comparator?.(a.order, b.order));
762
806
 
807
+ const isLarge = (type) =>
808
+ type === 'title' || type === 'group' || type.startsWith('legend');
809
+
810
+ const crossSizeOf = (type, small, bigger) => {
811
+ if (bigger === undefined) return small;
812
+ if (isLarge(type)) return bigger;
813
+ return small;
814
+ };
815
+
816
+ const crossStartOf = (type, x, minX) => {
817
+ if (minX === undefined) return x;
818
+ if (isLarge(type)) return minX;
819
+ return x;
820
+ };
821
+
763
822
  const startValue = reverse ? mainStartValue + mainSizeValue : mainStartValue;
764
823
  for (let i = 0, start = startValue; i < components.length; i++) {
765
824
  const component = components[i];
766
- const { crossPadding = 0 } = component;
825
+ const { crossPadding = 0, type } = component;
767
826
  const { size } = component;
768
827
  component.bbox = {
769
828
  [mainStartKey]: reverse
770
- ? start - size + crossPadding
829
+ ? start - size - crossPadding
771
830
  : start + crossPadding,
772
- [crossStartKey]: crossStartValue,
773
- [mainSizeKey]: size - crossPadding * 2,
774
- [crossSizeKey]: crossSizeValue,
831
+ [crossStartKey]: crossStartOf(type, crossStartValue, minX),
832
+ [mainSizeKey]: size,
833
+ [crossSizeKey]: crossSizeOf(type, crossSizeValue, totalSize),
775
834
  };
776
- start += size * (reverse ? -1 : 1);
835
+ start += (size + crossPadding) * (reverse ? -1 : 1);
777
836
  }
778
837
 
779
838
  // Place group components.
@@ -217,20 +217,20 @@ export async function plot<T extends G2ViewTree>(
217
217
  .attr('className', VIEW_CLASS_NAME)
218
218
  .attr('id', (view) => view.key)
219
219
  .call(applyTranslate)
220
- .each(function (view) {
221
- plotView(view, select(this), transitions, library, context);
222
- enterContainer.set(view, this);
220
+ .each(function (view, i, element) {
221
+ plotView(view, select(element), transitions, library, context);
222
+ enterContainer.set(view, element);
223
223
  }),
224
224
  (update) =>
225
- update.call(applyTranslate).each(function (view) {
226
- plotView(view, select(this), transitions, library, context);
227
- updateContainer.set(view, this);
225
+ update.call(applyTranslate).each(function (view, i, element) {
226
+ plotView(view, select(element), transitions, library, context);
227
+ updateContainer.set(view, element);
228
228
  }),
229
229
  (exit) =>
230
230
  exit
231
- .each(function () {
231
+ .each(function (d, i, element) {
232
232
  // Remove existed interactions.
233
- const interactions = this['nameInteraction'].values();
233
+ const interactions = element['nameInteraction'].values();
234
234
  for (const interaction of interactions) {
235
235
  interaction.destroy();
236
236
  }
@@ -775,8 +775,8 @@ async function plotView(
775
775
  .style('y', (i) => areaLayouts[i].y)
776
776
  .style('width', (i) => areaLayouts[i].width)
777
777
  .style('height', (i) => areaLayouts[i].height)
778
- .each(function (i) {
779
- applyStyle(select(this), areaStyles[i]);
778
+ .each(function (i, d, element) {
779
+ applyStyle(select(element), areaStyles[i]);
780
780
  });
781
781
  let px = 0;
782
782
  let py = 0;
@@ -847,7 +847,11 @@ async function plotView(
847
847
  ),
848
848
  ),
849
849
  (update) =>
850
- update.transition(function (options: G2GuideComponentOptions) {
850
+ update.transition(function (
851
+ options: G2GuideComponentOptions,
852
+ i,
853
+ element,
854
+ ) {
851
855
  const { preserve = false } = options;
852
856
  if (preserve) return;
853
857
  const newComponent = renderComponent(
@@ -858,7 +862,7 @@ async function plotView(
858
862
  markState,
859
863
  );
860
864
  const { attributes } = newComponent;
861
- const [node] = this.childNodes;
865
+ const [node] = element.childNodes;
862
866
  return node.update(attributes);
863
867
  }),
864
868
  )
@@ -933,8 +937,8 @@ async function plotView(
933
937
  // Using attribute as alternative for other classNames.
934
938
  .attr('className', ELEMENT_CLASS_NAME)
935
939
  .attr('markType', type)
936
- .transition(function (data) {
937
- return enterFunction(data, [this]);
940
+ .transition(function (data, i, element) {
941
+ return enterFunction(data, [element]);
938
942
  }),
939
943
  (update) =>
940
944
  update.call((selection) => {
@@ -944,14 +948,15 @@ async function plotView(
944
948
  return [x, y];
945
949
  });
946
950
  selection
947
- .transition(function (data, index) {
948
- maybeFacetElement(this, parent, origin);
951
+ .transition(function (data, index, element) {
952
+ maybeFacetElement(element, parent, origin);
949
953
  const node = shapeFunction(data, index);
950
- const animation = updateFunction(data, [this], [node]);
954
+ const animation = updateFunction(data, [element], [node]);
951
955
  if (animation !== null) return animation;
952
- if (this.nodeName === node.nodeName) copyAttributes(this, node);
956
+ if (element.nodeName === node.nodeName)
957
+ copyAttributes(element, node);
953
958
  else {
954
- this.parentNode.replaceChild(node, this);
959
+ element.parentNode.replaceChild(node, element);
955
960
  node.className = ELEMENT_CLASS_NAME;
956
961
  // @ts-ignore
957
962
  node.markType = type;
@@ -963,11 +968,11 @@ async function plotView(
963
968
  }),
964
969
  (exit) => {
965
970
  return exit
966
- .each(function () {
967
- this.__removed__ = true;
971
+ .each(function (d, i, element) {
972
+ element.__removed__ = true;
968
973
  })
969
- .transition(function (data) {
970
- return exitFunction(data, [this]);
974
+ .transition(function (data, i, element) {
975
+ return exitFunction(data, [element]);
971
976
  })
972
977
  .remove();
973
978
  },
@@ -977,25 +982,33 @@ async function plotView(
977
982
  .append(shapeFunction)
978
983
  .attr('className', ELEMENT_CLASS_NAME)
979
984
  .attr('markType', type)
980
- .transition(function (data) {
985
+ .transition(function (data, i, element) {
981
986
  // Remove merged elements after animation finishing.
982
- const { __fromElements__: fromElements } = this;
983
- const transition = updateFunction(data, fromElements, [this]);
984
- const exit = new Selection(fromElements, null, this.parentNode);
987
+ const { __fromElements__: fromElements } = element;
988
+ const transition = updateFunction(data, fromElements, [element]);
989
+ const exit = new Selection(
990
+ fromElements,
991
+ null,
992
+ element.parentNode,
993
+ );
985
994
  exit.transition(transition).remove();
986
995
  return transition;
987
996
  }),
988
997
  (split) =>
989
998
  split
990
- .transition(function (data) {
999
+ .transition(function (data, i, element) {
991
1000
  // Append splitted shapes.
992
- const enter = new Selection([], this.__toData__, this.parentNode);
1001
+ const enter = new Selection(
1002
+ [],
1003
+ element.__toData__,
1004
+ element.parentNode,
1005
+ );
993
1006
  const toElements = enter
994
1007
  .append(shapeFunction)
995
1008
  .attr('className', ELEMENT_CLASS_NAME)
996
1009
  .attr('markType', type)
997
1010
  .nodes();
998
- return updateFunction(data, [this], toElements);
1011
+ return updateFunction(data, [element], toElements);
999
1012
  })
1000
1013
  // Remove elements to be splitted after animation finishing.
1001
1014
  .remove(),
@@ -1071,11 +1084,11 @@ function plotLabel(
1071
1084
  .append((d) => labelShapeFunction.get(d)(d))
1072
1085
  .attr('className', LABEL_CLASS_NAME),
1073
1086
  (update) =>
1074
- update.each(function (d) {
1087
+ update.each(function (d, i, element) {
1075
1088
  // @todo Handle Label with different type.
1076
1089
  const shapeFunction = labelShapeFunction.get(d);
1077
1090
  const node = shapeFunction(d);
1078
- copyAttributes(this, node);
1091
+ copyAttributes(element, node);
1079
1092
  }),
1080
1093
  (exit) => exit.remove(),
1081
1094
  )
@@ -1525,7 +1538,7 @@ function createExitFunction(
1525
1538
 
1526
1539
  function inferTheme(theme: G2ThemeOptions = {}): G2ThemeOptions {
1527
1540
  if (typeof theme === 'string') return { type: theme };
1528
- const { type = 'classic', ...rest } = theme;
1541
+ const { type = 'light', ...rest } = theme;
1529
1542
  return { ...rest, type };
1530
1543
  }
1531
1544
 
@@ -1568,9 +1581,16 @@ function updateBBox(selection: Selection) {
1568
1581
 
1569
1582
  function animateBBox(selection: Selection, extent: [number, number]) {
1570
1583
  const [delay, duration] = extent;
1571
- selection.transition(function (data) {
1572
- const { x, y, width, height } = this.style;
1573
- const { paddingLeft, paddingTop, innerWidth, innerHeight } = data;
1584
+ selection.transition(function (data, i, element) {
1585
+ const { x, y, width, height } = element.style;
1586
+ const {
1587
+ paddingLeft,
1588
+ paddingTop,
1589
+ innerWidth,
1590
+ innerHeight,
1591
+ marginLeft,
1592
+ marginTop,
1593
+ } = data;
1574
1594
  const keyframes = [
1575
1595
  {
1576
1596
  x,
@@ -1579,13 +1599,13 @@ function animateBBox(selection: Selection, extent: [number, number]) {
1579
1599
  height,
1580
1600
  },
1581
1601
  {
1582
- x: paddingLeft,
1583
- y: paddingTop,
1602
+ x: paddingLeft + marginLeft,
1603
+ y: paddingTop + marginTop,
1584
1604
  width: innerWidth,
1585
1605
  height: innerHeight,
1586
1606
  },
1587
1607
  ];
1588
- return this.animate(keyframes, { delay, duration, fill: 'both' });
1608
+ return element.animate(keyframes, { delay, duration, fill: 'both' });
1589
1609
  });
1590
1610
  }
1591
1611
 
@@ -1645,10 +1665,12 @@ function applyClip(selection, clip?: boolean) {
1645
1665
  const {
1646
1666
  paddingTop: y,
1647
1667
  paddingLeft: x,
1668
+ marginLeft: x1,
1669
+ marginTop: y1,
1648
1670
  innerWidth: width,
1649
1671
  innerHeight: height,
1650
1672
  } = data;
1651
- return new Rect({ style: { x, y, width, height } });
1673
+ return new Rect({ style: { x: x + x1, y: y + y1, width, height } });
1652
1674
  });
1653
1675
  }
1654
1676
 
@@ -71,11 +71,6 @@ export function render<T extends G2ViewTree = G2ViewTree>(
71
71
  ): HTMLElement {
72
72
  // Initialize the context if it is not provided.
73
73
  const { width = 640, height = 480, depth = 0, theme } = options;
74
- if (!theme) {
75
- error(
76
- 'ChartOptions.theme is required, such as `const chart = new Chart({ theme: "classic"})`.',
77
- );
78
- }
79
74
  const keyed = inferKeys(options);
80
75
  const {
81
76
  canvas = Canvas(width, height),
@@ -423,6 +423,7 @@ function categoricalColors(
423
423
  const { category10: c10, category20: c20 } = theme;
424
424
  const defaultPalette = unique(values.flat()).length <= c10.length ? c10 : c20;
425
425
  const { palette = defaultPalette, offset } = options;
426
+ if (Array.isArray(palette)) return palette;
426
427
  // Built-in palettes have higher priority.
427
428
  try {
428
429
  return usePalette({ type: palette });
@@ -195,6 +195,8 @@ export type SectionArea = [
195
195
  direction: Direction,
196
196
  reverse: boolean,
197
197
  comparator: (a: Primitive, b: Primitive) => number,
198
+ minX?: number,
199
+ totalWidth?: number,
198
200
  ];
199
201
 
200
202
  export type Section = Record<GuideComponentPosition, SectionArea>;
@@ -68,6 +68,8 @@ type InteractionTheme = {
68
68
 
69
69
  type ComponentTheme = {
70
70
  axis?: any;
71
+ axisX?: any;
72
+ axisY?: any;
71
73
  axisLinear?: any;
72
74
  axisTop?: any;
73
75
  axisBottom?: any;
@@ -75,6 +77,7 @@ type ComponentTheme = {
75
77
  axisRight?: any;
76
78
  axisRadar?: any;
77
79
  axisArc?: any;
80
+ legend?: any;
78
81
  legendCategory?: any;
79
82
  legendContinuous?: any;
80
83
  label?: LabelStyleProps;
@@ -112,9 +115,12 @@ type AreaTheme = {
112
115
  };
113
116
 
114
117
  export type G2Theme = {
118
+ padding?: 'auto' | number;
119
+ inset?: 'auto' | number;
120
+ margin?: number;
115
121
  color?: string;
116
- category10?: string;
117
- category20?: string;
122
+ category10?: string | string[];
123
+ category20?: string | string[];
118
124
  size?: number;
119
125
  view?: WithPrefix<AreaTheme, 'view'> &
120
126
  WithPrefix<AreaTheme, 'plot'> &
@@ -1,10 +1,9 @@
1
1
  import { Coordinate } from '@antv/coord';
2
2
  import type { PathArray } from '@antv/util';
3
- import { PathStyleProps } from '@antv/g';
3
+ import { PathStyleProps, Path } from '@antv/g';
4
4
  import { Marker } from '@antv/gui';
5
5
  import { line as d3line } from 'd3-shape';
6
6
  import { ShapeComponent as SC, Vector2, WithPrefix } from '../../runtime';
7
- import { createElement } from '../../utils/createElement';
8
7
  import { isTranspose } from '../../utils/coordinate';
9
8
  import { subObject } from '../../utils/helper';
10
9
  import { select } from '../../utils/selection';
@@ -33,51 +32,19 @@ function inferConnectorPath(points: Vector2[]) {
33
32
  .y((d) => d[1])(points);
34
33
  }
35
34
 
36
- const ConnectorPath = createElement((g) => {
37
- // Do not copy className to path.
38
- const {
39
- points,
40
- class: className,
41
- endMarker = true,
42
- direction,
43
- ...rest
44
- } = g.attributes;
45
-
46
- const markerStyle = subObject(rest, 'endMarker');
47
- const path = inferConnectorPath(points);
48
-
49
- select(g)
50
- .maybeAppend('connector', 'path')
51
- .style('path', path)
52
- .style(
53
- 'markerEnd',
54
- endMarker
55
- ? new Marker({
56
- className: 'marker',
57
- style: {
58
- ...markerStyle,
59
- symbol: inferSymbol,
60
- },
61
- })
62
- : null,
63
- )
64
- .call(applyStyle, rest);
65
- });
66
-
67
35
  function getPoints(
68
36
  coordinate: Coordinate,
69
37
  points: Vector2[],
70
- offset: number,
38
+ offset1: number,
39
+ offset2: number,
71
40
  length1 = 0,
72
41
  ): Vector2[] {
73
42
  const [[x0, y0], [x1, y1]] = points;
74
43
 
75
44
  if (isTranspose(coordinate)) {
76
- const OFFSET = offset;
77
- const X0 = x0 + OFFSET;
78
- const X1 = x1 + OFFSET;
45
+ const X0 = x0 + offset1;
46
+ const X1 = x1 + offset2;
79
47
  const X = X0 + length1;
80
-
81
48
  return [
82
49
  [X0, y0],
83
50
  [X, y0],
@@ -86,10 +53,9 @@ function getPoints(
86
53
  ];
87
54
  }
88
55
 
89
- const OFFSET = -offset;
90
- const Y0 = y0 + OFFSET;
91
- const Y1 = y1 + OFFSET;
92
- const Y = Y0 + -length1;
56
+ const Y0 = y0 - offset1;
57
+ const Y1 = y1 - offset2;
58
+ const Y = Y0 - length1;
93
59
  return [
94
60
  [x0, Y0],
95
61
  [x0, Y],
@@ -99,17 +65,45 @@ function getPoints(
99
65
  }
100
66
 
101
67
  export const Connector: SC<ConnectorOptions> = (options, context) => {
102
- const { offset = 0, connectLength1: length1, ...style } = options;
68
+ const {
69
+ offset = 0,
70
+ offset1 = offset,
71
+ offset2 = offset,
72
+ connectLength1: length1,
73
+ endMarker = true,
74
+ ...style
75
+ } = options;
103
76
  const { coordinate } = context;
77
+
104
78
  return (points, value, defaults) => {
105
- const { color: defaultColor, connectLength1 = length1, ...rest } = defaults;
79
+ const { color: defaultColor, connectLength1, ...rest } = defaults;
106
80
  const { color, transform } = value;
107
- const P = getPoints(coordinate, points, offset, connectLength1);
108
- return select(new ConnectorPath())
81
+ const P = getPoints(
82
+ coordinate,
83
+ points,
84
+ offset1,
85
+ offset2,
86
+ length1 || connectLength1,
87
+ );
88
+ const makerStyle = subObject({ ...style, ...defaults }, 'endMarker');
89
+
90
+ return select(new Path())
109
91
  .call(applyStyle, rest)
110
- .style('points', P)
92
+ .style('path', inferConnectorPath(P))
111
93
  .style('stroke', color || defaultColor)
112
94
  .style('transform', transform)
95
+ .style(
96
+ 'markerEnd',
97
+ endMarker
98
+ ? new Marker({
99
+ className: 'marker',
100
+ style: {
101
+ ...makerStyle,
102
+ symbol: inferSymbol,
103
+ },
104
+ })
105
+ : null,
106
+ )
113
107
  .call(applyStyle, style)
114
108
  .node();
115
109
  };