@gravity-ui/chartkit 4.6.1 → 4.7.1
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/plugins/d3/examples/bar-x/Basic.d.ts +4 -0
- package/build/plugins/d3/examples/bar-x/Basic.js +78 -0
- package/build/plugins/d3/examples/bar-x/GroupedColumns.d.ts +2 -0
- package/build/plugins/d3/examples/bar-x/GroupedColumns.js +44 -0
- package/build/plugins/d3/examples/bar-x/StackedColumns.d.ts +2 -0
- package/build/plugins/d3/examples/bar-x/StackedColumns.js +45 -0
- package/build/plugins/d3/examples/nintendoGames.d.ts +62 -0
- package/build/plugins/d3/examples/nintendoGames.js +12037 -0
- package/build/plugins/d3/examples/pie/Basic.d.ts +2 -0
- package/build/plugins/d3/examples/pie/Basic.js +30 -0
- package/build/plugins/d3/examples/pie/Donut.d.ts +2 -0
- package/build/plugins/d3/examples/pie/Donut.js +31 -0
- package/build/plugins/d3/examples/scatter/Basic.d.ts +2 -0
- package/build/plugins/d3/examples/scatter/Basic.js +66 -0
- package/build/plugins/d3/renderer/components/AxisX.js +6 -7
- package/build/plugins/d3/renderer/components/AxisY.js +50 -18
- package/build/plugins/d3/renderer/components/Chart.js +24 -16
- package/build/plugins/d3/renderer/components/Legend.js +20 -22
- package/build/plugins/d3/renderer/components/Title.js +1 -1
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +2 -2
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +8 -0
- package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.d.ts +14 -0
- package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +70 -0
- package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +5 -3
- package/build/plugins/d3/renderer/components/Tooltip/index.js +4 -2
- package/build/plugins/d3/renderer/components/styles.css +3 -0
- package/build/plugins/d3/renderer/constants/defaults/axis.d.ts +9 -0
- package/build/plugins/d3/renderer/constants/defaults/axis.js +6 -0
- package/build/plugins/d3/renderer/constants/defaults/index.d.ts +1 -0
- package/build/plugins/d3/renderer/constants/defaults/index.js +1 -0
- package/build/plugins/d3/renderer/constants/defaults/series-options.d.ts +11 -0
- package/build/plugins/d3/renderer/constants/defaults/series-options.js +41 -0
- package/build/plugins/d3/renderer/constants/index.d.ts +0 -1
- package/build/plugins/d3/renderer/constants/index.js +0 -1
- package/build/plugins/d3/renderer/d3-dispatcher.d.ts +1 -0
- package/build/plugins/d3/renderer/d3-dispatcher.js +4 -0
- package/build/plugins/d3/renderer/hooks/index.d.ts +0 -1
- package/build/plugins/d3/renderer/hooks/index.js +0 -1
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.d.ts +6 -5
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +2 -1
- package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +8 -41
- package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.js +17 -4
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.d.ts +2 -4
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +4 -23
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.js +2 -10
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +1 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +8 -5
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.d.ts +5 -3
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +61 -6
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +20 -12
- package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +1 -0
- package/build/plugins/d3/renderer/hooks/useSeries/index.js +8 -2
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-legend.js +8 -3
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.js +5 -0
- package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +6 -3
- package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +5 -1
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.d.ts +12 -0
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.js +91 -0
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useShapes/{bar-x.js → bar-x/prepare-data.js} +7 -87
- package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +13 -10
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +28 -13
- package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +6 -4
- package/build/plugins/d3/renderer/hooks/useShapes/pie.js +98 -20
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.d.ts +15 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +89 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +55 -0
- package/build/plugins/d3/renderer/hooks/useShapes/styles.css +1 -9
- package/build/plugins/d3/renderer/hooks/useTooltip/index.d.ts +6 -6
- package/build/plugins/d3/renderer/hooks/useTooltip/index.js +15 -17
- package/build/plugins/d3/renderer/hooks/useTooltip/types.d.ts +0 -6
- package/build/plugins/d3/renderer/utils/axis-generators/bottom.d.ts +3 -1
- package/build/plugins/d3/renderer/utils/axis-generators/bottom.js +32 -22
- package/build/plugins/d3/renderer/utils/index.d.ts +5 -0
- package/build/plugins/d3/renderer/utils/index.js +13 -8
- package/build/plugins/d3/renderer/utils/math.d.ts +2 -0
- package/build/plugins/d3/renderer/utils/math.js +8 -0
- package/build/plugins/d3/renderer/utils/text.d.ts +6 -6
- package/build/plugins/d3/renderer/utils/text.js +24 -14
- package/build/types/widget-data/axis.d.ts +10 -0
- package/build/types/widget-data/series.d.ts +51 -0
- package/build/types/widget-data/tooltip.d.ts +18 -7
- package/package.json +2 -2
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.d.ts +0 -5
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.js +0 -15
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x.d.ts +0 -21
- package/build/plugins/d3/renderer/hooks/useShapes/defaults.d.ts +0 -5
- package/build/plugins/d3/renderer/hooks/useShapes/defaults.js +0 -5
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +0 -19
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +0 -89
|
@@ -2,4 +2,10 @@ export const axisLabelsDefaults = {
|
|
|
2
2
|
margin: 10,
|
|
3
3
|
padding: 10,
|
|
4
4
|
fontSize: 11,
|
|
5
|
+
maxWidth: 80,
|
|
5
6
|
};
|
|
7
|
+
const axisTitleDefaults = {
|
|
8
|
+
fontSize: '14px',
|
|
9
|
+
};
|
|
10
|
+
export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
|
|
11
|
+
export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChartKitWidgetSeriesOptions } from '../../../../../types';
|
|
2
|
+
type DefauleBarXSeriesOptions = Partial<ChartKitWidgetSeriesOptions['bar-x']> & {
|
|
3
|
+
'bar-x': {
|
|
4
|
+
barMaxWidth: number;
|
|
5
|
+
barPadding: number;
|
|
6
|
+
groupPadding: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export type SeriesOptionsDefaults = Partial<ChartKitWidgetSeriesOptions> & DefauleBarXSeriesOptions;
|
|
10
|
+
export declare const seriesOptionsDefaults: SeriesOptionsDefaults;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const seriesOptionsDefaults = {
|
|
2
|
+
'bar-x': {
|
|
3
|
+
barMaxWidth: 50,
|
|
4
|
+
barPadding: 0.1,
|
|
5
|
+
groupPadding: 0.2,
|
|
6
|
+
states: {
|
|
7
|
+
hover: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
brightness: 0.3,
|
|
10
|
+
},
|
|
11
|
+
inactive: {
|
|
12
|
+
enabled: true,
|
|
13
|
+
opacity: 0.5,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
pie: {
|
|
18
|
+
states: {
|
|
19
|
+
hover: {
|
|
20
|
+
enabled: true,
|
|
21
|
+
brightness: 0.3,
|
|
22
|
+
},
|
|
23
|
+
inactive: {
|
|
24
|
+
enabled: true,
|
|
25
|
+
opacity: 0.5,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
scatter: {
|
|
30
|
+
states: {
|
|
31
|
+
hover: {
|
|
32
|
+
enabled: true,
|
|
33
|
+
brightness: 0.3,
|
|
34
|
+
},
|
|
35
|
+
inactive: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
opacity: 0.5,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getD3Dispatcher: () => import("d3-dispatch").Dispatch<object>;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import type { ScaleBand, ScaleLinear, ScaleTime } from 'd3';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PreparedAxis } from '../useChartOptions/types';
|
|
3
3
|
import { PreparedSeries } from '../useSeries/types';
|
|
4
|
+
import { ChartKitWidgetAxis, ChartKitWidgetSeries } from '../../../../../types';
|
|
4
5
|
export type ChartScale = ScaleLinear<number, number> | ScaleBand<string> | ScaleTime<number, number>;
|
|
5
6
|
type Args = {
|
|
6
7
|
boundsWidth: number;
|
|
7
8
|
boundsHeight: number;
|
|
8
9
|
series: PreparedSeries[];
|
|
9
|
-
xAxis:
|
|
10
|
-
yAxis:
|
|
10
|
+
xAxis: PreparedAxis;
|
|
11
|
+
yAxis: PreparedAxis[];
|
|
11
12
|
};
|
|
12
13
|
type ReturnValue = {
|
|
13
14
|
xScale?: ChartScale;
|
|
14
15
|
yScale?: ChartScale;
|
|
15
16
|
};
|
|
16
|
-
export declare function createYScale(axis: PreparedAxis, series: PreparedSeries[], boundsHeight: number): ScaleLinear<number, number, never> |
|
|
17
|
-
export declare function createXScale(axis: PreparedAxis, series: PreparedSeries[], boundsWidth: number): ScaleLinear<number, number, never> |
|
|
17
|
+
export declare function createYScale(axis: PreparedAxis, series: PreparedSeries[], boundsHeight: number): ScaleBand<string> | ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
|
|
18
|
+
export declare function createXScale(axis: PreparedAxis | ChartKitWidgetAxis, series: (PreparedSeries | ChartKitWidgetSeries)[], boundsWidth: number): ScaleBand<string> | ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
|
|
18
19
|
/**
|
|
19
20
|
* Uses to create scales for axis related series
|
|
20
21
|
*/
|
|
@@ -67,7 +67,8 @@ export function createXScale(axis, series, boundsWidth) {
|
|
|
67
67
|
const xType = get(axis, 'type', 'linear');
|
|
68
68
|
const xCategories = get(axis, 'categories');
|
|
69
69
|
const xTimestamps = get(axis, 'timestamps');
|
|
70
|
-
const
|
|
70
|
+
const maxPadding = get(axis, 'maxPadding', 0);
|
|
71
|
+
const xAxisMinPadding = boundsWidth * maxPadding;
|
|
71
72
|
const xRange = [0, boundsWidth - xAxisMinPadding];
|
|
72
73
|
switch (xType) {
|
|
73
74
|
case 'linear': {
|
|
@@ -1,51 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsMaxHeight, getMaxTickCount, getTicksCount, getXAxisItems, hasOverlappingLabels, isAxisRelatedSeries, } from '../../utils';
|
|
2
|
+
import { isAxisRelatedSeries } from '../../utils';
|
|
4
3
|
import { getBoundsWidth } from './utils';
|
|
5
4
|
export { getBoundsWidth } from './utils';
|
|
6
|
-
const getHeightOccupiedByXAxis = ({ preparedXAxis, preparedSeries, width, }) => {
|
|
7
|
-
let height = preparedXAxis.title.height;
|
|
8
|
-
if (preparedXAxis.labels.enabled) {
|
|
9
|
-
const scale = createXScale(preparedXAxis, preparedSeries, width);
|
|
10
|
-
const tickCount = getTicksCount({ axis: preparedXAxis, range: width });
|
|
11
|
-
const ticks = getXAxisItems({
|
|
12
|
-
scale: scale,
|
|
13
|
-
count: tickCount,
|
|
14
|
-
maxCount: getMaxTickCount({ width, axis: preparedXAxis }),
|
|
15
|
-
});
|
|
16
|
-
const step = getClosestPointsRange(preparedXAxis, ticks);
|
|
17
|
-
const labels = ticks.map((value) => {
|
|
18
|
-
return formatAxisTickLabel({
|
|
19
|
-
axis: preparedXAxis,
|
|
20
|
-
value,
|
|
21
|
-
step,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
const overlapping = hasOverlappingLabels({
|
|
25
|
-
width,
|
|
26
|
-
labels,
|
|
27
|
-
padding: preparedXAxis.labels.padding,
|
|
28
|
-
style: preparedXAxis.labels.style,
|
|
29
|
-
});
|
|
30
|
-
const labelsHeight = overlapping
|
|
31
|
-
? getLabelsMaxHeight({
|
|
32
|
-
labels,
|
|
33
|
-
style: preparedXAxis.labels.style,
|
|
34
|
-
transform: 'rotate(-45)',
|
|
35
|
-
})
|
|
36
|
-
: getHorisontalSvgTextHeight({ text: 'Tmp', style: preparedXAxis.labels.style });
|
|
37
|
-
height += preparedXAxis.labels.margin + labelsHeight;
|
|
38
|
-
}
|
|
39
|
-
return height;
|
|
40
|
-
};
|
|
41
5
|
const getBottomOffset = (args) => {
|
|
42
|
-
const { hasAxisRelatedSeries, preparedLegend, preparedXAxis
|
|
6
|
+
const { hasAxisRelatedSeries, preparedLegend, preparedXAxis } = args;
|
|
43
7
|
let result = 0;
|
|
44
8
|
if (preparedLegend.enabled) {
|
|
45
9
|
result += preparedLegend.height + preparedLegend.margin;
|
|
46
10
|
}
|
|
47
11
|
if (hasAxisRelatedSeries) {
|
|
48
|
-
|
|
12
|
+
if (preparedXAxis.title.text) {
|
|
13
|
+
result += preparedXAxis.title.height + preparedXAxis.title.margin;
|
|
14
|
+
}
|
|
15
|
+
if (preparedXAxis.labels.enabled) {
|
|
16
|
+
result += preparedXAxis.labels.margin + preparedXAxis.labels.height;
|
|
17
|
+
}
|
|
49
18
|
}
|
|
50
19
|
return result;
|
|
51
20
|
};
|
|
@@ -58,8 +27,6 @@ export const useChartDimensions = (args) => {
|
|
|
58
27
|
hasAxisRelatedSeries,
|
|
59
28
|
preparedLegend,
|
|
60
29
|
preparedXAxis,
|
|
61
|
-
preparedSeries,
|
|
62
|
-
width: boundsWidth,
|
|
63
30
|
});
|
|
64
31
|
const boundsHeight = height - margin.top - margin.bottom - bottomOffset;
|
|
65
32
|
return { boundsWidth, boundsHeight };
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
export const getBoundsWidth = (args) => {
|
|
2
2
|
const { chartWidth, chartMargin, preparedYAxis } = args;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
return (chartWidth -
|
|
4
|
+
chartMargin.right -
|
|
5
|
+
chartMargin.left -
|
|
6
|
+
getWidthOccupiedByYAxis({ preparedAxis: preparedYAxis }));
|
|
7
7
|
};
|
|
8
|
+
export function getWidthOccupiedByYAxis(args) {
|
|
9
|
+
const { preparedAxis } = args;
|
|
10
|
+
let result = 0;
|
|
11
|
+
preparedAxis.forEach((axis) => {
|
|
12
|
+
if (axis.title.text) {
|
|
13
|
+
result += axis.title.height + axis.title.margin;
|
|
14
|
+
}
|
|
15
|
+
if (axis.labels.enabled) {
|
|
16
|
+
result += axis.labels.margin + axis.labels.width;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { ChartKitWidgetData } from '../../../../../types
|
|
2
|
-
import type {
|
|
1
|
+
import type { ChartKitWidgetData } from '../../../../../types';
|
|
2
|
+
import type { PreparedChart, PreparedTitle } from './types';
|
|
3
3
|
export declare const getPreparedChart: (args: {
|
|
4
4
|
chart: ChartKitWidgetData['chart'];
|
|
5
|
-
series: ChartKitWidgetData['series'];
|
|
6
|
-
preparedY1Axis: PreparedAxis;
|
|
7
5
|
preparedTitle?: PreparedTitle;
|
|
8
6
|
}) => PreparedChart;
|
|
@@ -1,40 +1,21 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import { isAxisRelatedSeries, getHorisontalSvgTextHeight } from '../../utils';
|
|
3
|
-
const AXIS_LINE_WIDTH = 1;
|
|
4
2
|
const getMarginTop = (args) => {
|
|
5
|
-
const { chart,
|
|
3
|
+
const { chart, preparedTitle } = args;
|
|
6
4
|
let marginTop = get(chart, 'margin.top', 0);
|
|
7
|
-
if (hasAxisRelatedSeries) {
|
|
8
|
-
marginTop +=
|
|
9
|
-
getHorisontalSvgTextHeight({ text: 'Tmp', style: preparedY1Axis.labels.style }) / 2;
|
|
10
|
-
}
|
|
11
5
|
if (preparedTitle === null || preparedTitle === void 0 ? void 0 : preparedTitle.height) {
|
|
12
6
|
marginTop += preparedTitle.height;
|
|
13
7
|
}
|
|
14
8
|
return marginTop;
|
|
15
9
|
};
|
|
16
|
-
const getMarginLeft = (args) => {
|
|
17
|
-
const { chart, hasAxisRelatedSeries, preparedY1Axis } = args;
|
|
18
|
-
let marginLeft = get(chart, 'margin.left', 0);
|
|
19
|
-
if (hasAxisRelatedSeries) {
|
|
20
|
-
marginLeft +=
|
|
21
|
-
AXIS_LINE_WIDTH +
|
|
22
|
-
preparedY1Axis.labels.margin +
|
|
23
|
-
(preparedY1Axis.labels.maxWidth || 0) +
|
|
24
|
-
preparedY1Axis.title.height;
|
|
25
|
-
}
|
|
26
|
-
return marginLeft;
|
|
27
|
-
};
|
|
28
10
|
const getMarginRight = (args) => {
|
|
29
11
|
const { chart } = args;
|
|
30
12
|
return get(chart, 'margin.right', 0);
|
|
31
13
|
};
|
|
32
14
|
export const getPreparedChart = (args) => {
|
|
33
|
-
const { chart,
|
|
34
|
-
const
|
|
35
|
-
const marginTop = getMarginTop({ chart, hasAxisRelatedSeries, preparedY1Axis, preparedTitle });
|
|
15
|
+
const { chart, preparedTitle } = args;
|
|
16
|
+
const marginTop = getMarginTop({ chart, preparedTitle });
|
|
36
17
|
const marginBottom = get(chart, 'margin.bottom', 0);
|
|
37
|
-
const marginLeft =
|
|
18
|
+
const marginLeft = get(chart, 'margin.left', 0);
|
|
38
19
|
const marginRight = getMarginRight({ chart });
|
|
39
20
|
return {
|
|
40
21
|
margin: {
|
|
@@ -2,28 +2,20 @@ import React from 'react';
|
|
|
2
2
|
import { getPreparedChart } from './chart';
|
|
3
3
|
import { getPreparedTitle } from './title';
|
|
4
4
|
import { getPreparedTooltip } from './tooltip';
|
|
5
|
-
import { getPreparedXAxis } from './x-axis';
|
|
6
|
-
import { getPreparedYAxis } from './y-axis';
|
|
7
5
|
export const useChartOptions = (args) => {
|
|
8
|
-
const { data: { chart,
|
|
6
|
+
const { data: { chart, title, tooltip }, } = args;
|
|
9
7
|
const options = React.useMemo(() => {
|
|
10
8
|
const preparedTitle = getPreparedTitle({ title });
|
|
11
9
|
const preparedTooltip = getPreparedTooltip({ tooltip });
|
|
12
|
-
const preparedYAxis = getPreparedYAxis({ series: series.data, yAxis });
|
|
13
|
-
const preparedXAxis = getPreparedXAxis({ xAxis });
|
|
14
10
|
const preparedChart = getPreparedChart({
|
|
15
11
|
chart,
|
|
16
|
-
series,
|
|
17
12
|
preparedTitle,
|
|
18
|
-
preparedY1Axis: preparedYAxis[0],
|
|
19
13
|
});
|
|
20
14
|
return {
|
|
21
15
|
chart: preparedChart,
|
|
22
16
|
title: preparedTitle,
|
|
23
17
|
tooltip: preparedTooltip,
|
|
24
|
-
xAxis: preparedXAxis,
|
|
25
|
-
yAxis: preparedYAxis,
|
|
26
18
|
};
|
|
27
|
-
}, [chart, title, tooltip
|
|
19
|
+
}, [chart, title, tooltip]);
|
|
28
20
|
return options;
|
|
29
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartKitWidgetData } from '../../../../../types
|
|
1
|
+
import type { ChartKitWidgetData } from '../../../../../types';
|
|
2
2
|
import type { PreparedTitle } from './types';
|
|
3
3
|
export declare const getPreparedTitle: ({ title, }: {
|
|
4
4
|
title: ChartKitWidgetData['title'];
|
|
@@ -6,6 +6,7 @@ export const getPreparedTitle = ({ title, }) => {
|
|
|
6
6
|
const titleText = get(title, 'text');
|
|
7
7
|
const titleStyle = {
|
|
8
8
|
fontSize: get(title, 'style.fontSize', DEFAULT_TITLE_FONT_SIZE),
|
|
9
|
+
fontWeight: get(title, 'style.fontWeight'),
|
|
9
10
|
};
|
|
10
11
|
const titleHeight = titleText
|
|
11
12
|
? getHorisontalSvgTextHeight({ text: titleText, style: titleStyle }) + TITLE_PADDINGS
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { BaseTextStyle, ChartKitWidgetData, ChartKitWidgetAxis, ChartKitWidgetAxisType, ChartKitWidgetAxisLabels, ChartMargin } from '../../../../../types
|
|
2
|
-
type PreparedAxisLabels = Omit<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'style'> & Required<Pick<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'margin'>> & {
|
|
1
|
+
import type { BaseTextStyle, ChartKitWidgetData, ChartKitWidgetAxis, ChartKitWidgetAxisType, ChartKitWidgetAxisLabels, ChartMargin } from '../../../../../types';
|
|
2
|
+
type PreparedAxisLabels = Omit<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'style' | 'autoRotation'> & Required<Pick<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'margin' | 'rotation'>> & {
|
|
3
3
|
style: BaseTextStyle;
|
|
4
|
-
|
|
4
|
+
rotation: number;
|
|
5
|
+
height: number;
|
|
6
|
+
width: number;
|
|
7
|
+
lineHeight: number;
|
|
8
|
+
maxWidth: number;
|
|
5
9
|
};
|
|
6
10
|
export type PreparedChart = {
|
|
7
11
|
margin: ChartMargin;
|
|
@@ -12,6 +16,7 @@ export type PreparedAxis = Omit<ChartKitWidgetAxis, 'type' | 'labels'> & {
|
|
|
12
16
|
title: {
|
|
13
17
|
height: number;
|
|
14
18
|
text: string;
|
|
19
|
+
margin: number;
|
|
15
20
|
style: BaseTextStyle;
|
|
16
21
|
};
|
|
17
22
|
min?: number;
|
|
@@ -32,8 +37,6 @@ export type PreparedTooltip = ChartKitWidgetData['tooltip'] & {
|
|
|
32
37
|
export type ChartOptions = {
|
|
33
38
|
chart: PreparedChart;
|
|
34
39
|
tooltip: PreparedTooltip;
|
|
35
|
-
xAxis: PreparedAxis;
|
|
36
|
-
yAxis: PreparedAxis[];
|
|
37
40
|
title?: PreparedTitle;
|
|
38
41
|
};
|
|
39
42
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChartKitWidgetSeries, ChartKitWidgetAxis } from '../../../../../types';
|
|
2
2
|
import type { PreparedAxis } from './types';
|
|
3
|
-
export declare const getPreparedXAxis: ({ xAxis }: {
|
|
4
|
-
xAxis
|
|
3
|
+
export declare const getPreparedXAxis: ({ xAxis, series, width, }: {
|
|
4
|
+
xAxis?: ChartKitWidgetAxis | undefined;
|
|
5
|
+
series: ChartKitWidgetSeries[];
|
|
6
|
+
width: number;
|
|
5
7
|
}) => PreparedAxis;
|
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE,
|
|
3
|
-
import { getHorisontalSvgTextHeight } from '../../utils';
|
|
4
|
-
|
|
2
|
+
import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE, xAxisTitleDefaults, } from '../../constants';
|
|
3
|
+
import { calculateCos, formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsMaxHeight, getMaxTickCount, getTicksCount, getXAxisItems, hasOverlappingLabels, } from '../../utils';
|
|
4
|
+
import { createXScale } from '../useAxisScales';
|
|
5
|
+
function getLabelSettings({ axis, series, width, autoRotation = true, }) {
|
|
6
|
+
const scale = createXScale(axis, series, width);
|
|
7
|
+
const tickCount = getTicksCount({ axis, range: width });
|
|
8
|
+
const ticks = getXAxisItems({
|
|
9
|
+
scale: scale,
|
|
10
|
+
count: tickCount,
|
|
11
|
+
maxCount: getMaxTickCount({ width, axis }),
|
|
12
|
+
});
|
|
13
|
+
const step = getClosestPointsRange(axis, ticks);
|
|
14
|
+
const labels = ticks.map((value) => {
|
|
15
|
+
return formatAxisTickLabel({
|
|
16
|
+
axis,
|
|
17
|
+
value,
|
|
18
|
+
step,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
const overlapping = hasOverlappingLabels({
|
|
22
|
+
width,
|
|
23
|
+
labels,
|
|
24
|
+
padding: axis.labels.padding,
|
|
25
|
+
style: axis.labels.style,
|
|
26
|
+
});
|
|
27
|
+
const defaultRotation = overlapping && autoRotation ? -45 : 0;
|
|
28
|
+
const rotation = axis.labels.rotation || defaultRotation;
|
|
29
|
+
const labelsHeight = rotation
|
|
30
|
+
? getLabelsMaxHeight({
|
|
31
|
+
labels,
|
|
32
|
+
style: {
|
|
33
|
+
'font-size': axis.labels.style.fontSize,
|
|
34
|
+
'font-weight': axis.labels.style.fontWeight || 'normal',
|
|
35
|
+
},
|
|
36
|
+
rotation,
|
|
37
|
+
})
|
|
38
|
+
: axis.labels.lineHeight;
|
|
39
|
+
const maxHeight = rotation ? calculateCos(rotation) * axis.labels.maxWidth : labelsHeight;
|
|
40
|
+
return { height: Math.min(maxHeight, labelsHeight), rotation };
|
|
41
|
+
}
|
|
42
|
+
export const getPreparedXAxis = ({ xAxis, series, width, }) => {
|
|
43
|
+
var _a;
|
|
5
44
|
const titleText = get(xAxis, 'title.text', '');
|
|
6
45
|
const titleStyle = {
|
|
7
|
-
fontSize: get(xAxis, 'title.style.fontSize',
|
|
46
|
+
fontSize: get(xAxis, 'title.style.fontSize', xAxisTitleDefaults.fontSize),
|
|
47
|
+
};
|
|
48
|
+
const labelsStyle = {
|
|
49
|
+
fontSize: get(xAxis, 'labels.style.fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE),
|
|
8
50
|
};
|
|
9
51
|
const preparedXAxis = {
|
|
10
52
|
type: get(xAxis, 'type', 'linear'),
|
|
@@ -14,8 +56,12 @@ export const getPreparedXAxis = ({ xAxis }) => {
|
|
|
14
56
|
padding: get(xAxis, 'labels.padding', axisLabelsDefaults.padding),
|
|
15
57
|
dateFormat: get(xAxis, 'labels.dateFormat'),
|
|
16
58
|
numberFormat: get(xAxis, 'labels.numberFormat'),
|
|
17
|
-
|
|
18
|
-
style:
|
|
59
|
+
rotation: get(xAxis, 'labels.rotation', 0),
|
|
60
|
+
style: labelsStyle,
|
|
61
|
+
width: 0,
|
|
62
|
+
height: 0,
|
|
63
|
+
lineHeight: getHorisontalSvgTextHeight({ text: 'Tmp', style: labelsStyle }),
|
|
64
|
+
maxWidth: get(xAxis, 'labels.maxWidth', axisLabelsDefaults.maxWidth),
|
|
19
65
|
},
|
|
20
66
|
lineColor: get(xAxis, 'lineColor'),
|
|
21
67
|
categories: get(xAxis, 'categories'),
|
|
@@ -23,6 +69,7 @@ export const getPreparedXAxis = ({ xAxis }) => {
|
|
|
23
69
|
title: {
|
|
24
70
|
text: titleText,
|
|
25
71
|
style: titleStyle,
|
|
72
|
+
margin: get(xAxis, 'title.margin', xAxisTitleDefaults.margin),
|
|
26
73
|
height: titleText
|
|
27
74
|
? getHorisontalSvgTextHeight({ text: titleText, style: titleStyle })
|
|
28
75
|
: 0,
|
|
@@ -36,5 +83,13 @@ export const getPreparedXAxis = ({ xAxis }) => {
|
|
|
36
83
|
pixelInterval: get(xAxis, 'ticks.pixelInterval'),
|
|
37
84
|
},
|
|
38
85
|
};
|
|
86
|
+
const { height, rotation } = getLabelSettings({
|
|
87
|
+
axis: preparedXAxis,
|
|
88
|
+
series,
|
|
89
|
+
width,
|
|
90
|
+
autoRotation: (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _a === void 0 ? void 0 : _a.autoRotation,
|
|
91
|
+
});
|
|
92
|
+
preparedXAxis.labels.height = height;
|
|
93
|
+
preparedXAxis.labels.rotation = rotation;
|
|
39
94
|
return preparedXAxis;
|
|
40
95
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartKitWidgetData, ChartKitWidgetSeries } from '../../../../../types
|
|
1
|
+
import type { ChartKitWidgetData, ChartKitWidgetSeries } from '../../../../../types';
|
|
2
2
|
import type { PreparedAxis } from './types';
|
|
3
3
|
export declare const getPreparedYAxis: ({ series, yAxis, }: {
|
|
4
4
|
series: ChartKitWidgetSeries[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE,
|
|
2
|
+
import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE, yAxisTitleDefaults, } from '../../constants';
|
|
3
3
|
import { getHorisontalSvgTextHeight, formatAxisTickLabel, getClosestPointsRange, getScaleTicks, getLabelsMaxWidth, } from '../../utils';
|
|
4
4
|
import { createYScale } from '../useAxisScales';
|
|
5
5
|
const getAxisLabelMaxWidth = (args) => {
|
|
@@ -18,39 +18,45 @@ const getAxisLabelMaxWidth = (args) => {
|
|
|
18
18
|
}));
|
|
19
19
|
return getLabelsMaxWidth({
|
|
20
20
|
labels,
|
|
21
|
-
style:
|
|
21
|
+
style: {
|
|
22
|
+
'font-size': axis.labels.style.fontSize,
|
|
23
|
+
'font-weight': axis.labels.style.fontWeight || '',
|
|
24
|
+
},
|
|
25
|
+
rotation: axis.labels.rotation,
|
|
22
26
|
});
|
|
23
27
|
};
|
|
24
|
-
const applyLabelsMaxWidth = (args) => {
|
|
25
|
-
const { series, preparedYAxis } = args;
|
|
26
|
-
preparedYAxis.labels.maxWidth = getAxisLabelMaxWidth({ axis: preparedYAxis, series });
|
|
27
|
-
};
|
|
28
28
|
export const getPreparedYAxis = ({ series, yAxis, }) => {
|
|
29
29
|
// FIXME: add support for n axises
|
|
30
30
|
const yAxis1 = yAxis === null || yAxis === void 0 ? void 0 : yAxis[0];
|
|
31
|
+
const labelsEnabled = get(yAxis1, 'labels.enabled', true);
|
|
31
32
|
const y1LabelsStyle = {
|
|
32
33
|
fontSize: get(yAxis1, 'labels.style.fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE),
|
|
33
34
|
};
|
|
34
35
|
const y1TitleText = get(yAxis1, 'title.text', '');
|
|
35
36
|
const y1TitleStyle = {
|
|
36
|
-
fontSize: get(yAxis1, 'title.style.fontSize',
|
|
37
|
+
fontSize: get(yAxis1, 'title.style.fontSize', yAxisTitleDefaults.fontSize),
|
|
37
38
|
};
|
|
38
39
|
const preparedY1Axis = {
|
|
39
40
|
type: get(yAxis1, 'type', 'linear'),
|
|
40
41
|
labels: {
|
|
41
|
-
enabled:
|
|
42
|
-
margin: get(yAxis1, 'labels.margin', axisLabelsDefaults.margin),
|
|
43
|
-
padding: get(yAxis1, 'labels.padding', axisLabelsDefaults.padding),
|
|
44
|
-
autoRotation: get(yAxis1, 'labels.autoRotation', false),
|
|
42
|
+
enabled: labelsEnabled,
|
|
43
|
+
margin: labelsEnabled ? get(yAxis1, 'labels.margin', axisLabelsDefaults.margin) : 0,
|
|
44
|
+
padding: labelsEnabled ? get(yAxis1, 'labels.padding', axisLabelsDefaults.padding) : 0,
|
|
45
45
|
dateFormat: get(yAxis1, 'labels.dateFormat'),
|
|
46
46
|
numberFormat: get(yAxis1, 'labels.numberFormat'),
|
|
47
47
|
style: y1LabelsStyle,
|
|
48
|
+
rotation: get(yAxis1, 'labels.rotation', 0),
|
|
49
|
+
width: 0,
|
|
50
|
+
height: 0,
|
|
51
|
+
lineHeight: getHorisontalSvgTextHeight({ text: 'TmpLabel', style: y1LabelsStyle }),
|
|
52
|
+
maxWidth: get(yAxis1, 'labels.maxWidth', axisLabelsDefaults.maxWidth),
|
|
48
53
|
},
|
|
49
54
|
lineColor: get(yAxis1, 'lineColor'),
|
|
50
55
|
categories: get(yAxis1, 'categories'),
|
|
51
56
|
timestamps: get(yAxis1, 'timestamps'),
|
|
52
57
|
title: {
|
|
53
58
|
text: y1TitleText,
|
|
59
|
+
margin: get(yAxis1, 'title.margin', yAxisTitleDefaults.margin),
|
|
54
60
|
style: y1TitleStyle,
|
|
55
61
|
height: y1TitleText
|
|
56
62
|
? getHorisontalSvgTextHeight({ text: y1TitleText, style: y1TitleStyle })
|
|
@@ -65,6 +71,8 @@ export const getPreparedYAxis = ({ series, yAxis, }) => {
|
|
|
65
71
|
pixelInterval: get(yAxis1, 'ticks.pixelInterval'),
|
|
66
72
|
},
|
|
67
73
|
};
|
|
68
|
-
|
|
74
|
+
if (labelsEnabled) {
|
|
75
|
+
preparedY1Axis.labels.width = getAxisLabelMaxWidth({ axis: preparedY1Axis, series });
|
|
76
|
+
}
|
|
69
77
|
return [preparedY1Axis];
|
|
70
78
|
};
|
|
@@ -23,6 +23,7 @@ export declare const useSeries: (args: Args) => {
|
|
|
23
23
|
};
|
|
24
24
|
preparedLegend: import("./types").PreparedLegend;
|
|
25
25
|
preparedSeries: PreparedSeries[];
|
|
26
|
+
preparedSeriesOptions: import("../../constants").SeriesOptionsDefaults;
|
|
26
27
|
handleLegendItemClick: OnLegendItemClick;
|
|
27
28
|
};
|
|
28
29
|
export {};
|
|
@@ -4,9 +4,10 @@ import { DEFAULT_PALETTE } from '../../constants';
|
|
|
4
4
|
import { getSeriesNames } from '../../utils';
|
|
5
5
|
import { getActiveLegendItems, getAllLegendItems } from './utils';
|
|
6
6
|
import { getPreparedLegend, getLegendComponents } from './prepare-legend';
|
|
7
|
+
import { getPreparedOptions } from './prepare-options';
|
|
7
8
|
import { prepareSeries } from './prepareSeries';
|
|
8
9
|
export const useSeries = (args) => {
|
|
9
|
-
const { chartWidth, chartHeight, chartMargin, legend, preparedYAxis, series: { data: series }, } = args;
|
|
10
|
+
const { chartWidth, chartHeight, chartMargin, legend, preparedYAxis, series: { data: series, options: seriesOptions }, } = args;
|
|
10
11
|
const preparedLegend = React.useMemo(() => getPreparedLegend({ legend, series }), [legend, series]);
|
|
11
12
|
const preparedSeries = React.useMemo(() => {
|
|
12
13
|
const seriesNames = getSeriesNames(series);
|
|
@@ -22,9 +23,13 @@ export const useSeries = (args) => {
|
|
|
22
23
|
return acc;
|
|
23
24
|
}, []);
|
|
24
25
|
}, [series, preparedLegend]);
|
|
26
|
+
const preparedSeriesOptions = React.useMemo(() => {
|
|
27
|
+
return getPreparedOptions(seriesOptions);
|
|
28
|
+
}, [seriesOptions]);
|
|
25
29
|
const [activeLegendItems, setActiveLegendItems] = React.useState(getActiveLegendItems(preparedSeries));
|
|
26
30
|
const chartSeries = React.useMemo(() => {
|
|
27
|
-
return preparedSeries.map((singleSeries) => {
|
|
31
|
+
return preparedSeries.map((singleSeries, i) => {
|
|
32
|
+
singleSeries.id = `Series ${i + 1}`;
|
|
28
33
|
if (singleSeries.legend.enabled) {
|
|
29
34
|
return Object.assign(Object.assign({}, singleSeries), { visible: activeLegendItems.includes(singleSeries.name) });
|
|
30
35
|
}
|
|
@@ -67,6 +72,7 @@ export const useSeries = (args) => {
|
|
|
67
72
|
legendConfig,
|
|
68
73
|
preparedLegend,
|
|
69
74
|
preparedSeries: chartSeries,
|
|
75
|
+
preparedSeriesOptions,
|
|
70
76
|
handleLegendItemClick,
|
|
71
77
|
};
|
|
72
78
|
};
|