@antv/g2 5.0.16 → 5.0.17

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 (109) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/api/chart.js +5 -1
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/mark/types.d.ts +2 -2
  7. package/esm/component/legendCategory.js +23 -21
  8. package/esm/component/legendCategory.js.map +1 -1
  9. package/esm/component/legendContinuous.js +1 -1
  10. package/esm/component/legendContinuous.js.map +1 -1
  11. package/esm/component/title.js +2 -4
  12. package/esm/component/title.js.map +1 -1
  13. package/esm/mark/point.js +1 -1
  14. package/esm/mark/point.js.map +1 -1
  15. package/esm/runtime/component.d.ts +3 -2
  16. package/esm/runtime/component.js +62 -22
  17. package/esm/runtime/component.js.map +1 -1
  18. package/esm/runtime/layout.js +3 -3
  19. package/esm/runtime/layout.js.map +1 -1
  20. package/esm/runtime/mark.js +3 -2
  21. package/esm/runtime/mark.js.map +1 -1
  22. package/esm/runtime/plot.js +5 -5
  23. package/esm/runtime/plot.js.map +1 -1
  24. package/esm/runtime/scale.d.ts +3 -3
  25. package/esm/runtime/scale.js +21 -13
  26. package/esm/runtime/scale.js.map +1 -1
  27. package/esm/runtime/types/common.d.ts +12 -14
  28. package/esm/runtime/types/theme.d.ts +9 -13
  29. package/esm/shape/label/position/default.js +7 -2
  30. package/esm/shape/label/position/default.js.map +1 -1
  31. package/esm/shape/text/advance.js +5 -2
  32. package/esm/shape/text/advance.js.map +1 -1
  33. package/esm/spec/component.d.ts +11 -12
  34. package/esm/spec/composition.d.ts +1 -1
  35. package/esm/spec/index.d.ts +2 -1
  36. package/esm/spec/index.js.map +1 -1
  37. package/esm/spec/interaction.d.ts +1 -2
  38. package/esm/spec/mark.d.ts +1 -1
  39. package/esm/theme/academy.js +11 -32
  40. package/esm/theme/academy.js.map +1 -1
  41. package/esm/theme/classic.js +12 -33
  42. package/esm/theme/classic.js.map +1 -1
  43. package/esm/theme/classicDark.js +11 -32
  44. package/esm/theme/classicDark.js.map +1 -1
  45. package/lib/api/chart.js +5 -1
  46. package/lib/api/chart.js.map +1 -1
  47. package/lib/api/mark/types.d.ts +2 -2
  48. package/lib/component/legendCategory.js +23 -21
  49. package/lib/component/legendCategory.js.map +1 -1
  50. package/lib/component/legendContinuous.js +1 -1
  51. package/lib/component/legendContinuous.js.map +1 -1
  52. package/lib/component/title.js +2 -4
  53. package/lib/component/title.js.map +1 -1
  54. package/lib/mark/point.js +1 -1
  55. package/lib/mark/point.js.map +1 -1
  56. package/lib/runtime/component.d.ts +3 -2
  57. package/lib/runtime/component.js +64 -23
  58. package/lib/runtime/component.js.map +1 -1
  59. package/lib/runtime/layout.js +3 -3
  60. package/lib/runtime/layout.js.map +1 -1
  61. package/lib/runtime/mark.js +3 -2
  62. package/lib/runtime/mark.js.map +1 -1
  63. package/lib/runtime/plot.js +4 -4
  64. package/lib/runtime/plot.js.map +1 -1
  65. package/lib/runtime/scale.d.ts +3 -3
  66. package/lib/runtime/scale.js +21 -13
  67. package/lib/runtime/scale.js.map +1 -1
  68. package/lib/runtime/types/common.d.ts +12 -14
  69. package/lib/runtime/types/theme.d.ts +9 -13
  70. package/lib/shape/label/position/default.js +7 -2
  71. package/lib/shape/label/position/default.js.map +1 -1
  72. package/lib/shape/text/advance.js +5 -2
  73. package/lib/shape/text/advance.js.map +1 -1
  74. package/lib/spec/component.d.ts +11 -12
  75. package/lib/spec/composition.d.ts +1 -1
  76. package/lib/spec/index.d.ts +2 -1
  77. package/lib/spec/index.js.map +1 -1
  78. package/lib/spec/interaction.d.ts +1 -2
  79. package/lib/spec/mark.d.ts +1 -1
  80. package/lib/theme/academy.js +11 -32
  81. package/lib/theme/academy.js.map +1 -1
  82. package/lib/theme/classic.js +12 -33
  83. package/lib/theme/classic.js.map +1 -1
  84. package/lib/theme/classicDark.js +11 -32
  85. package/lib/theme/classicDark.js.map +1 -1
  86. package/package.json +9 -6
  87. package/src/api/chart.ts +10 -1
  88. package/src/api/mark/types.ts +5 -2
  89. package/src/component/legendCategory.ts +26 -32
  90. package/src/component/legendContinuous.ts +1 -1
  91. package/src/component/title.ts +11 -15
  92. package/src/mark/point.ts +1 -1
  93. package/src/runtime/component.ts +76 -29
  94. package/src/runtime/layout.ts +3 -3
  95. package/src/runtime/mark.ts +10 -1
  96. package/src/runtime/plot.ts +10 -8
  97. package/src/runtime/scale.ts +30 -15
  98. package/src/runtime/types/common.ts +16 -18
  99. package/src/runtime/types/theme.ts +13 -17
  100. package/src/shape/label/position/default.ts +8 -2
  101. package/src/shape/text/advance.ts +7 -2
  102. package/src/spec/component.ts +11 -12
  103. package/src/spec/composition.ts +1 -1
  104. package/src/spec/index.ts +2 -1
  105. package/src/spec/interaction.ts +1 -2
  106. package/src/spec/mark.ts +1 -1
  107. package/src/theme/academy.ts +12 -32
  108. package/src/theme/classic.ts +13 -33
  109. package/src/theme/classicDark.ts +12 -32
@@ -17,7 +17,7 @@ function inferStyleByAlign(
17
17
  x: number,
18
18
  y: number,
19
19
  width: number,
20
- align: TitleStyleProps['style']['align'],
20
+ align: TitleStyleProps['align'],
21
21
  ) {
22
22
  switch (align) {
23
23
  case 'center':
@@ -49,7 +49,9 @@ const Title = createComponent<TitleStyleProps>({
49
49
  width,
50
50
  title,
51
51
  subtitle,
52
- style: { spacing = 2, align = 'left', ...style },
52
+ spacing = 2,
53
+ align = 'left',
54
+ ...style
53
55
  } = attributes;
54
56
 
55
57
  const titleStyle = subObject(style, 'title');
@@ -89,19 +91,13 @@ export const TitleComponent: GCC<TitleComponentOptions> = (options) => {
89
91
  return ({ value, theme }) => {
90
92
  const { x, y, width, height } = value.bbox;
91
93
  return new Title({
92
- style: deepMix(
93
- {},
94
- {
95
- style: theme.title,
96
- },
97
- {
98
- x,
99
- y,
100
- width,
101
- height,
102
- ...options,
103
- },
104
- ),
94
+ style: deepMix({}, theme.title, {
95
+ x,
96
+ y,
97
+ width,
98
+ height,
99
+ ...options,
100
+ }),
105
101
  });
106
102
  };
107
103
  };
package/src/mark/point.ts CHANGED
@@ -81,7 +81,7 @@ Point.props = {
81
81
  { name: 'x', required: true },
82
82
  { name: 'y', required: true },
83
83
  { name: 'series', scale: 'band' },
84
- { name: 'size', scale: 'sqrt' },
84
+ { name: 'size', quantitative: 'sqrt' },
85
85
  { name: 'dx', scale: 'identity' },
86
86
  { name: 'dy', scale: 'identity' },
87
87
  ],
@@ -188,6 +188,14 @@ export function renderComponent(
188
188
  });
189
189
  }
190
190
 
191
+ export function normalizeComponents(components: G2GuideComponentOptions[]) {
192
+ return components.map((d) => {
193
+ const component = deepMix(d, d.style);
194
+ delete component.style;
195
+ return component;
196
+ });
197
+ }
198
+
191
199
  export function flatComponents(
192
200
  components: G2GuideComponentOptions[],
193
201
  ): G2GuideComponentOptions[] {
@@ -294,6 +302,18 @@ function inferLegendComponentType(
294
302
  combination,
295
303
  option: combination.map((scale) => [scale.name, getScaleType(scale)]),
296
304
  }));
305
+
306
+ // For category legend.
307
+ for (const { option, combination } of options) {
308
+ // If every scale is constant, do not display legend.
309
+ if (option.every((d) => d[1] === 'constant')) continue;
310
+ if (option.every((d) => d[1] === 'discrete' || d[1] === 'constant')) {
311
+ return ['legendCategory', combination] as [string, G2ScaleOptions[]];
312
+ }
313
+ }
314
+
315
+ // For reset legend.
316
+ // @todo Remove this.
297
317
  for (const [componentType, accords] of LEGEND_INFER_STRATEGIES) {
298
318
  for (const { option, combination } of options) {
299
319
  if (accords.some((accord) => isEqual(sort(accord), sort(option)))) {
@@ -543,7 +563,7 @@ function inferScrollableComponents(
543
563
  .filter((d) => !!d);
544
564
  }
545
565
 
546
- // !!! Note Mutate component.size and component.style.
566
+ // !!! Note Mutate component.size and component.
547
567
  export function computeComponentSize(
548
568
  component: G2GuideComponentOptions,
549
569
  crossSize: number,
@@ -564,6 +584,7 @@ export function computeComponentSize(
564
584
  if (t.startsWith('legendContinuous')) return computeContinuousLegendSize;
565
585
  if (t === 'legendCategory') return computeCategoryLegendSize;
566
586
  if (t.startsWith('slider')) return computeSliderSize;
587
+ if (t === 'title') return computeTitleSize;
567
588
  return () => {};
568
589
  };
569
590
  return createCompute()(
@@ -605,6 +626,32 @@ function computeGroupSize(
605
626
  children.forEach((d) => (d.size = maxSize));
606
627
  }
607
628
 
629
+ function computeTitleSize(
630
+ component: G2GuideComponentOptions,
631
+ crossSize: number,
632
+ crossPadding: [number, number],
633
+ position: GCP,
634
+ theme: G2Theme,
635
+ library: G2Library,
636
+ ) {
637
+ const {
638
+ title,
639
+ subtitle,
640
+ spacing = 0,
641
+ ...style
642
+ } = deepMix({}, theme.title, component);
643
+ if (title) {
644
+ const titleStyle = subObject(style, 'title');
645
+ const titleBBox = computeLabelSize(title, titleStyle);
646
+ component.size = titleBBox.height;
647
+ }
648
+ if (subtitle) {
649
+ const subtitleStyle = subObject(style, 'subtitle');
650
+ const subtitleBBox = computeLabelSize(subtitle, subtitleStyle);
651
+ component.size += spacing + subtitleBBox.height;
652
+ }
653
+ }
654
+
608
655
  function computeSliderSize(
609
656
  component: G2GuideComponentOptions,
610
657
  crossSize: number,
@@ -615,7 +662,7 @@ function computeSliderSize(
615
662
  ) {
616
663
  const styleOf = () => {
617
664
  const { slider } = theme;
618
- return deepMix({}, slider, component.style);
665
+ return deepMix({}, slider, component);
619
666
  };
620
667
  const { trackSize, handleIconSize } = styleOf();
621
668
  const size = Math.max(trackSize, handleIconSize * 2.4);
@@ -643,36 +690,33 @@ function computeAxisSize(
643
690
 
644
691
  // Compute Labels.
645
692
  const scale = createScale(component, library);
646
- const labelBBoxes = computeLabelsBBox(component, scale, rest);
693
+ const labelBBoxes = computeLabelsBBox(rest, scale);
694
+ const paddingTick = tickLength + labelSpacing;
647
695
  if (labelBBoxes) {
648
696
  const maxLabelWidth = max(labelBBoxes, (d) => d.width);
649
697
  const maxLabelHeight = max(labelBBoxes, (d) => d.height);
650
- const paddingTick = tickLength + labelSpacing;
651
-
652
698
  if (isVertical) {
653
699
  component.size = maxLabelWidth + paddingTick;
654
700
  } else {
655
- const { tickFilter, style = {} } = component;
656
- const { labelTransform } = style;
701
+ const { tickFilter, labelTransform } = component;
657
702
  // If the labels can't be placed horizontally, and labelTransform is unset,
658
703
  // rotate 90 deg to display them.
659
704
  if (
660
705
  overflowX(scale, labelBBoxes, crossSize, crossPadding, tickFilter) &&
661
706
  !labelTransform
662
707
  ) {
663
- component.style = {
664
- ...style,
665
- labelTransform: 'rotate(90)',
666
- };
708
+ component.labelTransform = 'rotate(90)';
667
709
  component.size = maxLabelWidth + paddingTick;
668
710
  } else {
669
711
  component.size = maxLabelHeight + paddingTick;
670
712
  }
671
713
  }
714
+ } else {
715
+ component.size = paddingTick;
672
716
  }
673
717
 
674
718
  // Compute title.
675
- const titleBBox = computeTitleBBox(component, rest);
719
+ const titleBBox = computeTitleBBox(rest);
676
720
  if (titleBBox) {
677
721
  if (isVertical) {
678
722
  component.size += titleSpacing + titleBBox.width;
@@ -693,7 +737,7 @@ function computeContinuousLegendSize(
693
737
  // Get styles.
694
738
  const styleOf = () => {
695
739
  const { legendContinuous } = theme;
696
- return deepMix({}, legendContinuous, component.style);
740
+ return deepMix({}, legendContinuous, component);
697
741
  };
698
742
  const { labelSpacing = 0, titleSpacing = 0, ...rest } = styleOf();
699
743
 
@@ -716,7 +760,7 @@ function computeContinuousLegendSize(
716
760
 
717
761
  // Compute labels.
718
762
  const scale = createScale(component, library);
719
- const labelBBoxes = computeLabelsBBox(component, scale, rest);
763
+ const labelBBoxes = computeLabelsBBox(rest, scale);
720
764
  if (labelBBoxes) {
721
765
  const key = isVertical ? 'width' : 'height';
722
766
  const size = max(labelBBoxes, (d) => d[key]);
@@ -724,7 +768,7 @@ function computeContinuousLegendSize(
724
768
  }
725
769
 
726
770
  // Compute title.
727
- const titleBBox = computeTitleBBox(component, rest);
771
+ const titleBBox = computeTitleBBox(rest);
728
772
  if (titleBBox) {
729
773
  if (isVertical) {
730
774
  component.size = Math.max(component.size, titleBBox.width);
@@ -747,7 +791,7 @@ function computeCategoryLegendSize(
747
791
  ) {
748
792
  const styleOf = () => {
749
793
  const { legendCategory } = theme;
750
- return deepMix({}, legendCategory, component.style);
794
+ return deepMix({}, legendCategory, component);
751
795
  };
752
796
 
753
797
  const {
@@ -767,10 +811,10 @@ function computeCategoryLegendSize(
767
811
  const isVertical = position === 'left' || position === 'right';
768
812
 
769
813
  // Compute title.
770
- const titleBBox = computeTitleBBox(component, rest);
814
+ const titleBBox = computeTitleBBox(rest);
771
815
 
772
816
  const scale = createScale(component, library);
773
- const labelBBoxes = computeLabelsBBox(component, scale, rest, 'itemLabel');
817
+ const labelBBoxes = computeLabelsBBox(rest, scale, 'itemLabel');
774
818
 
775
819
  const height = Math.max(labelBBoxes[0].height, itemMarkerSize) + rowPadding;
776
820
  const widthOf = (w, padding = 0) =>
@@ -876,10 +920,9 @@ export function createScale(
876
920
  export function computeLabelsBBox(
877
921
  component: G2GuideComponentOptions,
878
922
  scale: Scale,
879
- style: Record<string, any>,
880
923
  key = 'label',
881
924
  ) {
882
- const { labelFormatter, tickFilter, label = true } = component;
925
+ const { labelFormatter, tickFilter, label = true, ...style } = component;
883
926
  if (!label) return null;
884
927
 
885
928
  // Get labels to be rendered.
@@ -912,20 +955,17 @@ export function computeLabelsBBox(
912
955
  return labelBBoxes;
913
956
  }
914
957
 
915
- export function computeTitleBBox(
916
- component: G2GuideComponentOptions,
917
- style: Record<string, any>,
918
- ) {
958
+ export function computeTitleBBox(component: G2GuideComponentOptions) {
919
959
  const isFalsy = (x) => x === false || x === null;
920
- const { title } = component;
921
- const { title: styleTitle } = style;
922
- if (isFalsy(title) || isFalsy(styleTitle) || title === undefined) return null;
960
+ const { title, ...style } = component;
961
+ if (isFalsy(title) || title === undefined) return null;
923
962
  const titleStyle = subObject(style, 'title');
924
963
  const { direction, transform } = titleStyle;
925
964
  const titleText = Array.isArray(title) ? title.join(',') : title;
965
+ if (typeof titleText !== 'string') return null;
926
966
  const titleBBox = computeLabelSize(titleText, {
927
967
  ...titleStyle,
928
- transform: transform || direction === 'vertical' ? 'rotate(-90)' : '',
968
+ transform: transform || (direction === 'vertical' ? 'rotate(-90)' : ''),
929
969
  });
930
970
  return titleBBox;
931
971
  }
@@ -935,12 +975,19 @@ export function styleOf(
935
975
  position: GCP,
936
976
  theme: G2Theme,
937
977
  ): Record<string, any> {
978
+ const { title } = axis;
979
+ const [defaultTitle, specifiedTitle] = Array.isArray(title)
980
+ ? [title, undefined]
981
+ : [undefined, title];
938
982
  const {
939
983
  axis: baseStyle,
940
984
  // @ts-ignore
941
985
  [`axis${capitalizeFirst(position)}`]: positionStyle,
942
986
  } = theme;
943
- return deepMix({}, baseStyle, positionStyle, axis.style);
987
+ return deepMix({ title: defaultTitle }, baseStyle, positionStyle, {
988
+ ...axis,
989
+ title: specifiedTitle,
990
+ });
944
991
  }
945
992
 
946
993
  function ticksOf(scale: Scale, tickFilter: (d: any) => boolean): any[] {
@@ -203,7 +203,7 @@ function computeInset(
203
203
  .flatMap((component, i) => {
204
204
  const style = styles[i];
205
205
  const scale = createScale(component, library);
206
- const labels = computeLabelsBBox(component, scale, style);
206
+ const labels = computeLabelsBBox(style, scale);
207
207
  return labels;
208
208
  })
209
209
  .filter(defined);
@@ -212,9 +212,9 @@ function computeInset(
212
212
 
213
213
  // Compute titles.
214
214
  const titleBBoxes = axes
215
- .flatMap((component, i) => {
215
+ .flatMap((_, i) => {
216
216
  const style = styles[i];
217
- return computeTitleBBox(component, style);
217
+ return computeTitleBBox(style);
218
218
  })
219
219
  .filter((d) => d !== null);
220
220
  const titleSize =
@@ -78,7 +78,14 @@ export async function initializeMark(
78
78
  return false;
79
79
  })
80
80
  .flatMap((descriptor) => {
81
- const { name, scale: scaleType, scaleKey, range } = descriptor;
81
+ const {
82
+ name,
83
+ scale: scaleType,
84
+ scaleKey,
85
+ range,
86
+ quantitative,
87
+ ordinal,
88
+ } = descriptor;
82
89
  const valuesArray = nameChannels.filter(([channel]) =>
83
90
  channel.startsWith(name),
84
91
  );
@@ -106,6 +113,8 @@ export async function initializeMark(
106
113
  type,
107
114
  range: finalRange,
108
115
  ...scaleOptions,
116
+ quantitative,
117
+ ordinal,
109
118
  },
110
119
  };
111
120
  });
@@ -17,9 +17,9 @@ import {
17
17
  } from '../utils/helper';
18
18
  import { G2Element, select, Selection } from '../utils/selection';
19
19
  import {
20
- flatComponents,
21
20
  groupComponents,
22
21
  inferComponent,
22
+ normalizeComponents,
23
23
  renderComponent,
24
24
  } from './component';
25
25
  import {
@@ -595,10 +595,12 @@ function initializeState(
595
595
  // Infer components and compute layout.
596
596
  const states = Array.from(markState.values());
597
597
  const scales = collectScales(states, options);
598
- const components = inferComponent(
599
- inferComponentScales(Array.from(scales), states, markState),
600
- options,
601
- library,
598
+ const components = normalizeComponents(
599
+ inferComponent(
600
+ inferComponentScales(Array.from(scales), states, markState),
601
+ options,
602
+ library,
603
+ ),
602
604
  );
603
605
  const layout = computeLayout(components, options, theme, library);
604
606
  const coordinate = createCoordinate(layout, options, library);
@@ -741,7 +743,7 @@ async function plotView(
741
743
  const I = areaKeys.map((_, i) => i);
742
744
  const sizeKeys = ['a', 'margin', 'padding', 'inset'];
743
745
  const areaStyles = areaKeys.map((d) =>
744
- maybeSubObject(Object.assign({}, theme, style), d),
746
+ maybeSubObject(Object.assign({}, theme.view, style), d),
745
747
  );
746
748
  const areaSizes = sizeKeys.map((d) => subObject(rest, d));
747
749
  const styleArea = (selection) =>
@@ -1375,10 +1377,10 @@ function getDefaultsStyle(
1375
1377
  defaultShape: string,
1376
1378
  ) {
1377
1379
  if (typeof mark !== 'string') return;
1378
- const { defaultColor } = theme;
1380
+ const { color } = theme;
1379
1381
  const markTheme = theme[mark] || {};
1380
1382
  const shapeTheme = markTheme[shape] || markTheme[defaultShape];
1381
- return Object.assign({ color: defaultColor }, shapeTheme);
1383
+ return Object.assign({ color }, shapeTheme);
1382
1384
  }
1383
1385
 
1384
1386
  function createAnimationFunction(
@@ -23,7 +23,14 @@ import { isTheta } from './coordinate';
23
23
  import { useLibrary } from './library';
24
24
  import { MarkChannel } from './types/mark';
25
25
 
26
- export function inferScale(name, values, options, coordinates, theme, library) {
26
+ export function inferScale(
27
+ name: string,
28
+ values: Primitive[][],
29
+ options: Record<string, any>,
30
+ coordinates: G2CoordinateOptions[],
31
+ theme: G2Theme,
32
+ library: G2Library,
33
+ ) {
27
34
  const { guide = {} } = options;
28
35
  const type = inferScaleType(name, values, options);
29
36
  if (typeof type !== 'string') return options;
@@ -292,19 +299,19 @@ function inferScaleType(
292
299
  values: Primitive[][],
293
300
  options: G2ScaleOptions,
294
301
  ): string | ScaleComponent {
295
- const { type, domain, range } = options;
302
+ const { type, domain, range, quantitative, ordinal } = options;
296
303
  if (type !== undefined) return type;
297
304
  if (isObject(values)) return 'identity';
298
305
  if (typeof range === 'string') return 'linear';
299
- if ((domain || range || []).length > 2) return asOrdinalType(name);
306
+ if ((domain || range || []).length > 2) return asOrdinalType(name, ordinal);
300
307
  if (domain !== undefined) {
301
- if (isOrdinal([domain])) return asOrdinalType(name);
308
+ if (isOrdinal([domain])) return asOrdinalType(name, ordinal);
302
309
  if (isTemporal(values)) return 'time';
303
- return asQuantitativeType(name, range);
310
+ return asQuantitativeType(name, range, quantitative);
304
311
  }
305
- if (isOrdinal(values)) return asOrdinalType(name);
312
+ if (isOrdinal(values)) return asOrdinalType(name, ordinal);
306
313
  if (isTemporal(values)) return 'time';
307
- return asQuantitativeType(name, range);
314
+ return asQuantitativeType(name, range, quantitative);
308
315
  }
309
316
 
310
317
  function inferScaleDomain(
@@ -361,8 +368,11 @@ function inferScaleRange(
361
368
  return [rangeMin || r0, rangeMax || r1];
362
369
  }
363
370
  case 'band':
364
- case 'point':
365
- return [rangeMin || 0, rangeMax || 1];
371
+ case 'point': {
372
+ const min = name === 'size' ? 5 : 0;
373
+ const max = name === 'size' ? 10 : 1;
374
+ return [rangeMin || min, rangeMax || max];
375
+ }
366
376
  case 'ordinal': {
367
377
  return categoricalColors(values, options, domain, theme, library);
368
378
  }
@@ -410,7 +420,7 @@ function categoricalColors(
410
420
  'palette',
411
421
  library,
412
422
  );
413
- const { defaultCategory10: c10, defaultCategory20: c20 } = theme;
423
+ const { category10: c10, category20: c20 } = theme;
414
424
  const defaultPalette = unique(values.flat()).length <= c10.length ? c10 : c20;
415
425
  const { palette = defaultPalette, offset } = options;
416
426
  // Built-in palettes have higher priority.
@@ -505,20 +515,25 @@ function inferPadding(
505
515
  // The scale for enterDelay and enterDuration should has zero padding by default.
506
516
  // Because there is no need to add extra delay for the start and the end.
507
517
  if (name === 'enterDelay' || name === 'enterDuration') return 0;
508
- if (type === 'band') {
509
- return isTheta(coordinates) ? 0 : 0.1;
510
- }
518
+ if (name === 'size') return 0;
519
+ if (type === 'band') return isTheta(coordinates) ? 0 : 0.1;
511
520
  // Point scale need 0.5 padding to make interval between first and last point
512
521
  // equal to other intervals in polar coordinate.
513
522
  if (type === 'point') return 0.5;
514
523
  return 0;
515
524
  }
516
525
 
517
- function asOrdinalType(name: string) {
526
+ function asOrdinalType(name: string, defaults: string) {
527
+ if (defaults) return defaults;
518
528
  return isQuantitative(name) ? 'point' : 'ordinal';
519
529
  }
520
530
 
521
- function asQuantitativeType(name: string, range: Primitive[]) {
531
+ function asQuantitativeType(
532
+ name: string,
533
+ range: Primitive[],
534
+ defaults: string,
535
+ ) {
536
+ if (defaults) return defaults;
522
537
  if (name !== 'color') return 'linear';
523
538
  return range ? 'linear' : 'sequential';
524
539
  }
@@ -20,24 +20,20 @@ export type G2Title = {
20
20
  * Text of subtitle.
21
21
  */
22
22
  subtitle?: string | null;
23
- /**
24
- * Styles.
25
- */
26
- style?: WithPrefix<Omit<TextStyleProps, 'x' | 'y' | 'text'>, 'title'> & // G.Text style for title.
27
- WithPrefix<Omit<TextStyleProps, 'x' | 'y' | 'text'>, 'subtitle'> & {
28
- // G.Text style for subtitle.
29
- titleAlign?: 'left' | 'center' | 'right';
30
- subtitleAilgn?: 'left' | 'center' | 'right';
31
- /**
32
- * Align method for title.
33
- */
34
- align?: 'left' | 'center' | 'right';
35
- /**
36
- * The vertical spacing between title and subtitle, default is 2.
37
- */
38
- spacing?: number;
39
- };
40
- };
23
+ } & WithPrefix<Omit<TextStyleProps, 'x' | 'y' | 'text'>, 'title'> & // G.Text style for title.
24
+ WithPrefix<Omit<TextStyleProps, 'x' | 'y' | 'text'>, 'subtitle'> & {
25
+ // G.Text style for subtitle.
26
+ titleAlign?: 'left' | 'center' | 'right';
27
+ subtitleAlign?: 'left' | 'center' | 'right';
28
+ /**
29
+ * Align method for title.
30
+ */
31
+ align?: 'left' | 'center' | 'right';
32
+ /**
33
+ * The vertical spacing between title and subtitle, default is 2.
34
+ */
35
+ spacing?: number;
36
+ };
41
37
 
42
38
  export type G2ViewDescriptor = {
43
39
  scale: Record<string, Scale>;
@@ -116,6 +112,8 @@ export type ChannelValue = MaybeArray<Primitive>[];
116
112
  export type Channel = {
117
113
  name?: string;
118
114
  scale?: string;
115
+ quantitative?: string;
116
+ ordinal?: string;
119
117
  scaleName?: string;
120
118
  required?: boolean;
121
119
  value?: Primitive[];
@@ -59,13 +59,11 @@ type MarkTheme = NestUnion<'interval', ['rect', 'hollowRect'], ElementStyle> &
59
59
  }
60
60
  >;
61
61
 
62
+ // @todo
62
63
  type InteractionTheme = {
63
- interaction?: {
64
- active: MarkTheme;
65
- inactive: MarkTheme;
66
- selected: MarkTheme;
67
- disabled: MarkTheme;
68
- };
64
+ tooltip?: Record<string, unknown>;
65
+ elementHighlight?: Record<string, unknown>;
66
+ elementSelect?: Record<string, unknown>;
69
67
  };
70
68
 
71
69
  type ComponentTheme = {
@@ -113,17 +111,15 @@ type AreaTheme = {
113
111
  };
114
112
 
115
113
  export type G2Theme = {
116
- backgroundColor?: string;
117
- defaultColor?: string;
118
- defaultCategory10?: string;
119
- defaultCategory20?: string;
120
- defaultSize?: number;
121
- elementActiveStroke?: string;
114
+ color?: string;
115
+ category10?: string;
116
+ category20?: string;
117
+ size?: number;
118
+ view?: WithPrefix<AreaTheme, 'view'> &
119
+ WithPrefix<AreaTheme, 'plot'> &
120
+ WithPrefix<AreaTheme, 'main'> &
121
+ WithPrefix<AreaTheme, 'content'>;
122
122
  } & MarkTheme &
123
123
  ComponentTheme &
124
124
  AnimationTheme &
125
- InteractionTheme &
126
- WithPrefix<AreaTheme, 'view'> &
127
- WithPrefix<AreaTheme, 'plot'> &
128
- WithPrefix<AreaTheme, 'main'> &
129
- WithPrefix<AreaTheme, 'content'>;
125
+ InteractionTheme;
@@ -145,12 +145,18 @@ function inferInnerCircularStyle(
145
145
  };
146
146
  }
147
147
 
148
+ // Set to null will not be set with default value as below.
149
+ // const { x = 0 } = options;
150
+ function maybeUndefined(d) {
151
+ return d === undefined ? null : d;
152
+ }
153
+
148
154
  export function inferIdentityStyle(position, points, value, coordinate) {
149
155
  const { bounds } = value;
150
156
  const [p] = bounds;
151
157
  return {
152
- x: p[0],
153
- y: p[1],
158
+ x: maybeUndefined(p[0]),
159
+ y: maybeUndefined(p[1]),
154
160
  };
155
161
  }
156
162
 
@@ -143,8 +143,13 @@ export const Advance = createElement((g) => {
143
143
  coordCenter,
144
144
  ...rest
145
145
  } = g.attributes as TextShapeStyleProps;
146
- // Position is invalid, do not render the UI.
147
- if ([x, y, x0, y0].some((v) => !isNumber(v))) return;
146
+
147
+ // Position is invalid, do not render the UI,
148
+ // or clear previous elements.
149
+ if ([x, y, x0, y0].some((v) => !isNumber(v))) {
150
+ g.children.forEach((d) => d.remove());
151
+ return;
152
+ }
148
153
 
149
154
  const { padding, ...backgroundStyle } = subObject(rest, 'background');
150
155
  const { points = [], ...connectorStyle } = subObject(rest, 'connector');
@@ -23,21 +23,17 @@ export type TitleComponent = {
23
23
  */
24
24
  subtitle?: string | null;
25
25
  /**
26
- * Styles.
26
+ * Align method for title.
27
27
  */
28
- style?: UsePrefix<'title' | 'subtitle', Record<string, any>> & {
29
- /**
30
- * Align method for title.
31
- */
32
- align?: 'left' | 'center' | 'right';
33
- /**
34
- * The vertical spacing between title and subtitle, default is 2.
35
- */
36
- spacing?: number;
37
- };
38
- };
28
+ align?: 'left' | 'center' | 'right';
29
+ /**
30
+ * The vertical spacing between title and subtitle, default is 2.
31
+ */
32
+ spacing?: number;
33
+ } & UsePrefix<'title' | 'subtitle', Record<string, any>>;
39
34
 
40
35
  export type AxisComponent = {
36
+ type?: 'axisX' | 'axisY';
41
37
  tickCount?: number;
42
38
  labelFormatter?: any;
43
39
  tickFilter?: any;
@@ -48,10 +44,12 @@ export type AxisComponent = {
48
44
  Record<string, any>
49
45
  >
50
46
  >;
47
+ scale?: Record<string, any>; //@todo
51
48
  [key: string]: any; // @todo
52
49
  };
53
50
 
54
51
  export type LegendComponent = {
52
+ type?: 'legends';
55
53
  tickCount?: number;
56
54
  labelFormatter?: any;
57
55
  tickFilter?: any;
@@ -63,6 +61,7 @@ export type LegendComponent = {
63
61
  Record<string, any>
64
62
  >
65
63
  >;
64
+ scale?: Record<string, any>; //@todo
66
65
  [key: string]: any; // @todo
67
66
  };
68
67
 
@@ -66,7 +66,7 @@ export type ViewComposition = {
66
66
  interaction?: Literal2Object<Interaction>;
67
67
  transform?: Transform[];
68
68
  theme?: Theme;
69
- children?: Mark[];
69
+ children?: (Mark | AxisComponent | LegendComponent)[];
70
70
  scale?: Record<string, Scale>;
71
71
  frame?: boolean;
72
72
  labelTransform?: LabelTransform[];