var TRANSDURATION = 5000;
var HEIGHT = 100;
var values = d3.range(10, 100, 10);
var svg = d3.select('svg#vis').attr('height', HEIGHT);
var shuffle = function (v) {
for (var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
$("#btnHor").click(
function () {
one();
values = shuffle(values);
});
$("#btnVer").click(
function () {
two();
}
);
var one = function () {
$("#btnVer").attr("disabled", "disabled");
setTimeout(function () {$("#btnVer").attr("disabled", null)}, 1000);
var linesData = svg.selectAll('line')
.data(values);
var linesEnter = linesData.enter()
.append('line')
.attr('x1', 0)
.attr('x2', 0);
svg.selectAll('line')
.attr('y1', HEIGHT);
var lineTransition = svg.selectAll('line')
.transition()
.attr('y2', function (d) {
return HEIGHT - d;
});
// HORIZONTAL POSITION - SHOULD BE ANIMATED
lineTransition.transition()
.duration(1000)
// 'x1' and 'x2' are the only values that
// need to be animated in this function
.attr('x1', function (d) {
return d;
})
.attr('x2', function (d) {
return d;
});
}
var two = function () {
// this is where the only transition concerning HEIGHT is supposed to take place
svg.selectAll('line')
.transition()
.ease('circle-out')
.duration(2000)
.attr('y2', function (d) {
return d - Math.random() * 30;
});
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.