Example of how to update the board programmatically in TnT Board
Last active
January 12, 2016 16:25
-
-
Save emepyc/40a14340cd802b5d6e48 to your computer and use it in GitHub Desktop.
Programmatically update the board
This file contains 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
<!DOCTYPE html> | |
<head> | |
<link rel="stylesheet" href="http://tntvis.github.io/tnt.board/build/tnt.board.css" type="text/css" /> | |
<style> | |
#mydiv { | |
margin-top: 200px; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://tntvis.github.io/tnt.board/build/tnt.board.min.js"></script> | |
<script src="track_update.js"></script> | |
</head> | |
<body> | |
<div id="mydiv"></div> | |
<script> | |
track_update(document.getElementById("mydiv")); | |
</script> | |
</body> |
This file contains 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 track_update = function (div) { | |
var board = tnt.board().from(20).to(500).width(950); | |
// Axis track | |
var axis_track = tnt.board.track() | |
.height(0) | |
.color("white") | |
.display(tnt.board.track.feature.axis() | |
.orientation("top") | |
); | |
// Data track | |
var pin_track = tnt.board.track() | |
.height(60) | |
.color("white") | |
.display(tnt.board.track.feature.pin() | |
.index(function (d) { | |
return d.pos; | |
}) | |
.domain([0.3, 1.2]) | |
.color("red") | |
) | |
.data(tnt.board.track.data.sync() | |
.retriever (function () { | |
return [ | |
{ | |
pos : 200, | |
val : 0.5, | |
label : "1" | |
}, | |
{ | |
pos : 355, | |
val : 0.8, | |
label : "2" | |
}, | |
{ | |
pos : 100, | |
val : 0.3, | |
label : "3" | |
}, | |
{ | |
pos : 400, | |
val : 1, | |
label : "4" | |
} | |
]; | |
}) | |
); | |
board | |
.add_track([axis_track, pin_track]); | |
board(div); | |
// Add 1 more track | |
var update = d3.select(div) | |
.append("button") | |
.text("update track") | |
.style("margin", "10px") | |
.on("click", function () { | |
var data = pin_track.data(); | |
var display = pin_track.display(); | |
var elems = data.elements(); | |
elems.shift(); | |
data.elements(elems); | |
display.update.call(pin_track); | |
}); | |
board.start(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment