Skip to content

Commit bde4e9d

Browse files
authored
Enable html in pie charts legend (#2899)
1 parent 0a9942e commit bde4e9d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/server/modes/charts/plugins/datalens/preparers/pie/gravity-charts.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ExtendedPieSeries = Omit<PieSeries, 'data'> & {
3030

3131
export function prepareD3Pie(args: PrepareFunctionArgs) {
3232
const {shared, labels, visualizationId, ChartEditor, colorsConfig, idToDataType} = args;
33-
const {graphs, label, measure, totals} = preparePieData(args);
33+
const {graphs, label, measure, totals, color, dimension} = preparePieData(args);
3434
const isLabelsEnabled = Boolean(labels?.length && label && measure?.hideLabelMode !== 'hide');
3535

3636
const shouldUseHtmlForLabels =
@@ -95,7 +95,7 @@ export function prepareD3Pie(args: PrepareFunctionArgs) {
9595
data = [];
9696
}
9797

98-
let legend: ChartData['legend'];
98+
let legend: ChartData['legend'] = {};
9999
if (graphs.length && isColoringByMeasure(args)) {
100100
legend = {
101101
enabled: true,
@@ -106,6 +106,11 @@ export function prepareD3Pie(args: PrepareFunctionArgs) {
106106
stops: colorsConfig.gradientColors.length === 2 ? [0, 1] : [0, 0.5, 1],
107107
},
108108
};
109+
} else {
110+
const shouldUseHtmlForLegend = [dimension, color].some(isHtmlField);
111+
if (shouldUseHtmlForLegend) {
112+
legend.html = true;
113+
}
109114
}
110115

111116
return merge(getBaseChartConfig(shared), {

src/server/modes/charts/plugins/datalens/preparers/pie/prepare-pie-data.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ export function preparePieData(args: PrepareFunctionArgs) {
242242
formattedName = wrapHtml(formattedName);
243243
}
244244

245-
// toDo: return as soon as the html legend in gravity-charts is supported
246-
// const shouldWrapPointName = isHtmlColor || isHtmlDimension;
247-
245+
const shouldWrapPointName = isHtmlColor || isHtmlDimension;
248246
const point: PiePoint = {
249-
// name: shouldWrapPointName ? wrapHtml(pointName) : pointName,
250-
name: pointName,
247+
name: shouldWrapPointName ? wrapHtml(pointName) : pointName,
251248
formattedName,
252249
drillDownFilterValue,
253250
y: Number(measureValue),

0 commit comments

Comments
 (0)