@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.
- package/CHANGELOG.md +325 -0
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +9 -17
- package/esm/api/chart.js.map +1 -1
- package/esm/api/extend.d.ts +5 -1
- package/esm/api/extend.js.map +1 -1
- package/esm/api/index.d.ts +1 -1
- package/esm/api/index.js.map +1 -1
- package/esm/api/library.d.ts +6 -16
- package/esm/api/runtime.js +4 -1
- package/esm/api/runtime.js.map +1 -1
- package/esm/component/axis.js +15 -10
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.js +2 -2
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +4 -5
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/scrollbar.js +2 -0
- package/esm/component/scrollbar.js.map +1 -1
- package/esm/component/slider.js +2 -0
- package/esm/component/slider.js.map +1 -1
- package/esm/component/title.js +4 -2
- package/esm/component/title.js.map +1 -1
- package/esm/component/utils.d.ts +1 -1
- package/esm/component/utils.js +2 -3
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/facetRect.js +2 -2
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/repeatMatrix.js +3 -3
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/tooltip.js +4 -3
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/builtinlib.d.ts +13 -0
- package/esm/lib/builtinlib.js +21 -0
- package/esm/lib/builtinlib.js.map +1 -0
- package/esm/lib/core.d.ts +2 -12
- package/esm/lib/core.js +8 -19
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/graph.d.ts +5 -0
- package/esm/lib/graph.js +7 -1
- package/esm/lib/graph.js.map +1 -1
- package/esm/lib/plot.d.ts +0 -5
- package/esm/lib/plot.js +2 -7
- package/esm/lib/plot.js.map +1 -1
- package/esm/lib/std.d.ts +6 -16
- package/esm/lib/threed.d.ts +1 -0
- package/esm/lib/threed.js +2 -1
- package/esm/lib/threed.js.map +1 -1
- package/esm/mark/index.d.ts +1 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line3D.d.ts +7 -0
- package/esm/mark/line3D.js +65 -0
- package/esm/mark/line3D.js.map +1 -0
- package/esm/runtime/component.js +33 -30
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.js +79 -28
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/library.d.ts +1 -1
- package/esm/runtime/library.js +3 -1
- package/esm/runtime/library.js.map +1 -1
- package/esm/runtime/plot.js +42 -42
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +1 -4
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/scale.js +2 -0
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/types/common.d.ts +3 -1
- package/esm/runtime/types/theme.d.ts +8 -2
- package/esm/shape/connector/connector.js +19 -30
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/index.d.ts +1 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/line3D/line.d.ts +3 -0
- package/esm/shape/line3D/line.js +30 -0
- package/esm/shape/line3D/line.js.map +1 -0
- package/esm/shape/point3D/cube.js +2 -2
- package/esm/shape/point3D/cube.js.map +1 -1
- package/esm/shape/point3D/sphere.js +2 -2
- package/esm/shape/point3D/sphere.js.map +1 -1
- package/esm/theme/classic.js +54 -37
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/index.d.ts +1 -0
- package/esm/theme/index.js +1 -0
- package/esm/theme/index.js.map +1 -1
- package/esm/theme/light.d.ts +6 -0
- package/esm/theme/light.js +476 -0
- package/esm/theme/light.js.map +1 -0
- package/esm/utils/selection.d.ts +1 -1
- package/esm/utils/selection.js +10 -10
- package/esm/utils/selection.js.map +1 -1
- package/esm/utils/size.js +1 -1
- package/lib/api/chart.d.ts +9 -17
- package/lib/api/chart.js.map +1 -1
- package/lib/api/extend.d.ts +5 -1
- package/lib/api/extend.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/library.d.ts +6 -16
- package/lib/api/runtime.js +4 -1
- package/lib/api/runtime.js.map +1 -1
- package/lib/component/axis.js +14 -9
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.js +2 -2
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +4 -5
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/scrollbar.js +2 -0
- package/lib/component/scrollbar.js.map +1 -1
- package/lib/component/slider.js +2 -0
- package/lib/component/slider.js.map +1 -1
- package/lib/component/title.js +4 -2
- package/lib/component/title.js.map +1 -1
- package/lib/component/utils.d.ts +1 -1
- package/lib/component/utils.js +2 -3
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/facetRect.js +2 -2
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/repeatMatrix.js +3 -3
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/tooltip.js +4 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/builtinlib.d.ts +13 -0
- package/lib/lib/builtinlib.js +25 -0
- package/lib/lib/builtinlib.js.map +1 -0
- package/lib/lib/core.d.ts +2 -12
- package/lib/lib/core.js +1 -12
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/graph.d.ts +5 -0
- package/lib/lib/graph.js +6 -0
- package/lib/lib/graph.js.map +1 -1
- package/lib/lib/plot.d.ts +0 -5
- package/lib/lib/plot.js +0 -5
- package/lib/lib/plot.js.map +1 -1
- package/lib/lib/std.d.ts +6 -16
- package/lib/lib/threed.d.ts +1 -0
- package/lib/lib/threed.js +1 -0
- package/lib/lib/threed.js.map +1 -1
- package/lib/mark/index.d.ts +1 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line3D.d.ts +7 -0
- package/lib/mark/line3D.js +69 -0
- package/lib/mark/line3D.js.map +1 -0
- package/lib/runtime/component.js +33 -30
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.js +77 -26
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/library.d.ts +1 -1
- package/lib/runtime/library.js +3 -1
- package/lib/runtime/library.js.map +1 -1
- package/lib/runtime/plot.js +42 -42
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +1 -4
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/scale.js +2 -0
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/types/common.d.ts +3 -1
- package/lib/runtime/types/theme.d.ts +8 -2
- package/lib/shape/connector/connector.js +19 -30
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/index.d.ts +1 -0
- package/lib/shape/index.js +8 -6
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/line3D/line.d.ts +3 -0
- package/lib/shape/line3D/line.js +34 -0
- package/lib/shape/line3D/line.js.map +1 -0
- package/lib/shape/point3D/cube.js +1 -1
- package/lib/shape/point3D/cube.js.map +1 -1
- package/lib/shape/point3D/sphere.js +1 -1
- package/lib/shape/point3D/sphere.js.map +1 -1
- package/lib/theme/classic.js +54 -37
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/index.d.ts +1 -0
- package/lib/theme/index.js +3 -1
- package/lib/theme/index.js.map +1 -1
- package/lib/theme/light.d.ts +6 -0
- package/lib/theme/light.js +480 -0
- package/lib/theme/light.js.map +1 -0
- package/lib/utils/selection.d.ts +1 -1
- package/lib/utils/selection.js +10 -10
- package/lib/utils/selection.js.map +1 -1
- package/lib/utils/size.js +1 -1
- package/package.json +4 -4
- package/src/api/chart.ts +3 -0
- package/src/api/extend.ts +6 -1
- package/src/api/index.ts +1 -1
- package/src/api/runtime.ts +6 -3
- package/src/component/axis.ts +17 -13
- package/src/component/legendCategory.ts +3 -5
- package/src/component/legendContinuous.ts +4 -5
- package/src/component/scrollbar.ts +4 -1
- package/src/component/slider.ts +4 -1
- package/src/component/title.ts +3 -3
- package/src/component/utils.ts +1 -3
- package/src/composition/facetRect.ts +4 -3
- package/src/composition/repeatMatrix.ts +4 -3
- package/src/index.ts +10 -1
- package/src/interaction/brushHighlight.ts +1 -1
- package/src/interaction/tooltip.ts +5 -3
- package/src/lib/builtinlib.ts +28 -0
- package/src/lib/core.ts +4 -25
- package/src/lib/graph.ts +7 -1
- package/src/lib/plot.ts +2 -7
- package/src/lib/threed.ts +2 -1
- package/src/mark/index.ts +1 -0
- package/src/mark/line3D.ts +81 -0
- package/src/runtime/component.ts +57 -30
- package/src/runtime/layout.ts +91 -31
- package/src/runtime/library.ts +4 -1
- package/src/runtime/plot.ts +62 -40
- package/src/runtime/render.ts +1 -6
- package/src/runtime/scale.ts +1 -0
- package/src/runtime/types/common.ts +2 -0
- package/src/runtime/types/theme.ts +8 -2
- package/src/shape/connector/connector.ts +41 -47
- package/src/shape/index.ts +1 -0
- package/src/shape/line3D/line.ts +29 -0
- package/src/shape/point3D/cube.ts +2 -2
- package/src/shape/point3D/sphere.ts +2 -2
- package/src/shape/utils.ts +2 -2
- package/src/theme/classic.ts +54 -37
- package/src/theme/index.ts +1 -0
- package/src/theme/light.ts +483 -0
- package/src/utils/selection.ts +11 -11
- package/src/utils/size.ts +1 -1
package/src/runtime/component.ts
CHANGED
|
@@ -82,14 +82,20 @@ export function inferComponent(
|
|
|
82
82
|
// Title components.
|
|
83
83
|
if (title) {
|
|
84
84
|
const { props } = createGuideComponent('title');
|
|
85
|
-
const {
|
|
86
|
-
|
|
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]
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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 {
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
1100
|
+
const { filter, ...rest } = style;
|
|
1101
|
+
shape.attr({ ...rest, visibility: 'none' });
|
|
1075
1102
|
const bbox = shape.getBBox();
|
|
1076
1103
|
return bbox;
|
|
1077
1104
|
}
|
package/src/runtime/layout.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
113
|
+
const shrinkSize = viewWidth * (1 - MIN_CONTENT_RATIO);
|
|
111
114
|
return [
|
|
112
|
-
paddingLeft === 'auto' ?
|
|
113
|
-
paddingRight === 'auto' ?
|
|
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' ?
|
|
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 =
|
|
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' ?
|
|
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))
|
|
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] =
|
|
362
|
+
layout[key] = 0;
|
|
344
363
|
} else {
|
|
345
|
-
const
|
|
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(
|
|
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: [
|
|
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: [
|
|
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
|
|
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
|
|
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] =
|
|
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
|
|
830
|
+
? start - size - crossPadding
|
|
771
831
|
: start + crossPadding,
|
|
772
|
-
[crossStartKey]: crossStartValue,
|
|
773
|
-
[mainSizeKey]: size
|
|
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.
|
package/src/runtime/library.ts
CHANGED
|
@@ -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
|
-
|
|
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}`;
|