1、写一个分辨率转换方法用来转换
//根据 1920 1080 转换
export function conversionResolution(val, type) {
if (type === 'wide') {
let clientWidth = window.innerWidth;
return rem = (clientWidth / 1920) * val;
} else if (type === 'high') {
let clientHeight = window.innerHeight;
if(isFullscreen()){
alert(1)
return rem = (clientHeight / 1080) * val;
}else{
return rem = (clientHeight / 969) * val;
}
} else {
return val;
}
}
export function isFullscreen() {
return document.fullscreenElement ||
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement || false;
}
2、在代码里面对 宽 高 x y 进行转换
//设置 子级
setChildrenNodes(nodes, position) {
let nodesFromPoint = this.graph.getNodesFromPoint(position.x, position.y);
let parentNode = nodesFromPoint[0];
let parentBBox = parentNode.getBBox();
let size = nodes.length;
let totalHeight = (nodes.length - 1) * (this.conversionResolution(this.childNodeHeight,'high') + this.conversionResolution(this.VerticalMargin,'high')) + this.conversionResolution(this.childNodeHeight,'high'); //子节点总高度
let Y = parentBBox.center.y - totalHeight / 2; // 获取居中 Y
for (let i = 0; i < nodes.length; i++) {
let childNode = nodes[i];
//设置X
let childX = parentBBox.x + parentBBox.width;
childX = childX + this.conversionResolution(this.childNodeWidth,'wide') + this.conversionResolution(this.HorizontalMargin,'wide');
// 子级高度 + 间距 乘 数量 加上居中Y 得出子级Y
let childY = Y + i * (this.conversionResolution(this.childNodeHeight,'high') + this.conversionResolution(this.VerticalMargin,'high'));
let node = this.createNode(childNode.isRoot, childNode, { x: childX, y: childY }, this.conversionResolution(this.childNodeWidth,'wide'),
this.conversionResolution(this.childNodeHeight,'high'));
node.addTo(parentNode);
this.createEdge(parentNode, node);
}
},