@antv/g2 5.0.14 → 5.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/animation/morphing.js +3 -2
- package/esm/animation/morphing.js.map +1 -1
- package/esm/component/slider.js +16 -4
- package/esm/component/slider.js.map +1 -1
- package/esm/component/utils.js +1 -0
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/brushFilter.js +3 -2
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/event.js +17 -4
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/legendFilter.js +4 -1
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +28 -20
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +8 -6
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/component.js +18 -5
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.js +33 -6
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +26 -13
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.d.ts +1 -0
- package/esm/runtime/scale.js +27 -1
- package/esm/runtime/scale.js.map +1 -1
- package/esm/theme/academy.js +2 -2
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/classic.js +2 -2
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +2 -2
- package/esm/theme/classicDark.js.map +1 -1
- package/lib/animation/morphing.js +3 -2
- package/lib/animation/morphing.js.map +1 -1
- package/lib/component/slider.js +16 -4
- package/lib/component/slider.js.map +1 -1
- package/lib/component/utils.js +1 -0
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/brushFilter.js +3 -2
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/event.js +17 -4
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/legendFilter.js +4 -1
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +28 -20
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +8 -6
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/component.js +18 -5
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.js +33 -6
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +24 -11
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.d.ts +1 -0
- package/lib/runtime/scale.js +28 -1
- package/lib/runtime/scale.js.map +1 -1
- package/lib/theme/academy.js +2 -2
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/classic.js +2 -2
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +2 -2
- package/lib/theme/classicDark.js.map +1 -1
- package/package.json +1 -1
- package/src/animation/morphing.ts +3 -2
- package/src/component/slider.ts +22 -6
- package/src/component/utils.ts +1 -0
- package/src/interaction/brushFilter.ts +3 -2
- package/src/interaction/event.ts +15 -4
- package/src/interaction/legendFilter.ts +4 -1
- package/src/interaction/sliderFilter.ts +14 -6
- package/src/interaction/tooltip.ts +10 -6
- package/src/runtime/component.ts +27 -4
- package/src/runtime/layout.ts +38 -15
- package/src/runtime/plot.ts +32 -21
- package/src/runtime/scale.ts +28 -1
- package/src/theme/academy.ts +2 -2
- package/src/theme/classic.ts +2 -2
- package/src/theme/classicDark.ts +2 -2
package/src/runtime/component.ts
CHANGED
|
@@ -90,7 +90,7 @@ export function inferComponent(
|
|
|
90
90
|
position: defaultPosition,
|
|
91
91
|
orientation: defaultOrientation,
|
|
92
92
|
order: defaultOrder,
|
|
93
|
-
|
|
93
|
+
defaultSize,
|
|
94
94
|
...titleOptions,
|
|
95
95
|
});
|
|
96
96
|
}
|
|
@@ -135,7 +135,7 @@ export function inferComponent(
|
|
|
135
135
|
const defaultCrossPadding = isVertical ? DCP[1] : DCP[0];
|
|
136
136
|
|
|
137
137
|
const {
|
|
138
|
-
size
|
|
138
|
+
size,
|
|
139
139
|
order = defaultOrder,
|
|
140
140
|
length = defaultLength,
|
|
141
141
|
padding = defaultPadding,
|
|
@@ -145,6 +145,7 @@ export function inferComponent(
|
|
|
145
145
|
components.push({
|
|
146
146
|
title: field,
|
|
147
147
|
...partialGuide,
|
|
148
|
+
defaultSize,
|
|
148
149
|
length,
|
|
149
150
|
position,
|
|
150
151
|
orientation,
|
|
@@ -523,7 +524,7 @@ function inferScrollableComponents(
|
|
|
523
524
|
const { defaultPosition, defaultSize, defaultOrder } = props;
|
|
524
525
|
return {
|
|
525
526
|
position: defaultPosition,
|
|
526
|
-
|
|
527
|
+
defaultSize,
|
|
527
528
|
order: defaultOrder,
|
|
528
529
|
type: componentType,
|
|
529
530
|
...options,
|
|
@@ -562,6 +563,7 @@ export function computeComponentSize(
|
|
|
562
563
|
if (t.startsWith('group')) return computeGroupSize;
|
|
563
564
|
if (t.startsWith('legendContinuous')) return computeContinuousLegendSize;
|
|
564
565
|
if (t === 'legendCategory') return computeCategoryLegendSize;
|
|
566
|
+
if (t.startsWith('slider')) return computeSliderSize;
|
|
565
567
|
return () => {};
|
|
566
568
|
};
|
|
567
569
|
return createCompute()(
|
|
@@ -603,6 +605,23 @@ function computeGroupSize(
|
|
|
603
605
|
children.forEach((d) => (d.size = maxSize));
|
|
604
606
|
}
|
|
605
607
|
|
|
608
|
+
function computeSliderSize(
|
|
609
|
+
component: G2GuideComponentOptions,
|
|
610
|
+
crossSize: number,
|
|
611
|
+
crossPadding: [number, number],
|
|
612
|
+
position: GCP,
|
|
613
|
+
theme: G2Theme,
|
|
614
|
+
library: G2Library,
|
|
615
|
+
) {
|
|
616
|
+
const styleOf = () => {
|
|
617
|
+
const { slider } = theme;
|
|
618
|
+
return deepMix({}, slider, component.style);
|
|
619
|
+
};
|
|
620
|
+
const { trackSize, handleIconSize } = styleOf();
|
|
621
|
+
const size = Math.max(trackSize, handleIconSize * 2.4);
|
|
622
|
+
component.size = size;
|
|
623
|
+
}
|
|
624
|
+
|
|
606
625
|
function computeAxisSize(
|
|
607
626
|
component: G2GuideComponentOptions,
|
|
608
627
|
crossSize: number,
|
|
@@ -902,8 +921,12 @@ export function computeTitleBBox(
|
|
|
902
921
|
const { title: styleTitle } = style;
|
|
903
922
|
if (isFalsy(title) || isFalsy(styleTitle) || title === undefined) return null;
|
|
904
923
|
const titleStyle = subObject(style, 'title');
|
|
924
|
+
const { direction, transform } = titleStyle;
|
|
905
925
|
const titleText = Array.isArray(title) ? title.join(',') : title;
|
|
906
|
-
const titleBBox = computeLabelSize(titleText,
|
|
926
|
+
const titleBBox = computeLabelSize(titleText, {
|
|
927
|
+
...titleStyle,
|
|
928
|
+
transform: transform || direction === 'vertical' ? 'rotate(-90)' : '',
|
|
929
|
+
});
|
|
907
930
|
return titleBBox;
|
|
908
931
|
}
|
|
909
932
|
|
package/src/runtime/layout.ts
CHANGED
|
@@ -257,32 +257,55 @@ function computePadding(
|
|
|
257
257
|
paddingTop,
|
|
258
258
|
paddingRight,
|
|
259
259
|
};
|
|
260
|
+
|
|
260
261
|
for (const position of positions) {
|
|
261
262
|
const key = `padding${capitalizeFirst(camelCase(position))}`;
|
|
263
|
+
const components = positionComponents.get(position) || [];
|
|
262
264
|
const value = layout[key];
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
+
const defaultSizeOf = (d) => {
|
|
266
|
+
if (d.size === undefined) d.size = d.defaultSize;
|
|
267
|
+
};
|
|
268
|
+
const sizeOf = (d) => {
|
|
269
|
+
if (d.type === 'group') {
|
|
270
|
+
d.children.forEach(defaultSizeOf);
|
|
271
|
+
d.size = max(d.children, (d) => (d as any).size);
|
|
272
|
+
} else {
|
|
273
|
+
d.size = d.defaultSize;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
const autoSizeOf = (d) => {
|
|
277
|
+
if (d.size) return;
|
|
278
|
+
if (value !== 'auto') sizeOf(d);
|
|
279
|
+
else {
|
|
280
|
+
// Compute component size dynamically.
|
|
281
|
+
computeComponentSize(
|
|
282
|
+
d,
|
|
283
|
+
crossSize,
|
|
284
|
+
crossPadding,
|
|
285
|
+
position,
|
|
286
|
+
theme,
|
|
287
|
+
library,
|
|
288
|
+
);
|
|
289
|
+
defaultSizeOf(d);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Specified padding.
|
|
294
|
+
if (typeof value === 'number') {
|
|
295
|
+
components.forEach(defaultSizeOf);
|
|
296
|
+
} else {
|
|
297
|
+
// Compute padding dynamically.
|
|
298
|
+
if (components.length === 0) {
|
|
265
299
|
layout[key] = 30;
|
|
266
300
|
} else {
|
|
267
|
-
const components = positionComponents.get(position);
|
|
268
301
|
const grouped = groupComponents(components, crossSize);
|
|
269
|
-
|
|
270
|
-
grouped.forEach((component) =>
|
|
271
|
-
computeComponentSize(
|
|
272
|
-
component,
|
|
273
|
-
crossSize,
|
|
274
|
-
crossPadding,
|
|
275
|
-
position,
|
|
276
|
-
theme,
|
|
277
|
-
library,
|
|
278
|
-
),
|
|
279
|
-
);
|
|
280
|
-
}
|
|
302
|
+
grouped.forEach(autoSizeOf);
|
|
281
303
|
const totalSize = grouped.reduce((sum, { size }) => sum + size, 0);
|
|
282
304
|
layout[key] = totalSize;
|
|
283
305
|
}
|
|
284
306
|
}
|
|
285
307
|
}
|
|
308
|
+
|
|
286
309
|
return layout;
|
|
287
310
|
}
|
|
288
311
|
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector2 } from '@antv/coord';
|
|
2
2
|
import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
|
|
3
3
|
import { deepMix, upperFirst } from '@antv/util';
|
|
4
|
-
import { group } from 'd3-array';
|
|
4
|
+
import { group, groups } from 'd3-array';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
7
|
import { ChartEvent } from '../utils/event';
|
|
@@ -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 =
|
|
554
|
-
name,
|
|
555
|
-
|
|
556
|
-
|
|
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
|
|
|
@@ -622,7 +620,7 @@ function initializeState(
|
|
|
622
620
|
const { name } = descriptor;
|
|
623
621
|
const scale = useRelationScale(descriptor, library);
|
|
624
622
|
scales.push(scale);
|
|
625
|
-
scaleInstance[name]
|
|
623
|
+
assignScale(scaleInstance, { [name]: scale });
|
|
626
624
|
}
|
|
627
625
|
component.scaleInstances = scales;
|
|
628
626
|
}
|
|
@@ -651,7 +649,7 @@ function initializeState(
|
|
|
651
649
|
const markScaleInstance = mapObject(scale, (options) => {
|
|
652
650
|
return useRelationScale(options, library);
|
|
653
651
|
});
|
|
654
|
-
|
|
652
|
+
assignScale(scaleInstance, markScaleInstance);
|
|
655
653
|
const value = applyScale(channels, markScaleInstance);
|
|
656
654
|
|
|
657
655
|
// Calc points and transformation for each data,
|
|
@@ -799,9 +797,15 @@ async function plotView(
|
|
|
799
797
|
|
|
800
798
|
// Render components.
|
|
801
799
|
// @todo renderComponent return ctor and options.
|
|
800
|
+
// Key for each type of component.
|
|
801
|
+
// Index them grouped by position.
|
|
802
|
+
for (const [, C] of groups(components, (d) => `${d.type}-${d.position}`)) {
|
|
803
|
+
C.forEach((d, i) => (d.index = i));
|
|
804
|
+
}
|
|
805
|
+
|
|
802
806
|
const componentsTransitions = selection
|
|
803
807
|
.selectAll(className(COMPONENT_CLASS_NAME))
|
|
804
|
-
.data(components, (d
|
|
808
|
+
.data(components, (d) => `${d.type}-${d.position}-${d.index}`)
|
|
805
809
|
.join(
|
|
806
810
|
(enter) =>
|
|
807
811
|
enter
|
|
@@ -914,16 +918,23 @@ async function plotView(
|
|
|
914
918
|
const [x, y] = node.getBounds().min;
|
|
915
919
|
return [x, y];
|
|
916
920
|
});
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
921
|
+
selection
|
|
922
|
+
.transition(function (data, index) {
|
|
923
|
+
maybeFacetElement(this, parent, origin);
|
|
924
|
+
const node = shapeFunction(data, index);
|
|
925
|
+
const animation = updateFunction(data, [this], [node]);
|
|
926
|
+
if (animation !== null) return animation;
|
|
922
927
|
if (this.nodeName === node.nodeName) copyAttributes(this, node);
|
|
923
|
-
else
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
928
|
+
else {
|
|
929
|
+
this.parentNode.replaceChild(node, this);
|
|
930
|
+
node.className = ELEMENT_CLASS_NAME;
|
|
931
|
+
// @ts-ignore
|
|
932
|
+
node.markType = type;
|
|
933
|
+
}
|
|
934
|
+
return animation;
|
|
935
|
+
})
|
|
936
|
+
.attr('markType', type)
|
|
937
|
+
.attr('className', ELEMENT_CLASS_NAME);
|
|
927
938
|
}),
|
|
928
939
|
(exit) => {
|
|
929
940
|
return exit
|
package/src/runtime/scale.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Linear, createInterpolateValue } from '@antv/scale';
|
|
2
|
-
import { extent } from 'd3-array';
|
|
2
|
+
import { extent, max } from 'd3-array';
|
|
3
3
|
import * as d3ScaleChromatic from 'd3-scale-chromatic';
|
|
4
4
|
import { deepMix, omit, upperFirst } from '@antv/util';
|
|
5
5
|
import { firstOf, lastOf, unique } from '../utils/array';
|
|
@@ -161,6 +161,33 @@ export function useRelation(
|
|
|
161
161
|
return [conditionalize, deconditionalize];
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
export function assignScale(
|
|
165
|
+
target: Record<string, Scale>,
|
|
166
|
+
source: Record<string, Scale>,
|
|
167
|
+
): Record<string, Scale> {
|
|
168
|
+
const keys = Object.keys(target);
|
|
169
|
+
for (const scale of Object.values(source)) {
|
|
170
|
+
const { name, key } = scale.getOptions();
|
|
171
|
+
if (typeof key === 'string') {
|
|
172
|
+
if (!(key in target)) target[key] = scale;
|
|
173
|
+
} else {
|
|
174
|
+
// For scale.key = Symbol('independent')
|
|
175
|
+
if (!(name in target)) target[name] = scale;
|
|
176
|
+
else {
|
|
177
|
+
const I = keys
|
|
178
|
+
.filter((d) => d.startsWith(name))
|
|
179
|
+
// Reg is for extract `1` from `x1`;
|
|
180
|
+
.map((d) => +(d.replace(name, '') || 0));
|
|
181
|
+
const index = max(I) + 1;
|
|
182
|
+
const newKey = `${name}${index}`;
|
|
183
|
+
target[newKey] = scale;
|
|
184
|
+
scale.getOptions().key = newKey;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return target;
|
|
189
|
+
}
|
|
190
|
+
|
|
164
191
|
export function useRelationScale(
|
|
165
192
|
options: Record<string, any>,
|
|
166
193
|
library: G2Library,
|
package/src/theme/academy.ts
CHANGED
|
@@ -272,7 +272,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
272
272
|
titlePosition: 'left',
|
|
273
273
|
titleSpacing: 4,
|
|
274
274
|
titleTextBaseline: 'middle',
|
|
275
|
-
|
|
275
|
+
titleDirection: 'vertical',
|
|
276
276
|
titleTransformOrigin: 'center',
|
|
277
277
|
},
|
|
278
278
|
axisRight: {
|
|
@@ -283,7 +283,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
283
283
|
titlePosition: 'right',
|
|
284
284
|
titleSpacing: 0,
|
|
285
285
|
titleTextBaseline: 'top',
|
|
286
|
-
|
|
286
|
+
titleDirection: 'vertical',
|
|
287
287
|
titleTransformOrigin: 'center',
|
|
288
288
|
},
|
|
289
289
|
axisLinear: {
|
package/src/theme/classic.ts
CHANGED
|
@@ -274,7 +274,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
274
274
|
titlePosition: 'left',
|
|
275
275
|
titleSpacing: 10,
|
|
276
276
|
titleTextBaseline: 'middle',
|
|
277
|
-
|
|
277
|
+
titleDirection: 'vertical',
|
|
278
278
|
titleTransformOrigin: 'center',
|
|
279
279
|
},
|
|
280
280
|
axisRight: {
|
|
@@ -286,7 +286,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
286
286
|
titlePosition: 'right',
|
|
287
287
|
titleSpacing: 0,
|
|
288
288
|
titleTextBaseline: 'top',
|
|
289
|
-
|
|
289
|
+
titleDirection: 'vertical',
|
|
290
290
|
titleTransformOrigin: 'center',
|
|
291
291
|
},
|
|
292
292
|
axisLinear: {
|
package/src/theme/classicDark.ts
CHANGED
|
@@ -272,7 +272,7 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
|
|
|
272
272
|
titlePosition: 'left',
|
|
273
273
|
titleSpacing: 10,
|
|
274
274
|
titleTextBaseline: 'middle',
|
|
275
|
-
|
|
275
|
+
titleDirection: 'vertical',
|
|
276
276
|
titleTransformOrigin: 'center',
|
|
277
277
|
},
|
|
278
278
|
axisRight: {
|
|
@@ -283,7 +283,7 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
|
|
|
283
283
|
titlePosition: 'right',
|
|
284
284
|
titleSpacing: 0,
|
|
285
285
|
titleTextBaseline: 'top',
|
|
286
|
-
|
|
286
|
+
titleDirection: 'vertical',
|
|
287
287
|
titleTransformOrigin: 'center',
|
|
288
288
|
},
|
|
289
289
|
axisLinear: {
|