@antv/g2 5.1.13 → 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 +27 -15
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +13 -7
- package/esm/component/axis.js.map +1 -1
- package/esm/component/title.js +2 -1
- package/esm/component/title.js.map +1 -1
- package/esm/coordinate/polar.d.ts +1 -1
- package/esm/coordinate/polar.js +3 -1
- package/esm/coordinate/polar.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/event.js +15 -3
- package/esm/interaction/event.js.map +1 -1
- 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 +52 -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/angle.d.ts +4 -0
- package/esm/utils/angle.js +18 -0
- package/esm/utils/angle.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 +27 -15
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +13 -7
- package/lib/component/axis.js.map +1 -1
- package/lib/component/title.js +2 -1
- package/lib/component/title.js.map +1 -1
- package/lib/coordinate/polar.d.ts +1 -1
- package/lib/coordinate/polar.js +3 -1
- package/lib/coordinate/polar.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/event.js +15 -3
- package/lib/interaction/event.js.map +1 -1
- 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 +51 -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/angle.d.ts +4 -0
- package/lib/utils/angle.js +20 -1
- package/lib/utils/angle.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 +41 -13
- package/src/component/axis.ts +17 -10
- package/src/component/title.ts +4 -0
- package/src/coordinate/polar.ts +6 -1
- package/src/interaction/event.ts +20 -7
- 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 +93 -45
- 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/angle.ts +22 -0
- 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, upperFirst } from '@antv/util';
|
|
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';
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
InteractionComponent,
|
|
67
67
|
LabelTransform,
|
|
68
68
|
LabelTransformComponent,
|
|
69
|
+
Scale,
|
|
69
70
|
Shape,
|
|
70
71
|
ShapeComponent,
|
|
71
72
|
Theme,
|
|
@@ -89,6 +90,8 @@ import {
|
|
|
89
90
|
G2ViewTree,
|
|
90
91
|
} from './types/options';
|
|
91
92
|
|
|
93
|
+
type Store = Map<any, (options: G2ViewTree) => G2ViewTree>;
|
|
94
|
+
|
|
92
95
|
export async function plot<T extends G2ViewTree>(
|
|
93
96
|
options: T,
|
|
94
97
|
selection: Selection,
|
|
@@ -241,12 +244,19 @@ export async function plot<T extends G2ViewTree>(
|
|
|
241
244
|
// Apply interactions.
|
|
242
245
|
const viewInstanceof = (
|
|
243
246
|
viewContainer: Map<G2ViewDescriptor, DisplayObject>,
|
|
247
|
+
updateInteractions?: (
|
|
248
|
+
container: Map<G2ViewDescriptor, DisplayObject>,
|
|
249
|
+
updateTypes?: string[],
|
|
250
|
+
store?: Store,
|
|
251
|
+
) => void,
|
|
252
|
+
oldStore?: Store,
|
|
244
253
|
) => {
|
|
245
254
|
return Array.from(viewContainer.entries()).map(([view, container]) => {
|
|
246
255
|
// Index state by component or interaction name,
|
|
247
256
|
// such as legend, scrollbar, brushFilter.
|
|
248
257
|
// Each state transform options to another options.
|
|
249
|
-
const store =
|
|
258
|
+
const store =
|
|
259
|
+
oldStore || new Map<any, (options: G2ViewTree) => G2ViewTree>();
|
|
250
260
|
const setState = (key, reducer = (x) => x) => store.set(key, reducer);
|
|
251
261
|
const options = viewNode.get(view);
|
|
252
262
|
const update = createUpdateView(
|
|
@@ -260,18 +270,68 @@ export async function plot<T extends G2ViewTree>(
|
|
|
260
270
|
container,
|
|
261
271
|
options,
|
|
262
272
|
setState,
|
|
263
|
-
update: async (from) => {
|
|
273
|
+
update: async (from, updateTypes) => {
|
|
264
274
|
// Apply all state functions to get new options.
|
|
265
275
|
const reducer = compose(Array.from(store.values()));
|
|
266
276
|
const newOptions = reducer(options);
|
|
267
|
-
return await update(newOptions, from)
|
|
277
|
+
return await update(newOptions, from, () => {
|
|
278
|
+
if (isArray(updateTypes)) {
|
|
279
|
+
updateInteractions(viewContainer, updateTypes, store);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
268
282
|
},
|
|
269
283
|
};
|
|
270
284
|
});
|
|
271
285
|
};
|
|
272
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
|
+
|
|
273
333
|
// Interactions for enter views.
|
|
274
|
-
const enterViewInstances = viewInstanceof(enterContainer);
|
|
334
|
+
const enterViewInstances = viewInstanceof(enterContainer, updateInteractions);
|
|
275
335
|
for (const target of enterViewInstances) {
|
|
276
336
|
const { options } = target;
|
|
277
337
|
|
|
@@ -299,35 +359,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
299
359
|
}
|
|
300
360
|
}
|
|
301
361
|
|
|
302
|
-
|
|
303
|
-
const updateViewInstances = viewInstanceof(updateContainer);
|
|
304
|
-
for (const target of updateViewInstances) {
|
|
305
|
-
const { options, container } = target;
|
|
306
|
-
const nameInteraction = container['nameInteraction'];
|
|
307
|
-
for (const typeOption of inferInteraction(options)) {
|
|
308
|
-
const [type, option] = typeOption;
|
|
309
|
-
|
|
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
|
-
}
|
|
362
|
+
updateInteractions();
|
|
331
363
|
|
|
332
364
|
// Author animations.
|
|
333
365
|
const { width, height } = options;
|
|
@@ -402,7 +434,7 @@ function createUpdateView(
|
|
|
402
434
|
.filter(filter)
|
|
403
435
|
.map((d) => d[0]);
|
|
404
436
|
|
|
405
|
-
return async (newOptions, source) => {
|
|
437
|
+
return async (newOptions, source, callback) => {
|
|
406
438
|
const transitions = [];
|
|
407
439
|
const [newView, newChildren] = await initializeView(newOptions, library);
|
|
408
440
|
plotView(newView, selection, transitions, library, context);
|
|
@@ -415,7 +447,7 @@ function createUpdateView(
|
|
|
415
447
|
for (const child of newChildren) {
|
|
416
448
|
plot(child, selection, library, context);
|
|
417
449
|
}
|
|
418
|
-
|
|
450
|
+
callback();
|
|
419
451
|
return { options: newOptions, view: newView };
|
|
420
452
|
};
|
|
421
453
|
}
|
|
@@ -710,7 +742,7 @@ function initializeState(
|
|
|
710
742
|
processAxisZ(components);
|
|
711
743
|
|
|
712
744
|
// Scale from marks and components.
|
|
713
|
-
const scaleInstance = {};
|
|
745
|
+
const scaleInstance: Record<string, Scale> = {};
|
|
714
746
|
|
|
715
747
|
// Initialize scale from components.
|
|
716
748
|
for (const component of components) {
|
|
@@ -720,8 +752,17 @@ function initializeState(
|
|
|
720
752
|
const { name } = descriptor;
|
|
721
753
|
const scale = useRelationScale(descriptor, library);
|
|
722
754
|
scales.push(scale);
|
|
755
|
+
// Delivery the scale of axisX to the AxisY,
|
|
756
|
+
// in order to calculate the angle of axisY component when rendering radar chart.
|
|
757
|
+
if (name === 'y') {
|
|
758
|
+
scale.update({
|
|
759
|
+
...scale.getOptions(),
|
|
760
|
+
xScale: scaleInstance.x,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
723
763
|
assignScale(scaleInstance, { [name]: scale });
|
|
724
764
|
}
|
|
765
|
+
|
|
725
766
|
component.scaleInstances = scales;
|
|
726
767
|
}
|
|
727
768
|
|
|
@@ -1653,8 +1694,15 @@ async function applyTransform<T extends G2ViewTree>(
|
|
|
1653
1694
|
|
|
1654
1695
|
function updateBBox(selection: Selection) {
|
|
1655
1696
|
selection
|
|
1656
|
-
.style(
|
|
1657
|
-
|
|
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)
|
|
1658
1706
|
.style('width', (d) => d.innerWidth)
|
|
1659
1707
|
.style('height', (d) => d.innerHeight);
|
|
1660
1708
|
}
|
|
@@ -1662,7 +1710,7 @@ function updateBBox(selection: Selection) {
|
|
|
1662
1710
|
function animateBBox(selection: Selection, extent: [number, number]) {
|
|
1663
1711
|
const [delay, duration] = extent;
|
|
1664
1712
|
selection.transition(function (data, i, element) {
|
|
1665
|
-
const {
|
|
1713
|
+
const { transform, width, height } = element.style;
|
|
1666
1714
|
const {
|
|
1667
1715
|
paddingLeft,
|
|
1668
1716
|
paddingTop,
|
|
@@ -1673,14 +1721,14 @@ function animateBBox(selection: Selection, extent: [number, number]) {
|
|
|
1673
1721
|
} = data;
|
|
1674
1722
|
const keyframes = [
|
|
1675
1723
|
{
|
|
1676
|
-
|
|
1677
|
-
y,
|
|
1724
|
+
transform,
|
|
1678
1725
|
width,
|
|
1679
1726
|
height,
|
|
1680
1727
|
},
|
|
1681
1728
|
{
|
|
1682
|
-
|
|
1683
|
-
|
|
1729
|
+
transform: `translate(${paddingLeft + marginLeft}, ${
|
|
1730
|
+
paddingTop + marginTop
|
|
1731
|
+
})`,
|
|
1684
1732
|
width: innerWidth,
|
|
1685
1733
|
height: innerHeight,
|
|
1686
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/angle.ts
CHANGED
|
@@ -5,3 +5,25 @@ export function toRadian(degree: number): number {
|
|
|
5
5
|
export function toDegree(radian: number): number {
|
|
6
6
|
return (radian * 180) / Math.PI;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
// convert the angle to the range of 0 to 4*Math.PI
|
|
10
|
+
export function convertAngles(startAngle: number, endAngle: number) {
|
|
11
|
+
startAngle = startAngle % (2 * Math.PI);
|
|
12
|
+
endAngle = endAngle % (2 * Math.PI);
|
|
13
|
+
|
|
14
|
+
if (startAngle < 0) {
|
|
15
|
+
startAngle = 2 * Math.PI + startAngle;
|
|
16
|
+
}
|
|
17
|
+
if (endAngle < 0) {
|
|
18
|
+
endAngle = 2 * Math.PI + endAngle;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (startAngle >= endAngle) {
|
|
22
|
+
endAngle = endAngle + 2 * Math.PI;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
startAngle,
|
|
27
|
+
endAngle,
|
|
28
|
+
};
|
|
29
|
+
}
|
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')
|