@antv/g2 5.0.15 → 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 (124) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/animation/morphing.js +2 -0
  5. package/esm/animation/morphing.js.map +1 -1
  6. package/esm/api/chart.js +5 -1
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/mark/types.d.ts +2 -2
  9. package/esm/component/legendCategory.js +23 -21
  10. package/esm/component/legendCategory.js.map +1 -1
  11. package/esm/component/legendContinuous.js +1 -1
  12. package/esm/component/legendContinuous.js.map +1 -1
  13. package/esm/component/title.js +2 -4
  14. package/esm/component/title.js.map +1 -1
  15. package/esm/component/utils.js +1 -0
  16. package/esm/component/utils.js.map +1 -1
  17. package/esm/interaction/event.js +17 -4
  18. package/esm/interaction/event.js.map +1 -1
  19. package/esm/mark/point.js +1 -1
  20. package/esm/mark/point.js.map +1 -1
  21. package/esm/runtime/component.d.ts +3 -2
  22. package/esm/runtime/component.js +62 -22
  23. package/esm/runtime/component.js.map +1 -1
  24. package/esm/runtime/layout.js +3 -3
  25. package/esm/runtime/layout.js.map +1 -1
  26. package/esm/runtime/mark.js +3 -2
  27. package/esm/runtime/mark.js.map +1 -1
  28. package/esm/runtime/plot.js +24 -16
  29. package/esm/runtime/plot.js.map +1 -1
  30. package/esm/runtime/scale.d.ts +4 -3
  31. package/esm/runtime/scale.js +48 -14
  32. package/esm/runtime/scale.js.map +1 -1
  33. package/esm/runtime/types/common.d.ts +12 -14
  34. package/esm/runtime/types/theme.d.ts +9 -13
  35. package/esm/shape/label/position/default.js +7 -2
  36. package/esm/shape/label/position/default.js.map +1 -1
  37. package/esm/shape/text/advance.js +5 -2
  38. package/esm/shape/text/advance.js.map +1 -1
  39. package/esm/spec/component.d.ts +11 -12
  40. package/esm/spec/composition.d.ts +1 -1
  41. package/esm/spec/index.d.ts +2 -1
  42. package/esm/spec/index.js.map +1 -1
  43. package/esm/spec/interaction.d.ts +1 -2
  44. package/esm/spec/mark.d.ts +1 -1
  45. package/esm/theme/academy.js +11 -32
  46. package/esm/theme/academy.js.map +1 -1
  47. package/esm/theme/classic.js +12 -33
  48. package/esm/theme/classic.js.map +1 -1
  49. package/esm/theme/classicDark.js +11 -32
  50. package/esm/theme/classicDark.js.map +1 -1
  51. package/lib/animation/morphing.js +2 -0
  52. package/lib/animation/morphing.js.map +1 -1
  53. package/lib/api/chart.js +5 -1
  54. package/lib/api/chart.js.map +1 -1
  55. package/lib/api/mark/types.d.ts +2 -2
  56. package/lib/component/legendCategory.js +23 -21
  57. package/lib/component/legendCategory.js.map +1 -1
  58. package/lib/component/legendContinuous.js +1 -1
  59. package/lib/component/legendContinuous.js.map +1 -1
  60. package/lib/component/title.js +2 -4
  61. package/lib/component/title.js.map +1 -1
  62. package/lib/component/utils.js +1 -0
  63. package/lib/component/utils.js.map +1 -1
  64. package/lib/interaction/event.js +17 -4
  65. package/lib/interaction/event.js.map +1 -1
  66. package/lib/mark/point.js +1 -1
  67. package/lib/mark/point.js.map +1 -1
  68. package/lib/runtime/component.d.ts +3 -2
  69. package/lib/runtime/component.js +64 -23
  70. package/lib/runtime/component.js.map +1 -1
  71. package/lib/runtime/layout.js +3 -3
  72. package/lib/runtime/layout.js.map +1 -1
  73. package/lib/runtime/mark.js +3 -2
  74. package/lib/runtime/mark.js.map +1 -1
  75. package/lib/runtime/plot.js +22 -14
  76. package/lib/runtime/plot.js.map +1 -1
  77. package/lib/runtime/scale.d.ts +4 -3
  78. package/lib/runtime/scale.js +49 -14
  79. package/lib/runtime/scale.js.map +1 -1
  80. package/lib/runtime/types/common.d.ts +12 -14
  81. package/lib/runtime/types/theme.d.ts +9 -13
  82. package/lib/shape/label/position/default.js +7 -2
  83. package/lib/shape/label/position/default.js.map +1 -1
  84. package/lib/shape/text/advance.js +5 -2
  85. package/lib/shape/text/advance.js.map +1 -1
  86. package/lib/spec/component.d.ts +11 -12
  87. package/lib/spec/composition.d.ts +1 -1
  88. package/lib/spec/index.d.ts +2 -1
  89. package/lib/spec/index.js.map +1 -1
  90. package/lib/spec/interaction.d.ts +1 -2
  91. package/lib/spec/mark.d.ts +1 -1
  92. package/lib/theme/academy.js +11 -32
  93. package/lib/theme/academy.js.map +1 -1
  94. package/lib/theme/classic.js +12 -33
  95. package/lib/theme/classic.js.map +1 -1
  96. package/lib/theme/classicDark.js +11 -32
  97. package/lib/theme/classicDark.js.map +1 -1
  98. package/package.json +9 -6
  99. package/src/animation/morphing.ts +2 -0
  100. package/src/api/chart.ts +10 -1
  101. package/src/api/mark/types.ts +5 -2
  102. package/src/component/legendCategory.ts +26 -32
  103. package/src/component/legendContinuous.ts +1 -1
  104. package/src/component/title.ts +11 -15
  105. package/src/component/utils.ts +1 -0
  106. package/src/interaction/event.ts +15 -4
  107. package/src/mark/point.ts +1 -1
  108. package/src/runtime/component.ts +76 -29
  109. package/src/runtime/layout.ts +3 -3
  110. package/src/runtime/mark.ts +10 -1
  111. package/src/runtime/plot.ts +34 -27
  112. package/src/runtime/scale.ts +58 -16
  113. package/src/runtime/types/common.ts +16 -18
  114. package/src/runtime/types/theme.ts +13 -17
  115. package/src/shape/label/position/default.ts +8 -2
  116. package/src/shape/text/advance.ts +7 -2
  117. package/src/spec/component.ts +11 -12
  118. package/src/spec/composition.ts +1 -1
  119. package/src/spec/index.ts +2 -1
  120. package/src/spec/interaction.ts +1 -2
  121. package/src/spec/mark.ts +1 -1
  122. package/src/theme/academy.ts +12 -32
  123. package/src/theme/classic.ts +13 -33
  124. package/src/theme/classicDark.ts +12 -32
@@ -3,6 +3,7 @@ import type { DisplayObject } from '@antv/g';
3
3
  import { Category } from '@antv/gui';
4
4
  import { last } from '@antv/util';
5
5
  import { format } from 'd3-format';
6
+ import { Identity, Point } from '@antv/scale';
6
7
  import type {
7
8
  FlexLayout,
8
9
  G2Library,
@@ -37,19 +38,6 @@ export type LegendCategoryOptions = {
37
38
  [key: string]: any;
38
39
  };
39
40
 
40
- function createShape(
41
- shape: string,
42
- library: G2Library,
43
- coordinate: Coordinate,
44
- theme: G2Theme,
45
- style: Record<string, any> = {},
46
- ) {
47
- const marker =
48
- (library[`shape.${shape}`]?.props?.defaultMarker as string) ||
49
- last(shape.split('.'));
50
- return () => useMarker(marker, style)(0, 0, 6);
51
- }
52
-
53
41
  function inferShape(scales: Scale[], markState: Map<G2Mark, G2MarkState>) {
54
42
  const shapeScale = scaleOf(scales, 'shape');
55
43
  const colorScale = scaleOf(scales, 'color');
@@ -92,28 +80,35 @@ function inferShape(scales: Scale[], markState: Map<G2Mark, G2MarkState>) {
92
80
 
93
81
  function inferItemMarker(
94
82
  options,
95
- { scales, library, coordinate, theme, markState }: GuideComponentContext,
83
+ context: GuideComponentContext,
96
84
  ): ((datum: any, i: number, data: any) => () => DisplayObject) | undefined {
85
+ const { scales, library, markState } = context;
97
86
  const [namespace, shapes] = inferShape(scales, markState);
98
- const create = (name, color) =>
99
- createShape(name, library, coordinate, theme, {
100
- color,
101
- });
87
+
88
+ const { itemMarker, itemMarkerSize: size } = options;
89
+
90
+ const create = (name, d) => {
91
+ const marker =
92
+ (library[`shape.${name}`]?.props?.defaultMarker as string) ||
93
+ last(name.split('.'));
94
+ const radius = typeof size === 'function' ? size(d) : size;
95
+ return () => useMarker(marker, { color: d.color })(0, 0, radius);
96
+ };
97
+
102
98
  const shapeOf = (i) => `${namespace}.${shapes[i]}`;
103
99
 
104
- const { itemMarker } = options;
105
100
  const shapeScale = scaleOf(scales, 'shape');
106
- if (shapeScale && !itemMarker) return (d, i) => create(shapeOf(i), d.color);
101
+ if (shapeScale && !itemMarker) return (d, i) => create(shapeOf(i), d);
107
102
  if (typeof itemMarker === 'function') {
108
103
  return (d, i) => {
109
104
  // @todo Fix this in GUI.
110
105
  // It should pass primitive value rather object.
111
106
  const node = itemMarker(d.id, i);
112
- if (typeof node === 'string') return create(node, d.color);
107
+ if (typeof node === 'string') return create(node, d);
113
108
  return node;
114
109
  };
115
110
  }
116
- return (d, i) => create(itemMarker || shapeOf(i), d.color);
111
+ return (d, i) => create(itemMarker || shapeOf(i), d);
117
112
  }
118
113
 
119
114
  function inferItemMarkerOpacity(scales: Scale[]) {
@@ -127,21 +122,18 @@ function inferItemMarkerOpacity(scales: Scale[]) {
127
122
 
128
123
  function inferItemMarkerSize(scales: Scale[], defaults: number) {
129
124
  const scale = scaleOf(scales, 'size');
130
- // only support constant size scale.
131
- // size in category legend means the marker radius.
132
- if (scale) return scale.map(NaN) * 2;
125
+ if (scale instanceof Identity) return scale.map(NaN) * 2;
133
126
  return defaults;
134
127
  }
135
128
 
136
129
  function inferCategoryStyle(options, context: GuideComponentContext) {
137
130
  const { labelFormatter = (d) => `${d}` } = options;
138
131
  const { scales, theme } = context;
132
+ const defaultSize = theme.legendCategory.itemMarkerSize;
133
+ const itemMarkerSize = inferItemMarkerSize(scales, defaultSize);
139
134
  const baseStyle = {
140
- itemMarker: inferItemMarker(options, context),
141
- itemMarkerSize: inferItemMarkerSize(
142
- scales,
143
- theme.legendCategory.itemMarkerSize,
144
- ),
135
+ itemMarker: inferItemMarker({ ...options, itemMarkerSize }, context),
136
+ itemMarkerSize: itemMarkerSize,
145
137
  itemMarkerOpacity: inferItemMarkerOpacity(scales),
146
138
  };
147
139
 
@@ -150,16 +142,18 @@ function inferCategoryStyle(options, context: GuideComponentContext) {
150
142
  ? format(labelFormatter)
151
143
  : labelFormatter;
152
144
 
153
- // here must exists a color scale
154
145
  const colorScale = scaleOf(scales, 'color');
155
146
  const domain = domainOf(scales);
147
+ const colorOf = colorScale
148
+ ? (d) => colorScale.map(d)
149
+ : () => context.theme.color;
156
150
 
157
151
  return {
158
152
  ...baseStyle,
159
153
  data: domain.map((d) => ({
160
154
  id: d,
161
155
  label: finalLabelFormatter(d),
162
- color: colorScale.map(d),
156
+ color: colorOf(d),
163
157
  })),
164
158
  };
165
159
  }
@@ -150,7 +150,7 @@ function getLinearConfig(
150
150
  // in this view.
151
151
  const defaultColor = scales.color
152
152
  ? theme.legendContinuous.ribbonFill || 'black'
153
- : theme.defaultColor;
153
+ : theme.color;
154
154
 
155
155
  const scale = colorScale || createColorScale(definedScale, defaultColor);
156
156
  const [min, max] = rangeOf(scale);
@@ -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
  };
@@ -97,6 +97,7 @@ export class G2Layout extends Layout {
97
97
  export class LegendCategoryLayout extends G2Layout {
98
98
  update(options: any) {
99
99
  const { subOptions } = options;
100
+ this.attr(options);
100
101
  this.child?.update(subOptions);
101
102
  }
102
103
  }
@@ -14,6 +14,14 @@ export function dataOf(element, view) {
14
14
  return selectedMark.data[index];
15
15
  }
16
16
 
17
+ // For extended shape.
18
+ function maybeElementRoot(node) {
19
+ if (node.className === 'element') return node;
20
+ let root = node.parent;
21
+ while (root && root.className !== 'element') root = root.parent;
22
+ return root;
23
+ }
24
+
17
25
  function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
18
26
  return (e) => {
19
27
  if (!predicate(e)) return;
@@ -26,17 +34,20 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
26
34
  // There is no target for pointerupoutside event if out of canvas.
27
35
  if (!target) return;
28
36
 
29
- const { className: elementType, markType } = target;
37
+ const { className } = target;
30
38
 
31
39
  // If target area is plot area, do not emit extra events.
32
- if (elementType === 'plot') return;
40
+ if (className === 'plot') return;
33
41
 
34
- // Emit wrapped events.
42
+ // If target is element or child of element.
43
+ const elementRoot = maybeElementRoot(target);
44
+ if (!elementRoot) return;
45
+ const { className: elementType, markType } = elementRoot;
35
46
  if (elementType === 'element') {
36
47
  const e1 = {
37
48
  ...e,
38
49
  nativeEvent: true,
39
- data: { data: dataOf(target, view) },
50
+ data: { data: dataOf(elementRoot, view) },
40
51
  };
41
52
  emitter.emit(`element:${eventType}`, e1);
42
53
  emitter.emit(`${markType}:${eventType}`, e1);
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 {
@@ -38,6 +38,7 @@ import { documentOf, useLibrary } from './library';
38
38
  import { initializeMark } from './mark';
39
39
  import {
40
40
  applyScale,
41
+ assignScale,
41
42
  collectScales,
42
43
  inferScale,
43
44
  syncFacetsScales,
@@ -535,6 +536,7 @@ async function initializeMarks(
535
536
  (total, { scale }) => deepMix(total, scale),
536
537
  {},
537
538
  );
539
+ const { scaleKey } = channels[0];
538
540
 
539
541
  // Use the fields of the first channel as the title.
540
542
  const { values: FV } = channels[0];
@@ -550,14 +552,10 @@ async function initializeMarks(
550
552
  // Use the name of the first channel as the scale name.
551
553
  const { name } = channels[0];
552
554
  const values = channels.flatMap(({ values }) => values.map((d) => d.value));
553
- const scale = inferScale(
554
- name,
555
- values,
556
- options,
557
- coordinates,
558
- theme,
559
- library,
560
- );
555
+ const scale = {
556
+ ...inferScale(name, values, options, coordinates, theme, library),
557
+ key: scaleKey,
558
+ };
561
559
  channels.forEach((channel) => (channel.scale = scale));
562
560
  }
563
561
 
@@ -597,10 +595,12 @@ function initializeState(
597
595
  // Infer components and compute layout.
598
596
  const states = Array.from(markState.values());
599
597
  const scales = collectScales(states, options);
600
- const components = inferComponent(
601
- inferComponentScales(Array.from(scales), states, markState),
602
- options,
603
- library,
598
+ const components = normalizeComponents(
599
+ inferComponent(
600
+ inferComponentScales(Array.from(scales), states, markState),
601
+ options,
602
+ library,
603
+ ),
604
604
  );
605
605
  const layout = computeLayout(components, options, theme, library);
606
606
  const coordinate = createCoordinate(layout, options, library);
@@ -622,7 +622,7 @@ function initializeState(
622
622
  const { name } = descriptor;
623
623
  const scale = useRelationScale(descriptor, library);
624
624
  scales.push(scale);
625
- scaleInstance[name] = scale;
625
+ assignScale(scaleInstance, { [name]: scale });
626
626
  }
627
627
  component.scaleInstances = scales;
628
628
  }
@@ -651,7 +651,7 @@ function initializeState(
651
651
  const markScaleInstance = mapObject(scale, (options) => {
652
652
  return useRelationScale(options, library);
653
653
  });
654
- Object.assign(scaleInstance, markScaleInstance);
654
+ assignScale(scaleInstance, markScaleInstance);
655
655
  const value = applyScale(channels, markScaleInstance);
656
656
 
657
657
  // Calc points and transformation for each data,
@@ -743,7 +743,7 @@ async function plotView(
743
743
  const I = areaKeys.map((_, i) => i);
744
744
  const sizeKeys = ['a', 'margin', 'padding', 'inset'];
745
745
  const areaStyles = areaKeys.map((d) =>
746
- maybeSubObject(Object.assign({}, theme, style), d),
746
+ maybeSubObject(Object.assign({}, theme.view, style), d),
747
747
  );
748
748
  const areaSizes = sizeKeys.map((d) => subObject(rest, d));
749
749
  const styleArea = (selection) =>
@@ -920,16 +920,23 @@ async function plotView(
920
920
  const [x, y] = node.getBounds().min;
921
921
  return [x, y];
922
922
  });
923
- update.transition(function (data, index) {
924
- maybeFacetElement(this, parent, origin);
925
- const node = shapeFunction(data, index);
926
- const animation = updateFunction(data, [this], [node]);
927
- if (animation === null) {
923
+ selection
924
+ .transition(function (data, index) {
925
+ maybeFacetElement(this, parent, origin);
926
+ const node = shapeFunction(data, index);
927
+ const animation = updateFunction(data, [this], [node]);
928
+ if (animation !== null) return animation;
928
929
  if (this.nodeName === node.nodeName) copyAttributes(this, node);
929
- else this.parentNode.replaceChild(node, this);
930
- }
931
- return animation;
932
- });
930
+ else {
931
+ this.parentNode.replaceChild(node, this);
932
+ node.className = ELEMENT_CLASS_NAME;
933
+ // @ts-ignore
934
+ node.markType = type;
935
+ }
936
+ return animation;
937
+ })
938
+ .attr('markType', type)
939
+ .attr('className', ELEMENT_CLASS_NAME);
933
940
  }),
934
941
  (exit) => {
935
942
  return exit
@@ -1370,10 +1377,10 @@ function getDefaultsStyle(
1370
1377
  defaultShape: string,
1371
1378
  ) {
1372
1379
  if (typeof mark !== 'string') return;
1373
- const { defaultColor } = theme;
1380
+ const { color } = theme;
1374
1381
  const markTheme = theme[mark] || {};
1375
1382
  const shapeTheme = markTheme[shape] || markTheme[defaultShape];
1376
- return Object.assign({ color: defaultColor }, shapeTheme);
1383
+ return Object.assign({ color }, shapeTheme);
1377
1384
  }
1378
1385
 
1379
1386
  function createAnimationFunction(