Standalone Flow Viewer Plugin

Hi There!

I have the same question as @rko

I thought about this while writing an article comparing Jupyter to Node-RED. Jupyter notebooks can be previewed on GitHub (for example) yet flows.json are simply long json files.

Is anyone working on such a viewer? I would hate to do duplicate work if there is already something available.

Are there any arguments against such a viewer? Even here in the forum it would be great to have previews of flows instead of code snippets ...

IMHO it would raise awareness of Node-RED as a tool if flows would be visualised at places such as GitHub or GitLab (or even Sourceforge ;)).

If you follow the 2 links in that post, you would arrive at this: What library to use only to render the flows in an React App? - #3 by knolleary

In short, no, and it isnt simple (or it would likely have been done already :wink: )

Well the best viewer for Node-RED flows is the editor of course, which is written in nodejs. So the best would be to embed the required parts into another nodejs app. I’ve no idea what GitHub is written in or how a plug-in could be added. In theory VS code may be worth looking at as that is node based, but then you could end up editing flows in vs code and the code inside function nodes using an internal version of vs code (Monaco). :slight_smile:

Oh, sorry didn't see the link to the other question.

And that surprises me since the flow in the editor is just one giant SVG and having a look at the flows.json, there are coordinates and text - so I would see it at something like:

  1. read the json file (or json snippet in web page) in a safe way (i.e. don't do eval(...json))
  2. create SVG element
  3. go through the flow .forEach(node) { ...} adding rectangle elements to SVG
  4. ... dunno but at least there is something :slight_smile:

I would think jQuery would be sufficient as a start, I won't know why React would be needed... nor NodeJS - it should all happen in the browser.

Your theory is not too far from the truth but without the full blown editor to install all of the extra contrib nodes, the representation will not be faithful.

For example, each node individually defines its colour, it's icon, how many outputs it has, if it has an LH input button or RH button & a default text to display when no name is set.

On top of that, logic in the front end part of a node can dynamically adjust the visibility of the LH or RH button, it's output count, it's icon and its label.

ok let us take a typical node definition from flows.json:

 {
        "id": "8bdcf0464a3270ca",
        "type": "change",
        "z": "543929cb2e9c4087",
        "g": "20b77a8b7c7caed7",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "origfilename",
                "pt": "msg",
                "to": "payload.origfilename",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.origfilename",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2242,
        "y": 485,
        "wires": [
            [
                "1924ae935c6999d9"
            ]
        ]
    },

I have the type and the name, so I have the text for the node (ok there might be more done in the label function but at https://flows.nodered.org/ the node names aren't always correct either), I've got a coordinate where the rectangle needs to go - x and y.

I've got the z so that I can group nodes into flows so that I can faithfully render a flow with its nodes.

I have the wires so I can draw the connections between nodes. So I can draw a flow with all its nodes and its connections between nodes.

What I don't have are the colours - true, but is that for a start that important? I understand that the purist would never attempt to do this because it will never be 100% as it is in the editor but that's not what I care about. What I care about is having, instead of a long line of json, an image of the flow, so that at least I can get an approximate idea what the flow does. I can't do that with a json.

A json, for me, is nothing or perhaps at the most, a waste of my time! So anything that gives me a bit of semantic info on what the json is trying to tell me is better than json!

Hence my enthusiasm for doing something here: json is wasting my time: mark json, copy, open node-red instance, go to import flow, paste and view flow. That's the process with a long line of json. If that long line of json were to be rendered in the browser, then I won't have to be doing that.

Of course, probably 80% of the time - to find the issue - one would still have to paste the flow into a running Node-Red instance but there is the 20% when I don't have to copy the json. 20% more time to philosophise about life, the universe and everything.

And of course there will be edge cases but since when has that stopped anyone from itching their scratch?

1 Like

Me neither but that doesn't matter, I know they have plugins that can be triggered by having a "type" definition in a code block, e.g. GitHub - caputomarcos/node-red-contrib-oauth2: The node-red-contrib-oauth2 is a Node-RED node that provides an OAuth2 authentication flow. This node uses the OAuth2 protocol to obtain an access token, which can be used to make authenticated API requests. checkout the readme in raw - there you see at the beginning of the first code block:

```mermaid

That tells the github renderer that the following is mermaid (which is a flow chart definition language) and instead of rendering the code, it uses the mermaid "plugin" to render and interactive image.

So I want to be able to do the same with Node-RED:

```nodered
[{"id":"b38fb08ea79029db","type":"Topic","z":"35a6d46cc7dc855c","name":" Listening is the key","info":"","x":508,"y":997.230712890625,"wires":[["0103af7cc01793d6"]]},{"id":"05d2027f7b3288a6","type":"Topic","z":"35a6d46cc7dc855c","name":"  When? When! Not now?","info":"","x":1618.923007965088,"y":722.7692031860352,"wires":[[]]},{"id":"9d205a31387c52d5","type":"Topic","z":"35a6d46cc7dc855c","name":" ","info":"","x":1672.307970046997,"y":1077.4038088321686,"wires":[[]]},{"id":"733721273f96ecfc","type":"Aphorism","z":"35a6d46cc7dc855c","name":"Open? Mind!","info":"","x":1385.0769805908203,"y":643.0768547058105,"wires":[[]]},{"id":"fc782d4bc1b92649","type":"Humour","z":"35a6d46cc7dc855c","name":" ","info":"","x":110.923095703125,"y":2355,"wires":[["4d8759d3ad694658"]]},{"id":"4d8759d3ad694658","type":"Blog-Post","z":"35a6d46cc7dc855c","name":"","info":"Reality changes by listening","x":1771.0768356323242,"y":2378.923049926758,"wires":[["1fdf83bba68a01ea"]]},{"id":"1fdf83bba68a01ea","type":"Thought","z":"35a6d46cc7dc855c","name":" ","info":"","x":1941.4809341430664,"y":1429.2883892059326,"wires":[[]]},{"id":"1078b731593c1afe","type":"Sketch","z":"35a6d46cc7dc855c","name":"Why? Why Not!","info":"![i](/content/open_mind.svg)","x":134.07693481445312,"y":33.61538887023926,"wires":[["0caf1a00e7c66912"]]},{"id":"08e613cfa9691390","type":"junction","z":"35a6d46cc7dc855c","x":821.6257319450378,"y":267.6397179365158,"wires":[["e26b165db67470c5"]]},{"id":"0caf1a00e7c66912","type":"junction","z":"35a6d46cc7dc855c","x":506.65778493881226,"y":343.40815222263336,"wires":[["8d93dccd4c5a247b"]]},{"id":"bd6ad4cc54e8c8ab","type":"junction","z":"35a6d46cc7dc855c","x":1316.9026651382446,"y":1327.2856966257095,"wires":[["3d028fd16c342ded"]]},{"id":"3d028fd16c342ded","type":"junction","z":"35a6d46cc7dc855c","x":1455.7802624702454,"y":1275.8571481704712,"wires":[["a50e3de13c8f72a5"]]},{"id":"8c20506a669a8c60","type":"junction","z":"35a6d46cc7dc855c","x":350.4945341348648,"y":734.7142906188965,"wires":[["1b42511e37bc84c8"]]},{"id":"8d93dccd4c5a247b","type":"junction","z":"35a6d46cc7dc855c","x":660.351655125618,"y":278.4285640716553,"wires":[["08e613cfa9691390"]]},{"id":"e26b165db67470c5","type":"junction","z":"35a6d46cc7dc855c","x":1018.4945154190063,"y":300.42857027053833,"wires":[["02cbd757c162b9a7"]]},{"id":"d83eeb87103c0e6e","type":"junction","z":"35a6d46cc7dc855c","x":965.1825600266457,"y":898.6939053535461,"wires":[["05d2027f7b3288a6"]]},{"id":"758df78a376f909c","type":"junction","z":"35a6d46cc7dc855c","x":1507.6608066558838,"y":928.1073594093323,"wires":[["05d2027f7b3288a6"]]},{"id":"68fcb1fb42a78d46","type":"junction","z":"35a6d46cc7dc855c","x":768.0813165903091,"y":823.1228846311569,"wires":[["4ed8fcc2aa09376d"]]},{"id":"9dc8ae436fd0fb89","type":"junction","z":"35a6d46cc7dc855c","x":1340.2883828878403,"y":819.098402261734,"wires":[["cbc3af06475a7ac2"]]},{"id":"5b72ced446535f91","type":"junction","z":"35a6d46cc7dc855c","x":1087.9638440012932,"y":1275.122441291809,"wires":[["9d205a31387c52d5"]]},{"id":"98d5c1c004f9dc0d","type":"junction","z":"35a6d46cc7dc855c","x":1544.131576538086,"y":1303.2337229251862,"wires":[["1fdf83bba68a01ea","bf60d283d2c4b1b5"]]},{"id":"ae80738b68063d78","type":"junction","z":"35a6d46cc7dc855c","x":894.3414540290833,"y":1239.7041156291962,"wires":[["b425a7d571cbe27b"]]},{"id":"83b146b30803511a","type":"junction","z":"35a6d46cc7dc855c","x":362.6166771054268,"y":442.8395987153053,"wires":[["8fcba7863ae8d5ce","0caf1a00e7c66912"]]},{"id":"02cbd757c162b9a7","type":"junction","z":"35a6d46cc7dc855c","x":1183.4844089746475,"y":417.01021909713745,"wires":[[]]},{"id":"4f777fd3bb8ff018","type":"junction","z":"35a6d46cc7dc855c","x":379.923095703125,"y":860,"wires":[["2623e6d0262dd2fc"]]},{"id":"d299efb9fc695fcd","type":"junction","z":"35a6d46cc7dc855c","x":654.5965490341187,"y":1305.408127784729,"wires":[["fa6e1d2e21f3cffd"]]},{"id":"a87b3f755bc4d8e9","type":"junction","z":"35a6d46cc7dc855c","x":59.27242451906204,"y":1600.0123792886734,"wires":[["fc782d4bc1b92649","d299efb9fc695fcd"]]},{"id":"fa6e1d2e21f3cffd","type":"junction","z":"35a6d46cc7dc855c","x":843.3254051208496,"y":1479.5023691654205,"wires":[["741660767b6ee204"]]},{"id":"741660767b6ee204","type":"junction","z":"35a6d46cc7dc855c","x":1112.5659841299057,"y":1539.357168018818,"wires":[["9d09b3e2d39ef83c"]]},{"id":"9d09b3e2d39ef83c","type":"junction","z":"35a6d46cc7dc855c","x":1212.6343435049057,"y":1542.1490015983582,"wires":[["235eea23fba90bce"]]},{"id":"235eea23fba90bce","type":"junction","z":"35a6d46cc7dc855c","x":1326.618602514267,"y":1521.6866738796234,"wires":[["ae2d28d722498aa6"]]},{"id":"ae2d28d722498aa6","type":"junction","z":"35a6d46cc7dc855c","x":1445.547385275364,"y":1341.9345393180847,"wires":[[]]},{"id":"bf60d283d2c4b1b5","type":"junction","z":"35a6d46cc7dc855c","x":1615.1482484340668,"y":1258.5992693901062,"wires":[["9d205a31387c52d5"]]},{"id":"0905b0b27511860d","type":"junction","z":"35a6d46cc7dc855c","x":967.9231190085411,"y":578.6428555250168,"wires":[["02cbd757c162b9a7"]]},{"id":"3dfcf7acc2c1b4ec","type":"junction","z":"35a6d46cc7dc855c","x":581.9537307024002,"y":722.265332698822,"wires":[["991c36d57d628b7d","ad6468d7a02de1d4"]]},{"id":"991c36d57d628b7d","type":"junction","z":"35a6d46cc7dc855c","x":589.7853737473488,"y":570.7092187404633,"wires":[["0905b0b27511860d"]]},{"id":"ad6468d7a02de1d4","type":"junction","z":"35a6d46cc7dc855c","x":589.8874029517174,"y":775.0714688301086,"wires":[[]]},{"id":"4219e94ee9e41d19","type":"junction","z":"35a6d46cc7dc855c","x":547.6424686908722,"y":851.0918807983398,"wires":[["ad6468d7a02de1d4","0103af7cc01793d6"]]},{"id":"0103af7cc01793d6","type":"junction","z":"35a6d46cc7dc855c","x":658.6471722722054,"y":1025.5875030755997,"wires":[[]]},{"id":"924f105f33e3750b","type":"junction","z":"35a6d46cc7dc855c","x":1342.9419490695,"y":869.698920249939,"wires":[["9dc8ae436fd0fb89","8b7bec49ec5bac3f"]]},{"id":"8b7bec49ec5bac3f","type":"junction","z":"35a6d46cc7dc855c","x":1337.946629703045,"y":925.3599179387093,"wires":[["cbc3af06475a7ac2"]]},{"id":"cbc3af06475a7ac2","type":"junction","z":"35a6d46cc7dc855c","x":1466.4159330129623,"y":884.3688468337059,"wires":[[]]},{"id":"4d22d9144a199eea","type":"junction","z":"35a6d46cc7dc855c","x":1124.84619140625,"y":897.4615478515625,"wires":[["9474df3f56ab46f4"]]},{"id":"a6b959de9425d17d","type":"junction","z":"35a6d46cc7dc855c","x":1127.4997575879097,"y":948.0620658397675,"wires":[["4d22d9144a199eea","24ed682007457420"]]},{"id":"24ed682007457420","type":"junction","z":"35a6d46cc7dc855c","x":1122.5044382214546,"y":1003.7230635285378,"wires":[["9474df3f56ab46f4"]]},{"id":"9474df3f56ab46f4","type":"junction","z":"35a6d46cc7dc855c","x":1250.973741531372,"y":962.7319924235344,"wires":[[]]},{"id":"7550ab6436a0e8f7","type":"junction","z":"35a6d46cc7dc855c","x":1267.750443637371,"y":1281.221434354782,"wires":[["bd6ad4cc54e8c8ab"]]},{"id":"19405f4365f0b649","type":"junction","z":"35a6d46cc7dc855c","x":1212.8131845593452,"y":1310.208763718605,"wires":[["7550ab6436a0e8f7"]]},{"id":"a50e3de13c8f72a5","type":"junction","z":"35a6d46cc7dc855c","x":1469.202463209629,"y":1195.0361613035202,"wires":[["71abcad7e483a193"]]},{"id":"71abcad7e483a193","type":"junction","z":"35a6d46cc7dc855c","x":1507.9780032634735,"y":1181.1428681015968,"wires":[[]]},{"id":"4ed8fcc2aa09376d","type":"junction","z":"35a6d46cc7dc855c","x":1248.307632446289,"y":665.1538198590279,"wires":[["02cbd757c162b9a7","733721273f96ecfc","acef50eabbf2f57c"]]},{"id":"acef50eabbf2f57c","type":"junction","z":"35a6d46cc7dc855c","x":1329.2967039346695,"y":719.8241367340088,"wires":[["05d2027f7b3288a6"]]},{"id":"54164659fdf0d8aa","type":"junction","z":"35a6d46cc7dc855c","x":978.2927975654602,"y":1130.113286972046,"wires":[["129505a0244519e4","d83eeb87103c0e6e"]]},{"id":"f8eb00ecbbc0583d","type":"junction","z":"35a6d46cc7dc855c","x":797.1651253700256,"y":1059.6346626877785,"wires":[["68fcb1fb42a78d46","54164659fdf0d8aa"]]},{"id":"bb26848df86904fc","type":"junction","z":"35a6d46cc7dc855c","x":1461.6986100673676,"y":1101.1584193706512,"wires":[["c0882b041d5e2c1e"]]},{"id":"b425a7d571cbe27b","type":"junction","z":"35a6d46cc7dc855c","x":1363.2605752944946,"y":1064.886951327324,"wires":[["1c42e0bc3e501a65"]]},{"id":"c0882b041d5e2c1e","type":"junction","z":"35a6d46cc7dc855c","x":1573.857127904892,"y":1075.7582718729973,"wires":[["9d205a31387c52d5"]]},{"id":"1c42e0bc3e501a65","type":"junction","z":"35a6d46cc7dc855c","x":1406.689724445343,"y":1094.1759296655655,"wires":[["bb26848df86904fc"]]},{"id":"129505a0244519e4","type":"junction","z":"35a6d46cc7dc855c","x":1404.5278577804565,"y":984.3455933332443,"wires":[["758df78a376f909c","bb26848df86904fc"]]},{"id":"bfd1d169dbfb4e62","type":"junction","z":"35a6d46cc7dc855c","x":909.3359839916229,"y":1409.8791140317917,"wires":[["ae80738b68063d78","3ffab9e1b4f3a299"]]},{"id":"3ffab9e1b4f3a299","type":"junction","z":"35a6d46cc7dc855c","x":1106.3436379432678,"y":1467.5343770980835,"wires":[["5b72ced446535f91","98d5c1c004f9dc0d"]]},{"id":"361ab858d5aa8a9c","type":"junction","z":"35a6d46cc7dc855c","x":610.8352094888687,"y":1257.8461803793907,"wires":[["d299efb9fc695fcd"]]},{"id":"a56f2e2021bc6702","type":"junction","z":"35a6d46cc7dc855c","x":477.8344781398773,"y":1232.798932313919,"wires":[["4b4bc57f5f7036b8"]]},{"id":"4b4bc57f5f7036b8","type":"junction","z":"35a6d46cc7dc855c","x":522.3187175989151,"y":1255.8131746053696,"wires":[["361ab858d5aa8a9c"]]},{"id":"f86069ac9013fca1","type":"junction","z":"35a6d46cc7dc855c","x":441.87913155555725,"y":1210.3736365437508,"wires":[["a56f2e2021bc6702"]]},{"id":"4ac7e3362cddc2ed","type":"junction","z":"35a6d46cc7dc855c","x":417.3736204504967,"y":1179.9889913797379,"wires":[["f86069ac9013fca1"]]},{"id":"1e3c230aef891435","type":"junction","z":"35a6d46cc7dc855c","x":381.65935492515564,"y":1122.5714629888535,"wires":[["e2124f3c9f7c8801","596bd8f6b9371777"]]},{"id":"e2124f3c9f7c8801","type":"junction","z":"35a6d46cc7dc855c","x":383.8287229537964,"y":1096.1363079547882,"wires":[[]]},{"id":"063713e69c4d8e0a","type":"junction","z":"35a6d46cc7dc855c","x":368.087916970253,"y":1030.9230452775955,"wires":[["b38fb08ea79029db"]]},{"id":"0d7e4b17ca5e6252","type":"junction","z":"35a6d46cc7dc855c","x":364.8461608886719,"y":1067.846215248108,"wires":[["e2124f3c9f7c8801","063713e69c4d8e0a"]]},{"id":"08c6de3c8d7850e1","type":"junction","z":"35a6d46cc7dc855c","x":417.0156993865967,"y":957.333604156971,"wires":[["b38fb08ea79029db"]]},{"id":"2623e6d0262dd2fc","type":"junction","z":"35a6d46cc7dc855c","x":398.923095703125,"y":908,"wires":[["08c6de3c8d7850e1"]]},{"id":"1b42511e37bc84c8","type":"junction","z":"35a6d46cc7dc855c","x":364.923095703125,"y":797,"wires":[["4f777fd3bb8ff018"]]},{"id":"8fcba7863ae8d5ce","type":"junction","z":"35a6d46cc7dc855c","x":348.19779962301254,"y":679.3846489191055,"wires":[["8c20506a669a8c60"]]},{"id":"a6e54e7bfdd16d15","type":"junction","z":"35a6d46cc7dc855c","x":1249.5289307236671,"y":2022.901917040348,"wires":[[]]},{"id":"af61c43b82268f05","type":"junction","z":"35a6d46cc7dc855c","x":1207.6894395947456,"y":1860.154681444168,"wires":[["a6e54e7bfdd16d15"]]},{"id":"87ea2ea8a5c32c3a","type":"junction","z":"35a6d46cc7dc855c","x":914.3728423118591,"y":2045.865023970604,"wires":[["bcd8d9e062637dfe"]]},{"id":"43e1f08d75a54c6d","type":"junction","z":"35a6d46cc7dc855c","x":912.0474154949188,"y":2207.829675912857,"wires":[["bcd8d9e062637dfe"]]},{"id":"f86b692521e88096","type":"junction","z":"35a6d46cc7dc855c","x":867.1342552304268,"y":2045.865023970604,"wires":[["87ea2ea8a5c32c3a","43e1f08d75a54c6d"]]},{"id":"bcd8d9e062637dfe","type":"junction","z":"35a6d46cc7dc855c","x":952.9570778608322,"y":2207.829675912857,"wires":[[]]},{"id":"c063615aa60c5910","type":"junction","z":"35a6d46cc7dc855c","x":1312.8875930905342,"y":2045.865023970604,"wires":[["a1541781f58d8d2b"]]},{"id":"f8d61fad0b53b97e","type":"junction","z":"35a6d46cc7dc855c","x":1295.4768906831741,"y":2163.828187227249,"wires":[["a1541781f58d8d2b"]]},{"id":"f1b87641af4cdf98","type":"junction","z":"35a6d46cc7dc855c","x":1280.1142130494118,"y":2045.865023970604,"wires":[["c063615aa60c5910","f8d61fad0b53b97e"]]},{"id":"a1541781f58d8d2b","type":"junction","z":"35a6d46cc7dc855c","x":1323.6000771522522,"y":2163.828187227249,"wires":[[]]},{"id":"b66d137eb1b637c5","type":"junction","z":"35a6d46cc7dc855c","x":1304.716658949852,"y":2178.9398958683014,"wires":[["18af656d9b2f63f9"]]},{"id":"5f4df2a0fa14af2d","type":"junction","z":"35a6d46cc7dc855c","x":1282.7941724658012,"y":2207.829675912857,"wires":[["18af656d9b2f63f9"]]},{"id":"de0fec96a122c75d","type":"junction","z":"35a6d46cc7dc855c","x":1267.0647376179695,"y":2178.9398958683014,"wires":[["b66d137eb1b637c5","5f4df2a0fa14af2d"]]},{"id":"18af656d9b2f63f9","type":"junction","z":"35a6d46cc7dc855c","x":1318.3849586248398,"y":2207.829675912857,"wires":[[]]},{"id":"1e658e41027c7ff8","type":"junction","z":"35a6d46cc7dc855c","x":1191.625000834465,"y":2045.865023970604,"wires":[["06479cc79e96e20d"]]},{"id":"f7e541b7d2419ca1","type":"junction","z":"35a6d46cc7dc855c","x":1143.484169125557,"y":2207.829675912857,"wires":[["0dd640587e211a89"]]},{"id":"41fb594ef047352d","type":"junction","z":"35a6d46cc7dc855c","x":1102.5338057279587,"y":2045.865023970604,"wires":[["1e658e41027c7ff8","f7e541b7d2419ca1"]]},{"id":"32c350a01856f1d5","type":"junction","z":"35a6d46cc7dc855c","x":1240.7878576517105,"y":2207.829675912857,"wires":[[]]},{"id":"0dd640587e211a89","type":"junction","z":"35a6d46cc7dc855c","x":1190.4015459418297,"y":2207.829675912857,"wires":[["32c350a01856f1d5"]]},{"id":"41762e935fcea755","type":"junction","z":"35a6d46cc7dc855c","x":811.4460501074791,"y":1860.154681444168,"wires":[["ee25c78c729ef367","8925945a2cd2949a"]]},{"id":"8925945a2cd2949a","type":"junction","z":"35a6d46cc7dc855c","x":861.3880884051323,"y":2022.901917040348,"wires":[["51301cc8bba5bda5"]]},{"id":"cdf42b6686745de6","type":"junction","z":"35a6d46cc7dc855c","x":857.3388322591782,"y":1969.3234001398087,"wires":[["51301cc8bba5bda5","89c9b9dfbd3a3249"]]},{"id":"51301cc8bba5bda5","type":"junction","z":"35a6d46cc7dc855c","x":904.2386295199394,"y":2022.901917040348,"wires":[[]]},{"id":"ee25c78c729ef367","type":"junction","z":"35a6d46cc7dc855c","x":895.6244294047356,"y":1860.154681444168,"wires":[["89c9b9dfbd3a3249"]]},{"id":"79574ce2dbebf135","type":"junction","z":"35a6d46cc7dc855c","x":1198.677808046341,"y":2022.901917040348,"wires":[["a6e54e7bfdd16d15"]]},{"id":"275d1a28c59bbfa8","type":"junction","z":"35a6d46cc7dc855c","x":1163.585294663906,"y":1860.154681444168,"wires":[["af61c43b82268f05","17e6b41f3c1c7ed5"]]},{"id":"17e6b41f3c1c7ed5","type":"junction","z":"35a6d46cc7dc855c","x":1208.2485904693604,"y":1953.4311581850052,"wires":[[]]},{"id":"7d1bcabe340d5d39","type":"junction","z":"35a6d46cc7dc855c","x":1110.5307458043098,"y":1860.154681444168,"wires":[["17e6b41f3c1c7ed5"]]},{"id":"4cbca926e891c68c","type":"junction","z":"35a6d46cc7dc855c","x":1072.6746148467064,"y":1860.154681444168,"wires":[["7d1bcabe340d5d39","8f405e24b84d88e0"]]},{"id":"8f405e24b84d88e0","type":"junction","z":"35a6d46cc7dc855c","x":1117.0319039225578,"y":2022.901917040348,"wires":[["3c38cb2966b93ab4"]]},{"id":"3c38cb2966b93ab4","type":"junction","z":"35a6d46cc7dc855c","x":1150.8606193065643,"y":2022.901917040348,"wires":[[]]},{"id":"a5677c7cf83f8f72","type":"junction","z":"35a6d46cc7dc855c","x":1119.7520471811295,"y":1938.7665715813637,"wires":[["3c38cb2966b93ab4","79574ce2dbebf135"]]},{"id":"89c9b9dfbd3a3249","type":"junction","z":"35a6d46cc7dc855c","x":938.548010468483,"y":1969.3234001398087,"wires":[[]]},{"id":"c789eb65691b413a","type":"junction","z":"35a6d46cc7dc855c","x":1119.495871424675,"y":2207.829675912857,"wires":[[]]},{"id":"b95f36907f286913","type":"junction","z":"35a6d46cc7dc855c","x":1077.6563802957535,"y":2045.865023970604,"wires":[["c789eb65691b413a"]]},{"id":"127ee115d3321785","type":"junction","z":"35a6d46cc7dc855c","x":1068.6447487473488,"y":2207.829675912857,"wires":[["c789eb65691b413a"]]},{"id":"86e055590f3821b1","type":"junction","z":"35a6d46cc7dc855c","x":1033.552235364914,"y":2045.865023970604,"wires":[["b95f36907f286913","41fac3d08e5bd427"]]},{"id":"41fac3d08e5bd427","type":"junction","z":"35a6d46cc7dc855c","x":1078.2155311703682,"y":2143.832494735718,"wires":[[]]},{"id":"a5c646e477e74667","type":"junction","z":"35a6d46cc7dc855c","x":980.4976865053177,"y":2045.865023970604,"wires":[["41fac3d08e5bd427"]]},{"id":"451e5a36587f4418","type":"junction","z":"35a6d46cc7dc855c","x":950.0832986831665,"y":2045.865023970604,"wires":[["a5c646e477e74667","12b654ed96bf8ebe"]]},{"id":"12b654ed96bf8ebe","type":"junction","z":"35a6d46cc7dc855c","x":986.9988446235657,"y":2207.829675912857,"wires":[["027a54b3efd47f21"]]},{"id":"027a54b3efd47f21","type":"junction","z":"35a6d46cc7dc855c","x":1020.8275600075722,"y":2207.829675912857,"wires":[[]]},{"id":"a1a7061fd6cd4bb6","type":"junction","z":"35a6d46cc7dc855c","x":989.7189878821373,"y":2129.1679081320763,"wires":[["027a54b3efd47f21","127ee115d3321785"]]},{"id":"c1999c7298914b0e","type":"junction","z":"35a6d46cc7dc855c","x":981.4640417098999,"y":2022.901917040348,"wires":[["d3330899ae71f237"]]},{"id":"d0c2847b73f91c30","type":"junction","z":"35a6d46cc7dc855c","x":945.2535161376,"y":1860.154681444168,"wires":[["c1999c7298914b0e","7c7fd79430948799"]]},{"id":"7c7fd79430948799","type":"junction","z":"35a6d46cc7dc855c","x":1049.6970399618149,"y":1860.154681444168,"wires":[["d6f2c56ae71c5de0"]]},{"id":"d6cb6c93121871e7","type":"junction","z":"35a6d46cc7dc855c","x":1010.3708941936493,"y":1992.4746037721634,"wires":[["16605e8ba44c2788"]]},{"id":"26fd17744f26b707","type":"junction","z":"35a6d46cc7dc855c","x":1013.47326785326,"y":1932.4669842720032,"wires":[["51dc31d9b9f18136"]]},{"id":"06479cc79e96e20d","type":"junction","z":"35a6d46cc7dc855c","x":1246.58377379179,"y":2045.865023970604,"wires":[["32c350a01856f1d5"]]},{"id":"e3fd81b2b5146739","type":"junction","z":"35a6d46cc7dc855c","x":1152.9024176597595,"y":2079.9947588443756,"wires":[["ee40e1abfc84ffe6","f73eee40beb64438"]]},{"id":"ee40e1abfc84ffe6","type":"junction","z":"35a6d46cc7dc855c","x":1184.3114322423935,"y":2079.9947588443756,"wires":[["615285352c331257"]]},{"id":"f73eee40beb64438","type":"junction","z":"35a6d46cc7dc855c","x":1166.9948880672455,"y":2163.828187227249,"wires":[["615285352c331257"]]},{"id":"615285352c331257","type":"junction","z":"35a6d46cc7dc855c","x":1201.6049777269363,"y":2163.828187227249,"wires":[[]]},{"id":"051383c2dab5e062","type":"junction","z":"35a6d46cc7dc855c","x":1325.6829209327698,"y":1860.154681444168,"wires":[["82d5faa583cfb052"]]},{"id":"df04ebc599ae3ff8","type":"junction","z":"35a6d46cc7dc855c","x":1299.794735133648,"y":1983.5433931946754,"wires":[["82d5faa583cfb052"]]},{"id":"989e91c38fd8708d","type":"junction","z":"35a6d46cc7dc855c","x":1289.4474171996117,"y":1895.8404690623283,"wires":[["df04ebc599ae3ff8"]]},{"id":"82d5faa583cfb052","type":"junction","z":"35a6d46cc7dc855c","x":1336.9211553931236,"y":1984.2797393202782,"wires":[[]]},{"id":"f4ad64c38bde9e91","type":"junction","z":"35a6d46cc7dc855c","x":1248.2383317351341,"y":1860.154681444168,"wires":[["989e91c38fd8708d","051383c2dab5e062"]]},{"id":"9c9c996a6a910559","type":"junction","z":"35a6d46cc7dc855c","x":1277.4659218788147,"y":1996.3198836445808,"wires":[["385d349a63c5380c","ae4066b356e777f6"]]},{"id":"385d349a63c5380c","type":"junction","z":"35a6d46cc7dc855c","x":1315.3902452588081,"y":1996.3198836445808,"wires":[["5f82b1f0158e10ff"]]},{"id":"ae4066b356e777f6","type":"junction","z":"35a6d46cc7dc855c","x":1294.184386074543,"y":2022.901917040348,"wires":[["5f82b1f0158e10ff"]]},{"id":"5f82b1f0158e10ff","type":"junction","z":"35a6d46cc7dc855c","x":1330.4870975613594,"y":2022.901917040348,"wires":[[]]},{"id":"78d6d7b44281c5c6","type":"junction","z":"35a6d46cc7dc855c","x":858.5334802269936,"y":1893.1537181138992,"wires":[["952e6682f1d2e9c9","0d9ff823697c4382"]]},{"id":"952e6682f1d2e9c9","type":"junction","z":"35a6d46cc7dc855c","x":884.9079356789589,"y":1893.1537181138992,"wires":[["0b920981dafabb2c"]]},{"id":"0d9ff823697c4382","type":"junction","z":"35a6d46cc7dc855c","x":876.1894698143005,"y":1945.8002157211304,"wires":[["0b920981dafabb2c"]]},{"id":"0b920981dafabb2c","type":"junction","z":"35a6d46cc7dc855c","x":897.2255442738533,"y":1945.8002157211304,"wires":[[]]},{"id":"d3330899ae71f237","type":"junction","z":"35a6d46cc7dc855c","x":1056.12667375803,"y":2022.901917040348,"wires":[[]]},{"id":"6c7df9d8c16dc1b4","type":"junction","z":"35a6d46cc7dc855c","x":655.6636772751808,"y":1860.154681444168,"wires":[["66cb5b80df7e956b","7405bb3e98ff719b"]]},{"id":"66cb5b80df7e956b","type":"junction","z":"35a6d46cc7dc855c","x":776.5140970349312,"y":1860.154681444168,"wires":[["38dbddcd3e3dcc42"]]},{"id":"7405bb3e98ff719b","type":"junction","z":"35a6d46cc7dc855c","x":731.0395306944847,"y":2022.901917040348,"wires":[["38dbddcd3e3dcc42"]]},{"id":"38dbddcd3e3dcc42","type":"junction","z":"35a6d46cc7dc855c","x":831.3542561531067,"y":2022.901917040348,"wires":[[]]},{"id":"8635c0025ef79d06","type":"junction","z":"35a6d46cc7dc855c","x":722.2680973410606,"y":1893.1537181138992,"wires":[["349342a0766a48ed","4b03f001b676ff5d"]]},{"id":"349342a0766a48ed","type":"junction","z":"35a6d46cc7dc855c","x":757.030094563961,"y":1893.1537181138992,"wires":[["73d4281257b39359"]]},{"id":"4b03f001b676ff5d","type":"junction","z":"35a6d46cc7dc855c","x":742.1322847604752,"y":1969.3234001398087,"wires":[["73d4281257b39359"]]},{"id":"73d4281257b39359","type":"junction","z":"35a6d46cc7dc855c","x":780.0827168822289,"y":1969.3234001398087,"wires":[[]]},{"id":"8b1e55fba4e7e1ae","type":"junction","z":"35a6d46cc7dc855c","x":659.0614987015724,"y":2045.865023970604,"wires":[["8893e5e10a9ecaeb","b7ea2f0eca03927b"]]},{"id":"8893e5e10a9ecaeb","type":"junction","z":"35a6d46cc7dc855c","x":715.9414130449295,"y":2045.865023970604,"wires":[["e8dabc7ab731951a"]]},{"id":"b7ea2f0eca03927b","type":"junction","z":"35a6d46cc7dc855c","x":716.9773102998734,"y":2207.829675912857,"wires":[["8401a9a9c40f7a40"]]},{"id":"8401a9a9c40f7a40","type":"junction","z":"35a6d46cc7dc855c","x":769.6326352357864,"y":2207.829675912857,"wires":[[]]},{"id":"ac1aa11995d8c9af","type":"junction","z":"35a6d46cc7dc855c","x":711.4905169010162,"y":2108.6232969760895,"wires":[["8401a9a9c40f7a40","925cbd8ca2485de9"]]},{"id":"1397cedab806bc42","type":"junction","z":"35a6d46cc7dc855c","x":827.1620188355446,"y":2045.865023970604,"wires":[["1c317a6458455d12"]]},{"id":"4b954988fc09eb29","type":"junction","z":"35a6d46cc7dc855c","x":840.5106638669968,"y":2207.829675912857,"wires":[["1c317a6458455d12"]]},{"id":"1c317a6458455d12","type":"junction","z":"35a6d46cc7dc855c","x":881.361786544323,"y":2207.829675912857,"wires":[[]]},{"id":"e8dabc7ab731951a","type":"junction","z":"35a6d46cc7dc855c","x":772.2510530948639,"y":2093.717644572258,"wires":[[]]},{"id":"39b5348c4287036f","type":"junction","z":"35a6d46cc7dc855c","x":771.5437506437302,"y":2045.865023970604,"wires":[["e8dabc7ab731951a","1397cedab806bc42"]]},{"id":"925cbd8ca2485de9","type":"junction","z":"35a6d46cc7dc855c","x":794.8461194038391,"y":2139.546073913574,"wires":[[]]},{"id":"e76297a04b0e2e29","type":"junction","z":"35a6d46cc7dc855c","x":793.9216415882111,"y":2088.5816671848297,"wires":[["4b954988fc09eb29","925cbd8ca2485de9"]]},{"id":"fac2f98126ef188c","type":"junction","z":"35a6d46cc7dc855c","x":499.12716203927994,"y":1776.3313028812408,"wires":[["76d963bce1a3e4d2","9090ee8746944cc4"]]},{"id":"76d963bce1a3e4d2","type":"junction","z":"35a6d46cc7dc855c","x":1409.9476080536842,"y":1787.9795681238174,"wires":[["6deb8c6b93a21670"]]},{"id":"9090ee8746944cc4","type":"junction","z":"35a6d46cc7dc855c","x":621.2149102687836,"y":2284.9097049236298,"wires":[["6deb8c6b93a21670"]]},{"id":"6deb8c6b93a21670","type":"junction","z":"35a6d46cc7dc855c","x":1539.0524089336395,"y":2298.7526757717133,"wires":[[]]},{"id":"596bd8f6b9371777","type":"junction","z":"35a6d46cc7dc855c","x":399.923095703125,"y":1151,"wires":[["4ac7e3362cddc2ed"]]},{"id":"51dc31d9b9f18136","type":"junction","z":"35a6d46cc7dc855c","x":1042.1373653411865,"y":1932.5000058412552,"wires":[["d9296381460c21fe"]]},{"id":"d9296381460c21fe","type":"junction","z":"35a6d46cc7dc855c","x":1046.9945166110992,"y":1969.3234001398087,"wires":[[]]},{"id":"dab1ce92fff76ad4","type":"junction","z":"35a6d46cc7dc855c","x":998.5863619446754,"y":1969.3234001398087,"wires":[["d6cb6c93121871e7","d9296381460c21fe"]]},{"id":"d6f2c56ae71c5de0","type":"junction","z":"35a6d46cc7dc855c","x":1053.6986439228058,"y":1893.1537181138992,"wires":[[]]},{"id":"fe047e0f8b7ec0a4","type":"junction","z":"35a6d46cc7dc855c","x":998.4537150859833,"y":1893.1537181138992,"wires":[["26fd17744f26b707","d6f2c56ae71c5de0"]]},{"id":"16605e8ba44c2788","type":"junction","z":"35a6d46cc7dc855c","x":1043.1373912096024,"y":1992.4746037721634,"wires":[["d3330899ae71f237"]]}]

And then the flow would be displayed!

Also I think that flow is a particular good example of you never know what you get when you copy long lines of json....

I don't (didn't) disagree & if faithful representation is not required, it would be a lot easier. But that still leaves the number of outputs a node has & whether it has buttons. If that is an excepted short coming then yes, doable.

Note: the wires property in the flow will not contain information that informs you of the number of outputs a node has, nor will the flow inform you whether the node has buttons.

You right about the outputs but when it comes to be important, e.g. switch, we can work it out:

{
        "id": "8e410c557e30a855",
        "type": "switch",
        "z": "73c1460c85149b2d",
        "name": "",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "200",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 711,
        "y": 265,
        "wires": [
            [
                "f2e95335fab2e989"
            ],
            []
        ]
    },

hm switch has a 2 rules, two sets of wires ... two outputs at least! And it even says it: outputs: 2 - so I can connect the outputs to the correct nodes.

I suspect one can assume each node has 1 input and 1 output unless otherwise defined!

This is just getting easier by the minute :wink: .oO(fools jump in where angels fear to tread ....)

Ok, so here is a quick mockup. Done with jQuery, purely in the frontend, no editor code included. (Only tested on Firefox + Opera.)

It's basically the flow above but rendered very simply. Of course, this is a very basic example which assumes that all non-junction nodes are 120px in width and 30px in height and coloured orange! Function nodes on the other hand, are assumed to be 15 by 15 and coloured black with red border!

No text, i.e. labels included. Connections are straight lines not bezier curves.

The flow is "live" i.e. I do a Ajax query to retrieve it and then render it, so if I changed the original, it would be rendered differently.

I put a div-element around the svg and can scale it by half - since the coordinates in the flows.json assume a svg of 5000px by 5000px.

For me, that is already something useful (specifically for the test flow :)) and it didn't take much to get something showing (worse part was finding the getNode function - see code).

1 Like

There is now a version with text in the nodes...

Does anyone have a link to the code that determines the d value for the svg path element for the links? It's a mix of 'C' and 'S' and also sorts ... then I could add the curvy link lines!

Start in view.js

found generateLinkPath - seems to be exactly what I need - Cheers :+1:

There is a now a version 3 that does curvy connection paths and rudimentary groups (no labels).

It also possible to select different flows to see how well stuff is supported. At the moment, there is still a lot missing: outputs, inputs, colours (subflows have colours), longer texts aren't wrapped as they are in the editor (when used as labels), ... and a lot more.

Also groups of groups don't work, which makes for an interesting question: how many levels of grouping should be supported? I guess unlimited.

Strange but true, the x,y coordinates in the flows.json are actually midpoint values not top-left corner as I had assumed - version 4 is the corrected version. But that's only true for nodes ... junctions are a little different again :slight_smile:

Codebase is online as Node-RED flow.

What's missing:

  1. output and input "connector rectangles"
  2. the right number of output connectors
  3. resizing of nodes if text particularly long and therefore wrapped
  4. icons for nodes
  5. correct colours for nodes
  6. groups still have no names
  7. ... list is already long enough!

I was thinking about the colours for nodes thingy, the flows.nodered.org (e.g.) site has colours and images, is there an api that could be used to retrieve those details? The catalogue endpoint only has type names but no other details. If I could obtain the details, then I could dynamically generate a CSS file and include it in the page.

It should be possible to get this datum from flow.json.

I may be wrong, but the node label is never wrapped due to length - unless it's a multiline label (with \r\n inside).

it is and it can be done, it's just not been done! :slight_smile:

You're right! I thought that too until I found this node - long text, no newlines and is wrapped. Then I realised I coded that node myself (and forgot) that it inserts newlines if it has a long info text - which then becomes the label ... doh! ok, so that's fairly simply too - wrap by splitting on newlines.

Unless coded by the node developer, node label wraps only with the string \n (with a space before and after it iirc). To be clear, it must be the 2 actual ASCII characters of \n not the newline value of 0xA

I'm not 100% certain the wires array property actually indicates the number of outputs a node has. I think it only has elements if connected. (Happy to be corrected)

@gregorius nice progress btw.

I haven't had a chance to look at your code but it appears you are NOT simply "stealing" code from node-red but rather writing this pretty much from scratch?

I can see the fun side of doing that but wondered why? much of the layout and oddities (like a nodes coordinates are the center, how/when the text wraps etc) is there for the taking :man_shrugging:

Looks like it's an array of arrays, empty if not connected:

        "wires": [
            [],
            [],
            [],
            [],
            []
        ]
1 Like