Cytoscape.js: 如何将节点 colors/shapes/size 导出到 json?

Cytoscape.js: How to export node colors/shapes/size to json?

我有一个 cytoscape.js 视口,用户可以在其中设置特定节点的颜色(和形状)。我想导出这些网络以及用户选择的颜色。

cy.json() 和 cy.style().json() return 节点的初始状态。

现在我在每次更改颜色时向节点添加一个新属性 "current_color",该属性由 cy.json() 导出。

有更好的方法吗?

你试过 ele.renderedStyle( name ) 了吗?

根据 documentation 这将

Get a particular rendered style property value

我看到这个函数对整个图不起作用。也许您可以导出 json,然后通过替换 ele.renderedStyle('background-color')

中的值来处理生成的字符串

如果您使用映射器并将自定义颜色等放在 ele.data() 中,您应该能够 import/export 非常轻松地完成所有操作。