in src/WordCloud.ts [948:990]
private computePositions(onPositionsComputed: (WordCloudDataView) => void): void {
const words: WordCloudDataPoint[] = this.data.dataPoints;
if (lodash.isEmpty(words)) {
this.clear();
return;
}
requestAnimationFrame(() => {
let surface: number[] = lodash.range(
WordCloud.MinViewport.width,
(this.specialViewport.width >> WordCloud.WidthOffset) * this.specialViewport.height,
WordCloud.MinViewport.width);
words.forEach((dataPoint: WordCloudDataPoint) => {
dataPoint.getWidthOfWord = () =>
dataPoint.widthOfWord
||
(dataPoint.widthOfWord = textMeasurementService.measureSvgTextWidth({
fontFamily: this.fontFamily,
fontSize: PixelConverter.toString(dataPoint.size + WordCloud.AdditionalDataPointSize),
text: dataPoint.text
}) + WordCloud.AdditionalTextWidth);
});
let wordsToDraw: WordCloudDataPoint[] = words;
if (this.settings.performance.preestimate) {
let countOfWordsToDraw: number = this.estimatePossibleWordsToDraw(words, this.specialViewport, this.settings.performance.quality);
wordsToDraw = words.slice(0, countOfWordsToDraw);
}
if (this.canvasContext) {
this.computeCycle(
wordsToDraw,
this.canvasContext,
surface,
null,
onPositionsComputed);
}
});
}