@antv/g2 5.0.6 → 5.0.8
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 +4 -7
- package/esm/api/chart.js +22 -90
- package/esm/api/chart.js.map +1 -1
- package/esm/api/mark/index.d.ts +3 -1
- package/esm/api/mark/index.js +2 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +7 -1
- package/esm/api/mark/mark.js +9 -0
- package/esm/api/mark/mark.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 +17 -19
- 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/composition/mark.js +2 -1
- package/esm/composition/mark.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/kde.d.ts +10 -0
- package/esm/data/kde.js +30 -0
- package/esm/data/kde.js.map +1 -0
- package/esm/interaction/brushFilter.js +2 -6
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -2
- package/esm/interaction/brushHighlight.js +202 -28
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -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/density.d.ts +4 -0
- package/esm/mark/density.js +61 -0
- package/esm/mark/density.js.map +1 -0
- 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/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/runtime/component.d.ts +4 -2
- package/esm/runtime/component.js +164 -12
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.d.ts +3 -3
- package/esm/runtime/layout.js +40 -21
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +10 -7
- 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/box/violin.d.ts +3 -0
- package/esm/shape/box/violin.js +85 -0
- package/esm/shape/box/violin.js.map +1 -0
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/density/density.d.ts +8 -0
- package/esm/shape/density/density.js +50 -0
- package/esm/shape/density/density.js.map +1 -0
- package/esm/shape/index.d.ts +4 -0
- package/esm/shape/index.js +2 -0
- package/esm/shape/index.js.map +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/composition.d.ts +22 -19
- package/esm/spec/dataTransform.d.ts +34 -2
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/spec/mark.d.ts +9 -8
- package/esm/spec/transform.d.ts +1 -1
- package/esm/spec/utils.d.ts +1 -0
- package/esm/stdlib/index.js +5 -5
- package/esm/stdlib/index.js.map +1 -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.js +5 -1
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/size.js +7 -4
- package/esm/utils/size.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 +4 -7
- package/lib/api/chart.js +27 -97
- package/lib/api/chart.js.map +1 -1
- package/lib/api/mark/index.d.ts +3 -1
- package/lib/api/mark/index.js +1 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +7 -1
- package/lib/api/mark/mark.js +10 -1
- package/lib/api/mark/mark.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 +17 -19
- 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/composition/mark.js +2 -1
- package/lib/composition/mark.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/kde.d.ts +10 -0
- package/lib/data/kde.js +38 -0
- package/lib/data/kde.js.map +1 -0
- package/lib/interaction/brushFilter.js +2 -6
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -2
- package/lib/interaction/brushHighlight.js +201 -27
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -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/density.d.ts +4 -0
- package/lib/mark/density.js +65 -0
- package/lib/mark/density.js.map +1 -0
- 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/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/runtime/component.d.ts +4 -2
- package/lib/runtime/component.js +163 -10
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.d.ts +3 -3
- package/lib/runtime/layout.js +40 -21
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +10 -7
- 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/box/violin.d.ts +3 -0
- package/lib/shape/box/violin.js +89 -0
- package/lib/shape/box/violin.js.map +1 -0
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/density/density.d.ts +8 -0
- package/lib/shape/density/density.js +54 -0
- package/lib/shape/density/density.js.map +1 -0
- package/lib/shape/index.d.ts +4 -0
- package/lib/shape/index.js +6 -1
- package/lib/shape/index.js.map +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/composition.d.ts +22 -19
- package/lib/spec/dataTransform.d.ts +34 -2
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/spec/mark.d.ts +9 -8
- package/lib/spec/transform.d.ts +1 -1
- package/lib/spec/utils.d.ts +1 -0
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -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.js +5 -1
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/size.js +7 -4
- package/lib/utils/size.js.map +1 -1
- package/package.json +5 -3
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +30 -113
- package/src/api/mark/index.ts +3 -0
- package/src/api/mark/mark.ts +12 -0
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +22 -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/composition/mark.ts +2 -0
- package/src/data/index.ts +2 -0
- package/src/data/kde.ts +53 -0
- package/src/interaction/brushFilter.ts +8 -6
- package/src/interaction/brushHighlight.ts +258 -20
- 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/density.ts +81 -0
- package/src/mark/gauge.ts +13 -7
- package/src/mark/index.ts +2 -0
- package/src/runtime/component.ts +210 -12
- package/src/runtime/layout.ts +74 -19
- package/src/runtime/plot.ts +8 -6
- 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/box/violin.ts +119 -0
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/density/density.ts +52 -0
- package/src/shape/index.ts +4 -0
- 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/composition.ts +22 -19
- package/src/spec/dataTransform.ts +35 -0
- package/src/spec/interaction.ts +3 -2
- package/src/spec/mark.ts +10 -6
- package/src/spec/transform.ts +1 -0
- package/src/spec/utils.ts +2 -0
- package/src/stdlib/index.ts +8 -0
- 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 +5 -1
- package/src/utils/size.ts +10 -4
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
package/src/runtime/component.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* @see https://github.com/antvis/G2/discussions/4557
|
|
3
3
|
*/
|
|
4
4
|
import { Coordinate } from '@antv/coord';
|
|
5
|
-
import { isEqual } from '@antv/util';
|
|
6
|
-
import { group } from 'd3-array';
|
|
5
|
+
import { deepMix, isEqual } from '@antv/util';
|
|
6
|
+
import { group, max, sum } from 'd3-array';
|
|
7
|
+
import { format } from 'd3-format';
|
|
8
|
+
import { DisplayObject, Text } from '@antv/g';
|
|
7
9
|
import {
|
|
8
10
|
getPolarOptions,
|
|
9
11
|
getRadialOptions,
|
|
@@ -11,7 +13,7 @@ import {
|
|
|
11
13
|
type RadialOptions,
|
|
12
14
|
} from '../coordinate';
|
|
13
15
|
import { combine } from '../utils/array';
|
|
14
|
-
import { defined } from '../utils/helper';
|
|
16
|
+
import { capitalizeFirst, defined, subObject } from '../utils/helper';
|
|
15
17
|
import { LEGEND_INFER_STRATEGIES } from '../component/constant';
|
|
16
18
|
import {
|
|
17
19
|
coordOf,
|
|
@@ -36,6 +38,8 @@ import {
|
|
|
36
38
|
import {
|
|
37
39
|
GuideComponent,
|
|
38
40
|
GuideComponentComponent as GCC,
|
|
41
|
+
ScaleComponent,
|
|
42
|
+
Scale,
|
|
39
43
|
} from './types/component';
|
|
40
44
|
import {
|
|
41
45
|
G2CoordinateOptions,
|
|
@@ -90,13 +94,13 @@ export function inferComponent(
|
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
const
|
|
97
|
+
const inferredComponents = inferComponentsType(displayedScales, coordinates);
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
inferredComponents.forEach(([type, relativeScales]) => {
|
|
96
100
|
const { props } = createGuideComponent(type);
|
|
97
101
|
const { defaultPosition, defaultOrientation, defaultSize, defaultOrder } =
|
|
98
102
|
props;
|
|
99
|
-
// @todo to be
|
|
103
|
+
// @todo to be confirm if the scale can be merged.
|
|
100
104
|
const scale: G2ScaleOptions = Object.assign({}, ...relativeScales);
|
|
101
105
|
const { guide: guideOptions, field } = scale;
|
|
102
106
|
// A scale may have multiple guides.
|
|
@@ -263,10 +267,10 @@ function inferComponentsType(
|
|
|
263
267
|
scales: G2ScaleOptions[],
|
|
264
268
|
coordinates: G2CoordinateOptions[],
|
|
265
269
|
): [string | GCC, G2ScaleOptions[]][] {
|
|
266
|
-
const
|
|
270
|
+
const availableScales = scales.filter((scale) => isValidScale(scale));
|
|
267
271
|
return [
|
|
268
|
-
...inferLegendComponentType(
|
|
269
|
-
...inferAxisComponentType(
|
|
272
|
+
...inferLegendComponentType(availableScales, coordinates),
|
|
273
|
+
...inferAxisComponentType(availableScales, coordinates),
|
|
270
274
|
];
|
|
271
275
|
}
|
|
272
276
|
|
|
@@ -307,7 +311,7 @@ function inferAxisPositionAndOrientation(
|
|
|
307
311
|
// todo, in current resolution, the radar chart is implement by parallel + polar coordinate.
|
|
308
312
|
// implementation plan to be confirmed.
|
|
309
313
|
// in current implementation, it must to add the first position encode to it's last.
|
|
310
|
-
// so we won't render the last axis
|
|
314
|
+
// so we won't render the last axis repeatably.
|
|
311
315
|
if (type === 'axisRadar') {
|
|
312
316
|
const positions = scales.filter((scale) =>
|
|
313
317
|
scale.name.startsWith('position'),
|
|
@@ -396,7 +400,7 @@ function inferComponentPositionAndOrientation(
|
|
|
396
400
|
return ordinalPositionAndOrientation;
|
|
397
401
|
}
|
|
398
402
|
|
|
399
|
-
function
|
|
403
|
+
function inferScrollableType(name: string, type: string, coordinates = []) {
|
|
400
404
|
if (name === 'x') return isTranspose(coordinates) ? `${type}Y` : `${type}X`;
|
|
401
405
|
if (name === 'y') return isTranspose(coordinates) ? `${type}X` : `${type}Y`;
|
|
402
406
|
return null;
|
|
@@ -424,7 +428,7 @@ function inferScrollableComponents(
|
|
|
424
428
|
scale: G2ScaleOptions,
|
|
425
429
|
options: Record<string, any>,
|
|
426
430
|
) {
|
|
427
|
-
const componentType =
|
|
431
|
+
const componentType = inferScrollableType(channelName, type, coordinates);
|
|
428
432
|
if (!options || !componentType) return;
|
|
429
433
|
|
|
430
434
|
const { props } = createGuideComponent(componentType);
|
|
@@ -450,3 +454,197 @@ function inferScrollableComponents(
|
|
|
450
454
|
})
|
|
451
455
|
.filter((d) => !!d);
|
|
452
456
|
}
|
|
457
|
+
|
|
458
|
+
// !!! Note Mutate component.size and component.style.
|
|
459
|
+
export function computeComponentSize(
|
|
460
|
+
component: G2GuideComponentOptions,
|
|
461
|
+
crossSize: number,
|
|
462
|
+
crossPadding: [number, number],
|
|
463
|
+
position: GCP,
|
|
464
|
+
theme: G2Theme,
|
|
465
|
+
library: G2Library,
|
|
466
|
+
): G2GuideComponentOptions {
|
|
467
|
+
const [useScale] = useLibrary<G2ScaleOptions, ScaleComponent, Scale>(
|
|
468
|
+
'scale',
|
|
469
|
+
library,
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
// Only compute and update size of axis component in padding area.
|
|
473
|
+
// @todo Legend, slider.
|
|
474
|
+
const { type } = component;
|
|
475
|
+
const paddingAreas = ['left', 'right', 'bottom', 'top'];
|
|
476
|
+
if (typeof type !== 'string' || !type.startsWith('axis')) return;
|
|
477
|
+
if (!paddingAreas.includes(position)) return;
|
|
478
|
+
|
|
479
|
+
// If padding is auto, use hide as the labelTransform by default
|
|
480
|
+
// to avoid overlap between labels.
|
|
481
|
+
component.transform = component.transform || [{ type: 'hide' }];
|
|
482
|
+
|
|
483
|
+
const { labelFormatter, scales, title, tickCount, tickMethod, tickFilter } =
|
|
484
|
+
component;
|
|
485
|
+
const isVertical = position === 'left' || position === 'right';
|
|
486
|
+
|
|
487
|
+
// Get styles to be applied.
|
|
488
|
+
const style = styleOf(component, position, theme);
|
|
489
|
+
const { tickLength = 0, labelSpacing = 0, titleSpacing = 0, ...rest } = style;
|
|
490
|
+
|
|
491
|
+
// Init scale, the tickCount of axis has higher priority than scale.
|
|
492
|
+
const [scaleOptions] = scales;
|
|
493
|
+
if (tickCount !== undefined) scaleOptions.tickCount = tickCount;
|
|
494
|
+
if (tickMethod !== undefined) scaleOptions.tickMethod = tickMethod;
|
|
495
|
+
const scale = useScale(scaleOptions);
|
|
496
|
+
|
|
497
|
+
// Get labels to be rendered.
|
|
498
|
+
const labels = labelsOf(scale, labelFormatter, tickFilter);
|
|
499
|
+
const labeStyle = subObject(rest, 'label');
|
|
500
|
+
const labelBBoxes = labels.map((d, i) => {
|
|
501
|
+
const normalizeStyle = Object.fromEntries(
|
|
502
|
+
Object.entries(labeStyle).map(([key, value]) => [
|
|
503
|
+
key,
|
|
504
|
+
typeof value === 'function' ? value(d, i) : value,
|
|
505
|
+
]),
|
|
506
|
+
);
|
|
507
|
+
// Auto padding should ignore transform for horizontal axis.
|
|
508
|
+
if (!isVertical) normalizeStyle.transform = 'none';
|
|
509
|
+
return computeLabelSize(d, normalizeStyle);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
const maxLabelWidth = max(labelBBoxes, (d) => d.width);
|
|
513
|
+
const paddingTick = tickLength + labelSpacing;
|
|
514
|
+
|
|
515
|
+
if (isVertical) {
|
|
516
|
+
component.size = maxLabelWidth + paddingTick;
|
|
517
|
+
} else {
|
|
518
|
+
// If the labels can't be placed horizontally,
|
|
519
|
+
// rotate 90 deg to display them.
|
|
520
|
+
if (overflowX(scale, labelBBoxes, crossSize, crossPadding, tickFilter)) {
|
|
521
|
+
component.size = maxLabelWidth + paddingTick;
|
|
522
|
+
component.style = {
|
|
523
|
+
...component.style,
|
|
524
|
+
labelTransform: 'rotate(90)',
|
|
525
|
+
};
|
|
526
|
+
} else {
|
|
527
|
+
const maxLabelHeight = max(labelBBoxes, (d) => d.height);
|
|
528
|
+
component.size = maxLabelHeight + paddingTick;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Cache boxes to avoid computed twice.
|
|
533
|
+
const I = labels.map((_, i) => i);
|
|
534
|
+
component.indexBBox = new Map(I.map((i) => [i, [labels[i], labelBBoxes[i]]]));
|
|
535
|
+
|
|
536
|
+
if (title === false || title === null || title === undefined) return;
|
|
537
|
+
|
|
538
|
+
// Get title to be rendered.
|
|
539
|
+
const titleStyle = subObject(rest, 'title');
|
|
540
|
+
const titleText = Array.isArray(title) ? title.join(',') : title;
|
|
541
|
+
const titleBBox = computeLabelSize(titleText, titleStyle);
|
|
542
|
+
|
|
543
|
+
if (isVertical) {
|
|
544
|
+
component.size += titleSpacing + titleBBox.width;
|
|
545
|
+
} else {
|
|
546
|
+
component.size += titleSpacing + titleBBox.height;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function styleOf(
|
|
551
|
+
axis: G2GuideComponentOptions,
|
|
552
|
+
position: GCP,
|
|
553
|
+
theme: G2Theme,
|
|
554
|
+
): Record<string, any> {
|
|
555
|
+
const {
|
|
556
|
+
axis: baseStyle,
|
|
557
|
+
// @ts-ignore
|
|
558
|
+
[`axis${capitalizeFirst(position)}`]: positionStyle,
|
|
559
|
+
} = theme;
|
|
560
|
+
return deepMix({}, baseStyle, positionStyle, axis.style);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function ticksOf(scale: Scale, tickFilter: (d: any) => boolean): any[] {
|
|
564
|
+
const ticks = scale.getTicks ? scale.getTicks() : scale.getOptions().domain;
|
|
565
|
+
if (!tickFilter) return ticks;
|
|
566
|
+
return ticks.filter(tickFilter);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function labelsOf(
|
|
570
|
+
scale: Scale,
|
|
571
|
+
labelFormatter: (d: any) => string | DisplayObject,
|
|
572
|
+
tickFilter,
|
|
573
|
+
): (string | DisplayObject)[] {
|
|
574
|
+
const T = ticksOf(scale, tickFilter);
|
|
575
|
+
const ticks = T.map((d) => (typeof d === 'number' ? prettyNumber(d) : d));
|
|
576
|
+
const formatter = labelFormatter
|
|
577
|
+
? typeof labelFormatter === 'string'
|
|
578
|
+
? format(labelFormatter)
|
|
579
|
+
: labelFormatter
|
|
580
|
+
: scale.getFormatter
|
|
581
|
+
? scale.getFormatter()
|
|
582
|
+
: (d) => `${d}`;
|
|
583
|
+
return ticks.map(formatter);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function offsetOf(scale: Scale, d: any): number {
|
|
587
|
+
if (!scale.getBandWidth) return 0;
|
|
588
|
+
const offset = scale.getBandWidth(d) / 2;
|
|
589
|
+
return offset;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function overflowX(
|
|
593
|
+
scale: Scale,
|
|
594
|
+
labelBBoxes: DOMRect[],
|
|
595
|
+
crossSize: number,
|
|
596
|
+
crossPadding: [number, number],
|
|
597
|
+
tickFilter: (d: any) => boolean,
|
|
598
|
+
): boolean {
|
|
599
|
+
// If actual size bigger than container size, overflow.
|
|
600
|
+
const totalSize = sum(labelBBoxes, (d) => d.width);
|
|
601
|
+
if (totalSize > crossSize) return true;
|
|
602
|
+
|
|
603
|
+
// Clone scale to get visual position for labels.
|
|
604
|
+
const scaleX = scale.clone();
|
|
605
|
+
scaleX.update({ range: [0, crossSize] });
|
|
606
|
+
const ticks = ticksOf(scale, tickFilter);
|
|
607
|
+
const X = ticks.map((d) => scaleX.map(d) + offsetOf(scaleX, d));
|
|
608
|
+
|
|
609
|
+
const I = ticks.map((_, i) => i);
|
|
610
|
+
const startX = -crossPadding[0];
|
|
611
|
+
const endX = crossSize + crossPadding[1];
|
|
612
|
+
const extent = (x, bbox) => {
|
|
613
|
+
const { width } = bbox;
|
|
614
|
+
return [x - width / 2, x + width / 2];
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
// Collision detection.
|
|
618
|
+
for (let i = 0; i < I.length; i++) {
|
|
619
|
+
const x = X[i];
|
|
620
|
+
const [x0, x1] = extent(x, labelBBoxes[i]);
|
|
621
|
+
// If a label is out of plot area, overflow.
|
|
622
|
+
if (x0 < startX || x1 > endX) return true;
|
|
623
|
+
const y = X[i + 1];
|
|
624
|
+
if (y) {
|
|
625
|
+
// If two labels intersect, overflow.
|
|
626
|
+
const [y0] = extent(y, labelBBoxes[i + 1]);
|
|
627
|
+
if (x1 > y0) return true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function computeLabelSize(
|
|
634
|
+
d: string | DisplayObject,
|
|
635
|
+
style: Record<string, any>,
|
|
636
|
+
): DOMRect {
|
|
637
|
+
const shape = normalizeLabel(d);
|
|
638
|
+
shape.attr({ ...style, visibility: 'none' });
|
|
639
|
+
const bbox = shape.getBBox();
|
|
640
|
+
return bbox;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function normalizeLabel(d: string | DisplayObject): DisplayObject {
|
|
644
|
+
if (d instanceof DisplayObject) return d;
|
|
645
|
+
return new Text({ style: { text: `${d}` } });
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function prettyNumber(n: number) {
|
|
649
|
+
return Math.abs(n) < 1e-15 ? n : parseFloat(n.toFixed(15));
|
|
650
|
+
}
|
package/src/runtime/layout.ts
CHANGED
|
@@ -3,21 +3,24 @@ import { ascending, group } from 'd3-array';
|
|
|
3
3
|
import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
|
|
4
4
|
import { capitalizeFirst } from '../utils/helper';
|
|
5
5
|
import { divide } from '../utils/array';
|
|
6
|
+
import { camelCase } from '../utils/string';
|
|
6
7
|
import {
|
|
7
8
|
GuideComponentPosition as GCP,
|
|
8
9
|
GuideComponentOrientation as GCO,
|
|
9
10
|
Layout,
|
|
10
11
|
Section,
|
|
11
12
|
SectionArea,
|
|
13
|
+
G2Theme,
|
|
12
14
|
} from './types/common';
|
|
13
|
-
import {
|
|
15
|
+
import { computeComponentSize } from './component';
|
|
16
|
+
import { G2GuideComponentOptions, G2Library, G2View } from './types/options';
|
|
14
17
|
|
|
15
18
|
export function computeLayout(
|
|
16
19
|
components: G2GuideComponentOptions[],
|
|
17
20
|
options: G2View,
|
|
21
|
+
theme: G2Theme,
|
|
22
|
+
library: G2Library,
|
|
18
23
|
): Layout {
|
|
19
|
-
const padding = computePadding(components, options);
|
|
20
|
-
const { paddingLeft, paddingRight, paddingTop, paddingBottom } = padding;
|
|
21
24
|
const {
|
|
22
25
|
width,
|
|
23
26
|
height,
|
|
@@ -33,18 +36,62 @@ export function computeLayout(
|
|
|
33
36
|
marginBottom = margin,
|
|
34
37
|
marginTop = margin,
|
|
35
38
|
marginRight = margin,
|
|
39
|
+
padding,
|
|
40
|
+
paddingBottom = padding,
|
|
41
|
+
paddingLeft = padding,
|
|
42
|
+
paddingRight = padding,
|
|
43
|
+
paddingTop = padding,
|
|
36
44
|
} = options;
|
|
37
45
|
|
|
46
|
+
const MAX_PADDING_RATIO = 1 / 3;
|
|
47
|
+
const clamp = (origin, computed, max) =>
|
|
48
|
+
origin === 'auto' ? Math.min(max, computed) : computed;
|
|
49
|
+
|
|
50
|
+
// Compute paddingLeft and paddingRight first to get innerWidth.
|
|
51
|
+
const horizontalPadding = computePadding(
|
|
52
|
+
components,
|
|
53
|
+
height,
|
|
54
|
+
[0, 0],
|
|
55
|
+
['left', 'right'],
|
|
56
|
+
options,
|
|
57
|
+
theme,
|
|
58
|
+
library,
|
|
59
|
+
);
|
|
60
|
+
const { paddingLeft: pl0, paddingRight: pr0 } = horizontalPadding;
|
|
61
|
+
const viewWidth = width - marginLeft - marginRight;
|
|
62
|
+
const pl = clamp(paddingLeft, pl0, viewWidth * MAX_PADDING_RATIO);
|
|
63
|
+
const pr = clamp(paddingRight, pr0, viewWidth * MAX_PADDING_RATIO);
|
|
64
|
+
const iw = viewWidth - pl - pr;
|
|
65
|
+
|
|
66
|
+
// Compute paddingBottom and paddingTop based on innerWidth.
|
|
67
|
+
const verticalPadding = computePadding(
|
|
68
|
+
components,
|
|
69
|
+
iw,
|
|
70
|
+
[pl, pr],
|
|
71
|
+
['bottom', 'top'],
|
|
72
|
+
options,
|
|
73
|
+
theme,
|
|
74
|
+
library,
|
|
75
|
+
);
|
|
76
|
+
const { paddingTop: pt0, paddingBottom: pb0 } = verticalPadding;
|
|
77
|
+
const viewHeight = height - marginBottom - marginTop;
|
|
78
|
+
const pb = clamp(paddingBottom, pb0, viewHeight * MAX_PADDING_RATIO);
|
|
79
|
+
const pt = clamp(paddingTop, pt0, viewHeight * MAX_PADDING_RATIO);
|
|
80
|
+
const ih = viewHeight - pb - pt;
|
|
81
|
+
|
|
38
82
|
return {
|
|
39
|
-
...padding,
|
|
40
83
|
width,
|
|
41
84
|
height,
|
|
42
85
|
insetLeft,
|
|
43
86
|
insetTop,
|
|
44
87
|
insetBottom,
|
|
45
88
|
insetRight,
|
|
46
|
-
innerWidth:
|
|
47
|
-
innerHeight:
|
|
89
|
+
innerWidth: iw,
|
|
90
|
+
innerHeight: ih,
|
|
91
|
+
paddingLeft: pl,
|
|
92
|
+
paddingRight: pr,
|
|
93
|
+
paddingTop: pt,
|
|
94
|
+
paddingBottom: pb,
|
|
48
95
|
marginLeft,
|
|
49
96
|
marginBottom,
|
|
50
97
|
marginTop,
|
|
@@ -59,18 +106,13 @@ export function computeLayout(
|
|
|
59
106
|
*/
|
|
60
107
|
function computePadding(
|
|
61
108
|
components: G2GuideComponentOptions[],
|
|
109
|
+
crossSize: number,
|
|
110
|
+
crossPadding: [number, number],
|
|
111
|
+
positions: GCP[],
|
|
62
112
|
options: G2View,
|
|
113
|
+
theme: G2Theme,
|
|
114
|
+
library: G2Library,
|
|
63
115
|
) {
|
|
64
|
-
const positions: GCP[] = [
|
|
65
|
-
'left',
|
|
66
|
-
'right',
|
|
67
|
-
'top',
|
|
68
|
-
'bottom',
|
|
69
|
-
'top-left',
|
|
70
|
-
'top-right',
|
|
71
|
-
'bottom-left',
|
|
72
|
-
'bottom-right',
|
|
73
|
-
];
|
|
74
116
|
const positionComponents = group(components, (d) => d.position);
|
|
75
117
|
const {
|
|
76
118
|
padding,
|
|
@@ -86,12 +128,25 @@ function computePadding(
|
|
|
86
128
|
paddingRight,
|
|
87
129
|
};
|
|
88
130
|
for (const position of positions) {
|
|
89
|
-
const key = `padding${capitalizeFirst(position)}`;
|
|
90
|
-
|
|
131
|
+
const key = `padding${capitalizeFirst(camelCase(position))}`;
|
|
132
|
+
const value = layout[key];
|
|
133
|
+
if (value === undefined || value === 'auto') {
|
|
91
134
|
if (!positionComponents.has(position)) {
|
|
92
135
|
layout[key] = 30;
|
|
93
136
|
} else {
|
|
94
137
|
const components = positionComponents.get(position);
|
|
138
|
+
if (value === 'auto') {
|
|
139
|
+
components.forEach((component) =>
|
|
140
|
+
computeComponentSize(
|
|
141
|
+
component,
|
|
142
|
+
crossSize,
|
|
143
|
+
crossPadding,
|
|
144
|
+
position,
|
|
145
|
+
theme,
|
|
146
|
+
library,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
95
150
|
const totalSize = components.reduce((sum, { size }) => sum + size, 0);
|
|
96
151
|
layout[key] = totalSize;
|
|
97
152
|
}
|
|
@@ -161,7 +216,7 @@ export function placeComponents(
|
|
|
161
216
|
/**
|
|
162
217
|
* @description non-entity components: axis in the center, inner, outer, component in the center
|
|
163
218
|
* @description entity components: other components
|
|
164
|
-
* @description no
|
|
219
|
+
* @description no volume components take up no extra space
|
|
165
220
|
*/
|
|
166
221
|
|
|
167
222
|
const [nonEntityComponents, entityComponents] = divide(
|
package/src/runtime/plot.ts
CHANGED
|
@@ -324,8 +324,7 @@ function updateTooltip(selection, options, view, library, context) {
|
|
|
324
324
|
// Instances for tooltip.
|
|
325
325
|
const container = selection.node();
|
|
326
326
|
const nameInteraction = container['nameInteraction'];
|
|
327
|
-
const
|
|
328
|
-
const tooltipOptions = inferInteraction(interaction).find(
|
|
327
|
+
const tooltipOptions = inferInteraction(options).find(
|
|
329
328
|
(d) => d.type === 'tooltip',
|
|
330
329
|
);
|
|
331
330
|
|
|
@@ -538,7 +537,7 @@ function initializeState(
|
|
|
538
537
|
options,
|
|
539
538
|
library,
|
|
540
539
|
);
|
|
541
|
-
const layout = computeLayout(components, options);
|
|
540
|
+
const layout = computeLayout(components, options, theme, library);
|
|
542
541
|
const coordinate = createCoordinate(layout, options, library);
|
|
543
542
|
const framedStyle = frame
|
|
544
543
|
? deepMix({ mainLineWidth: 1, mainStroke: '#000' }, style)
|
|
@@ -824,7 +823,10 @@ async function plotView(
|
|
|
824
823
|
maybeFacetElement(this, parent, origin);
|
|
825
824
|
const node = shapeFunction(data, index);
|
|
826
825
|
const animation = updateFunction(data, [this], [node]);
|
|
827
|
-
if (animation === null)
|
|
826
|
+
if (animation === null) {
|
|
827
|
+
if (this.nodeName === node.nodeName) copyAttributes(this, node);
|
|
828
|
+
else this.parentNode.replaceChild(node, this);
|
|
829
|
+
}
|
|
828
830
|
return animation;
|
|
829
831
|
});
|
|
830
832
|
}),
|
|
@@ -1211,10 +1213,10 @@ function createMarkShapeFunction(
|
|
|
1211
1213
|
const point2d = data.map((d) => d.points);
|
|
1212
1214
|
const { theme, coordinate } = view;
|
|
1213
1215
|
const { type: markType, style = {} } = mark;
|
|
1214
|
-
return (data
|
|
1216
|
+
return (data) => {
|
|
1215
1217
|
const { shape: styleShape = defaultShape } = style;
|
|
1216
1218
|
const { shape = styleShape, points, seriesIndex, index: i, ...v } = data;
|
|
1217
|
-
const value = { ...v, shape, mark: markType, defaultShape, index };
|
|
1219
|
+
const value = { ...v, shape, mark: markType, defaultShape, index: i };
|
|
1218
1220
|
|
|
1219
1221
|
// Get data-driven style.
|
|
1220
1222
|
// If it is a series shape, such as area and line,
|
package/src/runtime/scale.ts
CHANGED
|
@@ -200,7 +200,7 @@ function inferScaleDomain(
|
|
|
200
200
|
case 'quantize':
|
|
201
201
|
case 'threshold': {
|
|
202
202
|
const [d0, d1] = inferDomainQ(values, options);
|
|
203
|
-
return [domainMin
|
|
203
|
+
return [domainMin ?? d0, domainMax ?? d1];
|
|
204
204
|
}
|
|
205
205
|
case 'band':
|
|
206
206
|
case 'ordinal':
|
|
@@ -210,7 +210,7 @@ function inferScaleDomain(
|
|
|
210
210
|
return inferDomainO(values);
|
|
211
211
|
case 'sequential': {
|
|
212
212
|
const [d0, d1] = inferDomainS(values);
|
|
213
|
-
return [domainMin
|
|
213
|
+
return [domainMin ?? d0, domainMax ?? d1];
|
|
214
214
|
}
|
|
215
215
|
default:
|
|
216
216
|
return [];
|
package/src/runtime/transform.ts
CHANGED
|
@@ -268,7 +268,8 @@ export function addGuideToScale(
|
|
|
268
268
|
size: { guide: normalize(legend, 'size') },
|
|
269
269
|
shape: { guide: normalize(legend, 'shape') },
|
|
270
270
|
// fixme: opacity is conflict with DisplayObject.opacity
|
|
271
|
-
//
|
|
271
|
+
// to be comfirm.
|
|
272
|
+
opacity: { guide: normalize(legend, 'opacity') },
|
|
272
273
|
},
|
|
273
274
|
});
|
|
274
275
|
return [I, mark];
|
|
@@ -112,6 +112,7 @@ export type Scale = {
|
|
|
112
112
|
getFormatter?: () => (x: any) => string;
|
|
113
113
|
getOptions: () => Record<string, any>;
|
|
114
114
|
update(options: Record<string, any>): void;
|
|
115
|
+
clone: () => Scale;
|
|
115
116
|
};
|
|
116
117
|
export type ScaleComponent<O = Record<string, unknown>> = G2BaseComponent<
|
|
117
118
|
Scale,
|
package/src/shape/area/area.ts
CHANGED
package/src/shape/area/curve.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getTransform,
|
|
12
12
|
} from '../utils';
|
|
13
13
|
import { subObject } from '../../utils/helper';
|
|
14
|
-
import { createElement } from '
|
|
14
|
+
import { createElement } from '../../utils/createElement';
|
|
15
15
|
|
|
16
16
|
const DoubleArea = createElement((g) => {
|
|
17
17
|
const { areaPath, connectPath, areaStyle, connectStyle } = g.attributes;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Path as GPath } from '@antv/g';
|
|
2
|
+
import { path as d3path } from 'd3-path';
|
|
3
|
+
import { Coordinate } from '@antv/coord';
|
|
4
|
+
import { applyStyle, getShapeTheme } from '../utils';
|
|
5
|
+
import { select } from '../../utils/selection';
|
|
6
|
+
import { ShapeComponent as SC, Vector2 } from '../../runtime';
|
|
7
|
+
import { isPolar } from '../../utils/coordinate';
|
|
8
|
+
import { angle, sub, dist } from '../../utils/vector';
|
|
9
|
+
|
|
10
|
+
export type ViolinOptions = Record<string, any>;
|
|
11
|
+
|
|
12
|
+
function getPath(p: Vector2[], coordinate: Coordinate, size = 4) {
|
|
13
|
+
const path = d3path();
|
|
14
|
+
|
|
15
|
+
if (!isPolar(coordinate)) {
|
|
16
|
+
path.moveTo(...p[2]);
|
|
17
|
+
path.lineTo(...p[3]);
|
|
18
|
+
|
|
19
|
+
path.lineTo(p[3][0] - size, p[3][1]);
|
|
20
|
+
path.lineTo(p[10][0] - size, p[10][1]);
|
|
21
|
+
path.lineTo(p[10][0] + size, p[10][1]);
|
|
22
|
+
path.lineTo(p[3][0] + size, p[3][1]);
|
|
23
|
+
path.lineTo(...p[3]);
|
|
24
|
+
path.closePath();
|
|
25
|
+
|
|
26
|
+
path.moveTo(...p[10]);
|
|
27
|
+
path.lineTo(...p[11]);
|
|
28
|
+
|
|
29
|
+
path.moveTo(p[3][0] + size / 2, p[8][1]);
|
|
30
|
+
path.arc(p[3][0], p[8][1], size / 2, 0, Math.PI * 2);
|
|
31
|
+
path.closePath();
|
|
32
|
+
|
|
33
|
+
return path;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const center = coordinate.getCenter();
|
|
37
|
+
const [x, y] = center;
|
|
38
|
+
|
|
39
|
+
const radiusQ3 = dist(center, p[3]);
|
|
40
|
+
const radiusMedian = dist(center, p[8]);
|
|
41
|
+
const radiusQ1 = dist(center, p[10]);
|
|
42
|
+
|
|
43
|
+
const middleAngle = angle(sub(p[2], center));
|
|
44
|
+
const rectAngle = Math.asin(size / radiusMedian);
|
|
45
|
+
const startAngle = middleAngle - rectAngle;
|
|
46
|
+
const endAngle = middleAngle + rectAngle;
|
|
47
|
+
|
|
48
|
+
path.moveTo(...p[2]);
|
|
49
|
+
path.lineTo(...p[3]);
|
|
50
|
+
|
|
51
|
+
path.moveTo(
|
|
52
|
+
Math.cos(startAngle) * radiusQ3 + x,
|
|
53
|
+
Math.sin(startAngle) * radiusQ3 + y,
|
|
54
|
+
);
|
|
55
|
+
path.arc(x, y, radiusQ3, startAngle, endAngle);
|
|
56
|
+
path.lineTo(
|
|
57
|
+
Math.cos(endAngle) * radiusQ1 + x,
|
|
58
|
+
Math.sin(endAngle) * radiusQ1 + y,
|
|
59
|
+
);
|
|
60
|
+
path.arc(x, y, radiusQ1, endAngle, startAngle, true);
|
|
61
|
+
path.lineTo(
|
|
62
|
+
Math.cos(startAngle) * radiusQ3 + x,
|
|
63
|
+
Math.sin(startAngle) * radiusQ3 + y,
|
|
64
|
+
);
|
|
65
|
+
path.closePath();
|
|
66
|
+
|
|
67
|
+
path.moveTo(...p[10]);
|
|
68
|
+
path.lineTo(...p[11]);
|
|
69
|
+
|
|
70
|
+
const a = (startAngle + endAngle) / 2;
|
|
71
|
+
|
|
72
|
+
path.moveTo(
|
|
73
|
+
Math.cos(a) * (radiusMedian + size / 2) + x,
|
|
74
|
+
Math.sin(a) * (radiusMedian + size / 2) + y,
|
|
75
|
+
);
|
|
76
|
+
path.arc(
|
|
77
|
+
Math.cos(a) * radiusMedian + x,
|
|
78
|
+
Math.sin(a) * radiusMedian + y,
|
|
79
|
+
size / 2,
|
|
80
|
+
a,
|
|
81
|
+
Math.PI * 2 + a,
|
|
82
|
+
);
|
|
83
|
+
path.closePath();
|
|
84
|
+
|
|
85
|
+
return path;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const Violin: SC<ViolinOptions> = (options) => {
|
|
89
|
+
const { ...style } = options;
|
|
90
|
+
return (points, value, coordinate, theme) => {
|
|
91
|
+
const { mark, shape, defaultShape, color, transform } = value;
|
|
92
|
+
// TODO: how to setting it by size channel.
|
|
93
|
+
const size = 4;
|
|
94
|
+
const {
|
|
95
|
+
defaultColor,
|
|
96
|
+
fill = defaultColor,
|
|
97
|
+
stroke = defaultColor,
|
|
98
|
+
...shapeTheme
|
|
99
|
+
} = getShapeTheme(theme, mark, shape, defaultShape);
|
|
100
|
+
|
|
101
|
+
const path = getPath(points, coordinate, size);
|
|
102
|
+
|
|
103
|
+
return select(new GPath())
|
|
104
|
+
.call(applyStyle, shapeTheme)
|
|
105
|
+
.style('d', path.toString())
|
|
106
|
+
.style('stroke', stroke)
|
|
107
|
+
.style('fill', color || fill)
|
|
108
|
+
.style('transform', transform)
|
|
109
|
+
.call(applyStyle, style)
|
|
110
|
+
.node();
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
Violin.props = {
|
|
115
|
+
defaultMarker: 'point',
|
|
116
|
+
defaultEnterAnimation: 'fadeIn',
|
|
117
|
+
defaultUpdateAnimation: 'morphing',
|
|
118
|
+
defaultExitAnimation: 'fadeOut',
|
|
119
|
+
};
|
|
@@ -4,7 +4,7 @@ import { PathStyleProps } from '@antv/g';
|
|
|
4
4
|
import { Marker } from '@antv/gui';
|
|
5
5
|
import { line as d3line } from 'd3-shape';
|
|
6
6
|
import { ShapeComponent as SC, Vector2, WithPrefix } from '../../runtime';
|
|
7
|
-
import { createElement } from '../../
|
|
7
|
+
import { createElement } from '../../utils/createElement';
|
|
8
8
|
import { isTranspose } from '../../utils/coordinate';
|
|
9
9
|
import { subObject } from '../../utils/helper';
|
|
10
10
|
import { select } from '../../utils/selection';
|