mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-03-12 18:43:46 +00:00
Limit zooming out when the chart is small
This commit is contained in:
@@ -201,13 +201,22 @@ export class Chart extends React.PureComponent<ChartProps, {}> {
|
|||||||
const parent = d3.select('#svgContainer').node() as Element;
|
const parent = d3.select('#svgContainer').node() as Element;
|
||||||
|
|
||||||
const scale = this.props.enableZoom ? d3.zoomTransform(parent).k : 1;
|
const scale = this.props.enableZoom ? d3.zoomTransform(parent).k : 1;
|
||||||
|
const zoomOutFactor = d3.min([
|
||||||
|
1,
|
||||||
|
scale,
|
||||||
|
parent.clientWidth / chartInfo.size[0],
|
||||||
|
parent.clientHeight / chartInfo.size[1],
|
||||||
|
])!;
|
||||||
|
const extent: [number, number] = this.props.enableZoom
|
||||||
|
? [d3.max([0.1, zoomOutFactor])!, 2]
|
||||||
|
: [1, 1];
|
||||||
|
|
||||||
d3.select(parent)
|
d3.select(parent)
|
||||||
.on('scroll', () => scrolled(this.props.enableZoom))
|
.on('scroll', () => scrolled(this.props.enableZoom))
|
||||||
.call(
|
.call(
|
||||||
d3
|
d3
|
||||||
.zoom()
|
.zoom()
|
||||||
.scaleExtent(this.props.enableZoom ? [0.1, 2] : [1, 1])
|
.scaleExtent(extent)
|
||||||
.translateExtent([[0, 0], chartInfo.size])
|
.translateExtent([[0, 0], chartInfo.size])
|
||||||
.on('zoom', () => zoomed(chartInfo.size, this.props.enableZoom)),
|
.on('zoom', () => zoomed(chartInfo.size, this.props.enableZoom)),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user