in src/EnhancedScatterChart.ts [1323:1433]
private createDataPoints(
visualHost: IVisualHost,
dataValues: DataViewValueColumns,
metadata: EnhancedScatterChartMeasureMetadata,
categories: DataViewCategoryColumn[],
categoryValues: any[],
categoryFormatter: IValueFormatter,
categoryObjects: DataViewObjects[],
hasDynamicSeries: boolean,
colorHelper: ColorHelper,
settings: Settings
): EnhancedScatterChartDataPoint[] {
const dataPoints: EnhancedScatterChartDataPoint[] = [];
const indicies: EnhancedScatterChartMeasureMetadataIndexes = metadata.idx;
const dataValueSource: DataViewMetadataColumn = dataValues.source;
const grouped: DataViewValueColumnGroup[] = dataValues.grouped();
for (let categoryIdx: number = 0, ilen: number = categoryValues.length; categoryIdx < ilen; categoryIdx++) {
const categoryValue: any = categoryValues[categoryIdx];
for (let seriesIdx: number = 0, len: number = grouped.length; seriesIdx < len; seriesIdx++) {
const grouping: DataViewValueColumnGroup = grouped[seriesIdx];
const seriesValues: DataViewValueColumn[] = grouping.values;
let measures: { [propertyName: string]: DataViewValueColumn } = this.calculateMeasures(seriesValues, indicies, categories);
// TO BE CHANGED: need to update (refactor) these lines below.
const xVal: PrimitiveValue = EnhancedScatterChart.getDefinedNumberByCategoryId(measures.measureX, categoryIdx, metadata.cols.x.type);
const yVal: PrimitiveValue = EnhancedScatterChart.getDefinedNumberByCategoryId(measures.measureY, categoryIdx, metadata.cols.y.type);
const hasNullValue: boolean = (xVal == null) || (yVal == null);
if (hasNullValue) {
continue;
}
const { size, colorFill, shapeSymbolType, image, rotation, backdrop, xStart, xEnd, yStart, yEnd } =
this.getValuesFromDataViewValueColumnById(measures, categoryIdx);
const parsedColorFill: string = colorFill
? colorHelper.getHighContrastColor("foreground", d3.rgb(colorFill).toString())
: undefined;
let color: string;
if (hasDynamicSeries) {
color = colorHelper.getColorForSeriesValue(grouping.objects, grouping.name, "foreground");
} else {
// If we have no Size measure then use a blank query name
const measureSource: string = measures.measureSize != null
? measures.measureSize.source.queryName
: EnhancedScatterChart.EmptyString;
color = colorHelper.getColorForMeasure(categoryObjects && categoryObjects[categoryIdx], measureSource, "foreground");
}
let category: DataViewCategoryColumn = categories && categories.length > EnhancedScatterChart.MinAmountOfCategories
? categories[indicies.category]
: null;
const identity: ISelectionId = visualHost.createSelectionIdBuilder()
.withCategory(category, categoryIdx)
.withSeries(dataValues, grouping)
.createSelectionId();
// TO BE CHANGED: need to refactor these lines below.
const seriesData: tooltipBuilder.TooltipSeriesDataItem[] = [];
if (dataValueSource) {
// Dynamic series
seriesData.push({
value: grouping.name,
metadata: {
source: dataValueSource,
values: []
}
});
}
this.changeSeriesData(measures, seriesData, xVal, yVal, categoryIdx);
const tooltipInfo: VisualTooltipDataItem[] = tooltipBuilder.createTooltipInfo(
categoryValue,
category ? [category] : undefined,
seriesData
);
const currentFill: string = parsedColorFill || color;
const stroke: string = settings.outline.show ? d3.rgb(currentFill).darker().toString() : currentFill;
const fill: string = settings.fillPoint.show || settings.fillPoint.isHidden ? currentFill : null;
dataPoints.push({
size,
rotation,
backdrop,
xStart,
xEnd,
fill,
stroke,
yStart,
yEnd,
identity,
shapeSymbolType,
tooltipInfo,
x: xVal,
y: yVal,
radius: { sizeMeasure: measures.measureSize, index: categoryIdx },
strokeWidth: settings.dataPoint.strokeWidth,
formattedCategory: EnhancedScatterChart.CREATE_LAZY_FORMATTED_CATEGORY(categoryFormatter, categoryValue),
selected: EnhancedScatterChart.DefaultSelectionStateOfTheDataPoint,
contentPosition: EnhancedScatterChart.DefaultContentPosition,
svgurl: image,
});
}
}
return dataPoints;
}