FIX: Hide pie legend when results are grouped (#8445)
This commit is contained in:
parent
87a298a59b
commit
118fef2353
|
@ -490,7 +490,10 @@ createWidget("discourse-poll-grouped-pies", {
|
||||||
) {
|
) {
|
||||||
const data = result.grouped_results[chartIdx].options.mapBy("votes");
|
const data = result.grouped_results[chartIdx].options.mapBy("votes");
|
||||||
const labels = result.grouped_results[chartIdx].options.mapBy("html");
|
const labels = result.grouped_results[chartIdx].options.mapBy("html");
|
||||||
const chartConfig = pieChartConfig(data, labels, 1.2);
|
const chartConfig = pieChartConfig(data, labels, {
|
||||||
|
aspectRatio: 1.2,
|
||||||
|
displayLegend: false
|
||||||
|
});
|
||||||
const canvasId = `pie-${attrs.id}-${chartIdx}`;
|
const canvasId = `pie-${attrs.id}-${chartIdx}`;
|
||||||
let el = document.querySelector(`#${canvasId}`);
|
let el = document.querySelector(`#${canvasId}`);
|
||||||
if (!el) {
|
if (!el) {
|
||||||
|
@ -594,7 +597,9 @@ createWidget("discourse-poll-pie-chart", {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function pieChartConfig(data, labels, aspectRatio = 2.0) {
|
function pieChartConfig(data, labels, opts = {}) {
|
||||||
|
const aspectRatio = "aspectRatio" in opts ? opts.aspectRatio : 2.0;
|
||||||
|
const displayLegend = "displayLegend" in opts ? opts.displayLegend : true;
|
||||||
return {
|
return {
|
||||||
type: PIE_CHART_TYPE,
|
type: PIE_CHART_TYPE,
|
||||||
data: {
|
data: {
|
||||||
|
@ -609,7 +614,8 @@ function pieChartConfig(data, labels, aspectRatio = 2.0) {
|
||||||
options: {
|
options: {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
animation: { duration: 400 }
|
animation: { duration: 400 },
|
||||||
|
legend: { display: displayLegend }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue