@antv/g2 5.0.5 → 5.0.7

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 (198) hide show
  1. package/dist/g2-lite.min.js +4 -4
  2. package/dist/g2.min.js +4 -4
  3. package/esm/animation/morphing.js +4 -0
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.d.ts +7 -8
  6. package/esm/api/chart.js +34 -92
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/utils.d.ts +10 -0
  9. package/esm/api/utils.js +71 -0
  10. package/esm/api/utils.js.map +1 -0
  11. package/esm/component/axis.js +15 -17
  12. package/esm/component/axis.js.map +1 -1
  13. package/esm/component/axisX.js +3 -1
  14. package/esm/component/axisX.js.map +1 -1
  15. package/esm/component/axisY.js +1 -1
  16. package/esm/component/axisY.js.map +1 -1
  17. package/esm/component/constant.js +6 -0
  18. package/esm/component/constant.js.map +1 -1
  19. package/esm/component/legendCategory.js +8 -5
  20. package/esm/component/legendCategory.js.map +1 -1
  21. package/esm/component/legendContinuous.js +91 -33
  22. package/esm/component/legendContinuous.js.map +1 -1
  23. package/esm/component/utils.d.ts +9 -5
  24. package/esm/component/utils.js +14 -14
  25. package/esm/component/utils.js.map +1 -1
  26. package/esm/interaction/brushFilter.d.ts +5 -1
  27. package/esm/interaction/brushFilter.js +26 -23
  28. package/esm/interaction/brushFilter.js.map +1 -1
  29. package/esm/interaction/brushHighlight.d.ts +10 -3
  30. package/esm/interaction/brushHighlight.js +242 -30
  31. package/esm/interaction/brushHighlight.js.map +1 -1
  32. package/esm/interaction/brushXHighlight.d.ts +2 -1
  33. package/esm/interaction/brushXHighlight.js +1 -1
  34. package/esm/interaction/brushXHighlight.js.map +1 -1
  35. package/esm/interaction/brushYHighlight.d.ts +2 -1
  36. package/esm/interaction/brushYHighlight.js +1 -1
  37. package/esm/interaction/brushYHighlight.js.map +1 -1
  38. package/esm/interaction/event.d.ts +1 -0
  39. package/esm/interaction/event.js +14 -12
  40. package/esm/interaction/event.js.map +1 -1
  41. package/esm/interaction/tooltip.d.ts +4 -4
  42. package/esm/interaction/tooltip.js +103 -31
  43. package/esm/interaction/tooltip.js.map +1 -1
  44. package/esm/mark/gauge.d.ts +7 -0
  45. package/esm/mark/gauge.js +4 -6
  46. package/esm/mark/gauge.js.map +1 -1
  47. package/esm/runtime/plot.js +9 -6
  48. package/esm/runtime/plot.js.map +1 -1
  49. package/esm/runtime/scale.js +2 -2
  50. package/esm/runtime/scale.js.map +1 -1
  51. package/esm/runtime/transform.js +4 -1
  52. package/esm/runtime/transform.js.map +1 -1
  53. package/esm/runtime/types/component.d.ts +1 -0
  54. package/esm/shape/area/area.js +1 -1
  55. package/esm/shape/area/area.js.map +1 -1
  56. package/esm/shape/area/curve.js +1 -1
  57. package/esm/shape/area/curve.js.map +1 -1
  58. package/esm/shape/connector/connector.js +1 -1
  59. package/esm/shape/line/curve.js +1 -1
  60. package/esm/shape/line/curve.js.map +1 -1
  61. package/esm/shape/text/advance.d.ts +1 -1
  62. package/esm/shape/text/advance.js +1 -1
  63. package/esm/shape/text/advance.js.map +1 -1
  64. package/esm/shape/text/badge.js +1 -1
  65. package/esm/shape/utils.js +1 -1
  66. package/esm/shape/utils.js.map +1 -1
  67. package/esm/spec/interaction.d.ts +3 -1
  68. package/esm/theme/classic.js +3 -0
  69. package/esm/theme/classic.js.map +1 -1
  70. package/esm/theme/classicDark.js +1 -0
  71. package/esm/theme/classicDark.js.map +1 -1
  72. package/esm/transform/filter.js +6 -2
  73. package/esm/transform/filter.js.map +1 -1
  74. package/esm/{shape → utils}/createElement.d.ts +1 -1
  75. package/esm/{shape → utils}/createElement.js.map +1 -1
  76. package/esm/utils/helper.d.ts +3 -0
  77. package/esm/utils/helper.js +3 -0
  78. package/esm/utils/helper.js.map +1 -1
  79. package/esm/utils/scale.d.ts +2 -0
  80. package/esm/utils/scale.js +21 -0
  81. package/esm/utils/scale.js.map +1 -1
  82. package/lib/animation/morphing.js +4 -0
  83. package/lib/animation/morphing.js.map +1 -1
  84. package/lib/api/chart.d.ts +7 -8
  85. package/lib/api/chart.js +39 -99
  86. package/lib/api/chart.js.map +1 -1
  87. package/lib/api/utils.d.ts +10 -0
  88. package/lib/api/utils.js +80 -0
  89. package/lib/api/utils.js.map +1 -0
  90. package/lib/component/axis.js +15 -17
  91. package/lib/component/axis.js.map +1 -1
  92. package/lib/component/axisX.js +3 -1
  93. package/lib/component/axisX.js.map +1 -1
  94. package/lib/component/axisY.js +1 -1
  95. package/lib/component/axisY.js.map +1 -1
  96. package/lib/component/constant.js +6 -0
  97. package/lib/component/constant.js.map +1 -1
  98. package/lib/component/legendCategory.js +7 -4
  99. package/lib/component/legendCategory.js.map +1 -1
  100. package/lib/component/legendContinuous.js +90 -32
  101. package/lib/component/legendContinuous.js.map +1 -1
  102. package/lib/component/utils.d.ts +9 -5
  103. package/lib/component/utils.js +16 -15
  104. package/lib/component/utils.js.map +1 -1
  105. package/lib/interaction/brushFilter.d.ts +5 -1
  106. package/lib/interaction/brushFilter.js +25 -22
  107. package/lib/interaction/brushFilter.js.map +1 -1
  108. package/lib/interaction/brushHighlight.d.ts +10 -3
  109. package/lib/interaction/brushHighlight.js +241 -29
  110. package/lib/interaction/brushHighlight.js.map +1 -1
  111. package/lib/interaction/brushXHighlight.d.ts +2 -1
  112. package/lib/interaction/brushXHighlight.js +1 -1
  113. package/lib/interaction/brushXHighlight.js.map +1 -1
  114. package/lib/interaction/brushYHighlight.d.ts +2 -1
  115. package/lib/interaction/brushYHighlight.js +1 -1
  116. package/lib/interaction/brushYHighlight.js.map +1 -1
  117. package/lib/interaction/event.d.ts +1 -0
  118. package/lib/interaction/event.js +15 -12
  119. package/lib/interaction/event.js.map +1 -1
  120. package/lib/interaction/tooltip.d.ts +4 -4
  121. package/lib/interaction/tooltip.js +102 -30
  122. package/lib/interaction/tooltip.js.map +1 -1
  123. package/lib/mark/gauge.d.ts +7 -0
  124. package/lib/mark/gauge.js +4 -6
  125. package/lib/mark/gauge.js.map +1 -1
  126. package/lib/runtime/plot.js +9 -6
  127. package/lib/runtime/plot.js.map +1 -1
  128. package/lib/runtime/scale.js +2 -2
  129. package/lib/runtime/scale.js.map +1 -1
  130. package/lib/runtime/transform.js +4 -1
  131. package/lib/runtime/transform.js.map +1 -1
  132. package/lib/runtime/types/component.d.ts +1 -0
  133. package/lib/shape/area/area.js +1 -1
  134. package/lib/shape/area/area.js.map +1 -1
  135. package/lib/shape/area/curve.js +1 -1
  136. package/lib/shape/area/curve.js.map +1 -1
  137. package/lib/shape/connector/connector.js +1 -1
  138. package/lib/shape/line/curve.js +1 -1
  139. package/lib/shape/line/curve.js.map +1 -1
  140. package/lib/shape/text/advance.d.ts +1 -1
  141. package/lib/shape/text/advance.js +1 -1
  142. package/lib/shape/text/advance.js.map +1 -1
  143. package/lib/shape/text/badge.js +1 -1
  144. package/lib/shape/utils.js +1 -1
  145. package/lib/shape/utils.js.map +1 -1
  146. package/lib/spec/interaction.d.ts +3 -1
  147. package/lib/theme/classic.js +3 -0
  148. package/lib/theme/classic.js.map +1 -1
  149. package/lib/theme/classicDark.js +1 -0
  150. package/lib/theme/classicDark.js.map +1 -1
  151. package/lib/transform/filter.js +6 -2
  152. package/lib/transform/filter.js.map +1 -1
  153. package/lib/{shape → utils}/createElement.d.ts +1 -1
  154. package/lib/{shape → utils}/createElement.js.map +1 -1
  155. package/lib/utils/helper.d.ts +3 -0
  156. package/lib/utils/helper.js +5 -1
  157. package/lib/utils/helper.js.map +1 -1
  158. package/lib/utils/scale.d.ts +2 -0
  159. package/lib/utils/scale.js +24 -1
  160. package/lib/utils/scale.js.map +1 -1
  161. package/package.json +7 -6
  162. package/src/animation/morphing.ts +5 -0
  163. package/src/api/chart.ts +45 -116
  164. package/src/api/utils.ts +79 -0
  165. package/src/component/axis.ts +20 -18
  166. package/src/component/axisX.ts +3 -1
  167. package/src/component/axisY.ts +2 -1
  168. package/src/component/constant.ts +6 -0
  169. package/src/component/legendCategory.ts +19 -6
  170. package/src/component/legendContinuous.ts +185 -74
  171. package/src/component/utils.ts +14 -3
  172. package/src/interaction/brushFilter.ts +37 -22
  173. package/src/interaction/brushHighlight.ts +309 -23
  174. package/src/interaction/brushXHighlight.ts +1 -0
  175. package/src/interaction/brushYHighlight.ts +1 -0
  176. package/src/interaction/event.ts +19 -13
  177. package/src/interaction/tooltip.ts +154 -25
  178. package/src/mark/gauge.ts +13 -7
  179. package/src/runtime/plot.ts +7 -5
  180. package/src/runtime/scale.ts +2 -2
  181. package/src/runtime/transform.ts +2 -1
  182. package/src/runtime/types/component.ts +1 -0
  183. package/src/shape/area/area.ts +1 -1
  184. package/src/shape/area/curve.ts +1 -1
  185. package/src/shape/connector/connector.ts +1 -1
  186. package/src/shape/line/curve.ts +1 -1
  187. package/src/shape/text/advance.ts +1 -1
  188. package/src/shape/text/badge.ts +1 -1
  189. package/src/shape/utils.ts +1 -1
  190. package/src/spec/interaction.ts +3 -2
  191. package/src/theme/classic.ts +3 -0
  192. package/src/theme/classicDark.ts +1 -0
  193. package/src/transform/filter.ts +6 -2
  194. package/src/{shape → utils}/createElement.ts +1 -1
  195. package/src/utils/helper.ts +12 -1
  196. package/src/utils/scale.ts +23 -0
  197. /package/esm/{shape → utils}/createElement.js +0 -0
  198. /package/lib/{shape → utils}/createElement.js +0 -0
package/src/api/chart.ts CHANGED
@@ -1,14 +1,12 @@
1
- import { RendererPlugin, Canvas as GCanvas } from '@antv/g';
1
+ import { IRenderer, RendererPlugin, Canvas as GCanvas } from '@antv/g';
2
2
  import { Renderer as CanvasRenderer } from '@antv/g-canvas';
3
3
  import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
4
- import { debounce, deepMix, omit } from '@antv/util';
4
+ import { debounce, deepMix } from '@antv/util';
5
5
  import EventEmitter from '@antv/event-emitter';
6
6
  import { G2Context, render, destroy } from '../runtime';
7
7
  import { ViewComposition } from '../spec';
8
- import { getContainerSize } from '../utils/size';
9
8
  import { ChartEvent } from '../utils/event';
10
9
  import { G2ViewTree } from '../runtime/types/options';
11
- import { Node } from './node';
12
10
  import {
13
11
  defineProps,
14
12
  NodePropertyDescriptor,
@@ -24,113 +22,24 @@ import {
24
22
  import { mark, Mark } from './mark';
25
23
  import { composition, Composition, View } from './composition';
26
24
  import { library } from './library';
25
+ import {
26
+ normalizeContainer,
27
+ removeContainer,
28
+ sizeOf,
29
+ optionsOf,
30
+ } from './utils';
27
31
 
28
- export const SPEC_EXTERNAL_KEYS = ['container', 'renderer'];
29
32
  export const G2_CHART_KEY = 'G2_CHART_KEY';
30
33
 
31
- function normalizeContainer(container: string | HTMLElement): HTMLElement {
32
- if (container === undefined) return document.createElement('div');
33
- if (typeof container === 'string') {
34
- const node = document.getElementById(container);
35
- return node;
36
- }
37
- return container;
38
- }
39
-
40
- export function removeContainer(container: HTMLElement) {
41
- const parent = container.parentNode;
42
- if (parent) {
43
- parent.removeChild(container);
44
- }
45
- }
46
-
47
- function normalizeRoot(node: Node) {
48
- if (node.type !== null) return node;
49
- const root = node.children[node.children.length - 1];
50
- root.attr('width', node.attr('width'));
51
- root.attr('height', node.attr('height'));
52
- root.attr('paddingLeft', node.attr('paddingLeft'));
53
- root.attr('paddingTop', node.attr('paddingTop'));
54
- root.attr('paddingBottom', node.attr('paddingBottom'));
55
- root.attr('paddingRight', node.attr('paddingRight'));
56
- root.attr('insetLeft', node.attr('insetLeft'));
57
- root.attr('insetRight', node.attr('insetRight'));
58
- root.attr('insetBottom', node.attr('insetBottom'));
59
- root.attr('insetTop', node.attr('insetTop'));
60
- root.attr('marginLeft', node.attr('marginLeft'));
61
- root.attr('marginBottom', node.attr('marginBottom'));
62
- root.attr('marginTop', node.attr('marginTop'));
63
- root.attr('marginRight', node.attr('marginRight'));
64
- root.attr('autoFit', node.attr('autoFit'));
65
- root.attr('padding', node.attr('padding'));
66
- root.attr('margin', node.attr('margin'));
67
- root.attr('inset', node.attr('inset'));
68
- root.attr('theme', node.attr('theme'));
69
- return root;
70
- }
71
-
72
- function valueOf(node: Node): Record<string, any> {
73
- return {
74
- ...node.value,
75
- type: node.type,
76
- };
77
- }
78
-
79
- function Canvas(
80
- container: HTMLElement,
81
- width: number,
82
- height: number,
83
- renderer = new CanvasRenderer(),
84
- plugins = [],
85
- ) {
86
- // DragAndDropPlugin is for interaction.
87
- // It is OK to register more than one time, G will handle this.
88
- plugins.push(new DragAndDropPlugin());
89
- plugins.forEach((d) => renderer.registerPlugin(d));
90
- return new GCanvas({
91
- container,
92
- width,
93
- height,
94
- renderer,
95
- });
96
- }
97
-
98
- function sizeOf(options, container) {
99
- const { autoFit } = options;
100
- if (autoFit) return getContainerSize(container);
101
- const { width = 640, height = 480 } = options;
102
- return { width, height };
103
- }
104
-
105
- export function optionsOf(node: Node): Record<string, any> {
106
- const root = normalizeRoot(node);
107
- const discovered: Node[] = [root];
108
- const nodeValue = new Map<Node, Record<string, any>>();
109
- nodeValue.set(root, valueOf(root));
110
- while (discovered.length) {
111
- const node = discovered.pop();
112
- const value = nodeValue.get(node);
113
- for (const child of node.children) {
114
- const childValue = valueOf(child);
115
- const { children = [] } = value;
116
- children.push(childValue);
117
- discovered.push(child);
118
- nodeValue.set(child, childValue);
119
- value.children = children;
120
- }
121
- }
122
- return nodeValue.get(root);
123
- }
124
-
125
34
  export type ChartOptions = ViewComposition & {
126
35
  container?: string | HTMLElement;
127
36
  canvas?: GCanvas;
128
37
  width?: number;
129
38
  height?: number;
130
39
  autoFit?: boolean;
131
- renderer?: CanvasRenderer;
40
+ renderer?: IRenderer;
132
41
  plugins?: RendererPlugin[];
133
- theme: string;
42
+ theme?: string;
134
43
  };
135
44
 
136
45
  type ChartProps = Concrete<ViewComposition>;
@@ -178,29 +87,38 @@ export class Chart extends View<ChartOptions> {
178
87
  private _options: G2ViewTree;
179
88
  private _width: number;
180
89
  private _height: number;
90
+ private _renderer: IRenderer;
91
+ private _plugins: RendererPlugin[];
92
+ // Identifies whether bindAutoFit.
93
+ private _hasBindAutoFit = false;
181
94
 
182
95
  constructor(options: ChartOptions) {
183
- const { container, canvas, ...rest } = options || {};
96
+ const { container, canvas, renderer, plugins, ...rest } = options || {};
184
97
  super(rest, 'view');
98
+ this._renderer = renderer || new CanvasRenderer();
99
+ this._plugins = plugins || [];
185
100
  this._container = normalizeContainer(container);
186
101
  this._emitter = new EventEmitter();
187
102
  this._context = { library, emitter: this._emitter, canvas };
188
- this._bindAutoFit();
189
103
  }
190
104
 
191
105
  render(): Promise<Chart> {
106
+ this._bindAutoFit();
107
+
192
108
  if (!this._context.canvas) {
193
109
  // Init width and height.
194
- const { renderer, plugins } = this.options();
195
110
  const { width, height } = sizeOf(this.options(), this._container);
196
111
  // Create canvas if it does not exist.
197
- this._context.canvas = Canvas(
198
- this._container,
112
+ // DragAndDropPlugin is for interaction.
113
+ // It is OK to register more than one time, G will handle this.
114
+ this._plugins.push(new DragAndDropPlugin());
115
+ this._plugins.forEach((d) => this._renderer.registerPlugin(d));
116
+ this._context.canvas = new GCanvas({
117
+ container: this._container,
199
118
  width,
200
119
  height,
201
- renderer,
202
- plugins,
203
- );
120
+ renderer: this._renderer,
121
+ });
204
122
  }
205
123
 
206
124
  return new Promise((resolve, reject) => {
@@ -246,13 +164,17 @@ export class Chart extends View<ChartOptions> {
246
164
  if (arguments.length === 0) {
247
165
  return this._options || optionsOf(this);
248
166
  }
249
- this._options = deepMix(
250
- this._options || optionsOf(this),
251
- omit(options, SPEC_EXTERNAL_KEYS),
252
- );
167
+ this._options = deepMix(this._options || optionsOf(this), options);
253
168
  return this;
254
169
  }
255
170
 
171
+ // @todo Remove it when implement updateRoot.
172
+ changeData(data: any): Promise<Chart> {
173
+ // Update options data.
174
+ this.options({ data });
175
+ return super.changeData(data);
176
+ }
177
+
256
178
  getContainer(): HTMLElement {
257
179
  return this._container;
258
180
  }
@@ -332,15 +254,22 @@ export class Chart extends View<ChartOptions> {
332
254
  private _bindAutoFit() {
333
255
  const options = this.options();
334
256
  const { autoFit } = options;
257
+
258
+ if (this._hasBindAutoFit) {
259
+ // If it was bind before, unbind it now.
260
+ if (!autoFit) this._unbindAutoFit();
261
+ return;
262
+ }
263
+
335
264
  if (autoFit) {
265
+ this._hasBindAutoFit = true;
336
266
  window.addEventListener('resize', this._onResize);
337
267
  }
338
268
  }
339
269
 
340
270
  private _unbindAutoFit() {
341
- const options = this.options();
342
- const { autoFit } = options;
343
- if (autoFit) {
271
+ if (this._hasBindAutoFit) {
272
+ this._hasBindAutoFit = false;
344
273
  window.removeEventListener('resize', this._onResize);
345
274
  }
346
275
  }
@@ -0,0 +1,79 @@
1
+ import { getContainerSize } from '../utils/size';
2
+ import { Node } from './node';
3
+
4
+ export function normalizeContainer(
5
+ container: string | HTMLElement,
6
+ ): HTMLElement {
7
+ if (container === undefined) return document.createElement('div');
8
+ if (typeof container === 'string') {
9
+ const node = document.getElementById(container);
10
+ return node;
11
+ }
12
+ return container;
13
+ }
14
+
15
+ export function removeContainer(container: HTMLElement) {
16
+ const parent = container.parentNode;
17
+ if (parent) {
18
+ parent.removeChild(container);
19
+ }
20
+ }
21
+
22
+ export function normalizeRoot(node: Node) {
23
+ if (node.type !== null) return node;
24
+ const root = node.children[node.children.length - 1];
25
+ root.attr('width', node.attr('width'));
26
+ root.attr('height', node.attr('height'));
27
+ root.attr('paddingLeft', node.attr('paddingLeft'));
28
+ root.attr('paddingTop', node.attr('paddingTop'));
29
+ root.attr('paddingBottom', node.attr('paddingBottom'));
30
+ root.attr('paddingRight', node.attr('paddingRight'));
31
+ root.attr('insetLeft', node.attr('insetLeft'));
32
+ root.attr('insetRight', node.attr('insetRight'));
33
+ root.attr('insetBottom', node.attr('insetBottom'));
34
+ root.attr('insetTop', node.attr('insetTop'));
35
+ root.attr('marginLeft', node.attr('marginLeft'));
36
+ root.attr('marginBottom', node.attr('marginBottom'));
37
+ root.attr('marginTop', node.attr('marginTop'));
38
+ root.attr('marginRight', node.attr('marginRight'));
39
+ root.attr('autoFit', node.attr('autoFit'));
40
+ root.attr('padding', node.attr('padding'));
41
+ root.attr('margin', node.attr('margin'));
42
+ root.attr('inset', node.attr('inset'));
43
+ root.attr('theme', node.attr('theme'));
44
+ return root;
45
+ }
46
+
47
+ export function valueOf(node: Node): Record<string, any> {
48
+ return {
49
+ ...node.value,
50
+ type: node.type,
51
+ };
52
+ }
53
+
54
+ export function sizeOf(options, container) {
55
+ const { autoFit } = options;
56
+ if (autoFit) return getContainerSize(container);
57
+ const { width = 640, height = 480 } = options;
58
+ return { width, height };
59
+ }
60
+
61
+ export function optionsOf(node: Node): Record<string, any> {
62
+ const root = normalizeRoot(node);
63
+ const discovered: Node[] = [root];
64
+ const nodeValue = new Map<Node, Record<string, any>>();
65
+ nodeValue.set(root, valueOf(root));
66
+ while (discovered.length) {
67
+ const node = discovered.pop();
68
+ const value = nodeValue.get(node);
69
+ for (const child of node.children) {
70
+ const childValue = valueOf(child);
71
+ const { children = [] } = value;
72
+ children.push(childValue);
73
+ discovered.push(child);
74
+ nodeValue.set(child, childValue);
75
+ value.children = children;
76
+ }
77
+ }
78
+ return nodeValue.get(root);
79
+ }
@@ -2,7 +2,7 @@ import { Coordinate } from '@antv/coord';
2
2
  import type { DisplayObject } from '@antv/g';
3
3
  import { Axis as AxisComponent } from '@antv/gui';
4
4
  import { Linear as LinearScale } from '@antv/scale';
5
- import { deepMix } from '@antv/util';
5
+ import { deepMix, has } from '@antv/util';
6
6
  import { extent } from 'd3-array';
7
7
  import { format } from 'd3-format';
8
8
  import {
@@ -193,34 +193,31 @@ function inferGridLength(position: GCP, coordinate: Coordinate) {
193
193
  }
194
194
 
195
195
  function inferLabelOverlap(transform = [], style: Record<string, any>) {
196
- const {
197
- labelAutoRotate = true,
198
- labelAutoHide = false,
199
- labelAutoEllipsis = false,
200
- } = style;
196
+ if (transform.length > 0) return transform;
197
+ const { labelAutoRotate, labelAutoHide, labelAutoEllipsis, labelAutoWrap } =
198
+ style;
201
199
 
202
- const finalTransforms = [...transform];
200
+ const finalTransforms = [];
203
201
 
204
- const mutateLabelOverlap = (overlap, state) => {
202
+ const addToTransforms = (overlap, state) => {
205
203
  if (state) {
206
- const index = finalTransforms.findIndex((t) => t.type === overlap.type);
207
- if (index !== -1) finalTransforms[index] = overlap;
208
- else finalTransforms.push(overlap);
209
- } else {
210
- const index = finalTransforms.findIndex((t) => t.type === overlap.type);
211
- if (index !== -1) finalTransforms.splice(index, 1);
204
+ finalTransforms.push(overlap);
212
205
  }
213
206
  };
214
207
 
215
- mutateLabelOverlap(
208
+ addToTransforms(
216
209
  {
217
210
  type: 'rotate',
218
211
  optionalAngles: [0, 15, 30, 45, 60, 90],
219
212
  },
220
213
  labelAutoRotate,
221
214
  );
222
- mutateLabelOverlap({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
223
- mutateLabelOverlap({ type: 'hide' }, labelAutoHide);
215
+ addToTransforms({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
216
+ addToTransforms({ type: 'hide' }, labelAutoHide);
217
+ addToTransforms(
218
+ { type: 'wrap', wordWrapWidth: 100, maxLines: 3, recoveryWhenFail: true },
219
+ labelAutoWrap,
220
+ );
224
221
  return finalTransforms;
225
222
  }
226
223
 
@@ -503,7 +500,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
503
500
  };
504
501
 
505
502
  const gridLength = inferGridLength(position, coordinate);
506
-
507
503
  const overrideStyle = inferAxisLinearOverrideStyle(
508
504
  position,
509
505
  orientation,
@@ -523,6 +519,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
523
519
  position,
524
520
  coordinate,
525
521
  ),
522
+ crossSize: size,
526
523
  titleText: titleContent(title),
527
524
  labelOverlap: inferLabelOverlap(transform, internalAxisStyle),
528
525
  grid: inferGrid(internalAxisStyle.grid, coordinate, scale),
@@ -533,6 +530,11 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
533
530
  ...overrideStyle,
534
531
  ...important,
535
532
  };
533
+
534
+ // For hide overlap, do not set crossSize.
535
+ const hasHide = finalAxisStyle.labelOverlap.find((d) => d.type === 'hide');
536
+ if (hasHide) finalAxisStyle.crossSize = false;
537
+
536
538
  return new AxisComponent({
537
539
  className: 'axis',
538
540
  style: adaptor(finalAxisStyle),
@@ -7,7 +7,9 @@ export type AxisXOptions = AxisOptions;
7
7
  * LinearAxis component bind to x scale.
8
8
  */
9
9
  export const AxisX: GCC<AxisXOptions> = (options) => {
10
- return LinearAxis(options);
10
+ return (...args) =>
11
+ // empirical value for crossPadding
12
+ LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(...args);
11
13
  };
12
14
 
13
15
  AxisX.props = {
@@ -7,7 +7,8 @@ export type AxisYOptions = AxisOptions;
7
7
  * LinearAxis component bind to y scale.
8
8
  */
9
9
  export const AxisY: GCC<AxisYOptions> = (options) => {
10
- return LinearAxis(options);
10
+ return (...args) =>
11
+ LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(...args);
11
12
  };
12
13
 
13
14
  AxisY.props = {
@@ -198,6 +198,11 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
198
198
  ['color', 'constant'],
199
199
  ['size', 'continuous'],
200
200
  ],
201
+ [
202
+ ['size', 'continuous'],
203
+ ['opacity', 'continuous'],
204
+ ],
205
+ [['size', 'continuous']],
201
206
  ],
202
207
  ],
203
208
  [
@@ -232,6 +237,7 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
232
237
  ['opacity', 'continuous'],
233
238
  ],
234
239
  [['color', 'continuous']],
240
+ [['opacity', 'continuous']],
235
241
  ],
236
242
  ],
237
243
  ];
@@ -19,7 +19,7 @@ import { useMarker } from '../utils/marker';
19
19
  import {
20
20
  adaptor,
21
21
  domainOf,
22
- G2Layout,
22
+ LegendCategoryLayout,
23
23
  inferComponentLayout,
24
24
  inferComponentShape,
25
25
  scaleOf,
@@ -124,9 +124,15 @@ function inferItemMarker(
124
124
  }
125
125
  if (typeof itemMarker === 'function') return itemMarker;
126
126
  return (d, i) =>
127
- createShape(itemMarker || shapes[i], library, coordinate, theme, {
128
- color: d.color,
129
- });
127
+ createShape(
128
+ itemMarker || `${namespace}.${shapes[i]}`,
129
+ library,
130
+ coordinate,
131
+ theme,
132
+ {
133
+ color: d.color,
134
+ },
135
+ );
130
136
  }
131
137
 
132
138
  function inferItemMarkerOpacity(scales: Scale[]) {
@@ -238,20 +244,27 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
238
244
  };
239
245
 
240
246
  const { legend: legendTheme = {} } = theme;
241
- const layoutWrapper = new G2Layout({
247
+
248
+ const categoryStyle = adaptor(
249
+ Object.assign({}, legendTheme, legendStyle, style),
250
+ );
251
+
252
+ const layoutWrapper = new LegendCategoryLayout({
242
253
  style: {
243
254
  x: bbox.x,
244
255
  y: bbox.y,
245
256
  width: bbox.width,
246
257
  height: bbox.height,
247
258
  ...finalLayout,
259
+ // @ts-ignore
260
+ subOptions: categoryStyle,
248
261
  },
249
262
  });
250
263
 
251
264
  layoutWrapper.appendChild(
252
265
  new Category({
253
266
  className: 'legend-category',
254
- style: adaptor(Object.assign({}, legendTheme, legendStyle, style)),
267
+ style: categoryStyle,
255
268
  }),
256
269
  );
257
270
  return layoutWrapper;