(cy: Core)
| 51 | const HEIGHT_PAD = 46; |
| 52 | |
| 53 | export function toJSONCanvas(cy: Core): JSONCanvas { |
| 54 | const jsonCanvas: JSONCanvas = { |
| 55 | nodes: [], |
| 56 | edges: [], |
| 57 | }; |
| 58 | |
| 59 | cy.nodes().forEach((node) => { |
| 60 | const position = node.position(); |
| 61 | const data = node.data(); |
| 62 | |
| 63 | // Assuming 'group' nodes are represented in cytoscape with a 'parent' field |
| 64 | const type = node.isParent() ? "group" : "text"; |
| 65 | |
| 66 | const genericNode: TextNode = { |
| 67 | id: node.id(), |
| 68 | type, |
| 69 | x: position.x, |
| 70 | y: position.y, |
| 71 | width: Math.round(node.width() + HEIGHT_PAD), |
| 72 | height: Math.round(node.height() + HEIGHT_PAD), |
| 73 | text: data.label, |
| 74 | }; |
| 75 | |
| 76 | // get the node rendered background color |
| 77 | const renderedStyle = node.renderedStyle(); |
| 78 | const backgroundColor = renderedStyle.backgroundColor; |
| 79 | if (backgroundColor !== "transparent") { |
| 80 | const hex = rgbToHex(backgroundColor); |
| 81 | if (hex !== "#ffffff") { |
| 82 | genericNode.color = hex; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | jsonCanvas.nodes?.push({ |
| 87 | ...genericNode, |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | cy.edges().forEach((edge) => { |
| 92 | const data = edge.data(); |
| 93 | |
| 94 | const { fromSide, toSide } = getSideFromEndpoints(edge); |
| 95 | |
| 96 | jsonCanvas.edges?.push({ |
| 97 | id: edge.id(), |
| 98 | fromNode: data.source, |
| 99 | toNode: data.target, |
| 100 | // color: data.color ? { color: data.color } : undefined, |
| 101 | label: data.label, |
| 102 | fromSide, |
| 103 | toSide, |
| 104 | fromEnd: data.fromEnd, |
| 105 | toEnd: data.toEnd, |
| 106 | }); |
| 107 | }); |
| 108 | |
| 109 | return jsonCanvas; |
| 110 | } |
no test coverage detected