Scales Using Time- d3.min or Sorting - data[0]

621 views
Skip to first unread message

Jammer Jamski

unread,
Dec 5, 2012, 8:21:15 AM12/5/12
to d3...@googlegroups.com
Hi All,

I'm just trying to figure out how best to manipulate some data prior to visualising.

I'm stuck on getting this to work and from doing some Googling it appears that a lot of people don't even attempt it this way and it started me wondering.  Currently I'm trying to get this to work:

    var x = d3.time.scale()
        .domain(
            d3.min(plotCollection, function (plot) { return d3.min(plot.date, function (dateVar) { dateVar.date; }); }),
            d3.max(plotCollection, function (plot) { return d3.max(plot.date, function (dateVar) { dateVar.date; }); })
        )
        .range([0, width]);

But it seems a lot of people just sort the array and then pick the first and last items in order to build the Domain scale.

Which is "right"?

I know that is a subjective and (s'cus the pun) domain related issue but if you have a large data set which would be the method of choice?

I guess my lack of knowledge on Javascript doesn't help here.  If you sort an array is a new array generated and then populated or does it operate only on the indexing of the original array?

Cheers,

Jammer

Jammer Jamski

unread,
Dec 5, 2012, 8:38:50 AM12/5/12
to d3...@googlegroups.com
I've gotten this working using:

    var x = d3.time.scale()
        .domain(d3.extent(data, function(d) { return d.date; }))
        .range([0, width]);

This seem pretty nice syntactically but I would be interested to know if the sorting approach is somehow better?  Or is the sorting method simply wrapped up in d3.extent( ...)?

Cheers,

Jammer
Reply all
Reply to author
Forward
0 new messages