in src/WordCloud.ts [1562:1607]
private scaleMainView(wordCloudDataView: WordCloudDataView): void {
const rectangles: ClientRect[] = wordCloudDataView.data.map((dataPoint: WordCloudDataPoint) => {
const hw: number = dataPoint.width / 2,
hh: number = dataPoint.height / 2;
return <ClientRect>{
left: dataPoint.x - hw,
top: dataPoint.y - hh,
right: dataPoint.x + hw,
bottom: dataPoint.y + hh
};
});
if (lodash.isEmpty(rectangles)) {
return;
}
const rectangle: ClientRect = <ClientRect>{
left: lodash.minBy(rectangles, (rect: ClientRect) => rect.left).left,
top: lodash.minBy(rectangles, (rect: ClientRect) => rect.top).top,
right: lodash.maxBy(rectangles, (rect: ClientRect) => rect.right).right,
bottom: lodash.maxBy(rectangles, (rect: ClientRect) => rect.bottom).bottom
};
const rectWidth: number = rectangle.right - rectangle.left,
rectHeight: number = rectangle.bottom - rectangle.top;
const scaleByX: number = this.layout.viewportIn.width / rectWidth,
scaleByY: number = this.layout.viewportIn.height / rectHeight,
scale: number = Math.min(scaleByX, scaleByY);
const x: number = -rectangle.left * scale + WordCloud.ScalePositionOffset,
y: number = -rectangle.top * scale + WordCloud.ScalePositionOffset;
/**
* Note: This construction fixes bug #6343.
* Edge renders words out of the canvas, so we use this hack to fix it.
* The line-height doesn't work with svg, but it call the render cycle of the browser.
*/
this.main
.style("line-height", WordCloud.TheFirstLineHeight); // Note: This construction fixes bug #6343.
this.main
.attr("transform", translateAndScale(x, y, scale))
.style("line-height", WordCloud.TheSecondLineHeight); // Note: This construction fixes bug #6343.
}