@gravity-ui/chartkit 4.13.0 → 4.15.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/build/constants/index.d.ts +1 -0
- package/build/constants/index.js +1 -0
- package/build/constants/widget-data.d.ts +27 -0
- package/build/constants/widget-data.js +29 -0
- package/build/i18n/keysets/en.json +6 -1
- package/build/i18n/keysets/ru.json +6 -1
- package/build/libs/chartkit-error/chartkit-error.d.ts +1 -0
- package/build/libs/chartkit-error/chartkit-error.js +1 -0
- package/build/plugins/d3/examples/ExampleWrapper.d.ts +7 -0
- package/build/plugins/d3/examples/ExampleWrapper.js +5 -0
- package/build/plugins/d3/examples/area/Basic.d.ts +2 -0
- package/build/plugins/d3/examples/area/Basic.js +34 -0
- package/build/plugins/d3/examples/area/StackedArea.d.ts +2 -0
- package/build/plugins/d3/examples/area/StackedArea.js +47 -0
- package/build/plugins/d3/examples/bar-x/Basic.js +19 -9
- package/build/plugins/d3/examples/bar-x/DataLabels.js +4 -2
- package/build/plugins/d3/examples/bar-x/GroupedColumns.js +4 -2
- package/build/plugins/d3/examples/bar-x/StackedColumns.js +4 -2
- package/build/plugins/d3/examples/bar-y/Basic.js +4 -2
- package/build/plugins/d3/examples/bar-y/GroupedColumns.js +4 -2
- package/build/plugins/d3/examples/bar-y/StackedColumns.js +4 -2
- package/build/plugins/d3/examples/combined/LineAndBarX.js +5 -3
- package/build/plugins/d3/examples/line/Basic.js +4 -2
- package/build/plugins/d3/examples/line/DataLabels.js +4 -2
- package/build/plugins/d3/examples/line/LineWithMarkers.js +4 -2
- package/build/plugins/d3/examples/line/Shapes.d.ts +2 -0
- package/build/plugins/d3/examples/line/Shapes.js +93 -0
- package/build/plugins/d3/examples/pie/Basic.js +4 -2
- package/build/plugins/d3/examples/pie/Donut.js +4 -2
- package/build/plugins/d3/examples/scatter/Basic.js +4 -2
- package/build/plugins/d3/renderer/D3Widget.js +27 -23
- package/build/plugins/d3/renderer/components/Legend.js +4 -0
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +1 -0
- package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +1 -1
- package/build/plugins/d3/renderer/constants/defaults/axis.d.ts +2 -0
- package/build/plugins/d3/renderer/constants/defaults/axis.js +1 -0
- package/build/plugins/d3/renderer/constants/defaults/series-options.js +16 -4
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +3 -2
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +2 -1
- package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +2 -1
- package/build/plugins/d3/renderer/hooks/useSeries/constants.js +5 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.js +66 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-x.js +2 -7
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-y.js +2 -7
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.d.ts +2 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.js +13 -6
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-pie.d.ts +2 -1
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-pie.js +11 -1
- package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +10 -1
- package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +50 -7
- package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +2 -1
- package/build/plugins/d3/renderer/hooks/useSeries/utils.js +10 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/index.d.ts +11 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/index.js +137 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.d.ts +11 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.js +114 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/types.d.ts +27 -0
- package/build/plugins/d3/renderer/hooks/useShapes/area/types.js +1 -0
- package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +2 -1
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +16 -0
- package/build/plugins/d3/renderer/hooks/useShapes/line/index.js +9 -65
- package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.js +5 -2
- package/build/plugins/d3/renderer/hooks/useShapes/line/types.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useShapes/marker.d.ts +12 -0
- package/build/plugins/d3/renderer/hooks/useShapes/marker.js +70 -0
- package/build/plugins/d3/renderer/hooks/useShapes/pie/index.d.ts +3 -2
- package/build/plugins/d3/renderer/hooks/useShapes/pie/index.js +28 -0
- package/build/plugins/d3/renderer/hooks/useShapes/pie/prepare-data.js +9 -3
- package/build/plugins/d3/renderer/hooks/useShapes/pie/types.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +1 -1
- package/build/plugins/d3/renderer/hooks/useShapes/utils.d.ts +2 -0
- package/build/plugins/d3/renderer/hooks/useShapes/utils.js +17 -0
- package/build/plugins/d3/renderer/utils/index.d.ts +1 -1
- package/build/plugins/d3/renderer/utils/index.js +16 -9
- package/build/plugins/d3/renderer/validation/__mocks__/index.d.ts +3 -0
- package/build/plugins/d3/renderer/validation/__mocks__/index.js +44 -0
- package/build/plugins/d3/renderer/validation/index.d.ts +2 -0
- package/build/plugins/d3/renderer/validation/index.js +139 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.js +0 -3
- package/build/types/widget-data/area.d.ts +58 -0
- package/build/types/widget-data/area.js +1 -0
- package/build/types/widget-data/bar-x.d.ts +2 -1
- package/build/types/widget-data/bar-y.d.ts +2 -1
- package/build/types/widget-data/halo.d.ts +9 -0
- package/build/types/widget-data/halo.js +1 -0
- package/build/types/widget-data/index.d.ts +2 -0
- package/build/types/widget-data/index.js +2 -0
- package/build/types/widget-data/line.d.ts +9 -4
- package/build/types/widget-data/pie.d.ts +2 -1
- package/build/types/widget-data/scatter.d.ts +2 -1
- package/build/types/widget-data/series.d.ts +40 -9
- package/build/types/widget-data/tooltip.d.ts +10 -1
- package/package.json +7 -2
|
@@ -4,35 +4,13 @@ import debounce from 'lodash/debounce';
|
|
|
4
4
|
import afterFrame from 'afterframe';
|
|
5
5
|
import { getRandomCKId, measurePerformance } from '../../../utils';
|
|
6
6
|
import { Chart } from './components';
|
|
7
|
+
import { validateData } from './validation';
|
|
7
8
|
const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
|
|
8
9
|
const { data, onLoad, onRender, onChartLoad } = props;
|
|
9
10
|
const ref = React.useRef(null);
|
|
10
11
|
const debounced = React.useRef();
|
|
11
12
|
const [dimensions, setDimensions] = React.useState();
|
|
12
13
|
const performanceMeasure = React.useRef(measurePerformance());
|
|
13
|
-
React.useLayoutEffect(() => {
|
|
14
|
-
if (onChartLoad) {
|
|
15
|
-
onChartLoad({});
|
|
16
|
-
}
|
|
17
|
-
}, [onChartLoad]);
|
|
18
|
-
React.useLayoutEffect(() => {
|
|
19
|
-
if (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) {
|
|
20
|
-
if (!performanceMeasure.current) {
|
|
21
|
-
performanceMeasure.current = measurePerformance();
|
|
22
|
-
}
|
|
23
|
-
afterFrame(() => {
|
|
24
|
-
var _a;
|
|
25
|
-
const renderTime = (_a = performanceMeasure.current) === null || _a === void 0 ? void 0 : _a.end();
|
|
26
|
-
onRender === null || onRender === void 0 ? void 0 : onRender({
|
|
27
|
-
renderTime,
|
|
28
|
-
});
|
|
29
|
-
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
30
|
-
widgetRendering: renderTime,
|
|
31
|
-
});
|
|
32
|
-
performanceMeasure.current = null;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}, [data, onRender, onLoad, dimensions]);
|
|
36
14
|
const handleResize = React.useCallback(() => {
|
|
37
15
|
var _a;
|
|
38
16
|
const parentElement = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
@@ -66,6 +44,32 @@ const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
|
|
|
66
44
|
// dimensions initialize
|
|
67
45
|
handleResize();
|
|
68
46
|
}, [handleResize]);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
validateData(data);
|
|
49
|
+
}, [data]);
|
|
50
|
+
React.useLayoutEffect(() => {
|
|
51
|
+
if (onChartLoad) {
|
|
52
|
+
onChartLoad({});
|
|
53
|
+
}
|
|
54
|
+
}, [onChartLoad]);
|
|
55
|
+
React.useLayoutEffect(() => {
|
|
56
|
+
if (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) {
|
|
57
|
+
if (!performanceMeasure.current) {
|
|
58
|
+
performanceMeasure.current = measurePerformance();
|
|
59
|
+
}
|
|
60
|
+
afterFrame(() => {
|
|
61
|
+
var _a;
|
|
62
|
+
const renderTime = (_a = performanceMeasure.current) === null || _a === void 0 ? void 0 : _a.end();
|
|
63
|
+
onRender === null || onRender === void 0 ? void 0 : onRender({
|
|
64
|
+
renderTime,
|
|
65
|
+
});
|
|
66
|
+
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
67
|
+
widgetRendering: renderTime,
|
|
68
|
+
});
|
|
69
|
+
performanceMeasure.current = null;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, [data, onRender, onLoad, dimensions]);
|
|
69
73
|
return (React.createElement("div", { ref: ref, style: {
|
|
70
74
|
width: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) || '100%',
|
|
71
75
|
height: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.height) || '100%',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { select, line as lineGenerator } from 'd3';
|
|
3
3
|
import { block } from '../../../../utils/cn';
|
|
4
|
+
import { getLineDashArray } from '../hooks/useShapes/utils';
|
|
4
5
|
const b = block('d3-legend');
|
|
5
6
|
const getLegendPosition = (args) => {
|
|
6
7
|
const { align, offsetWidth, width, contentWidth } = args;
|
|
@@ -90,6 +91,9 @@ function renderLegendSymbol(args) {
|
|
|
90
91
|
.attr('stroke-width', d.symbol.strokeWidth)
|
|
91
92
|
.attr('class', className)
|
|
92
93
|
.style('stroke', color);
|
|
94
|
+
if (d.dashStyle) {
|
|
95
|
+
element.attr('stroke-dasharray', getLineDashArray(d.dashStyle, d.symbol.strokeWidth));
|
|
96
|
+
}
|
|
93
97
|
break;
|
|
94
98
|
}
|
|
95
99
|
case 'rect': {
|
|
@@ -72,7 +72,7 @@ export const TooltipTriggerArea = (args) => {
|
|
|
72
72
|
}, [shapesData]);
|
|
73
73
|
const xLineData = React.useMemo(() => {
|
|
74
74
|
const result = shapesData
|
|
75
|
-
.filter((sd) => sd.series.type
|
|
75
|
+
.filter((sd) => ['line', 'area'].includes(sd.series.type))
|
|
76
76
|
.reduce((acc, sd) => {
|
|
77
77
|
return acc.concat(sd.points.map((d) => ({
|
|
78
78
|
x: d.x,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChartKitWidgetAxisType } from '../../../../../types';
|
|
1
2
|
export declare const axisLabelsDefaults: {
|
|
2
3
|
margin: number;
|
|
3
4
|
padding: number;
|
|
@@ -12,3 +13,4 @@ export declare const yAxisTitleDefaults: {
|
|
|
12
13
|
margin: number;
|
|
13
14
|
fontSize: string;
|
|
14
15
|
};
|
|
16
|
+
export declare const DEFAULT_AXIS_TYPE: ChartKitWidgetAxisType;
|
|
@@ -9,3 +9,4 @@ const axisTitleDefaults = {
|
|
|
9
9
|
};
|
|
10
10
|
export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
|
|
11
11
|
export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
|
|
12
|
+
export const DEFAULT_AXIS_TYPE = 'linear';
|
|
@@ -9,7 +9,7 @@ export const seriesOptionsDefaults = {
|
|
|
9
9
|
brightness: 0.3,
|
|
10
10
|
},
|
|
11
11
|
inactive: {
|
|
12
|
-
enabled:
|
|
12
|
+
enabled: false,
|
|
13
13
|
opacity: 0.5,
|
|
14
14
|
},
|
|
15
15
|
},
|
|
@@ -24,7 +24,7 @@ export const seriesOptionsDefaults = {
|
|
|
24
24
|
brightness: 0.3,
|
|
25
25
|
},
|
|
26
26
|
inactive: {
|
|
27
|
-
enabled:
|
|
27
|
+
enabled: false,
|
|
28
28
|
opacity: 0.5,
|
|
29
29
|
},
|
|
30
30
|
},
|
|
@@ -36,7 +36,7 @@ export const seriesOptionsDefaults = {
|
|
|
36
36
|
brightness: 0.3,
|
|
37
37
|
},
|
|
38
38
|
inactive: {
|
|
39
|
-
enabled:
|
|
39
|
+
enabled: false,
|
|
40
40
|
opacity: 0.5,
|
|
41
41
|
},
|
|
42
42
|
},
|
|
@@ -48,7 +48,7 @@ export const seriesOptionsDefaults = {
|
|
|
48
48
|
brightness: 0.3,
|
|
49
49
|
},
|
|
50
50
|
inactive: {
|
|
51
|
-
enabled:
|
|
51
|
+
enabled: false,
|
|
52
52
|
opacity: 0.5,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
@@ -60,7 +60,19 @@ export const seriesOptionsDefaults = {
|
|
|
60
60
|
brightness: 0.3,
|
|
61
61
|
},
|
|
62
62
|
inactive: {
|
|
63
|
+
enabled: false,
|
|
64
|
+
opacity: 0.5,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
area: {
|
|
69
|
+
states: {
|
|
70
|
+
hover: {
|
|
63
71
|
enabled: true,
|
|
72
|
+
brightness: 0.3,
|
|
73
|
+
},
|
|
74
|
+
inactive: {
|
|
75
|
+
enabled: false,
|
|
64
76
|
opacity: 0.5,
|
|
65
77
|
},
|
|
66
78
|
},
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { scaleBand, scaleLinear, scaleUtc, extent } from 'd3';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { getOnlyVisibleSeries, getDataCategoryValue, getDomainDataYBySeries, getDomainDataXBySeries, isAxisRelatedSeries, isSeriesWithCategoryValues, } from '../../utils';
|
|
5
|
+
import { DEFAULT_AXIS_TYPE } from '../../constants';
|
|
5
6
|
const isNumericalArrayData = (data) => {
|
|
6
7
|
return data.every((d) => typeof d === 'number' || d === null);
|
|
7
8
|
};
|
|
@@ -18,7 +19,7 @@ const filterCategoriesByVisibleSeries = (args) => {
|
|
|
18
19
|
return categories.filter((c) => visibleCategories.has(c));
|
|
19
20
|
};
|
|
20
21
|
export function createYScale(axis, series, boundsHeight) {
|
|
21
|
-
const yType = get(axis, 'type',
|
|
22
|
+
const yType = get(axis, 'type', DEFAULT_AXIS_TYPE);
|
|
22
23
|
const yMin = get(axis, 'min');
|
|
23
24
|
const yCategories = get(axis, 'categories');
|
|
24
25
|
const yTimestamps = get(axis, 'timestamps');
|
|
@@ -78,7 +79,7 @@ function calculateXAxisPadding(series) {
|
|
|
78
79
|
}
|
|
79
80
|
export function createXScale(axis, series, boundsWidth) {
|
|
80
81
|
const xMin = get(axis, 'min');
|
|
81
|
-
const xType = get(axis, 'type',
|
|
82
|
+
const xType = get(axis, 'type', DEFAULT_AXIS_TYPE);
|
|
82
83
|
const xCategories = get(axis, 'categories');
|
|
83
84
|
const xTimestamps = get(axis, 'timestamps');
|
|
84
85
|
const maxPadding = get(axis, 'maxPadding', 0);
|
|
@@ -24,7 +24,8 @@ const getAxisLabelMaxWidth = (args) => {
|
|
|
24
24
|
};
|
|
25
25
|
function getAxisMin(axis, series) {
|
|
26
26
|
const min = axis === null || axis === void 0 ? void 0 : axis.min;
|
|
27
|
-
|
|
27
|
+
const seriesWithVolume = ['bar-x', 'area'];
|
|
28
|
+
if (typeof min === 'undefined' && (series === null || series === void 0 ? void 0 : series.some((s) => seriesWithVolume.includes(s.type)))) {
|
|
28
29
|
return 0;
|
|
29
30
|
}
|
|
30
31
|
return min;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BaseTextStyle } from '../../../../../types';
|
|
1
|
+
import type { BaseTextStyle, Halo } from '../../../../../types';
|
|
2
2
|
export declare const DEFAULT_LEGEND_SYMBOL_SIZE = 8;
|
|
3
3
|
export declare const DEFAULT_LEGEND_SYMBOL_PADDING = 5;
|
|
4
4
|
export declare const DEFAULT_DATALABELS_PADDING = 5;
|
|
5
5
|
export declare const DEFAULT_DATALABELS_STYLE: BaseTextStyle;
|
|
6
|
+
export declare const DEFAULT_HALO_OPTIONS: Required<Halo>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScaleOrdinal } from 'd3';
|
|
2
|
+
import { ChartKitWidgetSeriesOptions, AreaSeries } from '../../../../../types';
|
|
3
|
+
import { PreparedAreaSeries, PreparedLegend } from './types';
|
|
4
|
+
export declare const DEFAULT_LINE_WIDTH = 1;
|
|
5
|
+
export declare const DEFAULT_MARKER: {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
symbol: string;
|
|
8
|
+
radius: number;
|
|
9
|
+
borderWidth: number;
|
|
10
|
+
borderColor: string;
|
|
11
|
+
};
|
|
12
|
+
type PrepareAreaSeriesArgs = {
|
|
13
|
+
colorScale: ScaleOrdinal<string, string>;
|
|
14
|
+
series: AreaSeries[];
|
|
15
|
+
seriesOptions?: ChartKitWidgetSeriesOptions;
|
|
16
|
+
legend: PreparedLegend;
|
|
17
|
+
};
|
|
18
|
+
export declare function prepareArea(args: PrepareAreaSeriesArgs): PreparedAreaSeries[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import merge from 'lodash/merge';
|
|
3
|
+
import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, } from './constants';
|
|
4
|
+
import { getRandomCKId } from '../../../../../utils';
|
|
5
|
+
import { getSeriesStackId, prepareLegendSymbol } from './utils';
|
|
6
|
+
export const DEFAULT_LINE_WIDTH = 1;
|
|
7
|
+
export const DEFAULT_MARKER = {
|
|
8
|
+
enabled: false,
|
|
9
|
+
symbol: 'circle',
|
|
10
|
+
radius: 4,
|
|
11
|
+
borderWidth: 0,
|
|
12
|
+
borderColor: '',
|
|
13
|
+
};
|
|
14
|
+
function prepareMarker(series, seriesOptions) {
|
|
15
|
+
var _a;
|
|
16
|
+
const seriesHoverState = get(seriesOptions, 'area.states.hover');
|
|
17
|
+
const markerNormalState = Object.assign({}, DEFAULT_MARKER, (_a = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.area) === null || _a === void 0 ? void 0 : _a.marker, series.marker);
|
|
18
|
+
const hoveredMarkerDefaultOptions = {
|
|
19
|
+
enabled: true,
|
|
20
|
+
radius: markerNormalState.radius,
|
|
21
|
+
borderWidth: 1,
|
|
22
|
+
borderColor: '#ffffff',
|
|
23
|
+
halo: DEFAULT_HALO_OPTIONS,
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
states: {
|
|
27
|
+
normal: markerNormalState,
|
|
28
|
+
hover: merge(hoveredMarkerDefaultOptions, seriesHoverState === null || seriesHoverState === void 0 ? void 0 : seriesHoverState.marker),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function prepareArea(args) {
|
|
33
|
+
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
34
|
+
const defaultAreaWidth = get(seriesOptions, 'area.lineWidth', DEFAULT_LINE_WIDTH);
|
|
35
|
+
const defaultOpacity = get(seriesOptions, 'area.opacity', 0.75);
|
|
36
|
+
return seriesList.map((series) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const id = getRandomCKId();
|
|
39
|
+
const name = series.name || '';
|
|
40
|
+
const color = series.color || colorScale(name);
|
|
41
|
+
const prepared = {
|
|
42
|
+
type: series.type,
|
|
43
|
+
color,
|
|
44
|
+
opacity: get(series, 'opacity', defaultOpacity),
|
|
45
|
+
lineWidth: get(series, 'lineWidth', defaultAreaWidth),
|
|
46
|
+
name,
|
|
47
|
+
id,
|
|
48
|
+
visible: get(series, 'visible', true),
|
|
49
|
+
legend: {
|
|
50
|
+
enabled: get(series, 'legend.enabled', legend.enabled),
|
|
51
|
+
symbol: prepareLegendSymbol(series),
|
|
52
|
+
},
|
|
53
|
+
data: series.data,
|
|
54
|
+
stacking: series.stacking,
|
|
55
|
+
stackId: getSeriesStackId(series),
|
|
56
|
+
dataLabels: {
|
|
57
|
+
enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
|
|
58
|
+
style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
|
|
59
|
+
padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
|
|
60
|
+
allowOverlap: get(series, 'dataLabels.allowOverlap', false),
|
|
61
|
+
},
|
|
62
|
+
marker: prepareMarker(series, seriesOptions),
|
|
63
|
+
};
|
|
64
|
+
return prepared;
|
|
65
|
+
}, []);
|
|
66
|
+
}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import { getRandomCKId } from '../../../../../utils';
|
|
3
|
-
import { prepareLegendSymbol } from './utils';
|
|
3
|
+
import { getSeriesStackId, prepareLegendSymbol } from './utils';
|
|
4
4
|
import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE } from './constants';
|
|
5
5
|
export function prepareBarXSeries(args) {
|
|
6
6
|
const { colorScale, series: seriesList, legend } = args;
|
|
7
|
-
const commonStackId = getRandomCKId();
|
|
8
7
|
return seriesList.map((series) => {
|
|
9
8
|
var _a, _b, _c, _d, _e;
|
|
10
9
|
const name = series.name || '';
|
|
11
10
|
const color = series.color || colorScale(name);
|
|
12
|
-
let stackId = series.stackId;
|
|
13
|
-
if (!stackId) {
|
|
14
|
-
stackId = series.stacking === 'normal' ? commonStackId : getRandomCKId();
|
|
15
|
-
}
|
|
16
11
|
return {
|
|
17
12
|
type: series.type,
|
|
18
13
|
color,
|
|
@@ -25,7 +20,7 @@ export function prepareBarXSeries(args) {
|
|
|
25
20
|
},
|
|
26
21
|
data: series.data,
|
|
27
22
|
stacking: series.stacking,
|
|
28
|
-
stackId,
|
|
23
|
+
stackId: getSeriesStackId(series),
|
|
29
24
|
dataLabels: {
|
|
30
25
|
enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
|
|
31
26
|
inside: typeof ((_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.inside) === 'boolean'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import { getRandomCKId } from '../../../../../utils';
|
|
3
|
-
import { prepareLegendSymbol } from './utils';
|
|
3
|
+
import { getSeriesStackId, prepareLegendSymbol } from './utils';
|
|
4
4
|
import { DEFAULT_DATALABELS_STYLE } from './constants';
|
|
5
5
|
import { getLabelsSize } from '../../utils';
|
|
6
6
|
function prepareDataLabels(series) {
|
|
@@ -23,14 +23,9 @@ function prepareDataLabels(series) {
|
|
|
23
23
|
}
|
|
24
24
|
export function prepareBarYSeries(args) {
|
|
25
25
|
const { colorScale, series: seriesList, legend } = args;
|
|
26
|
-
const commonStackId = getRandomCKId();
|
|
27
26
|
return seriesList.map((series) => {
|
|
28
27
|
const name = series.name || '';
|
|
29
28
|
const color = series.color || colorScale(name);
|
|
30
|
-
let stackId = series.stackId;
|
|
31
|
-
if (!stackId) {
|
|
32
|
-
stackId = series.stacking === 'normal' ? commonStackId : getRandomCKId();
|
|
33
|
-
}
|
|
34
29
|
return {
|
|
35
30
|
type: series.type,
|
|
36
31
|
color,
|
|
@@ -43,7 +38,7 @@ export function prepareBarYSeries(args) {
|
|
|
43
38
|
},
|
|
44
39
|
data: series.data,
|
|
45
40
|
stacking: series.stacking,
|
|
46
|
-
stackId,
|
|
41
|
+
stackId: getSeriesStackId(series),
|
|
47
42
|
dataLabels: prepareDataLabels(series),
|
|
48
43
|
};
|
|
49
44
|
}, []);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ScaleOrdinal } from 'd3';
|
|
2
|
+
import { DashStyle } from '../../../../../constants';
|
|
2
3
|
import { ChartKitWidgetSeriesOptions, LineSeries } from '../../../../../types';
|
|
3
4
|
import { PreparedLineSeries, PreparedLegend } from './types';
|
|
4
5
|
export declare const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
|
|
5
6
|
export declare const DEFAULT_LINE_WIDTH = 1;
|
|
7
|
+
export declare const DEFAULT_DASH_STYLE = DashStyle.Solid;
|
|
6
8
|
export declare const DEFAULT_MARKER: {
|
|
7
9
|
enabled: boolean;
|
|
8
10
|
symbol: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import merge from 'lodash/merge';
|
|
3
|
-
import {
|
|
3
|
+
import { DashStyle, LineCap } from '../../../../../constants';
|
|
4
|
+
import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_LEGEND_SYMBOL_PADDING, } from './constants';
|
|
4
5
|
import { getRandomCKId } from '../../../../../utils';
|
|
5
6
|
export const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
|
|
6
7
|
export const DEFAULT_LINE_WIDTH = 1;
|
|
8
|
+
export const DEFAULT_DASH_STYLE = DashStyle.Solid;
|
|
7
9
|
export const DEFAULT_MARKER = {
|
|
8
10
|
enabled: false,
|
|
9
11
|
symbol: 'circle',
|
|
@@ -11,6 +13,11 @@ export const DEFAULT_MARKER = {
|
|
|
11
13
|
borderWidth: 0,
|
|
12
14
|
borderColor: '',
|
|
13
15
|
};
|
|
16
|
+
function prepareLinecap(dashStyle, series, seriesOptions) {
|
|
17
|
+
const defaultLineCap = dashStyle === DashStyle.Solid ? LineCap.Round : LineCap.None;
|
|
18
|
+
const lineCapFromSeriesOptions = get(seriesOptions, 'line.linecap', defaultLineCap);
|
|
19
|
+
return get(series, 'linecap', lineCapFromSeriesOptions);
|
|
20
|
+
}
|
|
14
21
|
function prepareLineLegendSymbol(series, seriesOptions) {
|
|
15
22
|
var _a;
|
|
16
23
|
const symbolOptions = ((_a = series.legend) === null || _a === void 0 ? void 0 : _a.symbol) || {};
|
|
@@ -31,11 +38,7 @@ function prepareMarker(series, seriesOptions) {
|
|
|
31
38
|
radius: markerNormalState.radius,
|
|
32
39
|
borderWidth: 1,
|
|
33
40
|
borderColor: '#ffffff',
|
|
34
|
-
halo:
|
|
35
|
-
enabled: true,
|
|
36
|
-
opacity: 0.25,
|
|
37
|
-
radius: 10,
|
|
38
|
-
},
|
|
41
|
+
halo: DEFAULT_HALO_OPTIONS,
|
|
39
42
|
};
|
|
40
43
|
return {
|
|
41
44
|
states: {
|
|
@@ -47,11 +50,13 @@ function prepareMarker(series, seriesOptions) {
|
|
|
47
50
|
export function prepareLineSeries(args) {
|
|
48
51
|
const { colorScale, series: seriesList, seriesOptions, legend } = args;
|
|
49
52
|
const defaultLineWidth = get(seriesOptions, 'line.lineWidth', DEFAULT_LINE_WIDTH);
|
|
53
|
+
const defaultDashStyle = get(seriesOptions, 'line.dashStyle', DEFAULT_DASH_STYLE);
|
|
50
54
|
return seriesList.map((series) => {
|
|
51
55
|
var _a, _b;
|
|
52
56
|
const id = getRandomCKId();
|
|
53
57
|
const name = series.name || '';
|
|
54
58
|
const color = series.color || colorScale(name);
|
|
59
|
+
const dashStyle = get(series, 'dashStyle', defaultDashStyle);
|
|
55
60
|
const prepared = {
|
|
56
61
|
type: series.type,
|
|
57
62
|
color,
|
|
@@ -71,6 +76,8 @@ export function prepareLineSeries(args) {
|
|
|
71
76
|
allowOverlap: get(series, 'dataLabels.allowOverlap', false),
|
|
72
77
|
},
|
|
73
78
|
marker: prepareMarker(series, seriesOptions),
|
|
79
|
+
dashStyle: dashStyle,
|
|
80
|
+
linecap: prepareLinecap(dashStyle, series, seriesOptions),
|
|
74
81
|
};
|
|
75
82
|
return prepared;
|
|
76
83
|
}, []);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { PieSeries } from '../../../../../types';
|
|
1
|
+
import { ChartKitWidgetSeriesOptions, PieSeries } from '../../../../../types';
|
|
2
2
|
import { PreparedLegend, PreparedSeries } from './types';
|
|
3
3
|
type PreparePieSeriesArgs = {
|
|
4
4
|
series: PieSeries;
|
|
5
|
+
seriesOptions?: ChartKitWidgetSeriesOptions;
|
|
5
6
|
legend: PreparedLegend;
|
|
6
7
|
};
|
|
7
8
|
export declare function preparePieSeries(args: PreparePieSeriesArgs): PreparedSeries[];
|
|
@@ -5,10 +5,11 @@ import get from 'lodash/get';
|
|
|
5
5
|
import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE } from './constants';
|
|
6
6
|
import { prepareLegendSymbol } from './utils';
|
|
7
7
|
export function preparePieSeries(args) {
|
|
8
|
-
const { series, legend } = args;
|
|
8
|
+
const { series, seriesOptions, legend } = args;
|
|
9
9
|
const dataNames = series.data.map((d) => d.name);
|
|
10
10
|
const colorScale = scaleOrdinal(dataNames, DEFAULT_PALETTE);
|
|
11
11
|
const stackId = getRandomCKId();
|
|
12
|
+
const seriesHoverState = get(seriesOptions, 'pie.states.hover');
|
|
12
13
|
const preparedSeries = series.data.map((dataItem) => {
|
|
13
14
|
var _a, _b, _c;
|
|
14
15
|
const result = {
|
|
@@ -41,6 +42,15 @@ export function preparePieSeries(args) {
|
|
|
41
42
|
radius: series.radius || '100%',
|
|
42
43
|
innerRadius: series.innerRadius || 0,
|
|
43
44
|
stackId,
|
|
45
|
+
states: {
|
|
46
|
+
hover: {
|
|
47
|
+
halo: {
|
|
48
|
+
enabled: get(seriesHoverState, 'halo.enabled', true),
|
|
49
|
+
opacity: get(seriesHoverState, 'halo.opacity', 0.25),
|
|
50
|
+
size: get(seriesHoverState, 'halo.size', 10),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
44
54
|
};
|
|
45
55
|
return result;
|
|
46
56
|
});
|
|
@@ -6,6 +6,7 @@ import { prepareBarYSeries } from './prepare-bar-y';
|
|
|
6
6
|
import { prepareLegendSymbol } from './utils';
|
|
7
7
|
import { ChartKitError } from '../../../../../libs';
|
|
8
8
|
import { preparePieSeries } from './prepare-pie';
|
|
9
|
+
import { prepareArea } from './prepare-area';
|
|
9
10
|
function prepareAxisRelatedSeries(args) {
|
|
10
11
|
const { colorScale, series, legend } = args;
|
|
11
12
|
const preparedSeries = cloneDeep(series);
|
|
@@ -24,7 +25,7 @@ export function prepareSeries(args) {
|
|
|
24
25
|
switch (type) {
|
|
25
26
|
case 'pie': {
|
|
26
27
|
return series.reduce((acc, singleSeries) => {
|
|
27
|
-
acc.push(...preparePieSeries({ series: singleSeries, legend }));
|
|
28
|
+
acc.push(...preparePieSeries({ series: singleSeries, seriesOptions, legend }));
|
|
28
29
|
return acc;
|
|
29
30
|
}, []);
|
|
30
31
|
}
|
|
@@ -48,6 +49,14 @@ export function prepareSeries(args) {
|
|
|
48
49
|
colorScale,
|
|
49
50
|
});
|
|
50
51
|
}
|
|
52
|
+
case 'area': {
|
|
53
|
+
return prepareArea({
|
|
54
|
+
series: series,
|
|
55
|
+
seriesOptions,
|
|
56
|
+
legend,
|
|
57
|
+
colorScale,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
51
60
|
default: {
|
|
52
61
|
throw new ChartKitError({
|
|
53
62
|
message: `Series type "${type}" does not support data preparation for series that do not support the presence of axes`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BarXSeries, BarXSeriesData, BaseTextStyle, ChartKitWidgetLegend, PieSeries, PieSeriesData, RectLegendSymbolOptions, ScatterSeries, ScatterSeriesData, BarYSeries, BarYSeriesData, LineSeries, LineSeriesData, ConnectorShape, ConnectorCurve, PathLegendSymbolOptions } from '../../../../../types';
|
|
1
|
+
import { BarXSeries, BarXSeriesData, BaseTextStyle, ChartKitWidgetLegend, PieSeries, PieSeriesData, RectLegendSymbolOptions, ScatterSeries, ScatterSeriesData, BarYSeries, BarYSeriesData, LineSeries, LineSeriesData, ConnectorShape, ConnectorCurve, PathLegendSymbolOptions, AreaSeries, AreaSeriesData } from '../../../../../types';
|
|
2
2
|
import type { SeriesOptionsDefaults } from '../../constants';
|
|
3
|
+
import { DashStyle, LineCap } from '../../../../../constants';
|
|
3
4
|
export type RectLegendSymbol = {
|
|
4
5
|
shape: 'rect';
|
|
5
6
|
} & Required<RectLegendSymbolOptions>;
|
|
@@ -22,6 +23,7 @@ export type LegendItem = {
|
|
|
22
23
|
symbol: PreparedLegendSymbol;
|
|
23
24
|
textWidth: number;
|
|
24
25
|
visible?: boolean;
|
|
26
|
+
dashStyle?: DashStyle;
|
|
25
27
|
};
|
|
26
28
|
export type LegendConfig = {
|
|
27
29
|
offset: {
|
|
@@ -33,6 +35,11 @@ export type LegendConfig = {
|
|
|
33
35
|
maxPage: number;
|
|
34
36
|
};
|
|
35
37
|
};
|
|
38
|
+
export type PreparedHaloOptions = {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
opacity: number;
|
|
41
|
+
size: number;
|
|
42
|
+
};
|
|
36
43
|
type BasePreparedSeries = {
|
|
37
44
|
color: string;
|
|
38
45
|
name: string;
|
|
@@ -93,6 +100,11 @@ export type PreparedPieSeries = {
|
|
|
93
100
|
distance: number;
|
|
94
101
|
connectorCurve: ConnectorCurve;
|
|
95
102
|
};
|
|
103
|
+
states: {
|
|
104
|
+
hover: {
|
|
105
|
+
halo: PreparedHaloOptions;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
96
108
|
} & BasePreparedSeries;
|
|
97
109
|
export type PreparedLineSeries = {
|
|
98
110
|
type: LineSeries['type'];
|
|
@@ -118,15 +130,46 @@ export type PreparedLineSeries = {
|
|
|
118
130
|
radius: number;
|
|
119
131
|
borderWidth: number;
|
|
120
132
|
borderColor: string;
|
|
121
|
-
halo:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
halo: PreparedHaloOptions;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
dashStyle: DashStyle;
|
|
138
|
+
linecap: LineCap;
|
|
139
|
+
} & BasePreparedSeries;
|
|
140
|
+
export type PreparedAreaSeries = {
|
|
141
|
+
type: AreaSeries['type'];
|
|
142
|
+
data: AreaSeriesData[];
|
|
143
|
+
stacking: AreaSeries['stacking'];
|
|
144
|
+
stackId: string;
|
|
145
|
+
lineWidth: number;
|
|
146
|
+
opacity: number;
|
|
147
|
+
dataLabels: {
|
|
148
|
+
enabled: boolean;
|
|
149
|
+
style: BaseTextStyle;
|
|
150
|
+
padding: number;
|
|
151
|
+
allowOverlap: boolean;
|
|
152
|
+
};
|
|
153
|
+
marker: {
|
|
154
|
+
states: {
|
|
155
|
+
normal: {
|
|
156
|
+
symbol: string;
|
|
157
|
+
enabled: boolean;
|
|
158
|
+
radius: number;
|
|
159
|
+
borderWidth: number;
|
|
160
|
+
borderColor: string;
|
|
161
|
+
};
|
|
162
|
+
hover: {
|
|
163
|
+
enabled: boolean;
|
|
164
|
+
radius: number;
|
|
165
|
+
borderWidth: number;
|
|
166
|
+
borderColor: string;
|
|
167
|
+
halo: PreparedHaloOptions;
|
|
126
168
|
};
|
|
127
169
|
};
|
|
128
170
|
};
|
|
129
171
|
} & BasePreparedSeries;
|
|
130
|
-
export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries;
|
|
172
|
+
export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries;
|
|
131
173
|
export type PreparedSeriesOptions = SeriesOptionsDefaults;
|
|
174
|
+
export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
|
|
132
175
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PreparedLegendSymbol, PreparedSeries } from './types';
|
|
1
|
+
import { PreparedLegendSymbol, PreparedSeries, StackedSeries } from './types';
|
|
2
2
|
import { ChartKitWidgetSeries } from '../../../../../types';
|
|
3
3
|
export declare const getActiveLegendItems: (series: PreparedSeries[]) => string[];
|
|
4
4
|
export declare const getAllLegendItems: (series: PreparedSeries[]) => string[];
|
|
5
5
|
export declare function prepareLegendSymbol(series: ChartKitWidgetSeries): PreparedLegendSymbol;
|
|
6
|
+
export declare function getSeriesStackId(series: StackedSeries): string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import memoize from 'lodash/memoize';
|
|
1
2
|
import { DEFAULT_LEGEND_SYMBOL_PADDING, DEFAULT_LEGEND_SYMBOL_SIZE } from './constants';
|
|
3
|
+
import { getRandomCKId } from '../../../../../utils';
|
|
2
4
|
export const getActiveLegendItems = (series) => {
|
|
3
5
|
return series.reduce((acc, s) => {
|
|
4
6
|
if (s.legend.enabled && s.visible) {
|
|
@@ -22,3 +24,11 @@ export function prepareLegendSymbol(series) {
|
|
|
22
24
|
padding: (symbolOptions === null || symbolOptions === void 0 ? void 0 : symbolOptions.padding) || DEFAULT_LEGEND_SYMBOL_PADDING,
|
|
23
25
|
};
|
|
24
26
|
}
|
|
27
|
+
const getCommonStackId = memoize(getRandomCKId);
|
|
28
|
+
export function getSeriesStackId(series) {
|
|
29
|
+
let stackId = series.stackId;
|
|
30
|
+
if (!stackId) {
|
|
31
|
+
stackId = series.stacking === 'normal' ? getCommonStackId() : getRandomCKId();
|
|
32
|
+
}
|
|
33
|
+
return stackId;
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Dispatch } from 'd3';
|
|
3
|
+
import type { PreparedSeriesOptions } from '../../useSeries/types';
|
|
4
|
+
import type { PreparedAreaData } from './types';
|
|
5
|
+
type Args = {
|
|
6
|
+
dispatcher: Dispatch<object>;
|
|
7
|
+
preparedData: PreparedAreaData[];
|
|
8
|
+
seriesOptions: PreparedSeriesOptions;
|
|
9
|
+
};
|
|
10
|
+
export declare const AreaSeriesShapes: (args: Args) => React.JSX.Element;
|
|
11
|
+
export {};
|