@antv/g2 5.0.22 → 5.0.24

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 (236) hide show
  1. package/CHANGELOG.md +325 -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 +9 -17
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/extend.d.ts +5 -1
  7. package/esm/api/extend.js.map +1 -1
  8. package/esm/api/index.d.ts +1 -1
  9. package/esm/api/index.js.map +1 -1
  10. package/esm/api/library.d.ts +6 -16
  11. package/esm/api/runtime.js +4 -1
  12. package/esm/api/runtime.js.map +1 -1
  13. package/esm/component/axis.js +15 -10
  14. package/esm/component/axis.js.map +1 -1
  15. package/esm/component/legendCategory.js +2 -2
  16. package/esm/component/legendCategory.js.map +1 -1
  17. package/esm/component/legendContinuous.js +4 -5
  18. package/esm/component/legendContinuous.js.map +1 -1
  19. package/esm/component/scrollbar.js +2 -0
  20. package/esm/component/scrollbar.js.map +1 -1
  21. package/esm/component/slider.js +2 -0
  22. package/esm/component/slider.js.map +1 -1
  23. package/esm/component/title.js +4 -2
  24. package/esm/component/title.js.map +1 -1
  25. package/esm/component/utils.d.ts +1 -1
  26. package/esm/component/utils.js +2 -3
  27. package/esm/component/utils.js.map +1 -1
  28. package/esm/composition/facetRect.js +2 -2
  29. package/esm/composition/facetRect.js.map +1 -1
  30. package/esm/composition/repeatMatrix.js +3 -3
  31. package/esm/composition/repeatMatrix.js.map +1 -1
  32. package/esm/index.d.ts +2 -2
  33. package/esm/index.js +1 -1
  34. package/esm/index.js.map +1 -1
  35. package/esm/interaction/brushHighlight.js.map +1 -1
  36. package/esm/interaction/tooltip.js +4 -3
  37. package/esm/interaction/tooltip.js.map +1 -1
  38. package/esm/lib/builtinlib.d.ts +13 -0
  39. package/esm/lib/builtinlib.js +21 -0
  40. package/esm/lib/builtinlib.js.map +1 -0
  41. package/esm/lib/core.d.ts +2 -12
  42. package/esm/lib/core.js +8 -19
  43. package/esm/lib/core.js.map +1 -1
  44. package/esm/lib/graph.d.ts +5 -0
  45. package/esm/lib/graph.js +7 -1
  46. package/esm/lib/graph.js.map +1 -1
  47. package/esm/lib/plot.d.ts +0 -5
  48. package/esm/lib/plot.js +2 -7
  49. package/esm/lib/plot.js.map +1 -1
  50. package/esm/lib/std.d.ts +6 -16
  51. package/esm/lib/threed.d.ts +1 -0
  52. package/esm/lib/threed.js +2 -1
  53. package/esm/lib/threed.js.map +1 -1
  54. package/esm/mark/index.d.ts +1 -0
  55. package/esm/mark/index.js +1 -0
  56. package/esm/mark/index.js.map +1 -1
  57. package/esm/mark/line3D.d.ts +7 -0
  58. package/esm/mark/line3D.js +65 -0
  59. package/esm/mark/line3D.js.map +1 -0
  60. package/esm/runtime/component.js +33 -30
  61. package/esm/runtime/component.js.map +1 -1
  62. package/esm/runtime/layout.js +79 -28
  63. package/esm/runtime/layout.js.map +1 -1
  64. package/esm/runtime/library.d.ts +1 -1
  65. package/esm/runtime/library.js +3 -1
  66. package/esm/runtime/library.js.map +1 -1
  67. package/esm/runtime/plot.js +42 -42
  68. package/esm/runtime/plot.js.map +1 -1
  69. package/esm/runtime/render.js +1 -4
  70. package/esm/runtime/render.js.map +1 -1
  71. package/esm/runtime/scale.js +2 -0
  72. package/esm/runtime/scale.js.map +1 -1
  73. package/esm/runtime/types/common.d.ts +3 -1
  74. package/esm/runtime/types/theme.d.ts +8 -2
  75. package/esm/shape/connector/connector.js +19 -30
  76. package/esm/shape/connector/connector.js.map +1 -1
  77. package/esm/shape/index.d.ts +1 -0
  78. package/esm/shape/index.js +1 -0
  79. package/esm/shape/index.js.map +1 -1
  80. package/esm/shape/line3D/line.d.ts +3 -0
  81. package/esm/shape/line3D/line.js +30 -0
  82. package/esm/shape/line3D/line.js.map +1 -0
  83. package/esm/shape/point3D/cube.js +2 -2
  84. package/esm/shape/point3D/cube.js.map +1 -1
  85. package/esm/shape/point3D/sphere.js +2 -2
  86. package/esm/shape/point3D/sphere.js.map +1 -1
  87. package/esm/theme/classic.js +54 -37
  88. package/esm/theme/classic.js.map +1 -1
  89. package/esm/theme/index.d.ts +1 -0
  90. package/esm/theme/index.js +1 -0
  91. package/esm/theme/index.js.map +1 -1
  92. package/esm/theme/light.d.ts +6 -0
  93. package/esm/theme/light.js +476 -0
  94. package/esm/theme/light.js.map +1 -0
  95. package/esm/utils/selection.d.ts +1 -1
  96. package/esm/utils/selection.js +10 -10
  97. package/esm/utils/selection.js.map +1 -1
  98. package/esm/utils/size.js +1 -1
  99. package/lib/api/chart.d.ts +9 -17
  100. package/lib/api/chart.js.map +1 -1
  101. package/lib/api/extend.d.ts +5 -1
  102. package/lib/api/extend.js.map +1 -1
  103. package/lib/api/index.d.ts +1 -1
  104. package/lib/api/index.js.map +1 -1
  105. package/lib/api/library.d.ts +6 -16
  106. package/lib/api/runtime.js +4 -1
  107. package/lib/api/runtime.js.map +1 -1
  108. package/lib/component/axis.js +14 -9
  109. package/lib/component/axis.js.map +1 -1
  110. package/lib/component/legendCategory.js +2 -2
  111. package/lib/component/legendCategory.js.map +1 -1
  112. package/lib/component/legendContinuous.js +4 -5
  113. package/lib/component/legendContinuous.js.map +1 -1
  114. package/lib/component/scrollbar.js +2 -0
  115. package/lib/component/scrollbar.js.map +1 -1
  116. package/lib/component/slider.js +2 -0
  117. package/lib/component/slider.js.map +1 -1
  118. package/lib/component/title.js +4 -2
  119. package/lib/component/title.js.map +1 -1
  120. package/lib/component/utils.d.ts +1 -1
  121. package/lib/component/utils.js +2 -3
  122. package/lib/component/utils.js.map +1 -1
  123. package/lib/composition/facetRect.js +2 -2
  124. package/lib/composition/facetRect.js.map +1 -1
  125. package/lib/composition/repeatMatrix.js +3 -3
  126. package/lib/composition/repeatMatrix.js.map +1 -1
  127. package/lib/index.d.ts +2 -2
  128. package/lib/index.js +4 -1
  129. package/lib/index.js.map +1 -1
  130. package/lib/interaction/brushHighlight.js.map +1 -1
  131. package/lib/interaction/tooltip.js +4 -3
  132. package/lib/interaction/tooltip.js.map +1 -1
  133. package/lib/lib/builtinlib.d.ts +13 -0
  134. package/lib/lib/builtinlib.js +25 -0
  135. package/lib/lib/builtinlib.js.map +1 -0
  136. package/lib/lib/core.d.ts +2 -12
  137. package/lib/lib/core.js +1 -12
  138. package/lib/lib/core.js.map +1 -1
  139. package/lib/lib/graph.d.ts +5 -0
  140. package/lib/lib/graph.js +6 -0
  141. package/lib/lib/graph.js.map +1 -1
  142. package/lib/lib/plot.d.ts +0 -5
  143. package/lib/lib/plot.js +0 -5
  144. package/lib/lib/plot.js.map +1 -1
  145. package/lib/lib/std.d.ts +6 -16
  146. package/lib/lib/threed.d.ts +1 -0
  147. package/lib/lib/threed.js +1 -0
  148. package/lib/lib/threed.js.map +1 -1
  149. package/lib/mark/index.d.ts +1 -0
  150. package/lib/mark/index.js +3 -1
  151. package/lib/mark/index.js.map +1 -1
  152. package/lib/mark/line3D.d.ts +7 -0
  153. package/lib/mark/line3D.js +69 -0
  154. package/lib/mark/line3D.js.map +1 -0
  155. package/lib/runtime/component.js +33 -30
  156. package/lib/runtime/component.js.map +1 -1
  157. package/lib/runtime/layout.js +77 -26
  158. package/lib/runtime/layout.js.map +1 -1
  159. package/lib/runtime/library.d.ts +1 -1
  160. package/lib/runtime/library.js +3 -1
  161. package/lib/runtime/library.js.map +1 -1
  162. package/lib/runtime/plot.js +42 -42
  163. package/lib/runtime/plot.js.map +1 -1
  164. package/lib/runtime/render.js +1 -4
  165. package/lib/runtime/render.js.map +1 -1
  166. package/lib/runtime/scale.js +2 -0
  167. package/lib/runtime/scale.js.map +1 -1
  168. package/lib/runtime/types/common.d.ts +3 -1
  169. package/lib/runtime/types/theme.d.ts +8 -2
  170. package/lib/shape/connector/connector.js +19 -30
  171. package/lib/shape/connector/connector.js.map +1 -1
  172. package/lib/shape/index.d.ts +1 -0
  173. package/lib/shape/index.js +8 -6
  174. package/lib/shape/index.js.map +1 -1
  175. package/lib/shape/line3D/line.d.ts +3 -0
  176. package/lib/shape/line3D/line.js +34 -0
  177. package/lib/shape/line3D/line.js.map +1 -0
  178. package/lib/shape/point3D/cube.js +1 -1
  179. package/lib/shape/point3D/cube.js.map +1 -1
  180. package/lib/shape/point3D/sphere.js +1 -1
  181. package/lib/shape/point3D/sphere.js.map +1 -1
  182. package/lib/theme/classic.js +54 -37
  183. package/lib/theme/classic.js.map +1 -1
  184. package/lib/theme/index.d.ts +1 -0
  185. package/lib/theme/index.js +3 -1
  186. package/lib/theme/index.js.map +1 -1
  187. package/lib/theme/light.d.ts +6 -0
  188. package/lib/theme/light.js +480 -0
  189. package/lib/theme/light.js.map +1 -0
  190. package/lib/utils/selection.d.ts +1 -1
  191. package/lib/utils/selection.js +10 -10
  192. package/lib/utils/selection.js.map +1 -1
  193. package/lib/utils/size.js +1 -1
  194. package/package.json +4 -4
  195. package/src/api/chart.ts +3 -0
  196. package/src/api/extend.ts +6 -1
  197. package/src/api/index.ts +1 -1
  198. package/src/api/runtime.ts +6 -3
  199. package/src/component/axis.ts +17 -13
  200. package/src/component/legendCategory.ts +3 -5
  201. package/src/component/legendContinuous.ts +4 -5
  202. package/src/component/scrollbar.ts +4 -1
  203. package/src/component/slider.ts +4 -1
  204. package/src/component/title.ts +3 -3
  205. package/src/component/utils.ts +1 -3
  206. package/src/composition/facetRect.ts +4 -3
  207. package/src/composition/repeatMatrix.ts +4 -3
  208. package/src/index.ts +10 -1
  209. package/src/interaction/brushHighlight.ts +1 -1
  210. package/src/interaction/tooltip.ts +5 -3
  211. package/src/lib/builtinlib.ts +28 -0
  212. package/src/lib/core.ts +4 -25
  213. package/src/lib/graph.ts +7 -1
  214. package/src/lib/plot.ts +2 -7
  215. package/src/lib/threed.ts +2 -1
  216. package/src/mark/index.ts +1 -0
  217. package/src/mark/line3D.ts +81 -0
  218. package/src/runtime/component.ts +57 -30
  219. package/src/runtime/layout.ts +91 -31
  220. package/src/runtime/library.ts +4 -1
  221. package/src/runtime/plot.ts +62 -40
  222. package/src/runtime/render.ts +1 -6
  223. package/src/runtime/scale.ts +1 -0
  224. package/src/runtime/types/common.ts +2 -0
  225. package/src/runtime/types/theme.ts +8 -2
  226. package/src/shape/connector/connector.ts +41 -47
  227. package/src/shape/index.ts +1 -0
  228. package/src/shape/line3D/line.ts +29 -0
  229. package/src/shape/point3D/cube.ts +2 -2
  230. package/src/shape/point3D/sphere.ts +2 -2
  231. package/src/shape/utils.ts +2 -2
  232. package/src/theme/classic.ts +54 -37
  233. package/src/theme/index.ts +1 -0
  234. package/src/theme/light.ts +483 -0
  235. package/src/utils/selection.ts +11 -11
  236. package/src/utils/size.ts +1 -1
@@ -82,14 +82,20 @@ export function inferComponent(
82
82
  // Title components.
83
83
  if (title) {
84
84
  const { props } = createGuideComponent('title');
85
- const { defaultPosition, defaultOrientation, defaultOrder, defaultSize } =
86
- props;
85
+ const {
86
+ defaultPosition,
87
+ defaultOrientation,
88
+ defaultOrder,
89
+ defaultSize,
90
+ defaultCrossPadding,
91
+ } = props;
87
92
  const titleOptions = typeof title === 'string' ? { title } : title;
88
93
  components.push({
89
94
  type: 'title',
90
95
  position: defaultPosition,
91
96
  orientation: defaultOrientation,
92
97
  order: defaultOrder,
98
+ crossPadding: defaultCrossPadding[0],
93
99
  defaultSize,
94
100
  ...titleOptions,
95
101
  });
@@ -224,7 +230,7 @@ export function groupComponents(
224
230
 
225
231
  // Update attributes of group components,
226
232
  // and maybe flatten group components without enough room.
227
- return grouped.flatMap(([, components], i) => {
233
+ return grouped.flatMap(([, components]) => {
228
234
  if (components.length === 1) return components[0];
229
235
 
230
236
  // If crossSize defined, group components only when has
@@ -441,17 +447,10 @@ function inferAxisPositionAndOrientation(
441
447
  return ['center', angle];
442
448
  }
443
449
 
444
- // There are multiple axes for parallel coordinate.
445
- // Place the first one in the border area and put others in the center.
446
450
  if (type === 'axisY' && isParallel(coordinates)) {
447
- // name looks like `position${number}`
448
- const index = matchPosition(name);
449
- if (index === null) return ordinalPosition;
450
-
451
- if (isTranspose(coordinates)) {
452
- return index === 0 ? ['top', null] : ['center', 'horizontal'];
453
- }
454
- return index === 0 ? ordinalPosition : ['center', 'vertical'];
451
+ return isTranspose(coordinates)
452
+ ? ['center', 'horizontal']
453
+ : ['center', 'vertical'];
455
454
  }
456
455
 
457
456
  // in non-cartesian coordinate systems, infer the arc axis angle
@@ -547,12 +546,18 @@ function inferScrollableComponents(
547
546
  if (!options || !componentType) return;
548
547
 
549
548
  const { props } = createGuideComponent(componentType);
550
- const { defaultPosition, defaultSize, defaultOrder } = props;
549
+ const {
550
+ defaultPosition,
551
+ defaultSize,
552
+ defaultOrder,
553
+ defaultCrossPadding: [crossPadding],
554
+ } = props;
551
555
  return {
552
556
  position: defaultPosition,
553
557
  defaultSize,
554
558
  order: defaultOrder,
555
559
  type: componentType,
560
+ crossPadding,
556
561
  ...options,
557
562
  scales: [scale],
558
563
  };
@@ -591,6 +596,7 @@ export function computeComponentSize(
591
596
  if (t === 'legendCategory') return computeCategoryLegendSize;
592
597
  if (t.startsWith('slider')) return computeSliderSize;
593
598
  if (t === 'title') return computeTitleSize;
599
+ if (t.startsWith('scrollbar')) return computeScrollbarSize;
594
600
  return () => {};
595
601
  };
596
602
  return createCompute()(
@@ -632,6 +638,18 @@ function computeGroupSize(
632
638
  children.forEach((d) => (d.size = maxSize));
633
639
  }
634
640
 
641
+ function computeScrollbarSize(
642
+ component: G2GuideComponentOptions,
643
+ crossSize: number,
644
+ crossPadding: [number, number],
645
+ position: GCP,
646
+ theme: G2Theme,
647
+ library: G2Library,
648
+ ) {
649
+ const { trackSize = 6 } = deepMix({}, theme.scrollbar, component);
650
+ component.size = trackSize;
651
+ }
652
+
635
653
  function computeTitleSize(
636
654
  component: G2GuideComponentOptions,
637
655
  crossSize: number,
@@ -698,7 +716,7 @@ function computeAxisSize(
698
716
  const scale = createScale(component, library);
699
717
  const labelBBoxes = computeLabelsBBox(rest, scale);
700
718
  const paddingTick = tickLength + labelSpacing;
701
- if (labelBBoxes) {
719
+ if (labelBBoxes && labelBBoxes.length) {
702
720
  const maxLabelWidth = max(labelBBoxes, (d) => d.width);
703
721
  const maxLabelHeight = max(labelBBoxes, (d) => d.height);
704
722
  if (isVertical) {
@@ -718,7 +736,7 @@ function computeAxisSize(
718
736
  }
719
737
  }
720
738
  } else {
721
- component.size = paddingTick;
739
+ component.size = tickLength;
722
740
  }
723
741
 
724
742
  // Compute title.
@@ -782,9 +800,6 @@ function computeContinuousLegendSize(
782
800
  component.size += titleSpacing + titleBBox.height;
783
801
  }
784
802
  }
785
-
786
- const { crossPadding: cp = 0 } = component;
787
- component.size += cp * 2;
788
803
  }
789
804
 
790
805
  function computeCategoryLegendSize(
@@ -797,7 +812,14 @@ function computeCategoryLegendSize(
797
812
  ) {
798
813
  const styleOf = () => {
799
814
  const { legendCategory } = theme;
800
- return deepMix({}, legendCategory, component);
815
+ const { title } = component;
816
+ const [defaultTitle, specifiedTitle] = Array.isArray(title)
817
+ ? [title, undefined]
818
+ : [undefined, title];
819
+ return deepMix({ title: defaultTitle }, legendCategory, {
820
+ ...component,
821
+ title: specifiedTitle,
822
+ });
801
823
  };
802
824
 
803
825
  const {
@@ -806,16 +828,24 @@ function computeCategoryLegendSize(
806
828
  titleSpacing,
807
829
  rowPadding,
808
830
  colPadding,
831
+ maxCols = Infinity,
832
+ maxRows = Infinity,
809
833
  ...rest
810
834
  } = styleOf();
811
835
 
812
836
  const { cols, length } = component;
813
837
 
814
- const crossSize = length === undefined ? crossSize0 : length;
838
+ const getRows = (rows) => Math.min(rows, maxRows);
839
+ const getCols = (cols) => Math.min(cols, maxCols);
815
840
 
816
841
  // Vertical or horizontal.
817
842
  const isVertical = position === 'left' || position === 'right';
818
843
 
844
+ const crossSize =
845
+ length === undefined
846
+ ? crossSize0 + (isVertical ? 0 : crossPadding[0] + crossPadding[1])
847
+ : length;
848
+
819
849
  // Compute title.
820
850
  const titleBBox = computeTitleBBox(rest);
821
851
 
@@ -854,16 +884,16 @@ function computeCategoryLegendSize(
854
884
  maxRows = rows;
855
885
  maxPos = pos;
856
886
  }
857
- component.size = maxSize * cols;
887
+ component.size = maxSize * getCols(cols);
858
888
  component.length = maxPos + titleHeight;
859
- deepMix(component, { cols, gridRow: maxRows });
889
+ deepMix(component, { cols: getCols(cols), gridRow: maxRows });
860
890
  };
861
891
 
862
892
  // Horizontal grid layout.
863
893
  const computeHorizontalGrid = () => {
864
894
  const rows = Math.ceil(labelBBoxes.length / cols);
865
895
  const maxWidth = max(labelBBoxes, (d) => widthOf(d.width)) * cols;
866
- component.size = height * rows;
896
+ component.size = height * getRows(rows) - rowPadding;
867
897
  component.length = Math.min(maxWidth, crossSize);
868
898
  };
869
899
 
@@ -883,7 +913,7 @@ function computeCategoryLegendSize(
883
913
  }
884
914
  }
885
915
  if (rows === 1) maxPos = pos;
886
- component.size = height * rows;
916
+ component.size = height * getRows(rows) - rowPadding;
887
917
  component.length = maxPos;
888
918
  };
889
919
 
@@ -899,10 +929,6 @@ function computeCategoryLegendSize(
899
929
  component.size += titleSpacing + titleBBox.height;
900
930
  }
901
931
  }
902
-
903
- // Compute crossPadding.
904
- const { crossPadding: cp = 0 } = component;
905
- component.size += cp * 2;
906
932
  }
907
933
 
908
934
  export function createScale(
@@ -1071,7 +1097,8 @@ function computeLabelSize(
1071
1097
  style: Record<string, any>,
1072
1098
  ): DOMRect {
1073
1099
  const shape = normalizeLabel(d);
1074
- shape.attr({ ...style, visibility: 'none' });
1100
+ const { filter, ...rest } = style;
1101
+ shape.attr({ ...rest, visibility: 'none' });
1075
1102
  const bbox = shape.getBBox();
1076
1103
  return bbox;
1077
1104
  }
@@ -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,
@@ -304,6 +311,7 @@ function computePadding(
304
311
 
305
312
  for (const position of positions) {
306
313
  const key = `padding${capitalizeFirst(camelCase(position))}`;
314
+ const insetKey = `inset${capitalizeFirst(camelCase(position))}`;
307
315
  const components = positionComponents.get(position) || [];
308
316
  const value = layout[key];
309
317
  const defaultSizeOf = (d) => {
@@ -334,17 +342,34 @@ function computePadding(
334
342
  }
335
343
  };
336
344
 
345
+ const isHorizontal = position === 'bottom' || position === 'top';
346
+
347
+ // !!!Note
348
+ // Mute axis component padding.
349
+ // The first axis do not has padding.
350
+ const minOrder = min(components, (d) => d.order);
351
+ const axes = components.filter(
352
+ (d) => (d.type as string).startsWith('axis') && d.order == minOrder,
353
+ );
354
+ if (axes.length) axes[0].crossPadding = 0;
355
+
337
356
  // Specified padding.
338
357
  if (typeof value === 'number') {
339
358
  components.forEach(defaultSizeOf);
340
359
  } else {
341
360
  // Compute padding dynamically.
342
361
  if (components.length === 0) {
343
- layout[key] = 30;
362
+ layout[key] = 0;
344
363
  } else {
345
- const grouped = groupComponents(components, crossSize);
364
+ const size = isHorizontal
365
+ ? crossSize + crossPadding[0] + crossPadding[1]
366
+ : crossSize;
367
+ const grouped = groupComponents(components, size);
346
368
  grouped.forEach(autoSizeOf);
347
- const totalSize = grouped.reduce((sum, { size }) => sum + size, 0);
369
+ const totalSize = grouped.reduce(
370
+ (sum, { size, crossPadding = 12 }) => sum + size + crossPadding,
371
+ 0,
372
+ );
348
373
  layout[key] = totalSize;
349
374
  }
350
375
  }
@@ -513,6 +538,7 @@ function createSection({
513
538
  const pt = paddingTop + marginTop;
514
539
  const pr = paddingRight + marginRight;
515
540
  const pb = paddingBottom + marginBottom;
541
+ const plotWidth = width - marginLeft - marginRight;
516
542
 
517
543
  const centerSection: SectionArea = [
518
544
  pl + insetLeft,
@@ -525,9 +551,29 @@ function createSection({
525
551
  ];
526
552
 
527
553
  const xySection: Section = {
528
- top: [pl, 0, innerWidth, pt, 'vertical', true, ascending],
554
+ top: [
555
+ pl,
556
+ 0,
557
+ innerWidth,
558
+ pt,
559
+ 'vertical',
560
+ true,
561
+ ascending,
562
+ marginLeft,
563
+ plotWidth,
564
+ ],
529
565
  right: [width - pr, pt, pr, innerHeight, 'horizontal', false, ascending],
530
- bottom: [pl, height - pb, innerWidth, pb, 'vertical', false, ascending],
566
+ bottom: [
567
+ pl,
568
+ height - pb,
569
+ innerWidth,
570
+ pb,
571
+ 'vertical',
572
+ false,
573
+ ascending,
574
+ marginLeft,
575
+ plotWidth,
576
+ ],
531
577
  left: [0, pt, pl, innerHeight, 'horizontal', true, ascending],
532
578
  'top-left': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
533
579
  'top-right': [pl, 0, innerWidth, pt, 'vertical', true, ascending],
@@ -677,7 +723,7 @@ function placeAxisParallelVertical(
677
723
 
678
724
  // Create a high dimension vector and map to a list of two-dimension points.
679
725
  // [0, 0, 0] -> [x0, 0, x1, 0, x2, 0]
680
- const vector = new Array(components.length + 1).fill(0);
726
+ const vector = new Array(components.length).fill(0);
681
727
  const points = coordinate.map(vector);
682
728
 
683
729
  // Extract x of each points.
@@ -702,7 +748,7 @@ function placeAxisParallelHorizontal(
702
748
 
703
749
  // Create a high dimension vector and map to a list of two-dimension points.
704
750
  // [0, 0, 0] -> [height, y0, height, y1, height, y2]
705
- const vector = new Array(components.length + 1).fill(0);
751
+ const vector = new Array(components.length).fill(0);
706
752
  const points = coordinate.map(vector);
707
753
 
708
754
  // Extract y of each points.
@@ -716,8 +762,6 @@ function placeAxisParallelHorizontal(
716
762
  const height = Y[i + 1] - y;
717
763
  component.bbox = { x, y, width, height };
718
764
  }
719
-
720
- // override style
721
765
  }
722
766
 
723
767
  function placeAxisRadar(
@@ -741,7 +785,8 @@ function placePaddingArea(
741
785
  coordinate: Coordinate,
742
786
  area: SectionArea,
743
787
  ) {
744
- const [x, y, width, height, direction, reverse, comparator] = area;
788
+ const [x, y, width, height, direction, reverse, comparator, minX, totalSize] =
789
+ area;
745
790
  const [
746
791
  mainStartKey,
747
792
  mainStartValue,
@@ -760,20 +805,35 @@ function placePaddingArea(
760
805
  // The smaller the order, the closer to center.
761
806
  components.sort((a, b) => comparator?.(a.order, b.order));
762
807
 
808
+ const isLarge = (type) =>
809
+ type === 'title' || type === 'group' || type.startsWith('legend');
810
+
811
+ const crossSizeOf = (type, small, bigger) => {
812
+ if (bigger === undefined) return small;
813
+ if (isLarge(type)) return bigger;
814
+ return small;
815
+ };
816
+
817
+ const crossStartOf = (type, x, minX) => {
818
+ if (minX === undefined) return x;
819
+ if (isLarge(type)) return minX;
820
+ return x;
821
+ };
822
+
763
823
  const startValue = reverse ? mainStartValue + mainSizeValue : mainStartValue;
764
824
  for (let i = 0, start = startValue; i < components.length; i++) {
765
825
  const component = components[i];
766
- const { crossPadding = 0 } = component;
826
+ const { crossPadding = 0, type } = component;
767
827
  const { size } = component;
768
828
  component.bbox = {
769
829
  [mainStartKey]: reverse
770
- ? start - size + crossPadding
830
+ ? start - size - crossPadding
771
831
  : start + crossPadding,
772
- [crossStartKey]: crossStartValue,
773
- [mainSizeKey]: size - crossPadding * 2,
774
- [crossSizeKey]: crossSizeValue,
832
+ [crossStartKey]: crossStartOf(type, crossStartValue, minX),
833
+ [mainSizeKey]: size,
834
+ [crossSizeKey]: crossSizeOf(type, crossSizeValue, totalSize),
775
835
  };
776
- start += size * (reverse ? -1 : 1);
836
+ start += (size + crossPadding) * (reverse ? -1 : 1);
777
837
  }
778
838
 
779
839
  // Place group components.
@@ -1,5 +1,6 @@
1
1
  import { IDocument } from '@antv/g';
2
2
  import { error } from '../utils/helper';
3
+ import { builtinlib } from '../lib/builtinlib';
3
4
  import { G2ComponentOptions, G2Context, G2Library } from './types/options';
4
5
  import {
5
6
  G2Component,
@@ -13,8 +14,10 @@ export function useLibrary<
13
14
  V extends G2ComponentValue,
14
15
  >(
15
16
  namespace: G2ComponentNamespaces,
16
- library: G2Library,
17
+ publicLibrary: G2Library,
17
18
  ): [(options: O, context?) => V, (type: O['type']) => C] {
19
+ const library = { ...builtinlib(), ...publicLibrary };
20
+
18
21
  const create = (type: O['type']) => {
19
22
  if (typeof type !== 'string') return type;
20
23
  const key = `${namespace}.${type}`;