in viz-lib/src/visualizations/chart/plotly/preparePieData.ts [26:95]
function prepareSeries(series: any, options: any, additionalOptions: any) {
const {
cellWidth,
cellHeight,
xPadding,
yPadding,
cellsInRow,
hasX,
index,
hoverInfoPattern,
getValueColor,
} = additionalOptions;
const seriesOptions = extend({ type: options.globalSeriesType, yAxis: 0 }, options.seriesOptions[series.name]);
const xPosition = (index % cellsInRow) * cellWidth;
const yPosition = Math.floor(index / cellsInRow) * cellHeight;
const labels: any = [];
const values: any = [];
const sourceData = new Map();
const seriesTotal = reduce(
series.data,
(result, row) => {
const y = cleanNumber(row.y);
return result + Math.abs(y);
},
0
);
each(series.data, row => {
const x = hasX ? normalizeValue(row.x, options.xAxis.type) : `Slice ${index}`;
const y = cleanNumber(row.y);
labels.push(x);
values.push(y);
sourceData.set(x, {
x,
y,
yPercent: (y / seriesTotal) * 100,
row,
});
});
const markerColors = map(series.data, row => getValueColor(row.x));
const textColors = map(markerColors, c => chooseTextColorForBackground(c));
return {
visible: true,
values,
labels,
type: "pie",
hole: 0.4,
marker: {
colors: markerColors,
},
hoverinfo: hoverInfoPattern,
text: [],
textinfo: options.showDataLabels ? "percent" : "none",
textposition: "inside",
textfont: {
color: textColors,
},
name: seriesOptions.name || series.name,
direction: options.direction.type,
domain: {
x: [xPosition, xPosition + cellWidth - xPadding],
y: [yPosition, yPosition + cellHeight - yPadding],
},
sourceData,
};
}