@gravity-ui/charts 0.6.0 → 0.6.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/components/Axis/AxisY.d.ts +1 -0
- package/dist/cjs/components/Axis/AxisY.js +55 -13
- package/dist/cjs/components/ChartInner/index.js +3 -2
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +4 -0
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +2 -2
- package/dist/cjs/components/Legend/index.js +1 -2
- package/dist/cjs/components/PlotTitle/index.js +1 -1
- package/dist/cjs/components/PlotTitle/styles.css +1 -1
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +2 -2
- package/dist/cjs/components/Tooltip/DefaultContent.js +19 -3
- package/dist/cjs/components/Tooltip/index.js +2 -2
- package/dist/cjs/components/Tooltip/styles.css +11 -9
- package/dist/cjs/components/index.d.ts +10 -9
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/hooks/useChartOptions/types.d.ts +11 -1
- package/dist/cjs/hooks/useChartOptions/x-axis.js +1 -0
- package/dist/cjs/hooks/useChartOptions/y-axis.js +9 -1
- package/dist/cjs/hooks/useSeries/prepare-area.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-x.d.ts +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-x.js +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +2 -1
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +3 -1
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-pie.js +2 -2
- package/dist/cjs/hooks/useSeries/prepare-sankey.d.ts +11 -0
- package/dist/cjs/hooks/useSeries/prepare-sankey.js +38 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.js +21 -2
- package/dist/cjs/hooks/useSeries/types.d.ts +12 -2
- package/dist/cjs/hooks/useSeries/utils.js +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +4 -0
- package/dist/cjs/hooks/useShapes/bar-x/index.js +16 -2
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +3 -1
- package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-y/index.js +16 -2
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +3 -1
- package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/index.js +19 -0
- package/dist/cjs/hooks/useShapes/line/index.js +2 -2
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/pie/index.js +5 -4
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +168 -118
- package/dist/cjs/hooks/useShapes/pie/types.d.ts +2 -2
- package/dist/cjs/hooks/useShapes/sankey/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/sankey/index.js +67 -0
- package/dist/cjs/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
- package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +72 -0
- package/dist/cjs/hooks/useShapes/sankey/types.d.ts +33 -0
- package/dist/cjs/hooks/useShapes/sankey/types.js +1 -0
- package/dist/cjs/hooks/useShapes/styles.css +2 -2
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +1 -0
- package/dist/cjs/hooks/useShapes/utils.d.ts +7 -2
- package/dist/cjs/hooks/useShapes/utils.js +22 -17
- package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/types/chart/area.d.ts +6 -6
- package/dist/cjs/types/chart/axis.d.ts +32 -7
- package/dist/cjs/types/chart/bar-x.d.ts +9 -4
- package/dist/cjs/types/chart/bar-y.d.ts +10 -6
- package/dist/cjs/types/chart/base.d.ts +6 -6
- package/dist/cjs/types/chart/chart.d.ts +4 -4
- package/dist/cjs/types/chart/halo.d.ts +2 -2
- package/dist/cjs/types/chart/legend.d.ts +10 -10
- package/dist/cjs/types/chart/line.d.ts +4 -4
- package/dist/cjs/types/chart/marker.d.ts +2 -2
- package/dist/cjs/types/chart/pie.d.ts +6 -4
- package/dist/cjs/types/chart/sankey.d.ts +22 -0
- package/dist/cjs/types/chart/sankey.js +1 -0
- package/dist/cjs/types/chart/scatter.d.ts +4 -4
- package/dist/cjs/types/chart/series.d.ts +21 -10
- package/dist/cjs/types/chart/split.d.ts +4 -4
- package/dist/cjs/types/chart/title.d.ts +2 -2
- package/dist/cjs/types/chart/tooltip.d.ts +27 -21
- package/dist/cjs/types/chart/treemap.d.ts +4 -4
- package/dist/cjs/types/chart/waterfall.d.ts +4 -4
- package/dist/cjs/types/chart-ui.d.ts +10 -6
- package/dist/cjs/types/formatter.d.ts +4 -4
- package/dist/cjs/types/index.d.ts +35 -4
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/utils/chart/get-closest-data.d.ts +2 -0
- package/dist/cjs/utils/chart/get-closest-data.js +39 -3
- package/dist/cjs/utils/chart/index.js +1 -1
- 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/line.d.ts +2 -0
- package/dist/cjs/utils/chart/series/line.js +17 -0
- package/dist/esm/components/Axis/AxisY.d.ts +1 -0
- package/dist/esm/components/Axis/AxisY.js +55 -13
- package/dist/esm/components/ChartInner/index.js +3 -2
- package/dist/esm/components/ChartInner/useChartInnerHandlers.js +4 -0
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +2 -2
- package/dist/esm/components/Legend/index.js +1 -2
- package/dist/esm/components/PlotTitle/index.js +1 -1
- package/dist/esm/components/PlotTitle/styles.css +1 -1
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +2 -2
- package/dist/esm/components/Tooltip/DefaultContent.js +19 -3
- package/dist/esm/components/Tooltip/index.js +2 -2
- package/dist/esm/components/Tooltip/styles.css +11 -9
- package/dist/esm/components/index.d.ts +10 -9
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/hooks/useChartOptions/types.d.ts +11 -1
- package/dist/esm/hooks/useChartOptions/x-axis.js +1 -0
- package/dist/esm/hooks/useChartOptions/y-axis.js +9 -1
- package/dist/esm/hooks/useSeries/prepare-area.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-bar-x.d.ts +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-x.js +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +2 -1
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +3 -1
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-pie.js +2 -2
- package/dist/esm/hooks/useSeries/prepare-sankey.d.ts +11 -0
- package/dist/esm/hooks/useSeries/prepare-sankey.js +38 -0
- package/dist/esm/hooks/useSeries/prepareSeries.js +21 -2
- package/dist/esm/hooks/useSeries/types.d.ts +12 -2
- package/dist/esm/hooks/useSeries/utils.js +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +4 -0
- package/dist/esm/hooks/useShapes/bar-x/index.js +16 -2
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +3 -1
- package/dist/esm/hooks/useShapes/bar-x/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-y/index.js +16 -2
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +3 -1
- package/dist/esm/hooks/useShapes/bar-y/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/index.d.ts +2 -1
- package/dist/esm/hooks/useShapes/index.js +19 -0
- package/dist/esm/hooks/useShapes/line/index.js +2 -2
- package/dist/esm/hooks/useShapes/line/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/pie/index.js +5 -4
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +168 -118
- package/dist/esm/hooks/useShapes/pie/types.d.ts +2 -2
- package/dist/esm/hooks/useShapes/sankey/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/sankey/index.js +67 -0
- package/dist/esm/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
- package/dist/esm/hooks/useShapes/sankey/prepare-data.js +72 -0
- package/dist/esm/hooks/useShapes/sankey/types.d.ts +33 -0
- package/dist/esm/hooks/useShapes/sankey/types.js +1 -0
- package/dist/esm/hooks/useShapes/styles.css +2 -2
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +1 -0
- package/dist/esm/hooks/useShapes/utils.d.ts +7 -2
- package/dist/esm/hooks/useShapes/utils.js +22 -17
- package/dist/esm/hooks/useShapes/waterfall/index.js +1 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/types/chart/area.d.ts +6 -6
- package/dist/esm/types/chart/axis.d.ts +32 -7
- package/dist/esm/types/chart/bar-x.d.ts +9 -4
- package/dist/esm/types/chart/bar-y.d.ts +10 -6
- package/dist/esm/types/chart/base.d.ts +6 -6
- package/dist/esm/types/chart/chart.d.ts +4 -4
- package/dist/esm/types/chart/halo.d.ts +2 -2
- package/dist/esm/types/chart/legend.d.ts +10 -10
- package/dist/esm/types/chart/line.d.ts +4 -4
- package/dist/esm/types/chart/marker.d.ts +2 -2
- package/dist/esm/types/chart/pie.d.ts +6 -4
- package/dist/esm/types/chart/sankey.d.ts +22 -0
- package/dist/esm/types/chart/sankey.js +1 -0
- package/dist/esm/types/chart/scatter.d.ts +4 -4
- package/dist/esm/types/chart/series.d.ts +21 -10
- package/dist/esm/types/chart/split.d.ts +4 -4
- package/dist/esm/types/chart/title.d.ts +2 -2
- package/dist/esm/types/chart/tooltip.d.ts +27 -21
- package/dist/esm/types/chart/treemap.d.ts +4 -4
- package/dist/esm/types/chart/waterfall.d.ts +4 -4
- package/dist/esm/types/chart-ui.d.ts +10 -6
- package/dist/esm/types/formatter.d.ts +4 -4
- package/dist/esm/types/index.d.ts +35 -4
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/chart/get-closest-data.d.ts +2 -0
- package/dist/esm/utils/chart/get-closest-data.js +39 -3
- package/dist/esm/utils/chart/index.js +1 -1
- 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/line.d.ts +2 -0
- package/dist/esm/utils/chart/series/line.js +17 -0
- package/package.json +7 -2
|
@@ -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 { prepareSankeySeries } from './prepare-sankey';
|
|
7
8
|
import { prepareScatterSeries } from './prepare-scatter';
|
|
8
9
|
import { prepareTreemap } from './prepare-treemap';
|
|
9
10
|
import { prepareWaterfallSeries } from './prepare-waterfall';
|
|
@@ -17,10 +18,20 @@ export function prepareSeries(args) {
|
|
|
17
18
|
}, []);
|
|
18
19
|
}
|
|
19
20
|
case 'bar-x': {
|
|
20
|
-
return prepareBarXSeries({
|
|
21
|
+
return prepareBarXSeries({
|
|
22
|
+
series: series,
|
|
23
|
+
legend,
|
|
24
|
+
colorScale,
|
|
25
|
+
seriesOptions,
|
|
26
|
+
});
|
|
21
27
|
}
|
|
22
28
|
case 'bar-y': {
|
|
23
|
-
return prepareBarYSeries({
|
|
29
|
+
return prepareBarYSeries({
|
|
30
|
+
series: series,
|
|
31
|
+
legend,
|
|
32
|
+
colorScale,
|
|
33
|
+
seriesOptions,
|
|
34
|
+
});
|
|
24
35
|
}
|
|
25
36
|
case 'scatter': {
|
|
26
37
|
return prepareScatterSeries({ series: series, legend, colorScale });
|
|
@@ -56,6 +67,14 @@ export function prepareSeries(args) {
|
|
|
56
67
|
colorScale,
|
|
57
68
|
});
|
|
58
69
|
}
|
|
70
|
+
case 'sankey': {
|
|
71
|
+
return prepareSankeySeries({
|
|
72
|
+
series: series,
|
|
73
|
+
seriesOptions,
|
|
74
|
+
colorScale,
|
|
75
|
+
legend,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
59
78
|
default: {
|
|
60
79
|
throw new ChartError({
|
|
61
80
|
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, 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, 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>;
|
|
@@ -107,6 +107,7 @@ export type PreparedBarXSeries = {
|
|
|
107
107
|
padding: number;
|
|
108
108
|
html: boolean;
|
|
109
109
|
};
|
|
110
|
+
borderRadius: number;
|
|
110
111
|
yAxis: number;
|
|
111
112
|
} & BasePreparedSeries;
|
|
112
113
|
export type PreparedBarYSeries = {
|
|
@@ -122,6 +123,7 @@ export type PreparedBarYSeries = {
|
|
|
122
123
|
maxWidth: number;
|
|
123
124
|
html: boolean;
|
|
124
125
|
};
|
|
126
|
+
borderRadius: number;
|
|
125
127
|
} & BasePreparedSeries;
|
|
126
128
|
export type PreparedPieSeries = {
|
|
127
129
|
type: PieSeries['type'];
|
|
@@ -248,7 +250,15 @@ export type PreparedWaterfallSeries = {
|
|
|
248
250
|
positiveColor: string;
|
|
249
251
|
negativeColor: string;
|
|
250
252
|
} & BasePreparedSeries;
|
|
251
|
-
export type
|
|
253
|
+
export type PreparedSankeySeries = {
|
|
254
|
+
type: SankeySeries['type'];
|
|
255
|
+
data: SankeySeriesData[];
|
|
256
|
+
dataLabels: {
|
|
257
|
+
enabled: boolean;
|
|
258
|
+
style: BaseTextStyle;
|
|
259
|
+
};
|
|
260
|
+
} & BasePreparedSeries & Omit<SankeySeries, keyof BasePreparedSeries>;
|
|
261
|
+
export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries;
|
|
252
262
|
export type PreparedSeriesOptions = SeriesOptionsDefaults;
|
|
253
263
|
export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
|
|
254
264
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import memoize from 'lodash/memoize';
|
|
2
2
|
import { SymbolType } from '../../constants';
|
|
3
|
-
import { getUniqId } from '../../utils';
|
|
3
|
+
import { getUniqId } from '../../utils/misc';
|
|
4
4
|
import { DEFAULT_LEGEND_SYMBOL_PADDING, DEFAULT_LEGEND_SYMBOL_SIZE } from './constants';
|
|
5
5
|
export const getActiveLegendItems = (series) => {
|
|
6
6
|
return series.reduce((acc, s) => {
|
|
@@ -102,10 +102,14 @@ export const prepareAreaData = (args) => {
|
|
|
102
102
|
const labelItems = points.map((p) => getLabelData(p, s, xMax));
|
|
103
103
|
if (s.dataLabels.html) {
|
|
104
104
|
const htmlLabels = labelItems.map((l) => {
|
|
105
|
+
var _a;
|
|
106
|
+
const style = (_a = l.style) !== null && _a !== void 0 ? _a : s.dataLabels.style;
|
|
107
|
+
const labelSize = getLabelsSize({ labels: [l.text], style, html: true });
|
|
105
108
|
return {
|
|
106
109
|
x: l.x - l.size.width / 2,
|
|
107
110
|
y: l.y,
|
|
108
111
|
content: l.text,
|
|
112
|
+
size: { width: labelSize.maxWidth, height: labelSize.maxHeight },
|
|
109
113
|
};
|
|
110
114
|
});
|
|
111
115
|
htmlElements.push(...htmlLabels);
|
|
@@ -3,9 +3,10 @@ import { color, select } from 'd3';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { block, filterOverlappingLabels } from '../../../utils';
|
|
5
5
|
import { HtmlLayer } from '../HtmlLayer';
|
|
6
|
+
import { getRectPath } from '../utils';
|
|
6
7
|
export { prepareBarXData } from './prepare-data';
|
|
7
8
|
export * from './types';
|
|
8
|
-
const b = block('
|
|
9
|
+
const b = block('bar-x');
|
|
9
10
|
export const BarXSeriesShapes = (args) => {
|
|
10
11
|
const { dispatcher, preparedData, seriesOptions, htmlLayout } = args;
|
|
11
12
|
const hoveredDataRef = React.useRef(null);
|
|
@@ -22,7 +23,20 @@ export const BarXSeriesShapes = (args) => {
|
|
|
22
23
|
const rectSelection = svgElement
|
|
23
24
|
.selectAll('allRects')
|
|
24
25
|
.data(preparedData)
|
|
25
|
-
.join('
|
|
26
|
+
.join('path')
|
|
27
|
+
.attr('d', (d) => {
|
|
28
|
+
const borderRadius = d.isLastStackItem
|
|
29
|
+
? Math.min(d.height, d.width / 2, d.series.borderRadius)
|
|
30
|
+
: 0;
|
|
31
|
+
const p = getRectPath({
|
|
32
|
+
x: d.x,
|
|
33
|
+
y: d.y,
|
|
34
|
+
width: d.width,
|
|
35
|
+
height: d.height,
|
|
36
|
+
borderRadius: [borderRadius, borderRadius, 0, 0],
|
|
37
|
+
});
|
|
38
|
+
return p.toString();
|
|
39
|
+
})
|
|
26
40
|
.attr('class', b('segment'))
|
|
27
41
|
.attr('x', (d) => d.x)
|
|
28
42
|
.attr('y', (d) => d.y)
|
|
@@ -103,7 +103,7 @@ export const prepareBarXData = (args) => {
|
|
|
103
103
|
const sortedData = sortKey
|
|
104
104
|
? sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
|
|
105
105
|
: yValues;
|
|
106
|
-
sortedData.forEach((yValue) => {
|
|
106
|
+
sortedData.forEach((yValue, yValueIndex) => {
|
|
107
107
|
const yAxisIndex = yValue.series.yAxis;
|
|
108
108
|
const seriesYScale = yScale[yAxisIndex];
|
|
109
109
|
let xCenter;
|
|
@@ -129,6 +129,7 @@ export const prepareBarXData = (args) => {
|
|
|
129
129
|
data: yValue.data,
|
|
130
130
|
series: yValue.series,
|
|
131
131
|
htmlElements: [],
|
|
132
|
+
isLastStackItem: yValueIndex === sortedData.length - 1,
|
|
132
133
|
};
|
|
133
134
|
const label = getLabelData(barData);
|
|
134
135
|
if (yValue.series.dataLabels.html && label) {
|
|
@@ -136,6 +137,7 @@ export const prepareBarXData = (args) => {
|
|
|
136
137
|
x: label.x,
|
|
137
138
|
y: label.y,
|
|
138
139
|
content: label.text,
|
|
140
|
+
size: label.size,
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
else {
|
|
@@ -3,8 +3,9 @@ import { color, select } from 'd3';
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { block } from '../../../utils';
|
|
5
5
|
import { HtmlLayer } from '../HtmlLayer';
|
|
6
|
+
import { getRectPath } from '../utils';
|
|
6
7
|
export { prepareBarYData } from './prepare-data';
|
|
7
|
-
const b = block('
|
|
8
|
+
const b = block('bar-y');
|
|
8
9
|
export const BarYSeriesShapes = (args) => {
|
|
9
10
|
const { dispatcher, preparedData, seriesOptions, htmlLayout } = args;
|
|
10
11
|
const hoveredDataRef = React.useRef(null);
|
|
@@ -18,7 +19,20 @@ export const BarYSeriesShapes = (args) => {
|
|
|
18
19
|
const rectSelection = svgElement
|
|
19
20
|
.selectAll('rect')
|
|
20
21
|
.data(preparedData)
|
|
21
|
-
.join('
|
|
22
|
+
.join('path')
|
|
23
|
+
.attr('d', (d) => {
|
|
24
|
+
const borderRadius = d.isLastStackItem
|
|
25
|
+
? Math.min(d.height, d.width / 2, d.series.borderRadius)
|
|
26
|
+
: 0;
|
|
27
|
+
const p = getRectPath({
|
|
28
|
+
x: d.x,
|
|
29
|
+
y: d.y,
|
|
30
|
+
width: d.width,
|
|
31
|
+
height: d.height,
|
|
32
|
+
borderRadius: [0, borderRadius, borderRadius, 0],
|
|
33
|
+
});
|
|
34
|
+
return p.toString();
|
|
35
|
+
})
|
|
22
36
|
.attr('class', b('segment'))
|
|
23
37
|
.attr('x', (d) => d.x)
|
|
24
38
|
.attr('y', (d) => d.y)
|
|
@@ -69,6 +69,7 @@ function setLabel(prepared) {
|
|
|
69
69
|
x,
|
|
70
70
|
y: y - height / 2,
|
|
71
71
|
content,
|
|
72
|
+
size: { width, height },
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
else {
|
|
@@ -123,7 +124,7 @@ export const prepareBarYData = (args) => {
|
|
|
123
124
|
const sortedData = sortKey
|
|
124
125
|
? sort(measureValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
|
|
125
126
|
: measureValues;
|
|
126
|
-
sortedData.forEach(({ data, series: s }) => {
|
|
127
|
+
sortedData.forEach(({ data, series: s }, xValueIndex) => {
|
|
127
128
|
let center;
|
|
128
129
|
if (yAxis[0].type === 'category') {
|
|
129
130
|
const bandScale = yScale;
|
|
@@ -146,6 +147,7 @@ export const prepareBarYData = (args) => {
|
|
|
146
147
|
data,
|
|
147
148
|
series: s,
|
|
148
149
|
htmlElements: [],
|
|
150
|
+
isLastStackItem: xValueIndex === sortedData.length - 1,
|
|
149
151
|
};
|
|
150
152
|
stackItems.push(item);
|
|
151
153
|
stackSum += width + 1;
|
|
@@ -8,12 +8,13 @@ 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 { PreparedSankeyData } from './sankey/types';
|
|
11
12
|
import type { PreparedScatterData } from './scatter/types';
|
|
12
13
|
export type { PreparedBarXData } from './bar-x';
|
|
13
14
|
export type { PreparedScatterData } from './scatter/types';
|
|
14
15
|
import type { PreparedWaterfallData } from './waterfall';
|
|
15
16
|
import './styles.css';
|
|
16
|
-
export type ShapeData = PreparedBarXData | PreparedBarYData | PreparedScatterData | PreparedLineData | PreparedPieData | PreparedAreaData | PreparedWaterfallData;
|
|
17
|
+
export type ShapeData = PreparedBarXData | PreparedBarYData | PreparedScatterData | PreparedLineData | PreparedPieData | PreparedAreaData | PreparedWaterfallData | PreparedSankeyData;
|
|
17
18
|
type Args = {
|
|
18
19
|
boundsWidth: number;
|
|
19
20
|
boundsHeight: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { group } from 'd3';
|
|
3
|
+
import { ChartError } from '../../libs';
|
|
3
4
|
import { getOnlyVisibleSeries } from '../../utils';
|
|
4
5
|
import { AreaSeriesShapes } from './area';
|
|
5
6
|
import { prepareAreaData } from './area/prepare-data';
|
|
@@ -9,6 +10,8 @@ import { LineSeriesShapes } from './line';
|
|
|
9
10
|
import { prepareLineData } from './line/prepare-data';
|
|
10
11
|
import { PieSeriesShapes } from './pie';
|
|
11
12
|
import { preparePieData } from './pie/prepare-data';
|
|
13
|
+
import { SankeySeriesShape } from './sankey';
|
|
14
|
+
import { prepareSankeyData } from './sankey/prepare-data';
|
|
12
15
|
import { ScatterSeriesShape, prepareScatterData } from './scatter';
|
|
13
16
|
import { TreemapSeriesShape } from './treemap';
|
|
14
17
|
import { prepareTreemapData } from './treemap/prepare-data';
|
|
@@ -134,6 +137,22 @@ export const useShapes = (args) => {
|
|
|
134
137
|
});
|
|
135
138
|
acc.push(React.createElement(TreemapSeriesShape, { key: "treemap", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
136
139
|
shapesData.push(preparedData);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case 'sankey': {
|
|
143
|
+
const preparedData = prepareSankeyData({
|
|
144
|
+
series: chartSeries[0],
|
|
145
|
+
width: boundsWidth,
|
|
146
|
+
height: boundsHeight,
|
|
147
|
+
});
|
|
148
|
+
acc.push(React.createElement(SankeySeriesShape, { key: "sankey", dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
|
|
149
|
+
shapesData.push(preparedData);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
default: {
|
|
153
|
+
throw new ChartError({
|
|
154
|
+
message: `The display method is not defined for a series with type "${seriesType}"`,
|
|
155
|
+
});
|
|
137
156
|
}
|
|
138
157
|
}
|
|
139
158
|
return acc;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { color, line as lineGenerator, select } from 'd3';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
|
-
import { block, filterOverlappingLabels } from '../../../utils';
|
|
4
|
+
import { block, filterOverlappingLabels, getLineDashArray } from '../../../utils';
|
|
5
5
|
import { HtmlLayer } from '../HtmlLayer';
|
|
6
6
|
import { getMarkerHaloVisibility, getMarkerVisibility, renderMarker, selectMarkerHalo, selectMarkerSymbol, setMarker, } from '../marker';
|
|
7
|
-
import {
|
|
7
|
+
import { setActiveState } from '../utils';
|
|
8
8
|
const b = block('d3-line');
|
|
9
9
|
export const LineSeriesShapes = (args) => {
|
|
10
10
|
const { dispatcher, preparedData, seriesOptions, htmlLayout } = args;
|
|
@@ -33,6 +33,7 @@ function getHtmlLabel(point, series, xMax) {
|
|
|
33
33
|
x: Math.min(xMax - size.maxWidth, Math.max(0, point.x)),
|
|
34
34
|
y: Math.max(0, point.y - series.dataLabels.padding - size.maxHeight),
|
|
35
35
|
content,
|
|
36
|
+
size: { width: size.maxWidth, height: size.maxHeight },
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
export const prepareLineData = (args) => {
|
|
@@ -30,7 +30,6 @@ export function PieSeriesShapes(args) {
|
|
|
30
30
|
const [x, y] = pieData.center;
|
|
31
31
|
return `translate(${x}, ${y})`;
|
|
32
32
|
})
|
|
33
|
-
.style('stroke', (pieData) => pieData.borderColor)
|
|
34
33
|
.style('stroke-width', (pieData) => pieData.borderWidth)
|
|
35
34
|
.attr('cursor', (pieData) => pieData.series.cursor);
|
|
36
35
|
// Render halo appearing outside the hovered slice
|
|
@@ -46,7 +45,7 @@ export function PieSeriesShapes(args) {
|
|
|
46
45
|
.attr('d', (d) => {
|
|
47
46
|
const arcGenerator = arc()
|
|
48
47
|
.innerRadius(d.data.pie.innerRadius)
|
|
49
|
-
.outerRadius(d.data.
|
|
48
|
+
.outerRadius(d.data.radius + d.data.pie.halo.size)
|
|
50
49
|
.cornerRadius(d.data.pie.borderRadius);
|
|
51
50
|
return arcGenerator(d);
|
|
52
51
|
})
|
|
@@ -63,11 +62,12 @@ export function PieSeriesShapes(args) {
|
|
|
63
62
|
.attr('d', (d) => {
|
|
64
63
|
const arcGenerator = arc()
|
|
65
64
|
.innerRadius(d.data.pie.innerRadius)
|
|
66
|
-
.outerRadius(d.data.
|
|
65
|
+
.outerRadius(d.data.radius)
|
|
67
66
|
.cornerRadius(d.data.pie.borderRadius);
|
|
68
67
|
return arcGenerator(d);
|
|
69
68
|
})
|
|
70
69
|
.attr('class', b('segment'))
|
|
70
|
+
.style('stroke', (d) => d.data.series.borderColor)
|
|
71
71
|
.attr('fill', (d) => d.data.color)
|
|
72
72
|
.attr('opacity', (d) => d.data.opacity);
|
|
73
73
|
// render Labels
|
|
@@ -165,7 +165,8 @@ export function PieSeriesShapes(args) {
|
|
|
165
165
|
dispatcher.on(eventName, null);
|
|
166
166
|
};
|
|
167
167
|
}, [dispatcher, preparedData, seriesOptions]);
|
|
168
|
+
const htmlElements = preparedData.map((d) => d.htmlLabels).flat();
|
|
168
169
|
return (React.createElement(React.Fragment, null,
|
|
169
170
|
React.createElement("g", { ref: ref, className: b(), style: { zIndex: 9 } }),
|
|
170
|
-
React.createElement(HtmlLayer, { preparedData:
|
|
171
|
+
React.createElement(HtmlLayer, { preparedData: { htmlElements }, htmlLayout: htmlLayout })));
|
|
171
172
|
}
|