Hello all,
First of all: I would like thank everyone involved in creating and supporting this programing tool!
I have a couple of notes and a question in regards to D3.js and node-red integration using DASHBOARD:
- Most of the time I get the D3.js charts to display whenever I "DEPLOY:FULL" (but not always).
- I almost never get the charts to show whenever "DEPOLY:MODIFIED_NODES" is used... I still don't understand why it does show as it has happened while refreshing the screen, or doing "DEPOLY:MODIFIED_NODES" once more.
- Is there something within the code I am failing to do correctly, so the charts get to come up right away?
- And the d3.js script be local to the computer so it loads faster?
NOTE:
-
An experienced UI friend of mine and I slightly modified and example I found on this forum that me greatly assisted me in getting an application started with d3.js and node-red. I believe it was originally created by @Andrei, and it can be found here: 3D plot in NodeRed
[{"id":"b8ad1d13.b43a","type":"debug","z":"9bffbe5c.ccd4d","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":1040,"y":180,"wires":[]},{"id":"b0fe2a06.f6f0e8","type":"inject","z":"9bffbe5c.ccd4d","name":"","topic":"PUSH_BOTTON_1","payload":"welcome","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":560,"y":40,"wires":[["2210b655.64f9ca"]]},{"id":"2210b655.64f9ca","type":"ui_template","z":"9bffbe5c.ccd4d","group":"36bda78d.d01f18","name":"testing payload","order":1,"width":"10","height":"12","format":"<!DOCTYPE html>\n<html>\n \n <head>\n <title>Scatter Plot</title>\n <script src=\"https://d3js.org/d3.v4.min.js\"></script>\n <style>\n .axis {\n fill: none;\n stroke: black;\n shape-rendering: crispEdges;\n }\n </style>\n \n </head>\n \n <body>\n \n <div id=\"plot\"></div>\n <div id=\"ELEMENT\"></div>\n <h2>{{msg.topic}}</h2>\n <h2>{{msg.payload}}</h2>\n \n <script>\n\n (function(scope) {\n \n // Watch for messages being send to this template node\n scope.$watch('msg', function (msg) {\n \n if (msg) {\n \n //var ELEMENT = document.getElementById('ELEMENT');\n ELEMENT = msg.payload;\n plotDraw();\n\n }\n \n });\n \n var w = 500, h = 500, pad = 50;\n \n var svg = d3.select(\"#plot\")\n .append(\"svg\")\n .attr(\"height\", h)\n .attr(\"width\", w);\n \n var xAxisGroup = svg.append(\"g\")\n .attr(\"class\", \"axis\")\n .attr(\"transform\", \"translate(0,\" + (h - pad) + \")\");\n \n var yAxisGroup = svg.append(\"g\")\n .attr(\"class\", \"axis\")\n .attr(\"transform\", \"translate(\" + pad +\", 0)\");\n \n const plotDraw = function(){\n var dataset = [ ELEMENT , [20, 20, 20],[30, 30, 30], [40, 40, 40], [50, 50, 50], [60, 60, 60]];\n \n var xScale = d3.scaleLinear()\n .domain([0, d3.max(dataset, function(d) { return d[0]; })])\n .range([pad, w - pad]);\n \n var yScale = d3.scaleLinear()\n .domain([0, d3.max(dataset, function(d) { return d[1]; })])\n .range([h - pad, pad]);\n \n var rScale = d3.scaleLinear()\n .domain([0, d3.max(dataset, function(d) { return d[2]; })])\n .range([1, 30]);\n \n var xAxis = d3.axisBottom(xScale);\n var yAxis = d3.axisLeft(yScale);\n \n var circ = svg.selectAll(\"circle\")\n .data(dataset);\n \n var circEnter = circ.enter()\n .append(\"circle\");\n \n circEnter\n .attr(\"fill\", \"red\")\n .attr(\"opacity\", 0.5);\n \n circ.merge(circEnter)\n .attr(\"cx\", function(d) { return xScale(d[0]); })\n .attr(\"cy\", function(d) { return yScale(d[1]); })\n .attr(\"r\", function(d) { return rScale(d[2]); })\n \n xAxisGroup.call(xAxis);\n yAxisGroup.call(yAxis);\n\n };\n \n plotDraw(); \n \n })(scope);\n\n </script>\n </body>\n</html>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":840,"y":180,"wires":[["b8ad1d13.b43a"]]},{"id":"be0e7a5a.035068","type":"inject","z":"9bffbe5c.ccd4d","name":"","topic":"PUSH_BOTTON_2","payload":"not welcome","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":550,"y":180,"wires":[["2210b655.64f9ca"]]},{"id":"87a9ec37.e7324","type":"ui_slider","z":"9bffbe5c.ccd4d","name":"","label":"X","tooltip":"","group":"36bda78d.d01f18","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"X","min":0,"max":"100","step":1,"x":450,"y":280,"wires":[["f2b66220.78ab6"]]},{"id":"93f55155.11c24","type":"ui_slider","z":"9bffbe5c.ccd4d","name":"","label":"Y","tooltip":"","group":"36bda78d.d01f18","order":3,"width":0,"height":0,"passthru":true,"outs":"all","topic":"Y","min":0,"max":"100","step":1,"x":450,"y":340,"wires":[["f2b66220.78ab6"]]},{"id":"7176f2ca.e3144c","type":"ui_slider","z":"9bffbe5c.ccd4d","name":"","label":"R","tooltip":"","group":"36bda78d.d01f18","order":4,"width":0,"height":0,"passthru":true,"outs":"all","topic":"R","min":0,"max":"100","step":1,"x":450,"y":400,"wires":[["f2b66220.78ab6"]]},{"id":"f2b66220.78ab6","type":"function","z":"9bffbe5c.ccd4d","name":"","func":"var X = {};\nvar Y = {};\nvar R = {};\nvar ELEMENT = {};\nvar STATE = \"\";\n\nif (msg.topic == \"X\") {\n\tcontext.X = msg.payload;\n\tSTATE = 'X';\n}\n\nif (msg.topic == \"Y\") {\n\tcontext.Y = msg.payload;\n STATE = 'Y';\n}\n\nif (msg.topic == \"R\") {\n\tcontext.R = msg.payload;\n STATE = 'R';\n}\n\nELEMENT.payload = [context.X || 0, context.Y || 0, context.R || 0];\nELEMENT.topic = 'ELEMENT: '+STATE;\n\nreturn ELEMENT;","outputs":1,"noerr":0,"x":630,"y":340,"wires":[["fb5a87ca.dc5768","2210b655.64f9ca"]]},{"id":"fb5a87ca.dc5768","type":"debug","z":"9bffbe5c.ccd4d","name":"","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":1040,"y":340,"wires":[]},{"id":"5295a89d.50f1c8","type":"inject","z":"9bffbe5c.ccd4d","name":"","topic":"X","payload":"10","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":".1","x":110,"y":340,"wires":[["d35c4de.f8c17b"]]},{"id":"d35c4de.f8c17b","type":"ui_button","z":"9bffbe5c.ccd4d","name":"","group":"36bda78d.d01f18","order":4,"width":0,"height":0,"passthru":true,"label":"*** RESET ***","tooltip":"","color":"","bgcolor":"","icon":"","payload":"10","payloadType":"num","topic":"","x":250,"y":340,"wires":[["87a9ec37.e7324","93f55155.11c24","7176f2ca.e3144c"]]},{"id":"36bda78d.d01f18","type":"ui_group","z":"","name":"D3.js","tab":"4b1c9046.2401e","order":2,"disp":true,"width":"10","collapse":false},{"id":"4b1c9046.2401e","type":"ui_tab","z":"9bffbe5c.ccd4d","name":"D3.js","icon":"dashboard","order":9}]
(I can't yet figure out how to "one-line this code"... apologize me for the eyesore)