@gravity-ui/charts 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Axis/AxisY.js +3 -0
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +37 -11
- package/dist/cjs/components/Legend/index.js +4 -1
- package/dist/cjs/components/Tooltip/DefaultContent.js +4 -4
- package/dist/cjs/hooks/useAxisScales/index.js +15 -6
- package/dist/cjs/hooks/useSeries/index.d.ts +1 -19
- package/dist/cjs/hooks/useSeries/index.js +7 -25
- package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -2
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +4 -3
- package/dist/cjs/hooks/useShapes/index.js +143 -139
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -2
- package/dist/cjs/hooks/useShapes/utils.d.ts +6 -0
- package/dist/cjs/hooks/useShapes/utils.js +29 -4
- package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -1
- package/dist/cjs/libs/format-number/index.d.ts +7 -3
- package/dist/cjs/libs/format-number/index.js +8 -3
- package/dist/cjs/libs/format-number/types.d.ts +0 -1
- package/dist/cjs/types/chart/tooltip.d.ts +1 -0
- package/dist/cjs/types/formatter.d.ts +0 -1
- package/dist/cjs/utils/chart/get-closest-data.d.ts +1 -0
- package/dist/cjs/utils/chart/get-closest-data.js +2 -5
- package/dist/cjs/utils/chart/index.d.ts +1 -0
- package/dist/cjs/utils/chart/index.js +3 -2
- package/dist/cjs/utils/chart/series/index.d.ts +1 -0
- package/dist/cjs/utils/chart/series/index.js +1 -0
- package/dist/cjs/utils/chart/series/sorting.d.ts +2 -0
- package/dist/cjs/utils/chart/series/sorting.js +12 -0
- package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.d.ts +5 -2
- package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.js +36 -9
- package/dist/esm/components/Axis/AxisY.js +3 -0
- package/dist/esm/components/ChartInner/useChartInnerProps.js +37 -11
- package/dist/esm/components/Legend/index.js +4 -1
- package/dist/esm/components/Tooltip/DefaultContent.js +4 -4
- package/dist/esm/hooks/useAxisScales/index.js +15 -6
- package/dist/esm/hooks/useSeries/index.d.ts +1 -19
- package/dist/esm/hooks/useSeries/index.js +7 -25
- package/dist/esm/hooks/useSeries/prepare-legend.js +2 -2
- package/dist/esm/hooks/useShapes/area/prepare-data.js +4 -3
- package/dist/esm/hooks/useShapes/index.js +143 -139
- package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -2
- package/dist/esm/hooks/useShapes/utils.d.ts +6 -0
- package/dist/esm/hooks/useShapes/utils.js +29 -4
- package/dist/esm/hooks/useShapes/waterfall/index.js +1 -1
- package/dist/esm/libs/format-number/index.d.ts +7 -3
- package/dist/esm/libs/format-number/index.js +8 -3
- package/dist/esm/libs/format-number/types.d.ts +0 -1
- package/dist/esm/types/chart/tooltip.d.ts +1 -0
- package/dist/esm/types/formatter.d.ts +0 -1
- package/dist/esm/utils/chart/get-closest-data.d.ts +1 -0
- package/dist/esm/utils/chart/get-closest-data.js +2 -5
- package/dist/esm/utils/chart/index.d.ts +1 -0
- package/dist/esm/utils/chart/index.js +3 -2
- package/dist/esm/utils/chart/series/index.d.ts +1 -0
- package/dist/esm/utils/chart/series/index.js +1 -0
- package/dist/esm/utils/chart/series/sorting.d.ts +2 -0
- package/dist/esm/utils/chart/series/sorting.js +12 -0
- package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.d.ts +5 -2
- package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.js +36 -9
- package/package.json +1 -1
- package/dist/cjs/hooks/hooks-utils/index.d.ts +0 -1
- package/dist/cjs/hooks/hooks-utils/index.js +0 -1
- package/dist/esm/hooks/hooks-utils/index.d.ts +0 -1
- package/dist/esm/hooks/hooks-utils/index.js +0 -1
|
@@ -125,6 +125,9 @@ export const AxisY = (props) => {
|
|
|
125
125
|
scale: seriesScale,
|
|
126
126
|
});
|
|
127
127
|
yAxisGenerator(axisItem);
|
|
128
|
+
// because the standard generator interrupts the desired font
|
|
129
|
+
// https://github.com/d3/d3-axis/blob/main/src/axis.js#L110
|
|
130
|
+
axisItem.attr('font-family', null);
|
|
128
131
|
if (d.labels.enabled) {
|
|
129
132
|
const labels = axisItem.selectAll('.tick text');
|
|
130
133
|
const tickTexts = labels
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useAxisScales, useChartDimensions, useChartOptions, usePrevious, useSeries, useShapes, useSplit, } from '../../hooks';
|
|
3
|
-
import { getZoomedSeriesData } from '../../hooks/hooks-utils';
|
|
4
3
|
import { getYAxisWidth } from '../../hooks/useChartDimensions/utils';
|
|
5
4
|
import { getPreparedXAxis } from '../../hooks/useChartOptions/x-axis';
|
|
6
5
|
import { getPreparedYAxis } from '../../hooks/useChartOptions/y-axis';
|
|
6
|
+
import { getLegendComponents } from '../../hooks/useSeries/prepare-legend';
|
|
7
|
+
import { getPreparedOptions } from '../../hooks/useSeries/prepare-options';
|
|
7
8
|
import { useZoom } from '../../hooks/useZoom';
|
|
9
|
+
import { getSortedSeriesData, getZoomedSeriesData } from '../../utils';
|
|
8
10
|
import { hasAtLeastOneSeriesDataPerPlot } from './utils';
|
|
9
11
|
export function useChartInnerProps(props) {
|
|
10
12
|
var _a;
|
|
@@ -13,33 +15,57 @@ export function useChartInnerProps(props) {
|
|
|
13
15
|
const prevHeight = usePrevious(height);
|
|
14
16
|
const [zoomState, setZoomState] = React.useState({});
|
|
15
17
|
const { chart, title, tooltip, colors } = useChartOptions({ data });
|
|
16
|
-
const
|
|
18
|
+
const sortedSeriesData = React.useMemo(() => {
|
|
19
|
+
return getSortedSeriesData(data.series.data);
|
|
20
|
+
}, [data.series.data]);
|
|
21
|
+
const { zoomedSeriesData, zoomedShapesSeriesData } = React.useMemo(() => {
|
|
17
22
|
return getZoomedSeriesData({
|
|
18
|
-
seriesData:
|
|
23
|
+
seriesData: sortedSeriesData,
|
|
19
24
|
xAxis: data.xAxis,
|
|
20
25
|
yAxes: data.yAxis,
|
|
21
26
|
zoomState,
|
|
22
27
|
});
|
|
23
|
-
}, [data.
|
|
28
|
+
}, [data.xAxis, data.yAxis, sortedSeriesData, zoomState]);
|
|
24
29
|
const [xAxis, setXAxis] = React.useState(null);
|
|
25
30
|
React.useEffect(() => {
|
|
31
|
+
setXAxis(null);
|
|
26
32
|
getPreparedXAxis({ xAxis: data.xAxis, width, seriesData: zoomedSeriesData }).then((val) => setXAxis(val));
|
|
27
33
|
}, [data.xAxis, width, zoomedSeriesData]);
|
|
28
34
|
const [yAxis, setYAxis] = React.useState([]);
|
|
29
35
|
React.useEffect(() => {
|
|
36
|
+
setYAxis([]);
|
|
30
37
|
getPreparedYAxis({ yAxis: data.yAxis, height, seriesData: zoomedSeriesData }).then((val) => setYAxis(val));
|
|
31
38
|
}, [data.yAxis, height, zoomedSeriesData]);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const preparedSeriesOptions = React.useMemo(() => {
|
|
40
|
+
return getPreparedOptions(data.series.options);
|
|
41
|
+
}, [data.series.options]);
|
|
42
|
+
const { preparedSeries, preparedLegend, handleLegendItemClick } = useSeries({
|
|
36
43
|
colors,
|
|
37
44
|
legend: data.legend,
|
|
38
45
|
originalSeriesData: data.series.data,
|
|
39
46
|
seriesData: zoomedSeriesData,
|
|
40
47
|
seriesOptions: data.series.options,
|
|
41
|
-
preparedYAxis: yAxis,
|
|
42
48
|
});
|
|
49
|
+
const { preparedSeries: preparedShapesSeries } = useSeries({
|
|
50
|
+
colors,
|
|
51
|
+
legend: data.legend,
|
|
52
|
+
originalSeriesData: data.series.data,
|
|
53
|
+
seriesData: zoomedShapesSeriesData,
|
|
54
|
+
seriesOptions: data.series.options,
|
|
55
|
+
});
|
|
56
|
+
const { legendConfig, legendItems } = React.useMemo(() => {
|
|
57
|
+
if (!preparedLegend) {
|
|
58
|
+
return { legendConfig: undefined, legendItems: [] };
|
|
59
|
+
}
|
|
60
|
+
return getLegendComponents({
|
|
61
|
+
chartWidth: width,
|
|
62
|
+
chartHeight: height,
|
|
63
|
+
chartMargin: chart.margin,
|
|
64
|
+
series: preparedSeries,
|
|
65
|
+
preparedLegend,
|
|
66
|
+
preparedYAxis: yAxis,
|
|
67
|
+
});
|
|
68
|
+
}, [width, height, chart.margin, preparedSeries, preparedLegend, yAxis]);
|
|
43
69
|
const { boundsWidth, boundsHeight } = useChartDimensions({
|
|
44
70
|
width,
|
|
45
71
|
height,
|
|
@@ -67,7 +93,7 @@ export function useChartInnerProps(props) {
|
|
|
67
93
|
boundsWidth,
|
|
68
94
|
boundsHeight,
|
|
69
95
|
dispatcher,
|
|
70
|
-
series:
|
|
96
|
+
series: preparedShapesSeries,
|
|
71
97
|
seriesOptions: preparedSeriesOptions,
|
|
72
98
|
xAxis,
|
|
73
99
|
xScale,
|
|
@@ -79,7 +105,7 @@ export function useChartInnerProps(props) {
|
|
|
79
105
|
isOutsideBounds,
|
|
80
106
|
});
|
|
81
107
|
const handleAttemptToSetZoomState = React.useCallback((nextZoomState) => {
|
|
82
|
-
const nextZoomedSeriesData = getZoomedSeriesData({
|
|
108
|
+
const { zoomedSeriesData: nextZoomedSeriesData } = getZoomedSeriesData({
|
|
83
109
|
seriesData: zoomedSeriesData,
|
|
84
110
|
xAxis: data.xAxis,
|
|
85
111
|
yAxes: data.yAxis,
|
|
@@ -321,6 +321,7 @@ export const Legend = (props) => {
|
|
|
321
321
|
.call(xAxisGenerator);
|
|
322
322
|
legendWidth = legend.width;
|
|
323
323
|
}
|
|
324
|
+
const legendTitleClassname = b('title');
|
|
324
325
|
if (legend.title.enable) {
|
|
325
326
|
const { maxWidth: titleWidth } = await getLabelsSize({
|
|
326
327
|
labels: [legend.title.text],
|
|
@@ -342,7 +343,6 @@ export const Legend = (props) => {
|
|
|
342
343
|
break;
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
|
-
const legendTitleClassname = b('title');
|
|
346
346
|
svgElement.selectAll(`.${legendTitleClassname}`).remove();
|
|
347
347
|
svgElement
|
|
348
348
|
.append('g')
|
|
@@ -355,6 +355,9 @@ export const Legend = (props) => {
|
|
|
355
355
|
.style('dominant-baseline', 'text-before-edge')
|
|
356
356
|
.html(legend.title.text);
|
|
357
357
|
}
|
|
358
|
+
else {
|
|
359
|
+
svgElement.selectAll(`.${legendTitleClassname}`).remove();
|
|
360
|
+
}
|
|
358
361
|
const { left } = getLegendPosition({
|
|
359
362
|
align: legend.align,
|
|
360
363
|
width: boundsWidth,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
|
-
import { block, getDataCategoryValue
|
|
3
|
+
import { block, getDataCategoryValue } from '../../utils';
|
|
4
4
|
import { getFormattedValue } from '../../utils/chart/format';
|
|
5
5
|
const b = block('tooltip');
|
|
6
6
|
const DEFAULT_DATE_FORMAT = 'DD.MM.YY';
|
|
@@ -62,7 +62,7 @@ export const DefaultContent = ({ hovered, xAxis, yAxis, valueFormat }) => {
|
|
|
62
62
|
measureValue && React.createElement("div", { className: b('series-name') }, measureValue),
|
|
63
63
|
// eslint-disable-next-line complexity
|
|
64
64
|
hovered.map((seriesItem, i) => {
|
|
65
|
-
var _a;
|
|
65
|
+
var _a, _b;
|
|
66
66
|
const { data, series, closest } = seriesItem;
|
|
67
67
|
const id = `${get(series, 'id')}_${i}`;
|
|
68
68
|
const color = get(series, 'color');
|
|
@@ -87,7 +87,7 @@ export const DefaultContent = ({ hovered, xAxis, yAxis, valueFormat }) => {
|
|
|
87
87
|
}
|
|
88
88
|
case 'waterfall': {
|
|
89
89
|
const isTotal = get(data, 'total', false);
|
|
90
|
-
const subTotalValue =
|
|
90
|
+
const subTotalValue = (_a = seriesItem.subTotal) !== null && _a !== void 0 ? _a : 0;
|
|
91
91
|
const format = valueFormat !== null && valueFormat !== void 0 ? valueFormat : getDefaultValueFormat({ axis: yAxis });
|
|
92
92
|
const subTotal = getFormattedValue({
|
|
93
93
|
value: subTotalValue,
|
|
@@ -145,7 +145,7 @@ export const DefaultContent = ({ hovered, xAxis, yAxis, valueFormat }) => {
|
|
|
145
145
|
}
|
|
146
146
|
case 'sankey': {
|
|
147
147
|
const { target, data: source } = seriesItem;
|
|
148
|
-
const value = (
|
|
148
|
+
const value = (_b = source.links.find((d) => d.name === (target === null || target === void 0 ? void 0 : target.name))) === null || _b === void 0 ? void 0 : _b.value;
|
|
149
149
|
const formattedValue = getFormattedValue({
|
|
150
150
|
value,
|
|
151
151
|
format: valueFormat !== null && valueFormat !== void 0 ? valueFormat : { type: 'number' },
|
|
@@ -3,6 +3,7 @@ import { extent, scaleBand, scaleLinear, scaleLog, scaleUtc } from 'd3';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { DEFAULT_AXIS_TYPE } from '../../constants';
|
|
5
5
|
import { CHART_SERIES_WITH_VOLUME_ON_Y_AXIS, getAxisHeight, getDataCategoryValue, getDefaultMaxXAxisValue, getDefaultMinXAxisValue, getDomainDataXBySeries, getDomainDataYBySeries, getOnlyVisibleSeries, isAxisRelatedSeries, isSeriesWithCategoryValues, } from '../../utils';
|
|
6
|
+
const X_AXIS_ZOOM_PADDING = 0.02;
|
|
6
7
|
const isNumericalArrayData = (data) => {
|
|
7
8
|
return data.every((d) => typeof d === 'number' || d === null);
|
|
8
9
|
};
|
|
@@ -103,8 +104,10 @@ export function createXScale(axis, series, boundsWidth, hasZoomX) {
|
|
|
103
104
|
const xCategories = get(axis, 'categories');
|
|
104
105
|
const xTimestamps = get(axis, 'timestamps');
|
|
105
106
|
const maxPadding = get(axis, 'maxPadding', 0);
|
|
106
|
-
const
|
|
107
|
-
const
|
|
107
|
+
const xAxisMaxPadding = boundsWidth * maxPadding + calculateXAxisPadding(series);
|
|
108
|
+
const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
|
|
109
|
+
const xRange = [0, boundsWidth - xAxisMaxPadding];
|
|
110
|
+
const xRangeZoom = [0 + xAxisZoomPadding, boundsWidth - xAxisZoomPadding];
|
|
108
111
|
switch (xType) {
|
|
109
112
|
case 'linear':
|
|
110
113
|
case 'logarithmic': {
|
|
@@ -131,7 +134,9 @@ export function createXScale(axis, series, boundsWidth, hasZoomX) {
|
|
|
131
134
|
: xMaxDomain;
|
|
132
135
|
}
|
|
133
136
|
const scaleFn = xType === 'logarithmic' ? scaleLog : scaleLinear;
|
|
134
|
-
const scale = scaleFn()
|
|
137
|
+
const scale = scaleFn()
|
|
138
|
+
.domain([xMin, xMax])
|
|
139
|
+
.range(hasZoomX ? xRangeZoom : xRange);
|
|
135
140
|
if (!hasZoomX) {
|
|
136
141
|
scale.nice();
|
|
137
142
|
}
|
|
@@ -147,7 +152,7 @@ export function createXScale(axis, series, boundsWidth, hasZoomX) {
|
|
|
147
152
|
series: series,
|
|
148
153
|
});
|
|
149
154
|
const xScale = scaleBand().domain(filteredCategories).range([0, boundsWidth]);
|
|
150
|
-
if (xScale.step() / 2 <
|
|
155
|
+
if (xScale.step() / 2 < xAxisMaxPadding) {
|
|
151
156
|
xScale.range(xRange);
|
|
152
157
|
}
|
|
153
158
|
return xScale;
|
|
@@ -159,7 +164,9 @@ export function createXScale(axis, series, boundsWidth, hasZoomX) {
|
|
|
159
164
|
const [xMinTimestamp, xMaxTimestamp] = extent(xTimestamps);
|
|
160
165
|
const xMin = typeof xMinProps === 'number' ? xMinProps : xMinTimestamp;
|
|
161
166
|
const xMax = typeof xMaxProps === 'number' ? xMaxProps : xMaxTimestamp;
|
|
162
|
-
const scale = scaleUtc()
|
|
167
|
+
const scale = scaleUtc()
|
|
168
|
+
.domain([xMin, xMax])
|
|
169
|
+
.range(hasZoomX ? xRangeZoom : xRange);
|
|
163
170
|
if (!hasZoomX) {
|
|
164
171
|
scale.nice();
|
|
165
172
|
}
|
|
@@ -171,7 +178,9 @@ export function createXScale(axis, series, boundsWidth, hasZoomX) {
|
|
|
171
178
|
const [xMinTimestamp, xMaxTimestamp] = extent(domain);
|
|
172
179
|
const xMin = typeof xMinProps === 'number' ? xMinProps : xMinTimestamp;
|
|
173
180
|
const xMax = typeof xMaxProps === 'number' ? xMaxProps : xMaxTimestamp;
|
|
174
|
-
const scale = scaleUtc()
|
|
181
|
+
const scale = scaleUtc()
|
|
182
|
+
.domain([xMin, xMax])
|
|
183
|
+
.range(hasZoomX ? xRangeZoom : xRange);
|
|
175
184
|
if (!hasZoomX) {
|
|
176
185
|
scale.nice();
|
|
177
186
|
}
|
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
import type { ChartData } from '../../types';
|
|
2
|
-
import type { PreparedAxis, PreparedChart } from '../useChartOptions/types';
|
|
3
2
|
import type { OnLegendItemClick, PreparedLegend, PreparedSeries } from './types';
|
|
4
3
|
type Args = {
|
|
5
|
-
chartWidth: number;
|
|
6
|
-
chartHeight: number;
|
|
7
|
-
chartMargin: PreparedChart['margin'];
|
|
8
4
|
colors: string[];
|
|
9
5
|
legend: ChartData['legend'];
|
|
10
6
|
originalSeriesData: ChartData['series']['data'];
|
|
11
7
|
seriesData: ChartData['series']['data'];
|
|
12
8
|
seriesOptions: ChartData['series']['options'];
|
|
13
|
-
|
|
9
|
+
preparedLegend?: PreparedLegend;
|
|
14
10
|
};
|
|
15
11
|
export declare const useSeries: (args: Args) => {
|
|
16
|
-
legendItems: never[] | import("./types").LegendItem[][];
|
|
17
|
-
legendConfig: {
|
|
18
|
-
offset: {
|
|
19
|
-
left: number;
|
|
20
|
-
top: number;
|
|
21
|
-
};
|
|
22
|
-
pagination: {
|
|
23
|
-
pages: {
|
|
24
|
-
start: number;
|
|
25
|
-
end: number;
|
|
26
|
-
}[];
|
|
27
|
-
} | undefined;
|
|
28
|
-
} | undefined;
|
|
29
12
|
preparedLegend: PreparedLegend | null;
|
|
30
13
|
preparedSeries: PreparedSeries[];
|
|
31
|
-
preparedSeriesOptions: import("../../constants").SeriesOptionsDefaults;
|
|
32
14
|
handleLegendItemClick: OnLegendItemClick;
|
|
33
15
|
};
|
|
34
16
|
export {};
|
|
@@ -2,16 +2,17 @@ import React from 'react';
|
|
|
2
2
|
import { group, scaleOrdinal } from 'd3';
|
|
3
3
|
import { getSeriesNames } from '../../utils';
|
|
4
4
|
import { usePrevious } from '../usePrevious';
|
|
5
|
-
import {
|
|
6
|
-
import { getPreparedOptions } from './prepare-options';
|
|
5
|
+
import { getPreparedLegend } from './prepare-legend';
|
|
7
6
|
import { prepareSeries } from './prepareSeries';
|
|
8
7
|
import { getActiveLegendItems, getAllLegendItems } from './utils';
|
|
9
8
|
export const useSeries = (args) => {
|
|
10
|
-
const {
|
|
11
|
-
const [preparedLegend, setPreparedLegend] = React.useState(
|
|
9
|
+
const { legend, originalSeriesData, seriesData, seriesOptions, colors, preparedLegend: preparedLegendProps = null, } = args;
|
|
10
|
+
const [preparedLegend, setPreparedLegend] = React.useState(preparedLegendProps);
|
|
12
11
|
React.useEffect(() => {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (!preparedLegendProps) {
|
|
13
|
+
getPreparedLegend({ legend, series: seriesData }).then((value) => setPreparedLegend(value));
|
|
14
|
+
}
|
|
15
|
+
}, [legend, preparedLegendProps, seriesData]);
|
|
15
16
|
const [preparedSeries, setPreparedSeries] = React.useState([]);
|
|
16
17
|
const [activeLegendItems, setActiveLegendItems] = React.useState(getActiveLegendItems(preparedSeries));
|
|
17
18
|
React.useEffect(() => {
|
|
@@ -39,9 +40,6 @@ export const useSeries = (args) => {
|
|
|
39
40
|
setActiveLegendItems(getActiveLegendItems(acc));
|
|
40
41
|
})();
|
|
41
42
|
}, [seriesData, seriesOptions, preparedLegend, colors]);
|
|
42
|
-
const preparedSeriesOptions = React.useMemo(() => {
|
|
43
|
-
return getPreparedOptions(seriesOptions);
|
|
44
|
-
}, [seriesOptions]);
|
|
45
43
|
const prevOriginalSeriesData = usePrevious(originalSeriesData);
|
|
46
44
|
const chartSeries = React.useMemo(() => {
|
|
47
45
|
return preparedSeries.map((singleSeries) => {
|
|
@@ -51,19 +49,6 @@ export const useSeries = (args) => {
|
|
|
51
49
|
return singleSeries;
|
|
52
50
|
});
|
|
53
51
|
}, [preparedSeries, activeLegendItems]);
|
|
54
|
-
const { legendConfig, legendItems } = React.useMemo(() => {
|
|
55
|
-
if (!preparedLegend) {
|
|
56
|
-
return { legendConfig: undefined, legendItems: [] };
|
|
57
|
-
}
|
|
58
|
-
return getLegendComponents({
|
|
59
|
-
chartHeight,
|
|
60
|
-
chartMargin,
|
|
61
|
-
chartWidth,
|
|
62
|
-
series: chartSeries,
|
|
63
|
-
preparedLegend,
|
|
64
|
-
preparedYAxis,
|
|
65
|
-
});
|
|
66
|
-
}, [chartWidth, chartHeight, chartMargin, chartSeries, preparedLegend, preparedYAxis]);
|
|
67
52
|
const handleLegendItemClick = React.useCallback(({ name, metaKey }) => {
|
|
68
53
|
const allItems = getAllLegendItems(preparedSeries);
|
|
69
54
|
const onlyItemSelected = activeLegendItems.length === 1 && activeLegendItems.includes(name);
|
|
@@ -91,11 +76,8 @@ export const useSeries = (args) => {
|
|
|
91
76
|
}
|
|
92
77
|
}, [originalSeriesData, prevOriginalSeriesData, preparedSeries]);
|
|
93
78
|
return {
|
|
94
|
-
legendItems,
|
|
95
|
-
legendConfig,
|
|
96
79
|
preparedLegend,
|
|
97
80
|
preparedSeries: chartSeries,
|
|
98
|
-
preparedSeriesOptions,
|
|
99
81
|
handleLegendItemClick,
|
|
100
82
|
};
|
|
101
83
|
};
|
|
@@ -3,7 +3,7 @@ import clone from 'lodash/clone';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import merge from 'lodash/merge';
|
|
5
5
|
import { CONTINUOUS_LEGEND_SIZE, legendDefaults } from '../../constants';
|
|
6
|
-
import { getDefaultColorStops, getDomainForContinuousColorScale,
|
|
6
|
+
import { getDefaultColorStops, getDomainForContinuousColorScale, getLabelsSize } from '../../utils';
|
|
7
7
|
import { getBoundsWidth } from '../useChartDimensions';
|
|
8
8
|
import { getYAxisWidth } from '../useChartDimensions/utils';
|
|
9
9
|
export async function getPreparedLegend(args) {
|
|
@@ -13,7 +13,7 @@ export async function getPreparedLegend(args) {
|
|
|
13
13
|
const defaultItemStyle = clone(legendDefaults.itemStyle);
|
|
14
14
|
const itemStyle = get(legend, 'itemStyle');
|
|
15
15
|
const computedItemStyle = merge(defaultItemStyle, itemStyle);
|
|
16
|
-
const lineHeight =
|
|
16
|
+
const lineHeight = (await getLabelsSize({ labels: ['Tmp'], style: computedItemStyle })).maxHeight;
|
|
17
17
|
const legendType = get(legend, 'type', 'discrete');
|
|
18
18
|
const isTitleEnabled = Boolean((_a = legend === null || legend === void 0 ? void 0 : legend.title) === null || _a === void 0 ? void 0 : _a.text);
|
|
19
19
|
const titleMargin = isTitleEnabled ? get(legend, 'title.margin', 4) : 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { group
|
|
1
|
+
import { group } from 'd3';
|
|
2
2
|
import { getDataCategoryValue, getLabelsSize, getLeftPosition } from '../../../utils';
|
|
3
3
|
import { getFormattedValue } from '../../../utils/chart/format';
|
|
4
4
|
import { getXValue, getYValue } from '../utils';
|
|
@@ -36,7 +36,7 @@ function getXValues(series, xAxis, xScale) {
|
|
|
36
36
|
? getDataCategoryValue({ axisDirection: 'x', categories, data: d })
|
|
37
37
|
: d.x);
|
|
38
38
|
if (!acc.has(key)) {
|
|
39
|
-
acc.set(key, getXValue({ point: d, xAxis, xScale }));
|
|
39
|
+
acc.set(key, getXValue({ point: d, points: s.data, xAxis, xScale }));
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
return acc;
|
|
@@ -50,7 +50,7 @@ function getXValues(series, xAxis, xScale) {
|
|
|
50
50
|
return acc;
|
|
51
51
|
}, []);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
53
|
+
return Array.from(xValues);
|
|
54
54
|
}
|
|
55
55
|
export const prepareAreaData = async (args) => {
|
|
56
56
|
const { series, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight, isOutsideBounds } = args;
|
|
@@ -73,6 +73,7 @@ export const prepareAreaData = async (args) => {
|
|
|
73
73
|
const seriesYScale = yScale[yAxisIndex];
|
|
74
74
|
const yMin = getYValue({
|
|
75
75
|
point: { y: 0 },
|
|
76
|
+
points: s.data,
|
|
76
77
|
yAxis: seriesYAxis,
|
|
77
78
|
yScale: seriesYScale,
|
|
78
79
|
});
|