Created
March 20, 2017 15:56
-
-
Save psbolden/40e94e9e5be2c2738d87cc604a0b028d to your computer and use it in GitHub Desktop.
d3 update example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<label for="nValue" | |
style="display: inline-block; width: 240px; text-align: right"> | |
angle = <span id="nValue-value"></span> | |
</label> | |
<input type="number" min="0" max="360" step="5" value="0" id="nValue"> | |
</p> | |
<p> | |
<label for="tValue" | |
style="display: inline-block; width: 240px; text-align: right"> | |
text = <span id="tValue-value"></span> | |
</label> | |
<input type="text" value="hello" id="tValue"> | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var width = 600; | |
var height = 300; | |
var holder = d3.select("body") | |
.append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
// draw the element | |
holder.append("text") | |
.style("fill", "black") | |
.style("font-size", "56px") | |
.attr("dy", ".35em") | |
.attr("text-anchor", "middle") | |
.attr("transform", "translate(300,150) rotate(0)") | |
.text("d3noob.org"); | |
function update() { | |
var updatetext = d3.select('#tValue').property('value'); | |
var updaterotation = d3.select('#nValue').property('value'); | |
holder.select("text") | |
.text(updatetext) | |
.attr("transform", "translate(300,150) rotate("+updaterotation+")"); | |
} | |
d3.selectAll('input').on('input', function() { | |
update(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment