Ordinal scale ticks

772 views
Skip to first unread message

Ivan L

unread,
May 22, 2013, 10:30:28 AM5/22/13
to d3...@googlegroups.com
I need to show only N ticks at ordinal scale.

This example with time scale http://bl.ocks.org/mbostock/1667367 works fine - if you move brush it will automatically scale x-axis domain to brush.extent()

Is it possible to do the same with ordinal values?

.ticks(N) doesn't work for some reason, so for every value that I put in .domain() new tick will be generated. 

How can I limit amount of ticks? Of course I can put only N medium values to domain, but how I will recount them on brush move, brush can only return x/y/extent

Thanks

Mike Bostock

unread,
May 22, 2013, 11:11:40 AM5/22/13
to d3...@googlegroups.com
With ordinal (or categorical) ticks, d3 has no way of knowing which ticks are more important, and therefore doesn’t know which to keep or throw away when you want to display fewer of them.

One way to show a subset of ticks is to use axis.tickValues:


If you want to show the tick marks, but not the labels, you can use axis.tickFormat:


Mike

Ivan L

unread,
May 23, 2013, 3:59:57 AM5/23/13
to d3...@googlegroups.com, mi...@ocks.org
Ok thanks, I think I got it.

But can I do something with brush?
I need to reset domain bymyself after each brush move and define (somehow) what points to show?

Ivan L

unread,
May 23, 2013, 4:02:27 AM5/23/13
to d3...@googlegroups.com, mi...@ocks.org
And also, maybe it will be useful, to include support for .ticks() for ordinal scales?
For example, if you got domain = [1...10] and apply .ticks(5) - ticks will be 1,3,5,7,9
Reply all
Reply to author
Forward
0 new messages