Skip to content

Commit e708ab4

Browse files
multiple pies renderer
1 parent 4b2ad87 commit e708ab4

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/PlotlyRenderers.jsx

+37-7
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ function makeRenderer(
4848
labels.push(datumKey.join('-') || ' ');
4949
}
5050
const trace = {name: traceKey.join('-') || fullAggName};
51-
trace.x = transpose ? values : labels;
52-
trace.y = transpose ? labels : values;
51+
if (traceOptions.type === 'pie') {
52+
trace.values = values;
53+
trace.labels = labels.length > 1 ? labels : [fullAggName];
54+
} else {
55+
trace.x = transpose ? values : labels;
56+
trace.y = transpose ? labels : values;
57+
}
5358
return Object.assign(trace, traceOptions);
5459
});
5560

@@ -74,15 +79,34 @@ function makeRenderer(
7479
width: window.innerWidth / 1.5,
7580
height: window.innerHeight / 1.4 - 50,
7681
/* eslint-enable no-magic-numbers */
77-
xaxis: {
82+
};
83+
84+
if (traceOptions.type === 'pie') {
85+
const columns = Math.ceil(Math.sqrt(data.length));
86+
const rows = Math.ceil(data.length / columns);
87+
layout.grid = {columns, rows};
88+
data.forEach((d, i) => {
89+
d.domain = {
90+
row: Math.floor(i / columns),
91+
column: i - columns * Math.floor(i / columns),
92+
};
93+
if (data.length > 1) {
94+
d.title = d.name;
95+
}
96+
});
97+
if (data[0].labels.length === 1) {
98+
layout.showlegend = false;
99+
}
100+
} else {
101+
layout.xaxis = {
78102
title: transpose ? fullAggName : null,
79103
automargin: true,
80-
},
81-
yaxis: {
104+
};
105+
layout.yaxis = {
82106
title: transpose ? null : fullAggName,
83107
automargin: true,
84-
},
85-
};
108+
};
109+
}
86110

87111
return (
88112
<PlotlyComponent
@@ -201,5 +225,11 @@ export default function createPlotlyRenderers(PlotlyComponent) {
201225
'Dot Chart': makeRenderer(PlotlyComponent, {mode: 'markers'}, {}, true),
202226
'Area Chart': makeRenderer(PlotlyComponent, {stackgroup: 1}),
203227
'Scatter Chart': makeScatterRenderer(PlotlyComponent),
228+
'Multiple Pie Chart': makeRenderer(
229+
PlotlyComponent,
230+
{type: 'pie', scalegroup: 1, hoverinfo: 'label+value', textinfo: 'none'},
231+
{},
232+
true
233+
),
204234
};
205235
}

0 commit comments

Comments
 (0)