@antv/g2 5.0.0-beta.1 → 5.0.0-beta.2
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 +2 -2
- package/dist/g2.min.js +2 -2
- package/esm/animation/morphing.js +10 -8
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.js +2 -5
- package/esm/api/chart.js.map +1 -1
- package/esm/component/axis.d.ts +1 -2
- package/esm/component/axis.js +81 -198
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.d.ts +0 -1
- package/esm/component/legendCategory.js +36 -49
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +29 -19
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +1 -0
- package/esm/component/utils.js +3 -0
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/facetRect.js +2 -4
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/repeatMatrix.js +2 -2
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
- package/esm/interaction/action/transformer/setItemState.js.map +1 -1
- package/esm/mark/cell.js +1 -1
- package/esm/shape/area/curve.js +2 -9
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/interval/color.js +2 -2
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/line/curve.js +23 -12
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/line/line.js +6 -2
- package/esm/shape/line/line.js.map +1 -1
- package/esm/shape/line/smooth.js +6 -2
- package/esm/shape/line/smooth.js.map +1 -1
- package/esm/shape/text/advance.js +2 -2
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.d.ts +1 -0
- package/esm/shape/utils.js +8 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/transform.d.ts +10 -2
- package/esm/stdlib/index.js +2 -2
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/dark.js +78 -65
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +84 -74
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/groupN.js +2 -0
- package/esm/transform/groupN.js.map +1 -1
- package/esm/transform/index.d.ts +8 -6
- package/esm/transform/index.js +4 -3
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/sample.d.ts +8 -0
- package/esm/transform/sample.js +48 -0
- package/esm/transform/sample.js.map +1 -0
- package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
- package/esm/transform/{Select.js → select.js} +1 -1
- package/esm/transform/{Select.js.map → select.js.map} +1 -1
- package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/esm/transform/{SelectX.js → selectX.js} +1 -1
- package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/esm/transform/{SelectY.js → selectY.js} +1 -1
- package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/esm/transform/sort.d.ts +1 -1
- package/esm/transform/sort.js +39 -21
- package/esm/transform/sort.js.map +1 -1
- package/lib/animation/morphing.js +10 -8
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.js +2 -5
- package/lib/api/chart.js.map +1 -1
- package/lib/component/axis.d.ts +1 -2
- package/lib/component/axis.js +80 -197
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.d.ts +0 -1
- package/lib/component/legendCategory.js +36 -49
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +29 -19
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +1 -0
- package/lib/component/utils.js +5 -1
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/facetRect.js +2 -4
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/repeatMatrix.js +2 -2
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
- package/lib/interaction/action/transformer/setItemState.js.map +1 -1
- package/lib/mark/cell.js +1 -1
- package/lib/shape/area/curve.js +2 -9
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/interval/color.js +2 -2
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/line/curve.js +21 -10
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/line/line.js +5 -1
- package/lib/shape/line/line.js.map +1 -1
- package/lib/shape/line/smooth.js +5 -1
- package/lib/shape/line/smooth.js.map +1 -1
- package/lib/shape/text/advance.js +2 -2
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.d.ts +1 -0
- package/lib/shape/utils.js +9 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/transform.d.ts +10 -2
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/dark.js +78 -65
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +84 -74
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/groupN.js +2 -0
- package/lib/transform/groupN.js.map +1 -1
- package/lib/transform/index.d.ts +8 -6
- package/lib/transform/index.js +9 -7
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/sample.d.ts +8 -0
- package/lib/transform/sample.js +52 -0
- package/lib/transform/sample.js.map +1 -0
- package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
- package/lib/transform/{Select.js → select.js} +1 -1
- package/lib/transform/{Select.js.map → select.js.map} +1 -1
- package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/lib/transform/{SelectX.js → selectX.js} +1 -1
- package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/lib/transform/{SelectY.js → selectY.js} +1 -1
- package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/lib/transform/sort.d.ts +1 -1
- package/lib/transform/sort.js +38 -20
- package/lib/transform/sort.js.map +1 -1
- package/package.json +3 -3
- package/src/animation/morphing.ts +12 -8
- package/src/api/chart.ts +2 -5
- package/src/component/axis.ts +233 -310
- package/src/component/legendCategory.ts +52 -68
- package/src/component/legendContinuous.ts +24 -25
- package/src/component/utils.ts +4 -0
- package/src/composition/facetRect.ts +2 -4
- package/src/composition/repeatMatrix.ts +2 -2
- package/src/interaction/action/service/legendItemSelection.ts +1 -2
- package/src/interaction/action/transformer/setItemState.ts +2 -3
- package/src/mark/cell.ts +1 -1
- package/src/shape/area/curve.ts +7 -9
- package/src/shape/interval/color.ts +7 -7
- package/src/shape/line/curve.ts +27 -12
- package/src/shape/line/line.ts +6 -2
- package/src/shape/line/smooth.ts +11 -2
- package/src/shape/text/advance.ts +2 -2
- package/src/shape/utils.ts +8 -1
- package/src/spec/transform.ts +10 -1
- package/src/stdlib/index.ts +2 -0
- package/src/theme/dark.ts +78 -66
- package/src/theme/light.ts +84 -75
- package/src/transform/groupN.ts +2 -0
- package/src/transform/index.ts +8 -6
- package/src/transform/sample.ts +45 -0
- package/src/transform/sort.ts +53 -21
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Category } from '@antv/gui';
|
|
2
|
-
import { deepMix } from '@antv/util';
|
|
3
2
|
import {
|
|
4
3
|
GuideComponentComponent as GCC,
|
|
5
4
|
GuideComponentPosition,
|
|
6
5
|
} from '../runtime';
|
|
6
|
+
import { titleContent } from './utils';
|
|
7
7
|
|
|
8
8
|
export type LegendCategoryOptions = {
|
|
9
9
|
position?: GuideComponentPosition;
|
|
@@ -14,19 +14,37 @@ export type LegendCategoryOptions = {
|
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
function inferLayout(
|
|
18
|
+
position: GuideComponentPosition,
|
|
19
|
+
gridRow?: number,
|
|
20
|
+
gridCol?: number,
|
|
21
|
+
): [number, number] {
|
|
22
|
+
const [gridRowLimit, gridColLimit] = [gridRow || 100, gridCol || 100];
|
|
23
|
+
const config = {
|
|
24
|
+
top: [1, gridColLimit],
|
|
25
|
+
bottom: [1, gridColLimit],
|
|
26
|
+
left: [gridRowLimit, 1],
|
|
27
|
+
right: [gridRowLimit, 1],
|
|
28
|
+
arcCenter: [gridRowLimit, 1],
|
|
29
|
+
}[position];
|
|
30
|
+
|
|
31
|
+
return config || [gridRow, gridCol];
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
/**
|
|
18
35
|
* Guide Component for ordinal color scale.
|
|
19
|
-
* @todo Custom style.
|
|
20
36
|
*/
|
|
21
37
|
export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
|
|
22
38
|
const {
|
|
39
|
+
order,
|
|
40
|
+
size,
|
|
23
41
|
position,
|
|
24
42
|
labelFormatter = (d) => `${d}`,
|
|
25
43
|
dx = 0,
|
|
26
44
|
dy = 0,
|
|
27
45
|
title,
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
gridCol,
|
|
47
|
+
gridRow,
|
|
30
48
|
...rest
|
|
31
49
|
} = options;
|
|
32
50
|
return (scale, value, coordinate, theme) => {
|
|
@@ -34,73 +52,39 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
|
|
|
34
52
|
const { x, y, width, height } = bbox;
|
|
35
53
|
const items = domain.map((d) => ({
|
|
36
54
|
id: d,
|
|
37
|
-
|
|
55
|
+
label: labelFormatter(d),
|
|
56
|
+
value: '',
|
|
38
57
|
color: scale.map(d),
|
|
39
58
|
}));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
y: y + dy,
|
|
47
|
-
orient: ['right', 'left', 'arcCenter'].includes(position)
|
|
48
|
-
? 'vertical'
|
|
49
|
-
: 'horizontal',
|
|
50
|
-
maxWidth: width,
|
|
51
|
-
maxHeight: height,
|
|
52
|
-
autoWrap,
|
|
53
|
-
maxItemWidth,
|
|
54
|
-
itemWidth: maxItemWidth,
|
|
55
|
-
spacing: [8, 0],
|
|
56
|
-
itemName: {
|
|
57
|
-
style: {
|
|
58
|
-
fontSize: 12,
|
|
59
|
-
fillOpacity: 1,
|
|
60
|
-
fill: '#000',
|
|
61
|
-
fontWeight: 'lighter',
|
|
62
|
-
active: {
|
|
63
|
-
fillOpacity: 0.8,
|
|
64
|
-
},
|
|
65
|
-
inactive: {
|
|
66
|
-
fill: '#d8d8d8',
|
|
67
|
-
},
|
|
68
|
-
unchecked: {
|
|
69
|
-
fill: '#d8d8d8',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
...(title && {
|
|
74
|
-
title: {
|
|
75
|
-
content: Array.isArray(title) ? title[0] : title,
|
|
76
|
-
style: {
|
|
77
|
-
fontSize: 12,
|
|
78
|
-
fontWeight: 'bold',
|
|
79
|
-
fillOpacity: 1,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
}),
|
|
83
|
-
itemMarker: {
|
|
84
|
-
size: 8,
|
|
85
|
-
symbol: 'circle',
|
|
86
|
-
style: {
|
|
87
|
-
fillOpacity: 1,
|
|
88
|
-
inactive: {
|
|
89
|
-
fillOpacity: 0.2,
|
|
90
|
-
},
|
|
91
|
-
unchecked: {
|
|
92
|
-
fill: '#d8d8d8',
|
|
93
|
-
stroke: '#d8d8d8',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
itemBackgroundStyle: {
|
|
98
|
-
fill: 'transparent',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
{ ...rest },
|
|
59
|
+
|
|
60
|
+
// Calc layout config
|
|
61
|
+
const [finalGridRow, finalGridCol] = inferLayout(
|
|
62
|
+
position,
|
|
63
|
+
gridRow,
|
|
64
|
+
gridCol,
|
|
102
65
|
);
|
|
103
|
-
|
|
66
|
+
|
|
67
|
+
const legendStyle = {
|
|
68
|
+
data: items,
|
|
69
|
+
x: x + dx,
|
|
70
|
+
y: y + dy,
|
|
71
|
+
orient: ['right', 'left', 'arcCenter'].includes(position)
|
|
72
|
+
? 'vertical'
|
|
73
|
+
: 'horizontal',
|
|
74
|
+
width,
|
|
75
|
+
height,
|
|
76
|
+
gridCol: finalGridCol,
|
|
77
|
+
gridRow: finalGridRow,
|
|
78
|
+
rowPadding: 0,
|
|
79
|
+
colPadding: 8,
|
|
80
|
+
titleText: titleContent(title),
|
|
81
|
+
itemMarkerFill: (d) => (d ? d.color : '#fff'),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const { legend: legendTheme = {} } = theme;
|
|
85
|
+
return new Category({
|
|
86
|
+
style: Object.assign({}, legendTheme, legendStyle, rest),
|
|
87
|
+
});
|
|
104
88
|
};
|
|
105
89
|
};
|
|
106
90
|
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
GuideComponentComponent as GCC,
|
|
4
4
|
GuideComponentPosition,
|
|
5
5
|
} from '../runtime';
|
|
6
|
+
import { titleContent } from './utils';
|
|
6
7
|
|
|
7
8
|
export type LegendContinuousOptions = {
|
|
8
9
|
position?: GuideComponentPosition;
|
|
@@ -14,37 +15,35 @@ export type LegendContinuousOptions = {
|
|
|
14
15
|
* @todo Custom style.
|
|
15
16
|
*/
|
|
16
17
|
export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
17
|
-
const { title } = options;
|
|
18
|
+
const { title, ...rest } = options;
|
|
18
19
|
return (scale, value, coordinate, theme) => {
|
|
19
20
|
const { domain, bbox } = value;
|
|
20
21
|
const { x, y } = bbox;
|
|
21
|
-
const ticks = scale.getTicks?.() || [];
|
|
22
22
|
const [min, max] = domain;
|
|
23
|
+
|
|
24
|
+
const { continuousLegend: legendTheme = {} } = theme;
|
|
25
|
+
|
|
23
26
|
return new Continuous({
|
|
24
|
-
style:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
style: Object.assign(
|
|
28
|
+
{},
|
|
29
|
+
legendTheme,
|
|
30
|
+
{
|
|
31
|
+
x,
|
|
32
|
+
y,
|
|
33
|
+
width: 400,
|
|
34
|
+
height: 300,
|
|
35
|
+
data: [{ value: min }, { value: max }],
|
|
36
|
+
titleText: titleContent(title),
|
|
37
|
+
titleFontSize: 12,
|
|
38
|
+
ribbonLen: 120,
|
|
39
|
+
ribbonSize: 12,
|
|
40
|
+
ribbonColor: domain.map((d) => scale.map(d)),
|
|
41
|
+
showHandle: false,
|
|
42
|
+
showIndicator: false,
|
|
43
|
+
labelAlign: 'value',
|
|
33
44
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
indicator: null,
|
|
37
|
-
handle: null,
|
|
38
|
-
...(title && {
|
|
39
|
-
title: {
|
|
40
|
-
content: Array.isArray(title) ? title[0] : title,
|
|
41
|
-
style: {
|
|
42
|
-
fontSize: 12,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
color: domain.map((d) => scale.map(d)),
|
|
47
|
-
},
|
|
45
|
+
rest,
|
|
46
|
+
),
|
|
48
47
|
});
|
|
49
48
|
};
|
|
50
49
|
};
|
package/src/component/utils.ts
CHANGED
|
@@ -296,18 +296,16 @@ export function createInnerGuide(guide, data) {
|
|
|
296
296
|
? deepMix(
|
|
297
297
|
{
|
|
298
298
|
title: false,
|
|
299
|
-
|
|
299
|
+
tick: null,
|
|
300
300
|
label: null,
|
|
301
|
-
subTickLine: null,
|
|
302
301
|
},
|
|
303
302
|
guide,
|
|
304
303
|
)
|
|
305
304
|
: deepMix(
|
|
306
305
|
{
|
|
307
306
|
title: false,
|
|
308
|
-
|
|
307
|
+
tick: null,
|
|
309
308
|
label: null,
|
|
310
|
-
subTickLine: null,
|
|
311
309
|
grid: null,
|
|
312
310
|
},
|
|
313
311
|
guide,
|
|
@@ -71,8 +71,8 @@ const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
|
|
|
71
71
|
y: createGuideY(guideY)(facet, data),
|
|
72
72
|
};
|
|
73
73
|
const defaultAxis = {
|
|
74
|
-
x: {
|
|
75
|
-
y: {
|
|
74
|
+
x: { tickCount: 5 },
|
|
75
|
+
y: { tickCount: 5 },
|
|
76
76
|
};
|
|
77
77
|
return {
|
|
78
78
|
data,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Category } from '@antv/gui';
|
|
2
1
|
import { ActionComponent as AC } from '../../types';
|
|
3
2
|
import { LegendItemSelectionAction } from '../../../spec';
|
|
4
3
|
|
|
@@ -14,7 +13,7 @@ export const LegendItemSelection: AC<LegendItemSelectionOptions> = (
|
|
|
14
13
|
|
|
15
14
|
return (context) => {
|
|
16
15
|
const { shared, selection, scale } = context;
|
|
17
|
-
const legend = selection.select('.category-legend').node() as
|
|
16
|
+
const legend = selection.select('.category-legend').node() as any;
|
|
18
17
|
|
|
19
18
|
if (from === 'triggerInfo') {
|
|
20
19
|
shared.selectedLegendItems = shared.triggerInfo.map(({ id }) =>
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Category } from '@antv/gui';
|
|
2
1
|
import { ActionComponent as AC } from '../../types';
|
|
3
2
|
import { SetItemStateAction } from '../../../spec';
|
|
4
3
|
|
|
5
4
|
export type SetItemStateOptions = Omit<SetItemStateAction, 'type'>;
|
|
6
5
|
|
|
7
|
-
function highlightLegendItems(legend:
|
|
6
|
+
function highlightLegendItems(legend: any, items) {
|
|
8
7
|
const itemStates = legend?.getItemsStates() || [];
|
|
9
8
|
|
|
10
9
|
if (items.length) {
|
|
@@ -22,7 +21,7 @@ export const SetItemState: AC<SetItemStateOptions> = (options) => {
|
|
|
22
21
|
|
|
23
22
|
if (items.includes('legendItem')) {
|
|
24
23
|
const { selectedLegendItems: selectedItems = [] } = shared;
|
|
25
|
-
const legend = selection.select('.category-legend').node() as
|
|
24
|
+
const legend = selection.select('.category-legend').node() as any;
|
|
26
25
|
if (state === 'highlight') {
|
|
27
26
|
highlightLegendItems(legend, selectedItems);
|
|
28
27
|
} else {
|
package/src/mark/cell.ts
CHANGED
package/src/shape/area/curve.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { select } from '../../utils/selection';
|
|
|
4
4
|
import { isPolar } from '../../utils/coordinate';
|
|
5
5
|
import { Vector2, ShapeComponent as SC } from '../../runtime';
|
|
6
6
|
import { angleWithQuadrant, sub, dist } from '../../utils/vector';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
applyStyle,
|
|
9
|
+
computeGradient,
|
|
10
|
+
getShapeTheme,
|
|
11
|
+
getTransform,
|
|
12
|
+
} from '../utils';
|
|
8
13
|
import { subObject } from '../../utils/helper';
|
|
9
14
|
import { createElement } from '../createElement';
|
|
10
15
|
|
|
@@ -65,13 +70,6 @@ function segmentation(
|
|
|
65
70
|
return [definedPointsY1.concat(definedPointsY0), segments];
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
function getTransform(coordinate, value) {
|
|
69
|
-
if (!isPolar(coordinate)) return '';
|
|
70
|
-
const center = coordinate.getCenter() as Vector2;
|
|
71
|
-
const { transform: suffix } = value;
|
|
72
|
-
return `translate(${center[0]}, ${center[1]}) ${suffix || ''}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
73
|
export type CurveOptions = {
|
|
76
74
|
curve?: CurveFactory;
|
|
77
75
|
gradient?: boolean | string;
|
|
@@ -113,7 +111,7 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
113
111
|
|
|
114
112
|
const [DP, MS] = segmentation(P, defined);
|
|
115
113
|
|
|
116
|
-
const connectStyle = subObject(
|
|
114
|
+
const connectStyle = subObject(finalStyle, 'connect');
|
|
117
115
|
const missing = !!MS.length;
|
|
118
116
|
|
|
119
117
|
const getPathNode = (path) => {
|
|
@@ -35,16 +35,16 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
35
35
|
|
|
36
36
|
return (points, value, coordinate, theme) => {
|
|
37
37
|
const { mark, shape, defaultShape } = value;
|
|
38
|
-
const {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const {
|
|
39
|
+
[colorAttribute]: defaultColor,
|
|
40
|
+
radius: defaultRadius = 0,
|
|
41
|
+
...defaults
|
|
42
|
+
} = getShapeTheme(theme, mark, shape, defaultShape);
|
|
43
|
+
|
|
44
44
|
const defaultLineWidth = defaults.lineWidth || 1;
|
|
45
45
|
const {
|
|
46
46
|
stroke,
|
|
47
|
-
radius =
|
|
47
|
+
radius = defaultRadius,
|
|
48
48
|
radiusTopLeft = radius,
|
|
49
49
|
radiusTopRight = radius,
|
|
50
50
|
radiusBottomRight = radius,
|
package/src/shape/line/curve.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { line, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
|
|
1
|
+
import { line, lineRadial, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
|
|
2
2
|
import { Vector2 } from '@antv/coord';
|
|
3
3
|
import { Path } from '@antv/g';
|
|
4
4
|
import { isPolar } from '../../utils/coordinate';
|
|
5
5
|
import { select } from '../../utils/selection';
|
|
6
6
|
import { ShapeComponent as SC } from '../../runtime';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
applyStyle,
|
|
9
|
+
computeGradient,
|
|
10
|
+
getShapeTheme,
|
|
11
|
+
getTransform,
|
|
12
|
+
} from '../utils';
|
|
8
13
|
import { createElement } from '../createElement';
|
|
9
14
|
import { subObject } from '../../utils/helper';
|
|
15
|
+
import { angleWithQuadrant, dist, sub } from '../../utils/vector';
|
|
10
16
|
|
|
11
17
|
const DoublePath = createElement((g) => {
|
|
12
18
|
const { d1, d2, style1, style2 } = g.attributes;
|
|
@@ -77,7 +83,7 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
77
83
|
connectNulls = false,
|
|
78
84
|
...style
|
|
79
85
|
} = options;
|
|
80
|
-
return (
|
|
86
|
+
return (P, value, coordinate, theme) => {
|
|
81
87
|
// Compute styles.
|
|
82
88
|
const { mark, shape, defaultShape } = value;
|
|
83
89
|
const {
|
|
@@ -88,7 +94,6 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
88
94
|
const {
|
|
89
95
|
color = defaultColor,
|
|
90
96
|
size = defaultSize,
|
|
91
|
-
transform,
|
|
92
97
|
seriesColor: sc,
|
|
93
98
|
seriesX: sx,
|
|
94
99
|
seriesY: sy,
|
|
@@ -97,6 +102,7 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
97
102
|
gradient && sc
|
|
98
103
|
? computeGradient(sc, sx, sy, gradient, gradientColor)
|
|
99
104
|
: color;
|
|
105
|
+
const transform = getTransform(coordinate, value);
|
|
100
106
|
const finalStyle = {
|
|
101
107
|
...defaults,
|
|
102
108
|
...(stroke && { stroke }),
|
|
@@ -106,15 +112,24 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
106
112
|
};
|
|
107
113
|
|
|
108
114
|
// Compute points and segments.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
let linePath;
|
|
116
|
+
if (isPolar(coordinate)) {
|
|
117
|
+
const center = coordinate.getCenter() as Vector2;
|
|
118
|
+
linePath = (points) =>
|
|
119
|
+
lineRadial()
|
|
120
|
+
.angle((_, idx) => angleWithQuadrant(sub(points[idx], center)))
|
|
121
|
+
.radius((_, idx) => dist(points[idx], center))
|
|
122
|
+
.defined(([x, y]) => defined(x) && defined(y))
|
|
123
|
+
.curve(curve)(points);
|
|
124
|
+
} else {
|
|
125
|
+
linePath = line()
|
|
126
|
+
.x((d) => d[0])
|
|
127
|
+
.y((d) => d[1])
|
|
128
|
+
.defined(([x, y]) => defined(x) && defined(y))
|
|
129
|
+
.curve(curve);
|
|
130
|
+
}
|
|
116
131
|
const [DP, MS] = segmentation(P, defined);
|
|
117
|
-
const connectStyle = subObject(
|
|
132
|
+
const connectStyle = subObject(finalStyle, 'connect');
|
|
118
133
|
const missing = !!MS.length;
|
|
119
134
|
|
|
120
135
|
// Draw one path of connected defined points.
|
package/src/shape/line/line.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { curveLinear } from 'd3-shape';
|
|
1
|
+
import { curveLinear, curveLinearClosed } from 'd3-shape';
|
|
2
|
+
import { isPolar } from '../../utils/coordinate';
|
|
2
3
|
import { ShapeComponent as SC } from '../../runtime';
|
|
3
4
|
import { Curve } from './curve';
|
|
4
5
|
|
|
5
6
|
export type LineOptions = Record<string, any>;
|
|
6
7
|
|
|
7
8
|
export const Line: SC<LineOptions> = (options) => {
|
|
8
|
-
return
|
|
9
|
+
return (P, value, coordinate, theme) => {
|
|
10
|
+
const curve = isPolar(coordinate) ? curveLinearClosed : curveLinear;
|
|
11
|
+
return Curve({ curve, ...options })(P, value, coordinate, theme);
|
|
12
|
+
};
|
|
9
13
|
};
|
|
10
14
|
|
|
11
15
|
Line.props = {
|
package/src/shape/line/smooth.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { curveCatmullRom } from 'd3-shape';
|
|
1
|
+
import { curveCatmullRom, curveCatmullRomClosed } from 'd3-shape';
|
|
2
|
+
import { isPolar } from '../../utils/coordinate';
|
|
2
3
|
import { ShapeComponent as SC } from '../../runtime';
|
|
3
4
|
import { Curve } from './curve';
|
|
4
5
|
|
|
@@ -8,7 +9,15 @@ export type SmoothOptions = {
|
|
|
8
9
|
|
|
9
10
|
export const Smooth: SC<SmoothOptions> = (options) => {
|
|
10
11
|
const { alpha = 0.5, ...rest } = options;
|
|
11
|
-
return
|
|
12
|
+
return (P, value, coordinate, theme) => {
|
|
13
|
+
const curve = isPolar(coordinate) ? curveCatmullRomClosed : curveCatmullRom;
|
|
14
|
+
return Curve({ curve: curve.alpha(alpha), ...rest })(
|
|
15
|
+
P,
|
|
16
|
+
value,
|
|
17
|
+
coordinate,
|
|
18
|
+
theme,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
12
21
|
};
|
|
13
22
|
|
|
14
23
|
Smooth.props = {
|
|
@@ -164,13 +164,13 @@ export const Advance = createElement((g) => {
|
|
|
164
164
|
startMarker &&
|
|
165
165
|
new Marker({
|
|
166
166
|
id: 'startMarker',
|
|
167
|
-
style: subObject(rest, 'startMarker') as any,
|
|
167
|
+
style: { x: 0, y: 0, ...(subObject(rest, 'startMarker') as any) },
|
|
168
168
|
});
|
|
169
169
|
const markerEnd =
|
|
170
170
|
endMarker &&
|
|
171
171
|
new Marker({
|
|
172
172
|
id: 'endMarker',
|
|
173
|
-
style: subObject(rest, 'endMarker') as any,
|
|
173
|
+
style: { x: 0, y: 0, ...(subObject(rest, 'endMarker') as any) },
|
|
174
174
|
});
|
|
175
175
|
select(g)
|
|
176
176
|
.maybeAppend('connector', 'path')
|
package/src/shape/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Coordinate } from '@antv/coord';
|
|
|
4
4
|
import { Linear } from '@antv/scale';
|
|
5
5
|
import { lowerFirst } from '@antv/util';
|
|
6
6
|
import { G2Theme, Primitive, Vector2 } from '../runtime';
|
|
7
|
-
import { isTranspose } from '../utils/coordinate';
|
|
7
|
+
import { isPolar, isTranspose } from '../utils/coordinate';
|
|
8
8
|
import { angle, angleWithQuadrant, dist, sub } from '../utils/vector';
|
|
9
9
|
import { Selection } from '../utils/selection';
|
|
10
10
|
import { indexOf } from '../utils/array';
|
|
@@ -232,3 +232,10 @@ export function toOpacityKey(options) {
|
|
|
232
232
|
const { opacityAttribute = 'fill' } = options;
|
|
233
233
|
return `${opacityAttribute}Opacity`;
|
|
234
234
|
}
|
|
235
|
+
|
|
236
|
+
export function getTransform(coordinate, value) {
|
|
237
|
+
if (!isPolar(coordinate)) return '';
|
|
238
|
+
const center = coordinate.getCenter() as Vector2;
|
|
239
|
+
const { transform: suffix } = value;
|
|
240
|
+
return `translate(${center[0]}, ${center[1]}) ${suffix || ''}`;
|
|
241
|
+
}
|
package/src/spec/transform.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type Transform =
|
|
|
23
23
|
| PackTransform
|
|
24
24
|
| BinXTransform
|
|
25
25
|
| BinTransform
|
|
26
|
+
| SampleTransform
|
|
26
27
|
| FlexXTransform;
|
|
27
28
|
|
|
28
29
|
export type TransformTypes =
|
|
@@ -45,7 +46,8 @@ export type TransformTypes =
|
|
|
45
46
|
| 'sortColor'
|
|
46
47
|
| 'sortY'
|
|
47
48
|
| 'flexX'
|
|
48
|
-
| '
|
|
49
|
+
| 'pack'
|
|
50
|
+
| 'sample'
|
|
49
51
|
| TransformComponent;
|
|
50
52
|
|
|
51
53
|
export type TransformOrder =
|
|
@@ -171,6 +173,7 @@ export type SortXTransform = {
|
|
|
171
173
|
reverse?: boolean;
|
|
172
174
|
by?: string;
|
|
173
175
|
slice?: number | [number, number];
|
|
176
|
+
ordinal?: boolean;
|
|
174
177
|
reducer?:
|
|
175
178
|
| 'max'
|
|
176
179
|
| 'min'
|
|
@@ -246,3 +249,9 @@ export type BinTransform = {
|
|
|
246
249
|
thresholdsX?: number;
|
|
247
250
|
thresholdsY?: number;
|
|
248
251
|
} & { [key in ChannelTypes]?: Reducer };
|
|
252
|
+
|
|
253
|
+
export type SampleTransform = {
|
|
254
|
+
type?: 'sample';
|
|
255
|
+
groupBy?: string | string[];
|
|
256
|
+
thresholds?: number;
|
|
257
|
+
} & { [key in ChannelTypes]?: Reducer };
|
package/src/stdlib/index.ts
CHANGED
|
@@ -230,6 +230,7 @@ import {
|
|
|
230
230
|
MaybeFunctionAttribute,
|
|
231
231
|
MaybeGradient,
|
|
232
232
|
MaybeTooltip,
|
|
233
|
+
Sample,
|
|
233
234
|
} from '../transform';
|
|
234
235
|
import {
|
|
235
236
|
Fetch,
|
|
@@ -311,6 +312,7 @@ export function createLibrary(): G2Library {
|
|
|
311
312
|
'transform.maybeGradient': MaybeGradient,
|
|
312
313
|
'transform.maybeTooltip': MaybeTooltip,
|
|
313
314
|
'transform.pack': Pack,
|
|
315
|
+
'transform.sample': Sample,
|
|
314
316
|
'coordinate.cartesian': Cartesian,
|
|
315
317
|
'coordinate.polar': Polar,
|
|
316
318
|
'coordinate.helix': Helix,
|