function createSegments()

in packages/attribute-slicer-powerbi/src/visual-utils/convertItemsWithSegments.ts [235:272]


function createSegments(
	columns: powerbiVisualsApi.DataViewValueColumns,
	segmentData: IColoredObject[],
	rowIdx: number,
) {
	"use strict";
	let total = 0;
	const segments = segmentData.map((si, colIdx) => {
		const highlights = columns[colIdx].highlights || [];
		const highlight = highlights[rowIdx];
		const segmentValue = columns[colIdx].values[rowIdx];
		if (typeof segmentValue === "number") {
			total += segmentValue;
		}

		const { color, name } = si;

		// There is some sort of highlighting going on
		const segment = <IValueSegment>{
			name,
			color,
			value: segmentValue,
			displayValue: segmentValue,
			width: 0,
		};

		if (highlights && highlights.length) {
			let highlightWidth = 0;
			if (segmentValue && typeof segmentValue === "number" && highlight) {
				highlightWidth = (<number>highlight / segmentValue) * 100;
			}
			segment.highlightWidth = highlightWidth;
		}

		return segment;
	});
	return { segments, total };
}