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);
“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?”
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.
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]); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With