in src/WordCloud.ts [407:494]
public static CONVERTER(
dataView: DataView,
colorPalette: IColorPalette,
visualHost: IVisualHost
): WordCloudData {
const categorical: WordCloudColumns<DataViewCategoryColumn> = WordCloudColumns.GET_CATEGORICAL_COLUMNS(dataView);
if (!categorical || !categorical.Category || lodash.isEmpty(categorical.Category.values)) {
return null;
}
const colorHelper: ColorHelper = new ColorHelper(
colorPalette,
WordCloud.DataPointFillProperty,
wordCloudUtils.getRandomColor()
);
const catValues: WordCloudColumns<any[]> = WordCloudColumns.GET_CATEGORICAL_VALUES(dataView);
const settings: WordCloudSettings = WordCloud.PARSE_SETTINGS(dataView, colorHelper);
const wordValueFormatter: IValueFormatter = ValueFormatter.create({
format: ValueFormatter.getFormatStringByColumn(categorical.Category.source)
});
const excludedSet: PrimitiveValue[] = !categorical.Excludes || lodash.isEmpty(categorical.Excludes.values)
? []
: categorical.Excludes.values;
const excludedWords = this.getExcludes(excludedSet, settings);
const queryName: string = (categorical.Values
&& categorical.Values[0]
&& categorical.Values[0].source
&& categorical.Values[0].source.queryName)
|| null;
const texts: WordCloudText[] = [];
for (let index: number = 0; index < catValues.Category.length; index += 1) {
let item: any = catValues.Category[index];
if (!item) continue;
let color: string;
if (categorical.Category.objects && categorical.Category.objects[index]) {
color = colorHelper.getColorForMeasure(categorical.Category.objects[index], "", "foreground");
} else {
color = colorHelper.getHighContrastColor(
"foreground",
settings.dataPoint.defaultColor || colorPalette.getColor(index.toString()).value
);
}
const selectionIdBuilder: ISelectionIdBuilder = visualHost
.createSelectionIdBuilder()
.withCategory(dataView.categorical.categories[0], index);
if (queryName) {
selectionIdBuilder.withMeasure(queryName);
}
item = wordValueFormatter.format(item);
texts.push({
text: item,
count: (catValues.Values
&& catValues.Values[index]
&& !isNaN(catValues.Values[index]))
? catValues.Values[index]
: WordCloud.MinCount,
index: index,
selectionId: <ISelectionId>selectionIdBuilder.createSelectionId(),
color: color,
textGroup: item
});
}
const reducedTexts: WordCloudGroup[] = WordCloud.getReducedText(texts, excludedWords, settings);
const dataPoints: WordCloudDataPoint[] = WordCloud.getDataPoints(reducedTexts, settings);
return {
texts,
settings,
dataView,
dataPoints,
};
}