@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.
- package/dist/g2-lite.min.js +4 -4
- package/dist/g2.min.js +4 -4
- package/esm/animation/morphing.js +4 -0
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.d.ts +7 -8
- package/esm/api/chart.js +34 -92
- package/esm/api/chart.js.map +1 -1
- package/esm/api/utils.d.ts +10 -0
- package/esm/api/utils.js +71 -0
- package/esm/api/utils.js.map +1 -0
- package/esm/component/axis.js +15 -17
- package/esm/component/axis.js.map +1 -1
- package/esm/component/axisX.js +3 -1
- package/esm/component/axisX.js.map +1 -1
- package/esm/component/axisY.js +1 -1
- package/esm/component/axisY.js.map +1 -1
- package/esm/component/constant.js +6 -0
- package/esm/component/constant.js.map +1 -1
- package/esm/component/legendCategory.js +8 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +91 -33
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +9 -5
- package/esm/component/utils.js +14 -14
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/brushFilter.d.ts +5 -1
- package/esm/interaction/brushFilter.js +26 -23
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +10 -3
- package/esm/interaction/brushHighlight.js +242 -30
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.d.ts +2 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -1
- package/esm/interaction/brushYHighlight.d.ts +2 -1
- package/esm/interaction/brushYHighlight.js +1 -1
- package/esm/interaction/brushYHighlight.js.map +1 -1
- package/esm/interaction/event.d.ts +1 -0
- package/esm/interaction/event.js +14 -12
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +4 -4
- package/esm/interaction/tooltip.js +103 -31
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/mark/gauge.d.ts +7 -0
- package/esm/mark/gauge.js +4 -6
- package/esm/mark/gauge.js.map +1 -1
- package/esm/runtime/plot.js +9 -6
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +2 -2
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -0
- package/esm/shape/area/area.js +1 -1
- package/esm/shape/area/area.js.map +1 -1
- package/esm/shape/area/curve.js +1 -1
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/text/advance.d.ts +1 -1
- package/esm/shape/text/advance.js +1 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +1 -1
- package/esm/shape/utils.js +1 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/theme/classic.js +3 -0
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +1 -0
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/transform/filter.js +6 -2
- package/esm/transform/filter.js.map +1 -1
- package/esm/{shape → utils}/createElement.d.ts +1 -1
- package/esm/{shape → utils}/createElement.js.map +1 -1
- package/esm/utils/helper.d.ts +3 -0
- package/esm/utils/helper.js +3 -0
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/scale.d.ts +2 -0
- package/esm/utils/scale.js +21 -0
- package/esm/utils/scale.js.map +1 -1
- package/lib/animation/morphing.js +4 -0
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +7 -8
- package/lib/api/chart.js +39 -99
- package/lib/api/chart.js.map +1 -1
- package/lib/api/utils.d.ts +10 -0
- package/lib/api/utils.js +80 -0
- package/lib/api/utils.js.map +1 -0
- package/lib/component/axis.js +15 -17
- package/lib/component/axis.js.map +1 -1
- package/lib/component/axisX.js +3 -1
- package/lib/component/axisX.js.map +1 -1
- package/lib/component/axisY.js +1 -1
- package/lib/component/axisY.js.map +1 -1
- package/lib/component/constant.js +6 -0
- package/lib/component/constant.js.map +1 -1
- package/lib/component/legendCategory.js +7 -4
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +90 -32
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +9 -5
- package/lib/component/utils.js +16 -15
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/brushFilter.d.ts +5 -1
- package/lib/interaction/brushFilter.js +25 -22
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +10 -3
- package/lib/interaction/brushHighlight.js +241 -29
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.d.ts +2 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -1
- package/lib/interaction/brushYHighlight.d.ts +2 -1
- package/lib/interaction/brushYHighlight.js +1 -1
- package/lib/interaction/brushYHighlight.js.map +1 -1
- package/lib/interaction/event.d.ts +1 -0
- package/lib/interaction/event.js +15 -12
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +4 -4
- package/lib/interaction/tooltip.js +102 -30
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/mark/gauge.d.ts +7 -0
- package/lib/mark/gauge.js +4 -6
- package/lib/mark/gauge.js.map +1 -1
- package/lib/runtime/plot.js +9 -6
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +2 -2
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +4 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -0
- package/lib/shape/area/area.js +1 -1
- package/lib/shape/area/area.js.map +1 -1
- package/lib/shape/area/curve.js +1 -1
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/text/advance.d.ts +1 -1
- package/lib/shape/text/advance.js +1 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/theme/classic.js +3 -0
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +1 -0
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/transform/filter.js +6 -2
- package/lib/transform/filter.js.map +1 -1
- package/lib/{shape → utils}/createElement.d.ts +1 -1
- package/lib/{shape → utils}/createElement.js.map +1 -1
- package/lib/utils/helper.d.ts +3 -0
- package/lib/utils/helper.js +5 -1
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/scale.d.ts +2 -0
- package/lib/utils/scale.js +24 -1
- package/lib/utils/scale.js.map +1 -1
- package/package.json +7 -6
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +45 -116
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +20 -18
- package/src/component/axisX.ts +3 -1
- package/src/component/axisY.ts +2 -1
- package/src/component/constant.ts +6 -0
- package/src/component/legendCategory.ts +19 -6
- package/src/component/legendContinuous.ts +185 -74
- package/src/component/utils.ts +14 -3
- package/src/interaction/brushFilter.ts +37 -22
- package/src/interaction/brushHighlight.ts +309 -23
- package/src/interaction/brushXHighlight.ts +1 -0
- package/src/interaction/brushYHighlight.ts +1 -0
- package/src/interaction/event.ts +19 -13
- package/src/interaction/tooltip.ts +154 -25
- package/src/mark/gauge.ts +13 -7
- package/src/runtime/plot.ts +7 -5
- package/src/runtime/scale.ts +2 -2
- package/src/runtime/transform.ts +2 -1
- package/src/runtime/types/component.ts +1 -0
- package/src/shape/area/area.ts +1 -1
- package/src/shape/area/curve.ts +1 -1
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/text/advance.ts +1 -1
- package/src/shape/text/badge.ts +1 -1
- package/src/shape/utils.ts +1 -1
- package/src/spec/interaction.ts +3 -2
- package/src/theme/classic.ts +3 -0
- package/src/theme/classicDark.ts +1 -0
- package/src/transform/filter.ts +6 -2
- package/src/{shape → utils}/createElement.ts +1 -1
- package/src/utils/helper.ts +12 -1
- package/src/utils/scale.ts +23 -0
- /package/esm/{shape → utils}/createElement.js +0 -0
- /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
|
|
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?:
|
|
40
|
+
renderer?: IRenderer;
|
|
132
41
|
plugins?: RendererPlugin[];
|
|
133
|
-
theme
|
|
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
|
-
|
|
198
|
-
|
|
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
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
if (autoFit) {
|
|
271
|
+
if (this._hasBindAutoFit) {
|
|
272
|
+
this._hasBindAutoFit = false;
|
|
344
273
|
window.removeEventListener('resize', this._onResize);
|
|
345
274
|
}
|
|
346
275
|
}
|
package/src/api/utils.ts
ADDED
|
@@ -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
|
+
}
|
package/src/component/axis.ts
CHANGED
|
@@ -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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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 = [
|
|
200
|
+
const finalTransforms = [];
|
|
203
201
|
|
|
204
|
-
const
|
|
202
|
+
const addToTransforms = (overlap, state) => {
|
|
205
203
|
if (state) {
|
|
206
|
-
|
|
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
|
-
|
|
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
|
-
|
|
223
|
-
|
|
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),
|
package/src/component/axisX.ts
CHANGED
|
@@ -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
|
|
10
|
+
return (...args) =>
|
|
11
|
+
// empirical value for crossPadding
|
|
12
|
+
LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(...args);
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
AxisX.props = {
|
package/src/component/axisY.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
128
|
-
|
|
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
|
-
|
|
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:
|
|
267
|
+
style: categoryStyle,
|
|
255
268
|
}),
|
|
256
269
|
);
|
|
257
270
|
return layoutWrapper;
|