Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inversion with ordinal scale

Tags:

Is there any way to find inversion of ordinal scale?

I am using string value on x axis which is using ordinal scale and i on mouse move i want to find inversion with x axis to find which string is there at mouse position?

Is there any way to find this?

var barLabels = dataset.map(function(datum) {     return datum.image; }); console.log(barLabels); var imageScale = d3.scale.ordinal()         .domain(barLabels)         .rangeRoundBands([0, w], 0.1); // divides bands equally among total width, with 10% spacing. console.log("imageScale...................."); console.log(imageScale.domain());   .  . var xPos = d3.mouse(this)[0]; xScale.invert(xPos); 
like image 556
Priya Avatar asked Dec 24 '13 09:12

Priya


People also ask

What is ordinal scale with example?

“Ordinal” indicates “order”. Ordinal data is quantitative data which have naturally occurring orders and the difference between is unknown. It can be named, grouped and also ranked. For example: “How satisfied are you with our products?”

What are the characteristics of ordinal scale?

2.1 Characteristics of ordinal scale:It has unequal units. It displays from highest to lowest by different measurement points. It has no zero point i.e. it is arbitrary or absolute. Interval size is unequal and unknown.


1 Answers

I actually think it doesn't make sense that there isn't an invert method for ordinal scales, but you can figure it out using the ordinal.range() method, which will give you back the start values for each bar, and the ordinal.rangeBand() method for their width.

Example here: http://fiddle.jshell.net/dMpbh/2/

The relevant code is

    .on("click", function(d,i) {         var xPos = d3.mouse(this)[0];         console.log("Clicked at " + xPos);         //console.log(imageScale.invert(xPos));         var leftEdges = imageScale.range();         var width = imageScale.rangeBand();         var j;         for(j=0; xPos > (leftEdges[j] + width); j++) {}             //do nothing, just increment j until case fails         console.log("Clicked on " + imageScale.domain()[j]);     }); 
like image 55
AmeliaBR Avatar answered Oct 21 '22 12:10

AmeliaBR