in src/radarChart.ts [273:420]
public static converter(dataView: DataView,
colorPalette: IColorPalette,
colorHelper: ColorHelper,
visualHost: IVisualHost,
interactivityService?: IInteractivityService): IRadarChartData {
if (!dataView
|| !dataView.categorical
|| !dataView.categorical.categories
|| !(dataView.categorical.categories.length > 0)
|| !dataView.categorical.categories[0]
|| !dataView.categorical.values
|| !(dataView.categorical.values.length > 0)
|| !colorPalette
|| !colorHelper
|| !visualHost) {
return {
legendData: {
dataPoints: []
},
settings: this.parseSettings(dataView, colorHelper),
labels: RadarChart.getLabelsData(dataView),
series: []
};
}
let catDv: DataViewCategorical = dataView.categorical,
values: DataViewValueColumns = catDv.values,
series: RadarChartSeries[] = [],
grouped: DataViewValueColumnGroup[];
const settings: RadarChartSettings = this.parseSettings(dataView, colorHelper);
RadarChart.checkAndUpdateAxis(dataView, values);
grouped = catDv && catDv.values
? catDv.values.grouped()
: null;
const fillProp: DataViewObjectPropertyIdentifier = {
objectName: "dataPoint",
propertyName: "fill"
};
const localColorHelper: ColorHelper = new ColorHelper(colorPalette, fillProp, settings.dataPoint.fill);
let hasHighlights: boolean = !!(values.length > 0 && values[0].highlights);
let legendData: LegendData = {
fontSize: settings.legend.fontSize,
dataPoints: [],
title: settings.legend.titleText,
labelColor: settings.legend.labelColor
};
for (let i: number = 0, iLen: number = values.length; i < iLen; i++) {
let color: string = colorPalette.getColor(i.toString()).value,
serieIdentity: ISelectionId,
queryName: string,
displayName: string,
dataPoints: RadarChartDatapoint[] = [];
let columnGroup: DataViewValueColumnGroup = grouped && grouped.length > i && grouped[i].values
? grouped[i]
: null;
if (values[i].source) {
let source: DataViewMetadataColumn = values[i].source;
if (source.queryName) {
queryName = source.queryName;
serieIdentity = visualHost.createSelectionIdBuilder()
.withMeasure(queryName)
.createSelectionId();
}
if (source.displayName) {
displayName = source.displayName;
}
if (source.objects) {
color = localColorHelper.getColorForMeasure(source.objects, queryName);
}
}
const legendDataPointsColor: string = colorHelper.isHighContrast ? colorHelper.getHighContrastColor("foreground", color) : color;
legendData.dataPoints.push(<LegendDataPoint>{
label: displayName,
color: legendDataPointsColor,
icon: LegendIcon.Box,
selected: false,
identity: serieIdentity
});
for (let k: number = 0, kLen: number = values[i].values.length; k < kLen; k++) {
let dataPointIdentity: ISelectionId = visualHost.createSelectionIdBuilder()
.withMeasure(queryName)
.withCategory(catDv.categories[0], k)
.withSeries(dataView.categorical.values, columnGroup)
.createSelectionId();
let tooltipInfo: VisualTooltipDataItem[] = TooltipBuilder.createTooltipInfo(
<any>catDv,
catDv.categories[0].values[k],
values[i].values[k],
i);
let currCatValue = catDv.categories[0].values[k];
let labelFormatString: string = valueFormatter.getFormatStringByColumn(catDv.values[i].source),
fontSizeInPx: string = PixelConverter.fromPoint(settings.labels.fontSize);
let notConvertedValue: PrimitiveValue = values[i].values[k],
y: number = notConvertedValue === RadarChart.fakeValue ? 0 : (notConvertedValue !== null ? Number(notConvertedValue) : NaN);
if (!isNaN(y)) {
dataPoints.push({
x: k,
y: y,
color: color,
identity: dataPointIdentity,
selected: false,
tooltipInfo: tooltipInfo,
value: y,
labelFormatString: labelFormatString,
labelFontSize: fontSizeInPx,
highlight: hasHighlights && !!(values[0].highlights[k]),
showPoint: currCatValue === " " || notConvertedValue === RadarChart.fakeValue ? false : true
});
}
}
if (dataPoints.length > 0) {
if (interactivityService) {
interactivityService.applySelectionStateToData(dataPoints, hasHighlights);
}
const radarChartSeries: RadarChartSeries = {
fill: color,
name: displayName,
dataPoints: dataPoints,
identity: <any>serieIdentity,
hasHighlights: hasHighlights
};
series.push(radarChartSeries);
}
}
return {
labels: RadarChart.getLabelsData(dataView),
legendData: legendData,
settings: settings,
series: series
};
}