我在 Angular 中使用 cytoscapejs,我希望用户在完成一些操作(例如平移、缩放、移动节点和边缘)后保存图形的状态。
我尝试将整个对象保存在临时变量中,并尝试通过单击按钮使用保存的对象重新加载图形来渲染图形。
const cy_contianer = this.renderer.selectRootElement('#cy');
const localselect = this.select;
this.cy = cytoscape({
container : cy_contianer,
layout: this.layout,
minZoom: this.zoom.min,
maxZoom: this.zoom.max,
style: this.style,
elements: this.elements,
});
上面的代码是我如何初始化呈现图形的“cy”对象。
我尝试保存
this.cy.json()
还尝试使用 this.cy.json().elements 取出元素,期望 x 和 y 位置也将在从元素重新渲染时保存和渲染,但这也不起作用。
可用于将 Cytoscape 与 Angular 一起使用的参考文献非常少。欢迎任何建议。
多谢!
我没有保存整个 cy 对象(这不起作用),而是从 cy 对象中提取了节点和边(其中还包含我需要的每个节点的 x、y 坐标)。
let elements = {
nodes: this.savedCyInstance.elements().nodes().jsons()
edges: this.savedCyInstance.elements().edges().jsons()
}
并调用初始化代码,并将更新的元素和布局名称设置为“预设”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)