D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
adry34160
Full window
Github gist
17 - Multiple HTML inputs linked with d3.js
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <title> Double input Test </title> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <p> <label for="nHeight" style="display: inline-block; width: 240px; text-align:right"> height= <span id="nHeight-value">...</span> <input type="range" min="1" max="280" id="nHeight"> </label> </p> <p> <label for="nWidth" style="display: inline-block; width: 240px; text-align:right"> height= <span id="nWidth-value">...</span> <input type="range" min="1" max="280" id="nWidth"> </label> </p> <script> var width = 600; var height = 300; var holder = d3.select("body") .append("svg") .attr("width", width) .attr("height", height); //draw a rectangle holder.append("rect") .attr("x", 300) .attr("y", 150) .style("fill", "none") .style("stroke", "blue") .attr("width", 150) .attr("height", 200); //Read a change in the height input d3.select("#nHeight").on("input", function () { updateHeight(+this.value); }) //Read a change in the width input d3.select("#nWidth").on("input", function () { updateWidth(+this.value); }) //Update the values updateHeight(150); updateWidth(100); //Update the height attributes function updateHeight(nHeight) { //adjust the text on the range slider d3.select("#nHeight-value").text(nHeight); d3.select("#nHeight").property("value", nHeight); //Update the rectangle height holder.selectAll("rect") .attr("y", 150-(nHeight/2)) .attr("height", nHeight); } function updateWidth(nWidth) { d3.select("#nWidth-value").text(nWidth); d3.select("#nWidth").property("value", nWidth); holder.selectAll("rect") .attr("x", 300-(nWidth/2)) .attr("width", nWidth); } </script>
https://d3js.org/d3.v4.min.js