A Pen by Riccardo Scalco on CodePen.
Last active
August 29, 2015 14:10
-
-
Save riccardoscalco/6a4d2e805a5e0f54218a to your computer and use it in GitHub Desktop.
Time axis changing in real time
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
<div id="box"> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> |
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 svg = d3.select("#box") | |
.append("svg") | |
.attr('width', 900) | |
.attr('height', 100) | |
var endingDate = Date.now(), | |
startingDate = endingDate - 1000 * 60; | |
var dt = 1000; | |
var x = d3.time.scale() | |
.range([0,900]) | |
.domain([startingDate,endingDate]); | |
var axis = svg.append("g") | |
.attr("class", "x axis") | |
.call(d3.svg.axis().scale(x).orient("bottom")); | |
axis.transition = d3.select({}) | |
.transition() | |
.duration(1000) | |
.ease("linear"); | |
(function tick() { | |
axis.transition = axis.transition.each(function() { | |
endingDate = Date.now(); | |
startingDate = endingDate - 1000 * 60; | |
axis.call(d3.svg.axis() | |
.scale(d3.time.scale() | |
.range([0,900]) | |
.domain([startingDate,endingDate])) | |
.orient("bottom")) | |
}).transition().each("start", tick); | |
})() | |
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
.axis path, .axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment