This question is about transitions with d3.js, e.g. the change of the x attribute of a rectangle.
If you want the change to occur immediately you may set delay = duration = 0 as in
svg.selectAll("rect")
.transition()
.delay(delay)
.duration(duration)
.attr("x", 0)
but this may be too expensive (assuming that transitions are more CPU consumpting than immediate changes). So how can I add the transition conditionally, behaving like
if (delay == 0 && duration == 0) {
svg.selectAll("rect")
.attr("x", 0)
} else {
svg.selectAll("rect")
.transition()
.delay(delay)
.duration(duration)
.attr("x", 0)
}
but less redundant and more compact, somehow like x = condition ? 0 : 1?