Scale.ticks returns a single value for a degenerate domain. #871

wants to merge 1 commit into


None yet
2 participants

bdon commented Oct 27, 2012

This diverges from the behavior of python's range() but seems more correct for display purposes.

> [1]

mbostock commented Jan 23, 2013

I'm curious why you want this behavior. A scale with a degenerate domain isn’t particularly useful, since it maps every value to the start of the range. So displaying any tick values would probably be misleading, or at any rate, also not very useful. :)

mbostock closed this Jan 23, 2013


bdon commented Jan 24, 2013

Yeah, handling a useless scale is precisely what I need because I'm creating scales dynamically based on the min/max values from database queries.

Here's an example for a single chart using a fixed number of ticks and different data. notice when there is one domain value, no labels appear. In my application the charts need to handle arbitrary data so locking them to a fixed scale is not an option.

It seems like the best solution for correctly labeling the domain when n=1 is to pad the min and max values e.g.

var xScale = d3.scale.linear()
    .domain([d3.min(data, xSelector) - 0.01, d3.max(data, xSelector) + 0.01])

mbostock commented Jan 24, 2013

Yeah, I think it'd probably be best to detect a degenerate domain in this case, and then pad it by some fixed value on both sides, and in that case request only 1 tick rather than 5 or whatever you normally use.

Unrelated, but I just visited your website and found your WebGL contours map, and I thought it was really cool. :) I liked the satellite visualization hooked up to crossfilter too!


bdon commented Jan 25, 2013

Glad you like them! Make sure you check out the bike map too: . My site does not have nearly as many epic demos as yours yet, but I'm working on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment