The use case:
I'm using the d3.svg.axis() and would like to show a
domain([-100,100]) on this pseudo-log scale so that -100 has the same
distance to 0 as 100.
2. Log scale ticks?
Would the code in this pull request be compatible with (1) or would I
have to adapt it to account for the negative values?
https://github.com/mbostock/d3/pull/308
Thanks :)
function d3_scale_logn(x) {
return -Math.log(-x) / Math.LN10;
}
But for the axis to make sense, I'd like to show both positive and
negative values on a log scale, i.e. the domain [-5,100]
The desired effect is something like this: http://i.imgur.com/uaVEc.png
Do I have to break the scale in two?
Negative values: domain([-5,-0.1?])
Positive values: domain([0.1?,100])
And how would I handle real 0 values?
Thanks!
function d3_scale_logn(x) {
return -Math.log(-x) / Math.LN10;
}
But how could I achieve something like this - http://i.imgur.com/nnyNZ.png
- using the axes generator?
Do I have to break the scale in two?
[-1,-0.1?], [0.1,1]
Thanks!
On Dec 16, 4:53 pm, Dan <dan...@lapidus.se> wrote:
function d3_scale_logn(x) {
return -Math.log(-x) / Math.LN10;
}
But suppose I'd like to create a log scale with the domain [-5,100].
1) Should I divide this into two domains? [-5,-0.1?] and [0.1?,100]
2) And how can I use two scales with the axes generator?
Thanks!
On Dec 16, 4:53 pm, Dan <dan...@lapidus.se> wrote:
> 1. What would be a clean way of "faking alogscale fornegative
> values"?
>
> The use case:
> I'm using the d3.svg.axis() and would like to show a
> domain([-100,100]) on this pseudo-logscale so that -100 has the same
> distance to 0 as 100.
>
> 2.Logscale ticks?
That's not possible with a log scale, because zero is at infinity.
Your image would look like this:
1%
0.1%
0.01%
0.001%
0.0001%
0.00001%
0.000001%
0.0000001%
… infinity passes
-0.0000001%
-0.000001%
-0.00001%
-0.0001%
-0.001%
-0.01%
-0.1%
-1%
You might be able to approximate this with a polylog domain that is
undefined in the intermediate region, i.e., has a hard break from
[-0.1%,0.1%]. That would look like this:
d3.scale.log()
.domain([-5.0, -0.1, 0.1, 100.0])
.range([-200, 0, 0, 200]);
But, that's kind of abusing the scale; if you do this, you should draw
a discontinuity on the axis for clarity.
If you have negative and positive values, you probably want to use a
sqrt scale (or more generally, a pow scale) instead. It handles this
automatically.
Mike
Good one, but there's a typo:
var naturalScale= d3.scale.linear()
.domain([salesRange[0],salesRange[1]])
.range([0,totalSalesRange]);
This sounds like a bad idea in that it introduces distortion. Maybe a
d3.scale.sqrt would be better, or a visible discontinuity in the axis?
Mike
--here's my solution.-----------var salesRange = ([-20, 100])// make range that log could take.var totalSalesRange = salesRange[1]-salesRange[0];// real number to natural number scalevar naturalScale= d3.scale.linear().domain([salesRange[1],salesRange[1]]).range([0,totalSalesRange]);// log sale. takes natural domain.var rScale = d3.scale.sqrt().range([0, maxRadius]).rScale.domain([0,totalSalesRange]);;// process sequencialydata.forEach(function (item, index) {var naturalSales = naturalScale(item.sales);item.r = rScale(naturalSales);-----------if you want to get negative value?just minus negative range. you'll get it.-----------item.r = rScale(naturalSales) - rScale(-salesRange[0]);-----------
You received this message because you are subscribed to a topic in the Google Groups "d3-js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/d3-js/QCOk9Or7vWI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.