Skip to content

Instantly share code, notes, and snippets.

@Dmitra
Forked from mbostock/.block
Last active August 12, 2016 06:39
Show Gist options
  • Select an option

  • Save Dmitra/e5c4f50be12a71b3fa19 to your computer and use it in GitHub Desktop.

Select an option

Save Dmitra/e5c4f50be12a71b3fa19 to your computer and use it in GitHub Desktop.
encapsulate D3 module functionality in one object

This examples shows bug in ticks positioning if using step method for animation.

Click timeline to animate. On animation end ticks are incorrectly positioned.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.axis path, .axis line {
fill: none;
stroke: #000;
}
</style>
<body>
<script src="http://d3js.org/d3.v2.min.js?2.9.4"></script>
<script>
var width = 960,
height = 100;
var domain0 = [new Date(2000, 0, 1), new Date(2003, 0, 1)],
domain1 = [new Date(2000, 1, 1), new Date(2001, 1, 1)];
var x = d3.time.scale.utc()
.domain(domain0)
.range([0, width]);
var xAxis = d3.svg.axis()
.scale(x);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(0,200)");
var gAxis = svg.append("g")
.attr("class", "x axis")
.call(xAxis);
d3.select(window).on("click", function() {
gAxis.transition().duration(700).tween("step", function(d, i) {
var i = d3.interpolate(domain0, domain1);
return function(t) {
x.domain(i(t));
gAxis.call(xAxis);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment