td-stylekit 28.20.0 → 28.21.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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [28.21.0](https://github.com/treasure-data/td-stylekit/compare/v28.20.0...v28.21.0) (2023-05-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **CON-12722:** Add a custom legend renderer to the PieChart component ([#1467](https://github.com/treasure-data/td-stylekit/issues/1467)) ([f812110](https://github.com/treasure-data/td-stylekit/commit/f812110))
|
|
7
|
+
|
|
1
8
|
# [28.20.0](https://github.com/treasure-data/td-stylekit/compare/v28.19.0...v28.20.0) (2023-04-13)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -5,6 +5,18 @@ export type PieChartData = {
|
|
|
5
5
|
percent?: string;
|
|
6
6
|
index?: number;
|
|
7
7
|
} & chartUtils.Datum;
|
|
8
|
+
export interface CustomLegendRendererArguments {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
colorScale: string[];
|
|
12
|
+
data: {
|
|
13
|
+
name: string;
|
|
14
|
+
symbol: {
|
|
15
|
+
type: string;
|
|
16
|
+
fill: string;
|
|
17
|
+
};
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
8
20
|
export type PieChartProps = {
|
|
9
21
|
width?: number;
|
|
10
22
|
height?: number;
|
|
@@ -12,12 +24,14 @@ export type PieChartProps = {
|
|
|
12
24
|
fixed?: number;
|
|
13
25
|
hoverTitle?: string;
|
|
14
26
|
hoverText?: string;
|
|
27
|
+
constrainTooltipSide?: ('left' | 'right' | 'top' | 'bottom')[];
|
|
28
|
+
customLegendRenderer?: (args: CustomLegendRendererArguments) => ReactElement;
|
|
15
29
|
numFormat?: (x: string | number) => string;
|
|
16
30
|
replaceToken?: string;
|
|
17
31
|
isRatioChart?: boolean;
|
|
18
32
|
chartColor?: ChartColors;
|
|
19
33
|
};
|
|
20
|
-
export declare function PieChart({ width, height, data, fixed, hoverText, hoverTitle, replaceToken, isRatioChart, chartColor, numFormat }: PieChartProps): ReactElement;
|
|
34
|
+
export declare function PieChart({ width, height, data, fixed, hoverText, hoverTitle, replaceToken, isRatioChart, chartColor, constrainTooltipSide, customLegendRenderer, numFormat }: PieChartProps): ReactElement;
|
|
21
35
|
export declare namespace PieChart {
|
|
22
36
|
var displayName: string;
|
|
23
37
|
}
|
|
@@ -70,6 +70,8 @@ function PieChart(_ref) {
|
|
|
70
70
|
_ref$isRatioChart = _ref.isRatioChart,
|
|
71
71
|
isRatioChart = _ref$isRatioChart === void 0 ? false : _ref$isRatioChart,
|
|
72
72
|
chartColor = _ref.chartColor,
|
|
73
|
+
constrainTooltipSide = _ref.constrainTooltipSide,
|
|
74
|
+
customLegendRenderer = _ref.customLegendRenderer,
|
|
73
75
|
_ref$numFormat = _ref.numFormat,
|
|
74
76
|
numFormat = _ref$numFormat === void 0 ? function (x) {
|
|
75
77
|
return new Intl.NumberFormat(undefined, {
|
|
@@ -194,13 +196,14 @@ function PieChart(_ref) {
|
|
|
194
196
|
// Need to cast to Record to prevent TS from complaining about incompatible types
|
|
195
197
|
|
|
196
198
|
var labelsStyle = (_theme$legend = theme.legend) === null || _theme$legend === void 0 ? void 0 : (_theme$legend$style = _theme$legend.style) === null || _theme$legend$style === void 0 ? void 0 : _theme$legend$style.labels;
|
|
197
|
-
return (0, _jsxRuntime.
|
|
199
|
+
return (0, _jsxRuntime.jsxs)(_Box["default"], {
|
|
198
200
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box"),
|
|
199
201
|
direction: "row",
|
|
202
|
+
align: "center",
|
|
200
203
|
padding: providerTheme.space[2],
|
|
201
|
-
children: (0, _jsxRuntime.jsxs)(_victory.VictoryContainer, {
|
|
204
|
+
children: [(0, _jsxRuntime.jsxs)(_victory.VictoryContainer, {
|
|
202
205
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box", "victory-container"),
|
|
203
|
-
width: containerWidth,
|
|
206
|
+
width: customLegendRenderer ? width : containerWidth,
|
|
204
207
|
height: height,
|
|
205
208
|
children: [(0, _jsxRuntime.jsx)(_victory.VictoryPie, {
|
|
206
209
|
"data-gs-c": gsC("pie"),
|
|
@@ -241,7 +244,7 @@ function PieChart(_ref) {
|
|
|
241
244
|
labels: function labels(_ref5) {
|
|
242
245
|
var datum = _ref5.datum;
|
|
243
246
|
return isRatioChart ? datum.index === 0 // only show the value label and hide total label
|
|
244
|
-
? [datum.y === 0 ? '-' : numFormat(Math.floor(datum.y)), datum.percent] : null : [datum.grey ? datum.x : hoverTitle ? hoverTitle.replace(replaceToken, datum.x) : datum.x, datum.percent
|
|
247
|
+
? [datum.y === 0 ? '-' : numFormat(Math.floor(datum.y)), datum.percent] : null : !hoverText ? [datum.grey ? datum.x : hoverTitle ? hoverTitle.replace(replaceToken, datum.x) : datum.x, datum.percent] : [datum.grey ? datum.x : hoverTitle ? hoverTitle.replace(replaceToken, datum.x) : datum.x, datum.percent, hoverText.replace(replaceToken, numFormat(Math.floor(parseFloat(datum.y))))];
|
|
245
248
|
},
|
|
246
249
|
labelComponent: isRatioChart ? (0, _jsxRuntime.jsx)(_victory.VictoryLabel, {
|
|
247
250
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box", "victory-container", "victory-pie", "victory-label"),
|
|
@@ -262,6 +265,25 @@ function PieChart(_ref) {
|
|
|
262
265
|
}]
|
|
263
266
|
}) : (0, _jsxRuntime.jsx)(_victory.VictoryTooltip, {
|
|
264
267
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box", "victory-container", "victory-pie", "victory-tooltip"),
|
|
268
|
+
orientation: constrainTooltipSide ? function () {
|
|
269
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
270
|
+
args[_key] = arguments[_key];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
var averageAngle = (Number(args[0].datum.startAngle) + Number(args[0].datum.endAngle)) / 2;
|
|
274
|
+
|
|
275
|
+
if (averageAngle < 45) {
|
|
276
|
+
return constrainTooltipSide !== null && constrainTooltipSide !== void 0 && constrainTooltipSide.includes('top') ? 'bottom' : 'top';
|
|
277
|
+
} else if (averageAngle < 135) {
|
|
278
|
+
return constrainTooltipSide !== null && constrainTooltipSide !== void 0 && constrainTooltipSide.includes('right') ? 'left' : 'right';
|
|
279
|
+
} else if (averageAngle < 225) {
|
|
280
|
+
return constrainTooltipSide !== null && constrainTooltipSide !== void 0 && constrainTooltipSide.includes('bottom') ? 'top' : 'bottom';
|
|
281
|
+
} else if (averageAngle < 315) {
|
|
282
|
+
return constrainTooltipSide !== null && constrainTooltipSide !== void 0 && constrainTooltipSide.includes('left') ? 'right' : 'left';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return constrainTooltipSide !== null && constrainTooltipSide !== void 0 && constrainTooltipSide.includes('top') ? 'bottom' : 'top';
|
|
286
|
+
} : undefined,
|
|
265
287
|
cornerRadius: 4,
|
|
266
288
|
pointerLength: 10,
|
|
267
289
|
flyoutStyle: {
|
|
@@ -294,7 +316,7 @@ function PieChart(_ref) {
|
|
|
294
316
|
})
|
|
295
317
|
}),
|
|
296
318
|
events: pieChartEvents
|
|
297
|
-
}), isRatioChart
|
|
319
|
+
}), !isRatioChart && !customLegendRenderer ? (0, _jsxRuntime.jsx)(_victory.VictoryLegend, {
|
|
298
320
|
"data-gs-c": gsC("legend"),
|
|
299
321
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box", "victory-container", "victory-legend"),
|
|
300
322
|
name: "legend",
|
|
@@ -313,8 +335,13 @@ function PieChart(_ref) {
|
|
|
313
335
|
labelComponent: (0, _jsxRuntime.jsx)(PieLegendLabel, {
|
|
314
336
|
"data-gs": gs("src", "piechart", "piechart.tsx", "pie-chart", "box", "victory-container", "victory-legend", "pie-legend-label")
|
|
315
337
|
})
|
|
316
|
-
})]
|
|
317
|
-
})
|
|
338
|
+
}) : (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {})]
|
|
339
|
+
}), customLegendRenderer && customLegendRenderer({
|
|
340
|
+
width: width,
|
|
341
|
+
height: legendHeight,
|
|
342
|
+
colorScale: _ChartPrimitives.chartUtils.DEFAULT_COLORS,
|
|
343
|
+
data: legend
|
|
344
|
+
})]
|
|
318
345
|
});
|
|
319
346
|
}
|
|
320
347
|
|