如何在平移和/或缩放后检查我的Cytoscape.js图形是否超出视图(甚至部分)?

问题描述 投票:2回答:1

我想检查我的图表是否在视图之外,可能是在平移和/或缩放之后,以便我可以激活Cytoscape导航器。

例子:

这些是不合时宜的enter image description here

enter image description here

但这不是:enter image description here

谢谢。

javascript viewport cytoscape.js
1个回答
2
投票
function isGraphOutOfView() {
  const width = cy.width();
  const height = cy.height();
  const boundingBox = cy.elements().boundingbox();
  const pan = cy.pan();
  const zoom = cy.zoom();

  return boundingBox.x1 * zoom + pan.x < 0
    || boundingBox.y1 * zoom + pan.y < 0
    || boundingBox.x2 * zoom + pan.x > width
    || boundingBox.y2 * zoom + pan.y > height;
}

编辑:与renderedBoundingBox

function isGraphOutOfView() {
  const width = cy.width();
  const height = cy.height();
  const rbb = cy.elements().renderedBoundingbox();

  return rbb.x1 < 0 || rbb.y1 < 0 || rbb.x2  > width || rbb.y2  > height;
}
© www.soinside.com 2019 - 2024. All rights reserved.