@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
41 lines (40 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMapPosition = void 0;
var map_1 = require("../constants/map/map");
function getMapPosition(mapType, chartHeight, chartWidth) {
var pos = { left: 'center', right: 'center' };
if (!chartHeight || !chartWidth) {
return pos;
}
var defaultPadding = 0;
var mapScale = 0.8;
var worldMapScale = 0.52;
// 地图的高度于宽度的比例;高度 / 宽度 = scale
var scale = mapType === map_1.MapType.China ? mapScale : worldMapScale;
if (chartHeight > chartWidth) {
var mapWidth = chartWidth;
var mapHeight = mapWidth * scale;
var top_1 = (chartHeight - mapHeight) / 2;
var bottom = top_1;
pos = { left: defaultPadding, right: 0, top: top_1, bottom: bottom };
}
else {
var mapHeight = chartHeight;
var mapWidth = mapHeight / scale;
var leftPadding = (chartWidth - mapWidth) / 2;
var bottom = defaultPadding;
var top_2 = defaultPadding;
var left = leftPadding;
var right = leftPadding;
if (leftPadding < 0) {
left = defaultPadding;
right = 0;
top_2 = (chartHeight - (chartWidth - left - right) * scale) / 2;
bottom = top_2;
}
pos = { right: right, left: left, top: top_2, bottom: bottom };
}
return pos;
}
exports.getMapPosition = getMapPosition;