NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/d3-composite-projections/src/fit.js
2023-09-14 14:47:11 +08:00

32 lines
890 B
Java

import {geoStream} from "d3-geo";
import boundsStream from "./bounds";
export function fitExtent(projection, extent, object) {
var w = extent[1][0] - extent[0][0],
h = extent[1][1] - extent[0][1],
clip = projection.clipExtent && projection.clipExtent();
projection
.scale(150)
.translate([0, 0]);
if (clip != null) projection.clipExtent(null);
geoStream(object, projection.stream(boundsStream));
var b = boundsStream.result(),
k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
if (clip != null) projection.clipExtent(clip);
return projection
.scale(k * 150)
.translate([x, y]);
}
export function fitSize(projection, size, object) {
return fitExtent(projection, [[0, 0], size], object);
}