in src/barChart.ts [133:207]
function visualTransform(options: VisualUpdateOptions, host: IVisualHost): BarChartViewModel {
let dataViews = options.dataViews;
let viewModel: BarChartViewModel = {
dataPoints: [],
dataMax: 0,
settings: <BarChartSettings>{}
};
if (!dataViews
|| !dataViews[0]
|| !dataViews[0].categorical
|| !dataViews[0].categorical.categories
|| !dataViews[0].categorical.categories[0].source
|| !dataViews[0].categorical.values
) {
return viewModel;
}
let categorical = dataViews[0].categorical;
let category = categorical.categories[0];
let dataValue = categorical.values[0];
let barChartDataPoints: BarChartDataPoint[] = [];
let dataMax: number;
let colorPalette: ISandboxExtendedColorPalette = host.colorPalette;
let objects = dataViews[0].metadata.objects;
const strokeColor: string = getColumnStrokeColor(colorPalette);
let barChartSettings: BarChartSettings = {
enableAxis: {
show: getValue<boolean>(objects, 'enableAxis', 'show', defaultSettings.enableAxis.show),
fill: getAxisTextFillColor(objects, colorPalette, defaultSettings.enableAxis.fill),
},
generalView: {
opacity: getValue<number>(objects, 'generalView', 'opacity', defaultSettings.generalView.opacity),
showHelpLink: getValue<boolean>(objects, 'generalView', 'showHelpLink', defaultSettings.generalView.showHelpLink),
helpLinkColor: strokeColor,
},
averageLine: {
show: getValue<boolean>(objects, 'averageLine', 'show', defaultSettings.averageLine.show),
displayName: getValue<string>(objects, 'averageLine', 'displayName', defaultSettings.averageLine.displayName),
fill: getValue<string>(objects, 'averageLine', 'fill', defaultSettings.averageLine.fill),
showDataLabel: getValue<boolean>(objects, 'averageLine', 'showDataLabel', defaultSettings.averageLine.showDataLabel),
},
};
const strokeWidth: number = getColumnStrokeWidth(colorPalette.isHighContrast);
for (let i = 0, len = Math.max(category.values.length, dataValue.values.length); i < len; i++) {
const color: string = getColumnColorByIndex(category, i, colorPalette);
const selectionId: ISelectionId = host.createSelectionIdBuilder()
.withCategory(category, i)
.createSelectionId();
barChartDataPoints.push({
color,
strokeColor,
strokeWidth,
selectionId,
value: dataValue.values[i],
category: `${category.values[i]}`,
});
}
dataMax = <number>dataValue.maxLocal;
return {
dataPoints: barChartDataPoints,
dataMax: dataMax,
settings: barChartSettings,
};
}