@gravity-ui/charts 0.9.0 → 0.10.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/cjs/components/Tooltip/DefaultContent.js +18 -3
- package/dist/cjs/constants/defaults/series-options.js +12 -0
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-radar.d.ts +16 -0
- package/dist/cjs/hooks/useSeries/prepare-radar.js +63 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.js +8 -0
- package/dist/cjs/hooks/useSeries/types.d.ts +35 -2
- package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/index.js +12 -0
- package/dist/cjs/hooks/useShapes/marker.d.ts +3 -2
- package/dist/cjs/hooks/useShapes/radar/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/radar/index.js +136 -0
- package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +9 -0
- package/dist/cjs/hooks/useShapes/radar/prepare-data.js +155 -0
- package/dist/cjs/hooks/useShapes/radar/types.d.ts +58 -0
- package/dist/cjs/hooks/useShapes/radar/types.js +1 -0
- package/dist/cjs/hooks/useShapes/styles.css +4 -0
- package/dist/cjs/types/chart/radar.d.ts +50 -0
- package/dist/cjs/types/chart/radar.js +1 -0
- package/dist/cjs/types/chart/series.d.ts +17 -2
- package/dist/cjs/types/chart/tooltip.d.ts +8 -1
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/utils/chart/get-closest-data.js +39 -2
- package/dist/cjs/utils/chart/index.js +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.js +18 -3
- package/dist/esm/constants/defaults/series-options.js +12 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-radar.d.ts +16 -0
- package/dist/esm/hooks/useSeries/prepare-radar.js +63 -0
- package/dist/esm/hooks/useSeries/prepareSeries.js +8 -0
- package/dist/esm/hooks/useSeries/types.d.ts +35 -2
- package/dist/esm/hooks/useShapes/index.d.ts +2 -1
- package/dist/esm/hooks/useShapes/index.js +12 -0
- package/dist/esm/hooks/useShapes/marker.d.ts +3 -2
- package/dist/esm/hooks/useShapes/radar/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/radar/index.js +136 -0
- package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +9 -0
- package/dist/esm/hooks/useShapes/radar/prepare-data.js +155 -0
- package/dist/esm/hooks/useShapes/radar/types.d.ts +58 -0
- package/dist/esm/hooks/useShapes/radar/types.js +1 -0
- package/dist/esm/hooks/useShapes/styles.css +4 -0
- package/dist/esm/types/chart/radar.d.ts +50 -0
- package/dist/esm/types/chart/radar.js +1 -0
- package/dist/esm/types/chart/series.d.ts +17 -2
- package/dist/esm/types/chart/tooltip.d.ts +8 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/chart/get-closest-data.js +39 -2
- package/dist/esm/utils/chart/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { SeriesType } from '../../constants';
|
|
2
|
+
import type { MeaningfulAny } from '../misc';
|
|
3
|
+
import type { BaseSeries, BaseSeriesData } from './base';
|
|
4
|
+
import type { ChartLegend, RectLegendSymbolOptions } from './legend';
|
|
5
|
+
import type { PointMarkerOptions } from './marker';
|
|
6
|
+
export interface RadarSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
|
|
7
|
+
/** The value of the radar point. */
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RadarSeriesCategory {
|
|
11
|
+
/** The categories for the radar chart. */
|
|
12
|
+
key: string;
|
|
13
|
+
/** Maximum value for current key. */
|
|
14
|
+
maxValue?: number;
|
|
15
|
+
}
|
|
16
|
+
export type RadarMarkerSymbol = 'circle' | 'square';
|
|
17
|
+
export interface RadarMarkerOptions extends PointMarkerOptions {
|
|
18
|
+
symbol?: RadarMarkerSymbol;
|
|
19
|
+
}
|
|
20
|
+
export interface RadarSeries<T = MeaningfulAny> extends BaseSeries {
|
|
21
|
+
type: typeof SeriesType.Radar;
|
|
22
|
+
/** The categories for the radar chart. */
|
|
23
|
+
categories?: RadarSeriesCategory[];
|
|
24
|
+
data: RadarSeriesData<T>[];
|
|
25
|
+
/** The name of the radar series. */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** The color of the radar series. */
|
|
28
|
+
color?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The color of the border surrounding the radar area.
|
|
31
|
+
* @default `--g-color-base-background` from @gravity-ui/uikit.
|
|
32
|
+
*/
|
|
33
|
+
borderColor?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The width of the border surrounding the radar area.
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
borderWidth?: number;
|
|
39
|
+
/**
|
|
40
|
+
* The opacity of the radar area fill.
|
|
41
|
+
* @default 0.5
|
|
42
|
+
*/
|
|
43
|
+
fillOpacity?: number;
|
|
44
|
+
/** Individual series legend options. Has higher priority than legend options in widget data */
|
|
45
|
+
legend?: ChartLegend & {
|
|
46
|
+
symbol?: RectLegendSymbolOptions;
|
|
47
|
+
};
|
|
48
|
+
/** Options for the point markers of line in radar series */
|
|
49
|
+
marker?: RadarMarkerOptions;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,12 +8,13 @@ import type { Halo } from './halo';
|
|
|
8
8
|
import type { LineSeries, LineSeriesData } from './line';
|
|
9
9
|
import type { PointMarkerOptions } from './marker';
|
|
10
10
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
11
|
+
import type { RadarSeries, RadarSeriesData } from './radar';
|
|
11
12
|
import type { SankeySeries, SankeySeriesData } from './sankey';
|
|
12
13
|
import type { ScatterSeries, ScatterSeriesData } from './scatter';
|
|
13
14
|
import type { TreemapSeries, TreemapSeriesData } from './treemap';
|
|
14
15
|
import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
|
|
15
|
-
export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T>;
|
|
16
|
-
export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T>;
|
|
16
|
+
export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T> | RadarSeries<T>;
|
|
17
|
+
export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T> | RadarSeriesData<T>;
|
|
17
18
|
export interface DataLabelRendererData<T = MeaningfulAny> {
|
|
18
19
|
data: ChartSeriesData<T>;
|
|
19
20
|
}
|
|
@@ -233,4 +234,18 @@ export interface ChartSeriesOptions {
|
|
|
233
234
|
inactive?: BasicInactiveState;
|
|
234
235
|
};
|
|
235
236
|
};
|
|
237
|
+
radar?: {
|
|
238
|
+
/** Options for the series states that provide additional styling information to the series. */
|
|
239
|
+
states?: {
|
|
240
|
+
hover?: BasicHoverState & {
|
|
241
|
+
marker?: PointMarkerOptions & {
|
|
242
|
+
/** Options for the halo appearing around the hovered point */
|
|
243
|
+
halo?: Halo;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
inactive?: BasicInactiveState;
|
|
247
|
+
};
|
|
248
|
+
/** Options for the point markers of radar series */
|
|
249
|
+
marker?: PointMarkerOptions;
|
|
250
|
+
};
|
|
236
251
|
}
|
|
@@ -5,6 +5,7 @@ import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
|
5
5
|
import type { BarYSeries, BarYSeriesData } from './bar-y';
|
|
6
6
|
import type { LineSeries, LineSeriesData } from './line';
|
|
7
7
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
8
|
+
import type { RadarSeries, RadarSeriesCategory, RadarSeriesData } from './radar';
|
|
8
9
|
import type { SankeySeries, SankeySeriesData } from './sankey';
|
|
9
10
|
import type { ScatterSeries, ScatterSeriesData } from './scatter';
|
|
10
11
|
import type { TreemapSeries, TreemapSeriesData } from './treemap';
|
|
@@ -62,7 +63,13 @@ export interface TooltipDataChunkWaterfall<T = MeaningfulAny> {
|
|
|
62
63
|
data: WaterfallSeriesData<T>;
|
|
63
64
|
series: WaterfallSeries<T>;
|
|
64
65
|
}
|
|
65
|
-
export
|
|
66
|
+
export interface TooltipDataChunkRadar<T = MeaningfulAny> {
|
|
67
|
+
data: RadarSeriesData<T>;
|
|
68
|
+
series: RadarSeries<T>;
|
|
69
|
+
category?: RadarSeriesCategory;
|
|
70
|
+
closest: boolean;
|
|
71
|
+
}
|
|
72
|
+
export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T> | TooltipDataChunkRadar<T>) & {
|
|
66
73
|
closest?: boolean;
|
|
67
74
|
};
|
|
68
75
|
export interface ChartTooltipRendererArgs<T = MeaningfulAny> {
|
|
@@ -26,6 +26,7 @@ export * from './chart/halo';
|
|
|
26
26
|
export * from './chart/treemap';
|
|
27
27
|
export * from './chart/waterfall';
|
|
28
28
|
export * from './chart/sankey';
|
|
29
|
+
export * from './chart/radar';
|
|
29
30
|
export interface ChartData<T = MeaningfulAny> {
|
|
30
31
|
/**
|
|
31
32
|
* General options for the chart.
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -32,13 +32,16 @@ function getClosestPointsByXValue(x, y, points) {
|
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
34
|
function getSeriesType(shapeData) {
|
|
35
|
-
return get(shapeData, 'series.type') ||
|
|
35
|
+
return (get(shapeData, 'series.type') ||
|
|
36
|
+
get(shapeData, 'point.series.type') ||
|
|
37
|
+
get(shapeData, 'type'));
|
|
36
38
|
}
|
|
37
39
|
export function getClosestPoints(args) {
|
|
38
40
|
const { position, shapesData, boundsHeight, boundsWidth } = args;
|
|
39
41
|
const [pointerX, pointerY] = position;
|
|
40
42
|
const result = [];
|
|
41
43
|
const groups = groupBy(shapesData, getSeriesType);
|
|
44
|
+
// eslint-disable-next-line complexity
|
|
42
45
|
Object.entries(groups).forEach(([seriesType, list]) => {
|
|
43
46
|
var _a, _b;
|
|
44
47
|
switch (seriesType) {
|
|
@@ -140,7 +143,7 @@ export function getClosestPoints(args) {
|
|
|
140
143
|
const y = pointerY - center[1];
|
|
141
144
|
let angle = Math.atan2(y, x) + 0.5 * Math.PI;
|
|
142
145
|
angle = angle < 0 ? Math.PI * 2 + angle : angle;
|
|
143
|
-
const polarRadius =
|
|
146
|
+
const polarRadius = getRadius({ center, pointer: [pointerX, pointerY] });
|
|
144
147
|
return (angle >= p.startAngle && angle <= p.endAngle && polarRadius < p.data.radius);
|
|
145
148
|
});
|
|
146
149
|
if (closestPoint) {
|
|
@@ -188,6 +191,33 @@ export function getClosestPoints(args) {
|
|
|
188
191
|
}
|
|
189
192
|
break;
|
|
190
193
|
}
|
|
194
|
+
case 'radar': {
|
|
195
|
+
const [radarData] = list;
|
|
196
|
+
const radius = getRadius({ center: radarData.center, pointer: [pointerX, pointerY] });
|
|
197
|
+
if (radius <= radarData.radius) {
|
|
198
|
+
const radarShapes = radarData.shapes.filter((shape) => isInsidePath({
|
|
199
|
+
path: shape.path,
|
|
200
|
+
point: [pointerX, pointerY],
|
|
201
|
+
width: boundsWidth,
|
|
202
|
+
height: boundsHeight,
|
|
203
|
+
strokeWidth: shape.borderWidth,
|
|
204
|
+
}));
|
|
205
|
+
const points = radarShapes.map((shape) => shape.points).flat();
|
|
206
|
+
const delaunayX = Delaunay.from(points, (d) => d.position[0], (d) => d.position[1]);
|
|
207
|
+
const closestPoint = points[delaunayX.find(pointerX, pointerY)];
|
|
208
|
+
if (closestPoint) {
|
|
209
|
+
radarData.shapes.forEach((shape) => {
|
|
210
|
+
result.push({
|
|
211
|
+
data: shape.points[closestPoint.index].data,
|
|
212
|
+
series: shape.series,
|
|
213
|
+
category: shape.series.categories[closestPoint.index],
|
|
214
|
+
closest: shape.series === closestPoint.series,
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
191
221
|
}
|
|
192
222
|
});
|
|
193
223
|
return result;
|
|
@@ -206,3 +236,10 @@ function isInsidePath(args) {
|
|
|
206
236
|
}
|
|
207
237
|
return null;
|
|
208
238
|
}
|
|
239
|
+
function getRadius(args) {
|
|
240
|
+
const { pointer, center } = args;
|
|
241
|
+
const x = pointer[0] - center[0];
|
|
242
|
+
const y = pointer[1] - center[1];
|
|
243
|
+
const polarRadius = Math.sqrt(x * x + y * y);
|
|
244
|
+
return polarRadius;
|
|
245
|
+
}
|
|
@@ -15,7 +15,7 @@ export * from './legend';
|
|
|
15
15
|
export * from './symbol';
|
|
16
16
|
export * from './series';
|
|
17
17
|
export * from './color';
|
|
18
|
-
const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey'];
|
|
18
|
+
const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey', 'radar'];
|
|
19
19
|
export const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS = [
|
|
20
20
|
'bar-x',
|
|
21
21
|
'area',
|
|
@@ -28,14 +28,17 @@ const getRowData = (fieldName, data, axis) => {
|
|
|
28
28
|
const getXRowData = (data, xAxis) => getRowData('x', data, xAxis);
|
|
29
29
|
const getYRowData = (data, yAxis) => getRowData('y', data, yAxis);
|
|
30
30
|
const getMeasureValue = (data, xAxis, yAxis) => {
|
|
31
|
-
var _a, _b;
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
32
|
if (data.every((item) => ['pie', 'treemap', 'waterfall', 'sankey'].includes(item.series.type))) {
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
|
+
if (data.some((item) => item.series.type === 'radar')) {
|
|
36
|
+
return (_b = (_a = data[0].category) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : null;
|
|
37
|
+
}
|
|
35
38
|
if (data.some((item) => item.series.type === 'bar-y')) {
|
|
36
|
-
return getYRowData((
|
|
39
|
+
return getYRowData((_c = data[0]) === null || _c === void 0 ? void 0 : _c.data, yAxis);
|
|
37
40
|
}
|
|
38
|
-
return getXRowData((
|
|
41
|
+
return getXRowData((_d = data[0]) === null || _d === void 0 ? void 0 : _d.data, xAxis);
|
|
39
42
|
};
|
|
40
43
|
export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
|
|
41
44
|
const measureValue = getMeasureValue(hovered, xAxis, yAxis);
|
|
@@ -109,6 +112,18 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
|
|
|
109
112
|
": ",
|
|
110
113
|
value)));
|
|
111
114
|
}
|
|
115
|
+
case 'radar': {
|
|
116
|
+
const radarSeries = series;
|
|
117
|
+
const seriesData = data;
|
|
118
|
+
const value = (React.createElement(React.Fragment, null,
|
|
119
|
+
React.createElement("span", null,
|
|
120
|
+
radarSeries.name || radarSeries.id,
|
|
121
|
+
"\u00A0"),
|
|
122
|
+
React.createElement("span", null, seriesData.value)));
|
|
123
|
+
return (React.createElement("div", { key: id, className: b('content-row') },
|
|
124
|
+
React.createElement("div", { className: b('color'), style: { backgroundColor: color } }),
|
|
125
|
+
React.createElement("div", null, closest ? React.createElement("b", null, value) : React.createElement("span", null, value))));
|
|
126
|
+
}
|
|
112
127
|
default: {
|
|
113
128
|
return null;
|
|
114
129
|
}
|
|
@@ -89,6 +89,18 @@ export const seriesOptionsDefaults = {
|
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
|
+
radar: {
|
|
93
|
+
states: {
|
|
94
|
+
hover: {
|
|
95
|
+
enabled: true,
|
|
96
|
+
brightness: 0.3,
|
|
97
|
+
},
|
|
98
|
+
inactive: {
|
|
99
|
+
enabled: true,
|
|
100
|
+
opacity: 0.5,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
92
104
|
waterfall: {
|
|
93
105
|
barMaxWidth: 50,
|
|
94
106
|
barPadding: 0.1,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChartSeriesOptions, RadarSeries } from '../../types';
|
|
2
|
+
import type { PreparedLegend, PreparedRadarSeries } from './types';
|
|
3
|
+
type PrepareRadarSeriesArgs = {
|
|
4
|
+
series: RadarSeries[];
|
|
5
|
+
seriesOptions?: ChartSeriesOptions;
|
|
6
|
+
legend: PreparedLegend;
|
|
7
|
+
};
|
|
8
|
+
export declare const DEFAULT_MARKER: {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
radius: number;
|
|
11
|
+
symbol: `${import("../../constants").SymbolType}`;
|
|
12
|
+
borderColor: string;
|
|
13
|
+
borderWidth: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function prepareRadarSeries(args: PrepareRadarSeriesArgs): PreparedRadarSeries[];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { scaleOrdinal } from 'd3';
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import merge from 'lodash/merge';
|
|
4
|
+
import { DEFAULT_PALETTE } from '../../constants';
|
|
5
|
+
import { getUniqId } from '../../utils';
|
|
6
|
+
import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_POINT_MARKER_OPTIONS, } from './constants';
|
|
7
|
+
import { prepareLegendSymbol } from './utils';
|
|
8
|
+
export const DEFAULT_MARKER = Object.assign(Object.assign({}, DEFAULT_POINT_MARKER_OPTIONS), { enabled: true, radius: 2 });
|
|
9
|
+
function prepareMarker(series, seriesOptions) {
|
|
10
|
+
var _a;
|
|
11
|
+
const seriesHoverState = get(seriesOptions, 'radar.states.hover');
|
|
12
|
+
const markerNormalState = Object.assign({}, DEFAULT_MARKER, (_a = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.radar) === null || _a === void 0 ? void 0 : _a.marker, series.marker);
|
|
13
|
+
const hoveredMarkerDefaultOptions = {
|
|
14
|
+
enabled: true,
|
|
15
|
+
radius: markerNormalState.radius + 1,
|
|
16
|
+
borderWidth: 1,
|
|
17
|
+
borderColor: '#ffffff',
|
|
18
|
+
halo: DEFAULT_HALO_OPTIONS,
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
states: {
|
|
22
|
+
normal: markerNormalState,
|
|
23
|
+
hover: merge(hoveredMarkerDefaultOptions, seriesHoverState === null || seriesHoverState === void 0 ? void 0 : seriesHoverState.marker),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function prepareRadarSeries(args) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const { series: radarSeries, seriesOptions, legend } = args;
|
|
30
|
+
const colorScale = scaleOrdinal(radarSeries.map((s, index) => { var _a; return (_a = s.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`; }), DEFAULT_PALETTE);
|
|
31
|
+
const categories = (_b = (_a = radarSeries.find((s) => s.categories)) === null || _a === void 0 ? void 0 : _a.categories) !== null && _b !== void 0 ? _b : [];
|
|
32
|
+
return radarSeries.map((series, index) => {
|
|
33
|
+
var _a, _b, _c, _d, _e;
|
|
34
|
+
const name = (_a = series.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`;
|
|
35
|
+
const color = (_b = series.color) !== null && _b !== void 0 ? _b : colorScale(name);
|
|
36
|
+
const preparedSeries = {
|
|
37
|
+
type: 'radar',
|
|
38
|
+
data: series.data,
|
|
39
|
+
categories,
|
|
40
|
+
id: getUniqId(),
|
|
41
|
+
name,
|
|
42
|
+
color,
|
|
43
|
+
visible: typeof series.visible === 'boolean' ? series.visible : true,
|
|
44
|
+
legend: {
|
|
45
|
+
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
46
|
+
symbol: prepareLegendSymbol(series),
|
|
47
|
+
},
|
|
48
|
+
borderColor: series.borderColor || color,
|
|
49
|
+
borderWidth: (_c = series.borderWidth) !== null && _c !== void 0 ? _c : 1,
|
|
50
|
+
fillOpacity: (_d = series.fillOpacity) !== null && _d !== void 0 ? _d : 0.25,
|
|
51
|
+
dataLabels: {
|
|
52
|
+
enabled: get(series, 'dataLabels.enabled', true),
|
|
53
|
+
style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.style),
|
|
54
|
+
padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
|
|
55
|
+
allowOverlap: get(series, 'dataLabels.allowOverlap', false),
|
|
56
|
+
html: get(series, 'dataLabels.html', false),
|
|
57
|
+
},
|
|
58
|
+
cursor: get(series, 'cursor', null),
|
|
59
|
+
marker: prepareMarker(series, seriesOptions),
|
|
60
|
+
};
|
|
61
|
+
return preparedSeries;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -4,6 +4,7 @@ import { prepareBarXSeries } from './prepare-bar-x';
|
|
|
4
4
|
import { prepareBarYSeries } from './prepare-bar-y';
|
|
5
5
|
import { prepareLineSeries } from './prepare-line';
|
|
6
6
|
import { preparePieSeries } from './prepare-pie';
|
|
7
|
+
import { prepareRadarSeries } from './prepare-radar';
|
|
7
8
|
import { prepareSankeySeries } from './prepare-sankey';
|
|
8
9
|
import { prepareScatterSeries } from './prepare-scatter';
|
|
9
10
|
import { prepareTreemap } from './prepare-treemap';
|
|
@@ -75,6 +76,13 @@ export function prepareSeries(args) {
|
|
|
75
76
|
legend,
|
|
76
77
|
});
|
|
77
78
|
}
|
|
79
|
+
case 'radar': {
|
|
80
|
+
return prepareRadarSeries({
|
|
81
|
+
series: series,
|
|
82
|
+
seriesOptions,
|
|
83
|
+
legend,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
78
86
|
default: {
|
|
79
87
|
throw new ChartError({
|
|
80
88
|
message: `Series type "${type}" does not support data preparation for series that do not support the presence of axes`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DashStyle, LayoutAlgorithm, LineCap, SeriesOptionsDefaults, SymbolType } from '../../constants';
|
|
2
|
-
import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, WaterfallSeries, WaterfallSeriesData } from '../../types';
|
|
2
|
+
import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, WaterfallSeries, WaterfallSeriesData } from '../../types';
|
|
3
3
|
export type RectLegendSymbol = {
|
|
4
4
|
shape: 'rect';
|
|
5
5
|
} & Required<RectLegendSymbolOptions>;
|
|
@@ -258,7 +258,40 @@ export type PreparedSankeySeries = {
|
|
|
258
258
|
style: BaseTextStyle;
|
|
259
259
|
};
|
|
260
260
|
} & BasePreparedSeries & Omit<SankeySeries, keyof BasePreparedSeries>;
|
|
261
|
-
export type
|
|
261
|
+
export type PreparedRadarSeries = {
|
|
262
|
+
type: RadarSeries['type'];
|
|
263
|
+
data: RadarSeriesData[];
|
|
264
|
+
categories: RadarSeriesCategory[];
|
|
265
|
+
borderColor: string;
|
|
266
|
+
borderWidth: number;
|
|
267
|
+
fillOpacity: number;
|
|
268
|
+
dataLabels: {
|
|
269
|
+
enabled: boolean;
|
|
270
|
+
style: BaseTextStyle;
|
|
271
|
+
padding: number;
|
|
272
|
+
allowOverlap: boolean;
|
|
273
|
+
html: boolean;
|
|
274
|
+
};
|
|
275
|
+
marker: {
|
|
276
|
+
states: {
|
|
277
|
+
normal: {
|
|
278
|
+
symbol: `${SymbolType}`;
|
|
279
|
+
enabled: boolean;
|
|
280
|
+
radius: number;
|
|
281
|
+
borderWidth: number;
|
|
282
|
+
borderColor: string;
|
|
283
|
+
};
|
|
284
|
+
hover: {
|
|
285
|
+
enabled: boolean;
|
|
286
|
+
radius: number;
|
|
287
|
+
borderWidth: number;
|
|
288
|
+
borderColor: string;
|
|
289
|
+
halo: PreparedHaloOptions;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
} & BasePreparedSeries;
|
|
294
|
+
export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries | PreparedRadarSeries;
|
|
262
295
|
export type PreparedSeriesOptions = SeriesOptionsDefaults;
|
|
263
296
|
export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
|
|
264
297
|
export {};
|
|
@@ -8,13 +8,14 @@ import type { PreparedBarXData } from './bar-x';
|
|
|
8
8
|
import type { PreparedBarYData } from './bar-y/types';
|
|
9
9
|
import type { PreparedLineData } from './line/types';
|
|
10
10
|
import type { PreparedPieData } from './pie/types';
|
|
11
|
+
import type { PreparedRadarData } from './radar/types';
|
|
11
12
|
import type { PreparedSankeyData } from './sankey/types';
|
|
12
13
|
import type { PreparedScatterData } from './scatter/types';
|
|
13
14
|
export type { PreparedBarXData } from './bar-x';
|
|
14
15
|
export type { PreparedScatterData } from './scatter/types';
|
|
15
16
|
import type { PreparedWaterfallData } from './waterfall';
|
|
16
17
|
import './styles.css';
|
|
17
|
-
export type ShapeData = PreparedBarXData | PreparedBarYData | PreparedScatterData | PreparedLineData | PreparedPieData | PreparedAreaData | PreparedWaterfallData | PreparedSankeyData;
|
|
18
|
+
export type ShapeData = PreparedBarXData | PreparedBarYData | PreparedScatterData | PreparedLineData | PreparedPieData | PreparedAreaData | PreparedWaterfallData | PreparedSankeyData | PreparedRadarData;
|
|
18
19
|
type Args = {
|
|
19
20
|
boundsWidth: number;
|
|
20
21
|
boundsHeight: number;
|
|
@@ -10,6 +10,8 @@ import { LineSeriesShapes } from './line';
|
|
|
10
10
|
import { prepareLineData } from './line/prepare-data';
|
|
11
11
|
import { PieSeriesShapes } from './pie';
|
|
12
12
|
import { preparePieData } from './pie/prepare-data';
|
|
13
|
+
import { RadarSeriesShapes } from './radar';
|
|
14
|
+
import { prepareRadarData } from './radar/prepare-data';
|
|
13
15
|
import { SankeySeriesShape } from './sankey';
|
|
14
16
|
import { prepareSankeyData } from './sankey/prepare-data';
|
|
15
17
|
import { ScatterSeriesShape, prepareScatterData } from './scatter';
|
|
@@ -149,6 +151,16 @@ export const useShapes = (args) => {
|
|
|
149
151
|
shapesData.push(preparedData);
|
|
150
152
|
break;
|
|
151
153
|
}
|
|
154
|
+
case 'radar': {
|
|
155
|
+
const preparedData = prepareRadarData({
|
|
156
|
+
series: chartSeries,
|
|
157
|
+
boundsWidth,
|
|
158
|
+
boundsHeight,
|
|
159
|
+
});
|
|
160
|
+
acc.push(React.createElement(RadarSeriesShapes, { key: "radar", dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
161
|
+
shapesData.push(...preparedData);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
152
164
|
default: {
|
|
153
165
|
throw new ChartError({
|
|
154
166
|
message: `The display method is not defined for a series with type "${seriesType}"`,
|
|
@@ -2,9 +2,10 @@ import type { BaseType, Selection } from 'd3';
|
|
|
2
2
|
import { SymbolType } from '../../constants';
|
|
3
3
|
import type { MarkerData as AreaMarkerData } from './area/types';
|
|
4
4
|
import type { MarkerData as LineMarkerData } from './line/types';
|
|
5
|
+
import type { RadarMarkerData } from './radar/types';
|
|
5
6
|
import type { MarkerData as ScatterMarkerData } from './scatter/types';
|
|
6
|
-
type MarkerData = LineMarkerData | AreaMarkerData | ScatterMarkerData;
|
|
7
|
-
export declare function renderMarker<T extends MarkerData>(selection: Selection<BaseType
|
|
7
|
+
type MarkerData = LineMarkerData | AreaMarkerData | ScatterMarkerData | RadarMarkerData;
|
|
8
|
+
export declare function renderMarker<T extends MarkerData>(selection: Selection<BaseType, T, BaseType, unknown>): Selection<BaseType, T, BaseType, unknown>;
|
|
8
9
|
export declare function getMarkerVisibility(d: MarkerData): "" | "hidden";
|
|
9
10
|
export declare function getMarkerHaloVisibility(d: MarkerData): "" | "hidden";
|
|
10
11
|
export declare function setMarker<T extends BaseType, D extends MarkerData>(selection: Selection<T, D, BaseType | null, unknown>, state: 'normal' | 'hover'): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Dispatch } from 'd3';
|
|
3
|
+
import type { PreparedSeriesOptions } from '../../useSeries/types';
|
|
4
|
+
import type { PreparedRadarData } from './types';
|
|
5
|
+
type PrepareRadarSeriesArgs = {
|
|
6
|
+
dispatcher: Dispatch<object>;
|
|
7
|
+
series: PreparedRadarData[];
|
|
8
|
+
seriesOptions: PreparedSeriesOptions;
|
|
9
|
+
htmlLayout: HTMLElement | null;
|
|
10
|
+
};
|
|
11
|
+
export declare function RadarSeriesShapes(args: PrepareRadarSeriesArgs): React.JSX.Element;
|
|
12
|
+
export {};
|