@antv/g2 5.1.14 → 5.1.15-beta.0
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 +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/growInX.js +1 -1
- package/esm/animation/growInX.js.map +1 -1
- package/esm/animation/growInY.js +1 -1
- package/esm/animation/growInY.js.map +1 -1
- package/esm/animation/morphing.js +8 -4
- package/esm/animation/morphing.js.map +1 -1
- package/esm/animation/scaleInY.js +2 -5
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/animation/waveIn.js +2 -1
- package/esm/animation/waveIn.js.map +1 -1
- package/esm/api/utils.js +5 -3
- package/esm/api/utils.js.map +1 -1
- package/esm/component/title.js +2 -1
- package/esm/component/title.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/legendFilter.d.ts +1 -0
- package/esm/interaction/legendFilter.js +6 -0
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/scrollbarFilter.js +5 -1
- package/esm/interaction/scrollbarFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.d.ts +1 -1
- package/esm/interaction/sliderFilter.js +19 -2
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +2 -2
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/treemapDrillDown.d.ts +10 -0
- package/esm/interaction/treemapDrillDown.js +229 -0
- package/esm/interaction/treemapDrillDown.js.map +1 -0
- package/esm/interaction/utils.js +7 -6
- package/esm/interaction/utils.js.map +1 -1
- package/esm/lib/core.d.ts +2 -1
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/chord.js +0 -1
- package/esm/mark/chord.js.map +1 -1
- package/esm/mark/gauge.js +4 -1
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/sankey.js +1 -1
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/treemap.js +37 -57
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/utils.d.ts +0 -5
- package/esm/mark/utils.js +0 -13
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/plot.js +47 -35
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/gauge/round.d.ts +3 -0
- package/esm/shape/gauge/round.js +40 -0
- package/esm/shape/gauge/round.js.map +1 -0
- package/esm/shape/image/image.js +1 -1
- package/esm/shape/index.d.ts +1 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.js +1 -1
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/interval/funnel.js +1 -1
- package/esm/shape/interval/funnel.js.map +1 -1
- package/esm/shape/label/position/default.js +9 -9
- package/esm/shape/label/position/default.js.map +1 -1
- package/esm/shape/lineXY/line.js +1 -1
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/liquid/liquid.js +4 -4
- package/esm/shape/liquid/liquid.js.map +1 -1
- package/esm/shape/liquid/wave.js +1 -1
- package/esm/shape/liquid/wave.js.map +1 -1
- package/esm/shape/point/color.js +1 -0
- package/esm/shape/point/color.js.map +1 -1
- package/esm/shape/text/advance.js +2 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.js +2 -2
- package/esm/shape/utils.js.map +1 -1
- package/esm/theme/create.d.ts +2 -2
- package/esm/theme/create.js +2 -2
- package/esm/theme/create.js.map +1 -1
- package/esm/utils/marker.d.ts +1 -1
- package/esm/utils/marker.js +2 -2
- package/esm/utils/marker.js.map +1 -1
- package/esm/utils/treeDataTransform.d.ts +21 -0
- package/esm/utils/treeDataTransform.js +90 -0
- package/esm/utils/treeDataTransform.js.map +1 -0
- package/lib/animation/growInX.js +1 -1
- package/lib/animation/growInX.js.map +1 -1
- package/lib/animation/growInY.js +1 -1
- package/lib/animation/growInY.js.map +1 -1
- package/lib/animation/morphing.js +8 -4
- package/lib/animation/morphing.js.map +1 -1
- package/lib/animation/scaleInY.js +2 -5
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/animation/waveIn.js +2 -1
- package/lib/animation/waveIn.js.map +1 -1
- package/lib/api/utils.js +5 -3
- package/lib/api/utils.js.map +1 -1
- package/lib/component/title.js +2 -1
- package/lib/component/title.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/legendFilter.d.ts +1 -0
- package/lib/interaction/legendFilter.js +8 -1
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/scrollbarFilter.js +5 -1
- package/lib/interaction/scrollbarFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.d.ts +1 -1
- package/lib/interaction/sliderFilter.js +19 -2
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +2 -2
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/treemapDrillDown.d.ts +10 -0
- package/lib/interaction/treemapDrillDown.js +233 -0
- package/lib/interaction/treemapDrillDown.js.map +1 -0
- package/lib/interaction/utils.js +7 -6
- package/lib/interaction/utils.js.map +1 -1
- package/lib/lib/core.d.ts +2 -1
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/chord.js +0 -1
- package/lib/mark/chord.js.map +1 -1
- package/lib/mark/gauge.js +4 -1
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/sankey.js +1 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/treemap.js +36 -56
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/utils.d.ts +0 -5
- package/lib/mark/utils.js +1 -15
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/plot.js +46 -34
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/gauge/round.d.ts +3 -0
- package/lib/shape/gauge/round.js +44 -0
- package/lib/shape/gauge/round.js.map +1 -0
- package/lib/shape/image/image.js +1 -1
- package/lib/shape/index.d.ts +1 -0
- package/lib/shape/index.js +3 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.js +1 -1
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/interval/funnel.js +1 -1
- package/lib/shape/interval/funnel.js.map +1 -1
- package/lib/shape/label/position/default.js +9 -9
- package/lib/shape/label/position/default.js.map +1 -1
- package/lib/shape/lineXY/line.js +1 -1
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/liquid/liquid.js +4 -4
- package/lib/shape/liquid/liquid.js.map +1 -1
- package/lib/shape/liquid/wave.js +1 -1
- package/lib/shape/liquid/wave.js.map +1 -1
- package/lib/shape/point/color.js +1 -0
- package/lib/shape/point/color.js.map +1 -1
- package/lib/shape/text/advance.js +2 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/theme/create.d.ts +2 -2
- package/lib/theme/create.js +2 -2
- package/lib/theme/create.js.map +1 -1
- package/lib/utils/marker.d.ts +1 -1
- package/lib/utils/marker.js +2 -2
- package/lib/utils/marker.js.map +1 -1
- package/lib/utils/treeDataTransform.d.ts +21 -0
- package/lib/utils/treeDataTransform.js +94 -0
- package/lib/utils/treeDataTransform.js.map +1 -0
- package/package.json +15 -15
- package/src/animation/growInX.ts +1 -1
- package/src/animation/growInY.ts +1 -1
- package/src/animation/morphing.ts +7 -5
- package/src/animation/scaleInY.ts +2 -5
- package/src/animation/waveIn.ts +2 -1
- package/src/api/utils.ts +6 -3
- package/src/component/title.ts +4 -0
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +8 -0
- package/src/interaction/scrollbarFilter.ts +4 -0
- package/src/interaction/sliderFilter.ts +21 -1
- package/src/interaction/tooltip.ts +3 -3
- package/src/interaction/treemapDrillDown.ts +282 -0
- package/src/interaction/utils.ts +8 -5
- package/src/lib/core.ts +2 -0
- package/src/mark/chord.ts +0 -1
- package/src/mark/gauge.ts +5 -1
- package/src/mark/sankey.ts +1 -1
- package/src/mark/treemap.ts +76 -123
- package/src/mark/utils.ts +0 -17
- package/src/runtime/plot.ts +82 -44
- package/src/runtime/types/common.ts +5 -1
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/gauge/round.ts +57 -0
- package/src/shape/image/image.ts +1 -1
- package/src/shape/index.ts +1 -0
- package/src/shape/interval/color.ts +1 -1
- package/src/shape/interval/funnel.ts +1 -1
- package/src/shape/label/position/default.ts +9 -9
- package/src/shape/lineXY/line.ts +1 -2
- package/src/shape/liquid/liquid.ts +4 -4
- package/src/shape/liquid/wave.ts +1 -1
- package/src/shape/point/color.ts +1 -0
- package/src/shape/text/advance.ts +3 -1
- package/src/shape/utils.ts +3 -2
- package/src/theme/create.ts +2 -2
- package/src/utils/marker.ts +2 -11
- package/src/utils/treeDataTransform.ts +153 -0
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
|
-
import { deepMix,
|
|
4
|
-
import { group, groups
|
|
3
|
+
import { deepMix, upperFirst, isArray } from '@antv/util';
|
|
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';
|
|
@@ -90,6 +90,8 @@ import {
|
|
|
90
90
|
G2ViewTree,
|
|
91
91
|
} from './types/options';
|
|
92
92
|
|
|
93
|
+
type Store = Map<any, (options: G2ViewTree) => G2ViewTree>;
|
|
94
|
+
|
|
93
95
|
export async function plot<T extends G2ViewTree>(
|
|
94
96
|
options: T,
|
|
95
97
|
selection: Selection,
|
|
@@ -242,12 +244,19 @@ export async function plot<T extends G2ViewTree>(
|
|
|
242
244
|
// Apply interactions.
|
|
243
245
|
const viewInstanceof = (
|
|
244
246
|
viewContainer: Map<G2ViewDescriptor, DisplayObject>,
|
|
247
|
+
updateInteractions?: (
|
|
248
|
+
container: Map<G2ViewDescriptor, DisplayObject>,
|
|
249
|
+
updateTypes?: string[],
|
|
250
|
+
store?: Store,
|
|
251
|
+
) => void,
|
|
252
|
+
oldStore?: Store,
|
|
245
253
|
) => {
|
|
246
254
|
return Array.from(viewContainer.entries()).map(([view, container]) => {
|
|
247
255
|
// Index state by component or interaction name,
|
|
248
256
|
// such as legend, scrollbar, brushFilter.
|
|
249
257
|
// Each state transform options to another options.
|
|
250
|
-
const store =
|
|
258
|
+
const store =
|
|
259
|
+
oldStore || new Map<any, (options: G2ViewTree) => G2ViewTree>();
|
|
251
260
|
const setState = (key, reducer = (x) => x) => store.set(key, reducer);
|
|
252
261
|
const options = viewNode.get(view);
|
|
253
262
|
const update = createUpdateView(
|
|
@@ -261,18 +270,68 @@ export async function plot<T extends G2ViewTree>(
|
|
|
261
270
|
container,
|
|
262
271
|
options,
|
|
263
272
|
setState,
|
|
264
|
-
update: async (from) => {
|
|
273
|
+
update: async (from, updateTypes) => {
|
|
265
274
|
// Apply all state functions to get new options.
|
|
266
275
|
const reducer = compose(Array.from(store.values()));
|
|
267
276
|
const newOptions = reducer(options);
|
|
268
|
-
return await update(newOptions, from)
|
|
277
|
+
return await update(newOptions, from, () => {
|
|
278
|
+
if (isArray(updateTypes)) {
|
|
279
|
+
updateInteractions(viewContainer, updateTypes, store);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
269
282
|
},
|
|
270
283
|
};
|
|
271
284
|
});
|
|
272
285
|
};
|
|
273
286
|
|
|
287
|
+
const updateInteractions = (
|
|
288
|
+
container = updateContainer,
|
|
289
|
+
updateType?: string[],
|
|
290
|
+
oldStore?: Map<any, (options: G2ViewTree) => G2ViewTree>,
|
|
291
|
+
) => {
|
|
292
|
+
// Interactions for update views.
|
|
293
|
+
const updateViewInstances = viewInstanceof(
|
|
294
|
+
container,
|
|
295
|
+
updateInteractions,
|
|
296
|
+
oldStore,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
for (const target of updateViewInstances) {
|
|
300
|
+
const { options, container } = target;
|
|
301
|
+
const nameInteraction = container['nameInteraction'];
|
|
302
|
+
let typeOptions = inferInteraction(options);
|
|
303
|
+
|
|
304
|
+
if (updateType) {
|
|
305
|
+
typeOptions = typeOptions.filter((v) => updateType.includes(v[0]));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
for (const typeOption of typeOptions) {
|
|
309
|
+
const [type, option] = typeOption;
|
|
310
|
+
// Remove interaction for existed views.
|
|
311
|
+
const prevInteraction = nameInteraction.get(type);
|
|
312
|
+
if (prevInteraction) prevInteraction.destroy?.();
|
|
313
|
+
|
|
314
|
+
// Apply new interaction.
|
|
315
|
+
if (option) {
|
|
316
|
+
const interaction = useThemeInteraction(
|
|
317
|
+
target.view,
|
|
318
|
+
type,
|
|
319
|
+
option as Record<string, any>,
|
|
320
|
+
useInteraction,
|
|
321
|
+
);
|
|
322
|
+
const destroy = interaction(
|
|
323
|
+
target,
|
|
324
|
+
updateViewInstances,
|
|
325
|
+
context.emitter,
|
|
326
|
+
);
|
|
327
|
+
nameInteraction.set(type, { destroy });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
274
333
|
// Interactions for enter views.
|
|
275
|
-
const enterViewInstances = viewInstanceof(enterContainer);
|
|
334
|
+
const enterViewInstances = viewInstanceof(enterContainer, updateInteractions);
|
|
276
335
|
for (const target of enterViewInstances) {
|
|
277
336
|
const { options } = target;
|
|
278
337
|
|
|
@@ -300,35 +359,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
300
359
|
}
|
|
301
360
|
}
|
|
302
361
|
|
|
303
|
-
|
|
304
|
-
const updateViewInstances = viewInstanceof(updateContainer);
|
|
305
|
-
for (const target of updateViewInstances) {
|
|
306
|
-
const { options, container } = target;
|
|
307
|
-
const nameInteraction = container['nameInteraction'];
|
|
308
|
-
for (const typeOption of inferInteraction(options)) {
|
|
309
|
-
const [type, option] = typeOption;
|
|
310
|
-
|
|
311
|
-
// Remove interaction for existed views.
|
|
312
|
-
const prevInteraction = nameInteraction.get(type);
|
|
313
|
-
if (prevInteraction) prevInteraction.destroy?.();
|
|
314
|
-
|
|
315
|
-
// Apply new interaction.
|
|
316
|
-
if (option) {
|
|
317
|
-
const interaction = useThemeInteraction(
|
|
318
|
-
target.view,
|
|
319
|
-
type,
|
|
320
|
-
option as Record<string, any>,
|
|
321
|
-
useInteraction,
|
|
322
|
-
);
|
|
323
|
-
const destroy = interaction(
|
|
324
|
-
target,
|
|
325
|
-
updateViewInstances,
|
|
326
|
-
context.emitter,
|
|
327
|
-
);
|
|
328
|
-
nameInteraction.set(type, { destroy });
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
362
|
+
updateInteractions();
|
|
332
363
|
|
|
333
364
|
// Author animations.
|
|
334
365
|
const { width, height } = options;
|
|
@@ -403,7 +434,7 @@ function createUpdateView(
|
|
|
403
434
|
.filter(filter)
|
|
404
435
|
.map((d) => d[0]);
|
|
405
436
|
|
|
406
|
-
return async (newOptions, source) => {
|
|
437
|
+
return async (newOptions, source, callback) => {
|
|
407
438
|
const transitions = [];
|
|
408
439
|
const [newView, newChildren] = await initializeView(newOptions, library);
|
|
409
440
|
plotView(newView, selection, transitions, library, context);
|
|
@@ -416,7 +447,7 @@ function createUpdateView(
|
|
|
416
447
|
for (const child of newChildren) {
|
|
417
448
|
plot(child, selection, library, context);
|
|
418
449
|
}
|
|
419
|
-
|
|
450
|
+
callback();
|
|
420
451
|
return { options: newOptions, view: newView };
|
|
421
452
|
};
|
|
422
453
|
}
|
|
@@ -1663,8 +1694,15 @@ async function applyTransform<T extends G2ViewTree>(
|
|
|
1663
1694
|
|
|
1664
1695
|
function updateBBox(selection: Selection) {
|
|
1665
1696
|
selection
|
|
1666
|
-
.style(
|
|
1667
|
-
|
|
1697
|
+
.style(
|
|
1698
|
+
'transform',
|
|
1699
|
+
(d) =>
|
|
1700
|
+
`translate(${d.paddingLeft + d.marginLeft}, ${
|
|
1701
|
+
d.paddingTop + d.marginTop
|
|
1702
|
+
})`,
|
|
1703
|
+
)
|
|
1704
|
+
// .style('x', (d) => d.paddingLeft + d.marginLeft)
|
|
1705
|
+
// .style('y', (d) => d.paddingTop + d.marginTop)
|
|
1668
1706
|
.style('width', (d) => d.innerWidth)
|
|
1669
1707
|
.style('height', (d) => d.innerHeight);
|
|
1670
1708
|
}
|
|
@@ -1672,7 +1710,7 @@ function updateBBox(selection: Selection) {
|
|
|
1672
1710
|
function animateBBox(selection: Selection, extent: [number, number]) {
|
|
1673
1711
|
const [delay, duration] = extent;
|
|
1674
1712
|
selection.transition(function (data, i, element) {
|
|
1675
|
-
const {
|
|
1713
|
+
const { transform, width, height } = element.style;
|
|
1676
1714
|
const {
|
|
1677
1715
|
paddingLeft,
|
|
1678
1716
|
paddingTop,
|
|
@@ -1683,14 +1721,14 @@ function animateBBox(selection: Selection, extent: [number, number]) {
|
|
|
1683
1721
|
} = data;
|
|
1684
1722
|
const keyframes = [
|
|
1685
1723
|
{
|
|
1686
|
-
|
|
1687
|
-
y,
|
|
1724
|
+
transform,
|
|
1688
1725
|
width,
|
|
1689
1726
|
height,
|
|
1690
1727
|
},
|
|
1691
1728
|
{
|
|
1692
|
-
|
|
1693
|
-
|
|
1729
|
+
transform: `translate(${paddingLeft + marginLeft}, ${
|
|
1730
|
+
paddingTop + marginTop
|
|
1731
|
+
})`,
|
|
1694
1732
|
width: innerWidth,
|
|
1695
1733
|
height: innerHeight,
|
|
1696
1734
|
},
|
|
@@ -53,7 +53,11 @@ export type G2ViewInstance = {
|
|
|
53
53
|
view: G2ViewDescriptor;
|
|
54
54
|
container: DisplayObject;
|
|
55
55
|
options: G2ViewTree;
|
|
56
|
-
update: (
|
|
56
|
+
update: (
|
|
57
|
+
options: G2ViewTree,
|
|
58
|
+
source?: string | string[],
|
|
59
|
+
callback?: any,
|
|
60
|
+
) => Promise<any>;
|
|
57
61
|
};
|
|
58
62
|
|
|
59
63
|
export type ChannelGroups = {
|
|
@@ -89,7 +89,7 @@ export const Connector: SC<ConnectorOptions> = (options, context) => {
|
|
|
89
89
|
|
|
90
90
|
return select(new Path())
|
|
91
91
|
.call(applyStyle, rest)
|
|
92
|
-
.style('
|
|
92
|
+
.style('d', inferConnectorPath(P))
|
|
93
93
|
.style('stroke', color || defaultColor)
|
|
94
94
|
.style('transform', transform)
|
|
95
95
|
.style(
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { omit } from '@antv/util';
|
|
2
|
+
import type { Vector2, ShapeComponent as SC } from '../../runtime';
|
|
3
|
+
|
|
4
|
+
export type RoundOptions = Record<string, any>;
|
|
5
|
+
|
|
6
|
+
// Get point1 point2 radius.
|
|
7
|
+
const getR = (point1, point2) => {
|
|
8
|
+
return (
|
|
9
|
+
Math.sqrt(
|
|
10
|
+
Math.pow(point1[0] - point2[0], 2) + Math.pow(point1[1] - point2[1], 2),
|
|
11
|
+
) / 2
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Gauge round.
|
|
16
|
+
export const Round: SC<RoundOptions> = (options, context) => {
|
|
17
|
+
if (!context) return;
|
|
18
|
+
const { coordinate } = context;
|
|
19
|
+
if (!coordinate?.getCenter) return;
|
|
20
|
+
// Get coordinate center point.
|
|
21
|
+
const center = coordinate.getCenter() as Vector2;
|
|
22
|
+
|
|
23
|
+
return (points, cfg, defaultCfg) => {
|
|
24
|
+
const { document } = context.canvas;
|
|
25
|
+
const { color, index } = cfg;
|
|
26
|
+
|
|
27
|
+
const g = document.createElement('g', {});
|
|
28
|
+
|
|
29
|
+
const minR = getR(points[0], points[1]);
|
|
30
|
+
const maxR = getR(points[0], center) * 2;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* MinR small circle radius, maxR big circle radius.
|
|
34
|
+
* Draw four arcs.
|
|
35
|
+
* Style lineWidth and stroke for the time being inset.
|
|
36
|
+
*/
|
|
37
|
+
const roundPath = document.createElement('path', {
|
|
38
|
+
style: {
|
|
39
|
+
d: [
|
|
40
|
+
['M', ...points[0]],
|
|
41
|
+
['A', minR, minR, 0, 1, 0, ...points[1]],
|
|
42
|
+
['A', maxR + minR * 2, maxR + minR * 2, 0, 0, 0, ...points[2]],
|
|
43
|
+
['A', minR, minR, 0, 1, index === 0 ? 0 : 1, ...points[3]],
|
|
44
|
+
['A', maxR, maxR, 0, 0, 1, ...points[0]],
|
|
45
|
+
['Z'],
|
|
46
|
+
],
|
|
47
|
+
...defaultCfg,
|
|
48
|
+
...omit(options, ['shape', 'last', 'first']),
|
|
49
|
+
fill: color || defaultCfg.color,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
g.appendChild(roundPath);
|
|
54
|
+
|
|
55
|
+
return g;
|
|
56
|
+
};
|
|
57
|
+
};
|
package/src/shape/image/image.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const Image: SC<ImageOptions> = (options, context) => {
|
|
|
25
25
|
.call(applyStyle, rest)
|
|
26
26
|
.style('x', x)
|
|
27
27
|
.style('y', y)
|
|
28
|
-
.style('
|
|
28
|
+
.style('src', src)
|
|
29
29
|
.style('stroke', color)
|
|
30
30
|
.style('transform', transform)
|
|
31
31
|
.call(applyStyle, options)
|
package/src/shape/index.ts
CHANGED
|
@@ -58,6 +58,7 @@ export { Rect as RectShape } from './interval/rect';
|
|
|
58
58
|
export { Hollow as RectHollow } from './interval/hollow';
|
|
59
59
|
export { Shape as ShapeShape } from './shape/shape';
|
|
60
60
|
export { Liquid as LiquidShape } from './liquid/liquid';
|
|
61
|
+
export { Round as GaugeRound } from './gauge/round';
|
|
61
62
|
|
|
62
63
|
export type { RectOptions as IntervalShapeOptions } from './interval/rect';
|
|
63
64
|
export type { HollowOptions as IntervalHollowOptions } from './interval/hollow';
|
|
@@ -101,7 +101,7 @@ export function rect(
|
|
|
101
101
|
.padAngle((inset * Math.PI) / 180);
|
|
102
102
|
|
|
103
103
|
return select(document.createElement('path', {}))
|
|
104
|
-
.style('
|
|
104
|
+
.style('d', path(arcObject))
|
|
105
105
|
.style('transform', `translate(${center[0]}, ${center[1]})`)
|
|
106
106
|
.style('radius', radius)
|
|
107
107
|
.style('inset', inset)
|
|
@@ -51,7 +51,7 @@ export const Funnel: SC<FunnelOptions> = (options, context) => {
|
|
|
51
51
|
const b = line().curve(curveLinearClosed)([p0, p1, p2, p3]);
|
|
52
52
|
return select(document.createElement('path', {}))
|
|
53
53
|
.call(applyStyle, rest)
|
|
54
|
-
.style('
|
|
54
|
+
.style('d', b)
|
|
55
55
|
.style('fill', color)
|
|
56
56
|
.style('fillOpacity', opacity)
|
|
57
57
|
.call(applyStyle, style)
|
|
@@ -42,27 +42,27 @@ export function inferNonCircularStyle(
|
|
|
42
42
|
};
|
|
43
43
|
// 4 direction.
|
|
44
44
|
if (position === 'left')
|
|
45
|
-
return xy({ x: 0, y: h / 2,
|
|
45
|
+
return xy({ x: 0, y: h / 2, textAlign: 'start', textBaseline: 'middle' });
|
|
46
46
|
if (position === 'right')
|
|
47
|
-
return xy({ x: w, y: h / 2,
|
|
47
|
+
return xy({ x: w, y: h / 2, textAlign: 'end', textBaseline: 'middle' });
|
|
48
48
|
if (position === 'top')
|
|
49
|
-
return xy({ x: w / 2, y: 0,
|
|
49
|
+
return xy({ x: w / 2, y: 0, textAlign: 'center', textBaseline: 'top' });
|
|
50
50
|
if (position === 'bottom')
|
|
51
|
-
return xy({ x: w / 2, y: h,
|
|
51
|
+
return xy({ x: w / 2, y: h, textAlign: 'center', textBaseline: 'bottom' });
|
|
52
52
|
// 4 corner position.
|
|
53
53
|
if (position === 'top-left')
|
|
54
|
-
return xy({ x: 0, y: 0,
|
|
54
|
+
return xy({ x: 0, y: 0, textAlign: 'start', textBaseline: 'top' });
|
|
55
55
|
if (position === 'top-right')
|
|
56
|
-
return xy({ x: w, y: 0,
|
|
56
|
+
return xy({ x: w, y: 0, textAlign: 'end', textBaseline: 'top' });
|
|
57
57
|
if (position === 'bottom-left')
|
|
58
|
-
return xy({ x: 0, y: h,
|
|
58
|
+
return xy({ x: 0, y: h, textAlign: 'start', textBaseline: 'bottom' });
|
|
59
59
|
if (position === 'bottom-right')
|
|
60
|
-
return xy({ x: w, y: h,
|
|
60
|
+
return xy({ x: w, y: h, textAlign: 'end', textBaseline: 'bottom' });
|
|
61
61
|
// default return 'inside'
|
|
62
62
|
return xy({
|
|
63
63
|
x: w / 2,
|
|
64
64
|
y: h / 2,
|
|
65
|
-
|
|
65
|
+
textAlign: 'center',
|
|
66
66
|
textBaseline: 'middle',
|
|
67
67
|
});
|
|
68
68
|
}
|
package/src/shape/lineXY/line.ts
CHANGED
|
@@ -38,8 +38,7 @@ function getArrowMarker(
|
|
|
38
38
|
) {
|
|
39
39
|
const arrowMarker = document.createElement('path', {
|
|
40
40
|
style: {
|
|
41
|
-
|
|
42
|
-
anchor: '0.5 0.5',
|
|
41
|
+
d: `M ${arrowSize},${arrowSize} L -${arrowSize},0 L ${arrowSize},-${arrowSize} L 0,0 Z`,
|
|
43
42
|
transformOrigin: 'center',
|
|
44
43
|
...arrowStyle,
|
|
45
44
|
},
|
|
@@ -46,7 +46,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
46
46
|
if (Object.keys(backgroundStyle).length) {
|
|
47
47
|
const backgroundShape = document.createElement('path', {
|
|
48
48
|
style: {
|
|
49
|
-
|
|
49
|
+
d: shapePath,
|
|
50
50
|
fill: '#fff',
|
|
51
51
|
...backgroundStyle,
|
|
52
52
|
},
|
|
@@ -60,7 +60,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
60
60
|
// 3. Clip create.
|
|
61
61
|
const clipShape = document.createElement('path', {
|
|
62
62
|
style: {
|
|
63
|
-
|
|
63
|
+
d: shapePath,
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
66
|
|
|
@@ -86,7 +86,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
86
86
|
// 5. Draw distance.
|
|
87
87
|
const distanceShape = document.createElement('path', {
|
|
88
88
|
style: {
|
|
89
|
-
|
|
89
|
+
d: shapePath,
|
|
90
90
|
fill: 'transparent',
|
|
91
91
|
lineWidth: border + 2 * distance,
|
|
92
92
|
stroke: '#fff',
|
|
@@ -96,7 +96,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
96
96
|
// 6. Draw border.
|
|
97
97
|
const borderShape = document.createElement('path', {
|
|
98
98
|
style: {
|
|
99
|
-
|
|
99
|
+
d: shapePath,
|
|
100
100
|
stroke: color,
|
|
101
101
|
strokeOpacity: fillOpacity,
|
|
102
102
|
lineWidth: border,
|
package/src/shape/liquid/wave.ts
CHANGED
package/src/shape/point/color.ts
CHANGED
|
@@ -51,6 +51,7 @@ export const Color: SC<ColorOptions> = (options, context) => {
|
|
|
51
51
|
.style('d', path(cx, cy, finalRadius))
|
|
52
52
|
.style('lineWidth', finalLineWidth)
|
|
53
53
|
.style('transform', transform)
|
|
54
|
+
.style('transformOrigin', `${cx - finalRadius} ${cy - finalRadius}`)
|
|
54
55
|
.style('stroke', color)
|
|
55
56
|
.style(toOpacityKey(options), opacity)
|
|
56
57
|
.style(colorAttribute, color)
|
|
@@ -151,6 +151,8 @@ export const Advance = createElement((g) => {
|
|
|
151
151
|
...rest
|
|
152
152
|
} = g.attributes as TextShapeStyleProps;
|
|
153
153
|
|
|
154
|
+
g.style.transform = `translate(${x}, ${y})`;
|
|
155
|
+
|
|
154
156
|
// Position is invalid, do not render the UI,
|
|
155
157
|
// or clear previous elements.
|
|
156
158
|
if ([x, y, x0, y0].some((v) => !isNumber(v))) {
|
|
@@ -220,7 +222,7 @@ export const Advance = createElement((g) => {
|
|
|
220
222
|
select(g)
|
|
221
223
|
.maybeAppend('connector', 'path')
|
|
222
224
|
.style('zIndex', 0)
|
|
223
|
-
.style('
|
|
225
|
+
.style('d', connectorPath)
|
|
224
226
|
.style('markerStart', markerStart)
|
|
225
227
|
.style('markerEnd', markerEnd)
|
|
226
228
|
.call(applyStyle, connector ? connectorStyle : {});
|
package/src/shape/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Coordinate } from '@antv/coord';
|
|
2
2
|
import { Linear } from '@antv/scale';
|
|
3
|
-
import { lowerFirst } from '@antv/util';
|
|
3
|
+
import { isNumber, lowerFirst } from '@antv/util';
|
|
4
4
|
import { extent } from 'd3-array';
|
|
5
5
|
import { Path as D3Path } from 'd3-path';
|
|
6
6
|
import { Primitive, Vector2, Vector3 } from '../runtime';
|
|
@@ -148,7 +148,8 @@ export function computeGradient(
|
|
|
148
148
|
range: [0, 100],
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
const percentage = (i) =>
|
|
151
|
+
const percentage = (i) =>
|
|
152
|
+
isNumber(P[i]) && !Number.isNaN(P[i]) ? p.map(P[i]) : 0;
|
|
152
153
|
|
|
153
154
|
const gradientMode = {
|
|
154
155
|
// Interpolate the colors for this segment.
|
package/src/theme/create.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function create({
|
|
|
139
139
|
text: {
|
|
140
140
|
fill: '#1D2129',
|
|
141
141
|
fontSize: 12,
|
|
142
|
-
|
|
142
|
+
lineWidth: 0,
|
|
143
143
|
connectorStroke: colorStroke,
|
|
144
144
|
connectorStrokeOpacity: 0.45,
|
|
145
145
|
connectorLineWidth: 1,
|
|
@@ -154,7 +154,7 @@ export function create({
|
|
|
154
154
|
badge: {
|
|
155
155
|
fill: '#1D2129',
|
|
156
156
|
fillOpacity: 0.65,
|
|
157
|
-
|
|
157
|
+
lineWidth: 0,
|
|
158
158
|
fontSize: 10,
|
|
159
159
|
textAlign: 'center',
|
|
160
160
|
textBaseline: 'middle',
|
package/src/utils/marker.ts
CHANGED
|
@@ -255,23 +255,14 @@ export const Symbols = new Map<string, SymbolFactor>([
|
|
|
255
255
|
|
|
256
256
|
export function useMarker(
|
|
257
257
|
type: string,
|
|
258
|
-
{
|
|
259
|
-
d,
|
|
260
|
-
fill,
|
|
261
|
-
strokeWidth,
|
|
262
|
-
path,
|
|
263
|
-
stroke,
|
|
264
|
-
lineWidth,
|
|
265
|
-
color,
|
|
266
|
-
...style
|
|
267
|
-
}: Record<string, any>,
|
|
258
|
+
{ d, fill, lineWidth, path, stroke, color, ...style }: Record<string, any>,
|
|
268
259
|
) {
|
|
269
260
|
const symbol = Symbols.get(type) || Symbols.get('point');
|
|
270
261
|
return (...args: Parameters<SymbolFactor>) => {
|
|
271
262
|
const path = new Path({
|
|
272
263
|
style: {
|
|
273
264
|
...style,
|
|
274
|
-
|
|
265
|
+
d: symbol(...args),
|
|
275
266
|
stroke: symbol.style.includes('stroke') ? color || stroke : '',
|
|
276
267
|
fill: symbol.style.includes('fill') ? color || fill : '',
|
|
277
268
|
lineWidth: symbol.style.includes('lineWidth')
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { isArray, get } from '@antv/util';
|
|
2
|
+
import {
|
|
3
|
+
stratify,
|
|
4
|
+
hierarchy,
|
|
5
|
+
treemap as treemapLayout,
|
|
6
|
+
treemapBinary,
|
|
7
|
+
treemapDice,
|
|
8
|
+
treemapSlice,
|
|
9
|
+
treemapSliceDice,
|
|
10
|
+
treemapSquarify,
|
|
11
|
+
treemapResquarify,
|
|
12
|
+
} from 'd3-hierarchy';
|
|
13
|
+
import type { Node } from 'd3-hierarchy';
|
|
14
|
+
import { field } from '../mark/utils';
|
|
15
|
+
|
|
16
|
+
type Layout = {
|
|
17
|
+
tile?:
|
|
18
|
+
| 'treemapBinary'
|
|
19
|
+
| 'treemapDice'
|
|
20
|
+
| 'treemapSlice'
|
|
21
|
+
| 'treemapSliceDice'
|
|
22
|
+
| 'treemapSquarify'
|
|
23
|
+
| 'treemapResquarify';
|
|
24
|
+
size?: [number, number];
|
|
25
|
+
round?: boolean;
|
|
26
|
+
// Ignore the value of the parent node when calculating the total value.
|
|
27
|
+
ignoreParentValue?: boolean;
|
|
28
|
+
ratio?: number;
|
|
29
|
+
padding?: number;
|
|
30
|
+
paddingInner?: number;
|
|
31
|
+
paddingOuter?: number;
|
|
32
|
+
paddingTop?: number;
|
|
33
|
+
paddingRight?: number;
|
|
34
|
+
paddingBottom?: number;
|
|
35
|
+
paddingLeft?: number;
|
|
36
|
+
sort?(a: any, b: any): number;
|
|
37
|
+
path?: (d: any) => any;
|
|
38
|
+
/** The granularity of Display layer. */
|
|
39
|
+
layer?: number | ((d: any) => any);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description Path need when the data is a flat json structure,
|
|
44
|
+
* and the tree object structure do not need.
|
|
45
|
+
*/
|
|
46
|
+
function generateHierarchyRoot(
|
|
47
|
+
data: any[] | Record<string, any>,
|
|
48
|
+
path: (d: any) => any,
|
|
49
|
+
): Node {
|
|
50
|
+
if (Array.isArray(data)) {
|
|
51
|
+
return typeof path === 'function'
|
|
52
|
+
? stratify().path(path)(data)
|
|
53
|
+
: stratify()(data);
|
|
54
|
+
}
|
|
55
|
+
return hierarchy(data);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function addObjectDataPath(root: Node, path = [root.data.name]) {
|
|
59
|
+
root.id = root.id || root.data.name;
|
|
60
|
+
root.path = path;
|
|
61
|
+
|
|
62
|
+
if (root.children) {
|
|
63
|
+
root.children.forEach((item) => {
|
|
64
|
+
item.id = `${root.id}/${item.data.name}`;
|
|
65
|
+
item.path = [...path, item.data.name];
|
|
66
|
+
addObjectDataPath(item, item.path);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function addArrayDataPath(root: Node) {
|
|
72
|
+
const name = get(root, ['data', 'name']);
|
|
73
|
+
if (name.replaceAll) {
|
|
74
|
+
root.path = name.replaceAll('.', '/').split('/');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (root.children) {
|
|
78
|
+
root.children.forEach((item) => {
|
|
79
|
+
addArrayDataPath(item);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getTileMethod(tile: string, ratio: number) {
|
|
85
|
+
const tiles = {
|
|
86
|
+
treemapBinary,
|
|
87
|
+
treemapDice,
|
|
88
|
+
treemapSlice,
|
|
89
|
+
treemapSliceDice,
|
|
90
|
+
treemapSquarify,
|
|
91
|
+
treemapResquarify,
|
|
92
|
+
};
|
|
93
|
+
const tileMethod =
|
|
94
|
+
tile === 'treemapSquarify' ? tiles[tile].ratio(ratio) : tiles[tile];
|
|
95
|
+
if (!tileMethod) {
|
|
96
|
+
throw new TypeError('Invalid tile method!');
|
|
97
|
+
}
|
|
98
|
+
return tileMethod;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function treeDataTransform(
|
|
102
|
+
data,
|
|
103
|
+
layout: Layout,
|
|
104
|
+
encode,
|
|
105
|
+
): [Node[], Node[]] {
|
|
106
|
+
const { value } = encode;
|
|
107
|
+
const tileMethod = getTileMethod(layout.tile, layout.ratio);
|
|
108
|
+
|
|
109
|
+
const root = generateHierarchyRoot(data, layout.path);
|
|
110
|
+
|
|
111
|
+
if (isArray(data)) {
|
|
112
|
+
addArrayDataPath(root);
|
|
113
|
+
} else {
|
|
114
|
+
addObjectDataPath(root);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Calculate the value and sort.
|
|
118
|
+
value
|
|
119
|
+
? root
|
|
120
|
+
.sum((d) =>
|
|
121
|
+
layout.ignoreParentValue && d.children ? 0 : field(value)(d),
|
|
122
|
+
)
|
|
123
|
+
.sort(layout.sort)
|
|
124
|
+
: root.count();
|
|
125
|
+
|
|
126
|
+
treemapLayout()
|
|
127
|
+
.tile(tileMethod)
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
.size(layout.size)
|
|
130
|
+
.round(layout.round)
|
|
131
|
+
.paddingInner(layout.paddingInner)
|
|
132
|
+
.paddingOuter(layout.paddingOuter)
|
|
133
|
+
.paddingTop(layout.paddingTop)
|
|
134
|
+
.paddingRight(layout.paddingRight)
|
|
135
|
+
.paddingBottom(layout.paddingBottom)
|
|
136
|
+
.paddingLeft(layout.paddingLeft)(root);
|
|
137
|
+
|
|
138
|
+
const nodes = root.descendants().map((d) =>
|
|
139
|
+
Object.assign(d, {
|
|
140
|
+
id: d.id.replace(/^\//, ''),
|
|
141
|
+
x: [d.x0, d.x1],
|
|
142
|
+
y: [d.y0, d.y1],
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const filterData = nodes.filter(
|
|
147
|
+
typeof layout.layer === 'function'
|
|
148
|
+
? layout.layer
|
|
149
|
+
: (d) => d.height === layout.layer,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return [filterData, nodes];
|
|
153
|
+
}
|