Logarithmic scales #105

Open
dnschnur opened this Issue Sep 28, 2012 · 22 comments

Comments

Projects
None yet
1 participant
@dnschnur
Member

dnschnur commented Sep 28, 2012

Original author: ketan.kh...@gmail.com (February 10, 2008 17:53:24)

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
flot 0.3 on win xp/vista

Please provide any additional information below.

In some of the scientific graphs the values for x axis are uneven and plotted graphs provide the necessary information in that way only.
i.e. for values between 300 and 500 points are plotted for every 20 units. and For values from 500 to 3000 values are plotted for every 100 units and beyond 3000 points are plotted for every 500 points.
Can we do this using current library easily

Original issue: http://code.google.com/p/flot/issues/detail?id=26

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From olau%iol...@gtempaccount.com on February 11, 2008 11:11:18
Are we talking about logarithmic scales here? The automatic stuff in Flot can't do it
at the moment, but it shouldn't be too hard to prescale the values and provide ticks
yourself.

Member

dnschnur commented Sep 28, 2012

From olau%iol...@gtempaccount.com on February 11, 2008 11:11:18
Are we talking about logarithmic scales here? The automatic stuff in Flot can't do it
at the moment, but it shouldn't be too hard to prescale the values and provide ticks
yourself.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From simonebe...@gmail.com on August 20, 2008 15:34:48

i've made a quick implementation of logarithmic scales on y axis
I'think that this match the requirements

I'm working on modified flot version downloaded from Issue #5
you can see the code in attach

to use logarithmic scale set yaxis:{logarithmicScale:true} in options

questions are welcome

Member

dnschnur commented Sep 28, 2012

From simonebe...@gmail.com on August 20, 2008 15:34:48

i've made a quick implementation of logarithmic scales on y axis
I'think that this match the requirements

I'm working on modified flot version downloaded from Issue #5
you can see the code in attach

to use logarithmic scale set yaxis:{logarithmicScale:true} in options

questions are welcome

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From olau%iol...@gtempaccount.com on September 10, 2008 20:09:40
Something happened with the attachment. Would you mind creating a patch against SVN?
I'm curious as to how many lines of code this requires.

Member

dnschnur commented Sep 28, 2012

From olau%iol...@gtempaccount.com on September 10, 2008 20:09:40
Something happened with the attachment. Would you mind creating a patch against SVN?
I'm curious as to how many lines of code this requires.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From simonebe...@gmail.com on September 12, 2008 14:03:55
I cannot access SVN here, and in this moment it's hard to make a patch from a very
modified version ..

btw logarithmic Yscale require 6 lines of code

first define option default value (line 47)
yaxis: {
autoscaleMargin: 0.02, logarithmicScale: false
},

then in processData (insert after line 262) prescale all values to log scale

                if (options.yaxis.logarithmicScale&& y!=0)
                    data[j][1]=(y=Math.log(y)/Math.log(10));

finally as you said, provide a custom yaxis.tickFormatter (in parseOptions before
line 150)
if (options.yaxis.logarithmicScale)
options.yaxis.tickFormatter=function(n, axis)
{return Math.pow(10,n).toFixed(axis.tickDecimals);}

Member

dnschnur commented Sep 28, 2012

From simonebe...@gmail.com on September 12, 2008 14:03:55
I cannot access SVN here, and in this moment it's hard to make a patch from a very
modified version ..

btw logarithmic Yscale require 6 lines of code

first define option default value (line 47)
yaxis: {
autoscaleMargin: 0.02, logarithmicScale: false
},

then in processData (insert after line 262) prescale all values to log scale

                if (options.yaxis.logarithmicScale&& y!=0)
                    data[j][1]=(y=Math.log(y)/Math.log(10));

finally as you said, provide a custom yaxis.tickFormatter (in parseOptions before
line 150)
if (options.yaxis.logarithmicScale)
options.yaxis.tickFormatter=function(n, axis)
{return Math.pow(10,n).toFixed(axis.tickDecimals);}

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From olau%iol...@gtempaccount.com on September 25, 2008 12:59:44
I've just released version 0.5 so it should be easier now.

I think it makes sense to have logarithmic: null or number instead of just
true/false, otherwise I'm going to get spammed by people wanting to use log base 2 or
log base e.

Note that the patch must be general enough to work with all four axes (actually I
think this is pretty easy to do.

Member

dnschnur commented Sep 28, 2012

From olau%iol...@gtempaccount.com on September 25, 2008 12:59:44
I've just released version 0.5 so it should be easier now.

I think it makes sense to have logarithmic: null or number instead of just
true/false, otherwise I'm going to get spammed by people wanting to use log base 2 or
log base e.

Note that the patch must be general enough to work with all four axes (actually I
think this is pretty easy to do.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From tsuchimo...@gmail.com on September 29, 2008 14:26:21
This is very good idea.
I'm looking forward to be included this patch into the main stream.

Member

dnschnur commented Sep 28, 2012

From tsuchimo...@gmail.com on September 29, 2008 14:26:21
This is very good idea.
I'm looking forward to be included this patch into the main stream.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From jal...@gmail.com on November 26, 2008 08:57:15
Hello,

I have added preliminary support for arbitrary bases in axes, you can find it on my gitweb:

http://www.leto.net/gitweb/?p=flot.git;a=shortlog;h=refs/heads/leto

Or you can grab it on the command line with:

git clone http://leto.net/code/flot.git

Here is the example page that I added to the examples/ directory:

http://leto.net/plot/examples/logarithms.html

Any suggestions for improvement are welcome.

Cheers

Member

dnschnur commented Sep 28, 2012

From jal...@gmail.com on November 26, 2008 08:57:15
Hello,

I have added preliminary support for arbitrary bases in axes, you can find it on my gitweb:

http://www.leto.net/gitweb/?p=flot.git;a=shortlog;h=refs/heads/leto

Or you can grab it on the command line with:

git clone http://leto.net/code/flot.git

Here is the example page that I added to the examples/ directory:

http://leto.net/plot/examples/logarithms.html

Any suggestions for improvement are welcome.

Cheers

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From jal...@gmail.com on January 22, 2009 18:14:03
Here is a patch for logarithmic bases against svn rev 131. Any comments for
refactoring and improvements are welcome.

Cheers

Member

dnschnur commented Sep 28, 2012

From jal...@gmail.com on January 22, 2009 18:14:03
Here is a patch for logarithmic bases against svn rev 131. Any comments for
refactoring and improvements are welcome.

Cheers

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From ben.chy...@gmail.com on January 23, 2009 15:58:26
Hi, Correct me if I'm wrong, but I've been messing around with your examples and
noticed that this doesn't account for zooming. Also, if using any type of tooltip you
have to Math.pow(n, value) to get the actual value (which may lead to values being
off). Is there any way around this? Specifically the zooming part.

Thanks
Ben

Member

dnschnur commented Sep 28, 2012

From ben.chy...@gmail.com on January 23, 2009 15:58:26
Hi, Correct me if I'm wrong, but I've been messing around with your examples and
noticed that this doesn't account for zooming. Also, if using any type of tooltip you
have to Math.pow(n, value) to get the actual value (which may lead to values being
off). Is there any way around this? Specifically the zooming part.

Thanks
Ben

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From chris.le...@gmail.com on January 31, 2009 01:18:52
Hi jaleto,

I've been using your mods from your git for weeks now and found them incredibly useful. I did find one bug. A logarithmic data value <= 0 passes through the code unscaled and is plotted at it's unscaled position. This
is a bug, since negative values will show up as some sort of positive value. I've fixed so these values are
nulled out and attached a patch file. The patch file is diffed against the already patched r131 version of
jquery.flot.js

Thanks!
Chris

Member

dnschnur commented Sep 28, 2012

From chris.le...@gmail.com on January 31, 2009 01:18:52
Hi jaleto,

I've been using your mods from your git for weeks now and found them incredibly useful. I did find one bug. A logarithmic data value <= 0 passes through the code unscaled and is plotted at it's unscaled position. This
is a bug, since negative values will show up as some sort of positive value. I've fixed so these values are
nulled out and attached a patch file. The patch file is diffed against the already patched r131 version of
jquery.flot.js

Thanks!
Chris

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From jal...@gmail.com on January 31, 2009 18:41:00
Ben is totally correct, the way the patch works is to change the rendering of the
ticks on each axis, but tooltips and zooming don't play nice yet. I am thinking about
how to best deal with this.

Chris: Thanks for squashing that bug, I really need to write some tests! I will
incorporate your patch and submit a new patch to Ole.

Cheers

Member

dnschnur commented Sep 28, 2012

From jal...@gmail.com on January 31, 2009 18:41:00
Ben is totally correct, the way the patch works is to change the rendering of the
ticks on each axis, but tooltips and zooming don't play nice yet. I am thinking about
how to best deal with this.

Chris: Thanks for squashing that bug, I really need to write some tests! I will
incorporate your patch and submit a new patch to Ole.

Cheers

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From philip.t...@gmail.com on February 21, 2009 15:45:25
there's much more required to implement log scaling.

  1. data has to be transformed in processData, but original data has to be retained to
    pass back when events are fired (plothover, plotclick, etc.) Just converting to log
    and then taking the exponent later is lossy so should not be done.
  2. The axes have to be logscaled as well, however the ticks have to be displayed in
    the units of the original data
  3. options.?axis.min and max have to be transformed
  4. any ticks passed in by the caller have to be transformed
  5. custom grid markers have to be transformed

I've done all of the above in a version of flot that I ported to YUI, unfortunately,
I cannot provide a diff against the jQuery version because I don't use that version,
but in general the changes are identical to the code above, just that you have to
apply them to many more places.

Member

dnschnur commented Sep 28, 2012

From philip.t...@gmail.com on February 21, 2009 15:45:25
there's much more required to implement log scaling.

  1. data has to be transformed in processData, but original data has to be retained to
    pass back when events are fired (plothover, plotclick, etc.) Just converting to log
    and then taking the exponent later is lossy so should not be done.
  2. The axes have to be logscaled as well, however the ticks have to be displayed in
    the units of the original data
  3. options.?axis.min and max have to be transformed
  4. any ticks passed in by the caller have to be transformed
  5. custom grid markers have to be transformed

I've done all of the above in a version of flot that I ported to YUI, unfortunately,
I cannot provide a diff against the jQuery version because I don't use that version,
but in general the changes are identical to the code above, just that you have to
apply them to many more places.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From olau%iol...@gtempaccount.com on October 27, 2009 15:06:05
FYI, the transform callback in Flot 0.6 should make this much, much easier. I think
it would make sense to make a little plugin that wraps it up. We just need a
transform function, intelligent ticks and some error checking. Probably just a
question of porting the above patch.

Member

dnschnur commented Sep 28, 2012

From olau%iol...@gtempaccount.com on October 27, 2009 15:06:05
FYI, the transform callback in Flot 0.6 should make this much, much easier. I think
it would make sense to make a little plugin that wraps it up. We just need a
transform function, intelligent ticks and some error checking. Probably just a
question of porting the above patch.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From ptar...@gmail.com on April 03, 2010 18:48:40
pillip, can you pretty please port your log thing to jquery flot? It'll make webnumbr.com that much cooler :)

Member

dnschnur commented Sep 28, 2012

From ptar...@gmail.com on April 03, 2010 18:48:40
pillip, can you pretty please port your log thing to jquery flot? It'll make webnumbr.com that much cooler :)

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From paul.p...@gmail.com on June 07, 2010 15:31:21
Sorry, my ignorance maybe, but I don't seem to get the transform callback option to
work properly because I pass all my data in JSON. I mean, I can't explicitely pass

xaxis: {
transform: function (v) { return Math.log(v); },
inverseTransform: function (v) { return Math.exp(v); }
}

but all I can pass to flot is

xaxis: {
transform: "function (v) { return Math.log(v); }",
inverseTransform: "function (v) { return Math.exp(v); }"
}

(unless I would add a layer when I import my JSON to "revive" the functions in the
JSON, if any)

Or is there a logarithmic scale plugin available? (didn't find one under the plugins
page).
[[and by the way I'm a huge fan of flot -- thanks for a very nice app]]

Member

dnschnur commented Sep 28, 2012

From paul.p...@gmail.com on June 07, 2010 15:31:21
Sorry, my ignorance maybe, but I don't seem to get the transform callback option to
work properly because I pass all my data in JSON. I mean, I can't explicitely pass

xaxis: {
transform: function (v) { return Math.log(v); },
inverseTransform: function (v) { return Math.exp(v); }
}

but all I can pass to flot is

xaxis: {
transform: "function (v) { return Math.log(v); }",
inverseTransform: "function (v) { return Math.exp(v); }"
}

(unless I would add a layer when I import my JSON to "revive" the functions in the
JSON, if any)

Or is there a logarithmic scale plugin available? (didn't find one under the plugins
page).
[[and by the way I'm a huge fan of flot -- thanks for a very nice app]]

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From dmcoo...@gmail.com on June 30, 2010 14:54:25
It it correct that zooming and tooltips are still problematic when using the transform/inverseTransform functions?

I'm using a transform in order to display stock data over multiple weeks (hiding the weekend days), but anything past the first weekend fails to render when zoomed, and won't show tooltips on the datapoints.

Member

dnschnur commented Sep 28, 2012

From dmcoo...@gmail.com on June 30, 2010 14:54:25
It it correct that zooming and tooltips are still problematic when using the transform/inverseTransform functions?

I'm using a transform in order to display stock data over multiple weeks (hiding the weekend days), but anything past the first weekend fails to render when zoomed, and won't show tooltips on the datapoints.

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From dusan.si...@gmail.com on January 07, 2011 13:29:10
Hi,
One piece of data that I charted recently showed all the points on a Y scale of about 0 to 50, but there is one point which hits 3000. Because of this, when I look at the chart I cant really see the trends of most data because it gets scaled down. Is there any way to have dynamic Y axis, where it would conform evenly to 90% (or variable percentage) of data, and the rest to be shown out of proportion. And the grid lines could change to reflect it.
Something like this:

http://www.jqplot.com/tests/logAxisTests.php

Your help much appreciated

Member

dnschnur commented Sep 28, 2012

From dusan.si...@gmail.com on January 07, 2011 13:29:10
Hi,
One piece of data that I charted recently showed all the points on a Y scale of about 0 to 50, but there is one point which hits 3000. Because of this, when I look at the chart I cant really see the trends of most data because it gets scaled down. Is there any way to have dynamic Y axis, where it would conform evenly to 90% (or variable percentage) of data, and the rest to be shown out of proportion. And the grid lines could change to reflect it.
Something like this:

http://www.jqplot.com/tests/logAxisTests.php

Your help much appreciated

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From maurizio...@gmail.com on February 10, 2011 22:56:28
hi!
I've been struggling with log scales as well!
Actually, I'm really not an expert in javascript, I'm not even a professional programmer, but I found flot as been so useful for my needs!
Would you please help me in fixing the crosshair/tooltip with log scale? I think the visualization now is correct, but I can get the tooltip to catch the points in the plot! What should I do?
PS: any other comment on my crappy code is expected :D

Thanks

Member

dnschnur commented Sep 28, 2012

From maurizio...@gmail.com on February 10, 2011 22:56:28
hi!
I've been struggling with log scales as well!
Actually, I'm really not an expert in javascript, I'm not even a professional programmer, but I found flot as been so useful for my needs!
Would you please help me in fixing the crosshair/tooltip with log scale? I think the visualization now is correct, but I can get the tooltip to catch the points in the plot! What should I do?
PS: any other comment on my crappy code is expected :D

Thanks

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From simonegi...@gmail.com on February 14, 2011 12:22:33
The instructions on comment #15 works correctly (at least for y axis), including zoom and pan using the navigation plugin, and with correct informations form plothover/click events.

I haven't tested it on xaxis, cause i don't need a log-log plot, but only a vertical log scale.

However, pay attention if your yaxis goes to 0, since log(0) is negative infinity, it causes errors inside flot (it would be nice if flot could report this errors, like invalid values returned from the transform function, instead of simply forwarding the innermost canvas error, which does not say a lot).

I decided to return log(0.0001) for zero (it's more or less -10), and have no data series that goes negative, so I don't handle them.

So, this works for me :

options.yaxis = {
transform: function (v) {
if (v == 0) v = 0.0001;
return Math.log(v);
},
inverseTransform: function (v) { return Math.exp(v); }
};

Member

dnschnur commented Sep 28, 2012

From simonegi...@gmail.com on February 14, 2011 12:22:33
The instructions on comment #15 works correctly (at least for y axis), including zoom and pan using the navigation plugin, and with correct informations form plothover/click events.

I haven't tested it on xaxis, cause i don't need a log-log plot, but only a vertical log scale.

However, pay attention if your yaxis goes to 0, since log(0) is negative infinity, it causes errors inside flot (it would be nice if flot could report this errors, like invalid values returned from the transform function, instead of simply forwarding the innermost canvas error, which does not say a lot).

I decided to return log(0.0001) for zero (it's more or less -10), and have no data series that goes negative, so I don't handle them.

So, this works for me :

options.yaxis = {
transform: function (v) {
if (v == 0) v = 0.0001;
return Math.log(v);
},
inverseTransform: function (v) { return Math.exp(v); }
};

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From Mostafa.Shokrof on August 09, 2011 00:08:19
I read all the comments in this issue and i still cant draw log-log graph can you provide me by example

why the transform functions wont be {
transform: function (v) {
Math.pow(10,v);
},
inverseTransform: function (v) { return Math.log(v)/Math.log(10); }
};

Member

dnschnur commented Sep 28, 2012

From Mostafa.Shokrof on August 09, 2011 00:08:19
I read all the comments in this issue and i still cant draw log-log graph can you provide me by example

why the transform functions wont be {
transform: function (v) {
Math.pow(10,v);
},
inverseTransform: function (v) { return Math.log(v)/Math.log(10); }
};

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From lmuri...@codebeta.net on March 11, 2012 21:00:20
Wanted to follow up on this Enhancement request.
So far I've found that the modified code provided in the 2nd comment does it's job well and have modified it myself a bit more in order to allow for both axis to use the logarithmic scale as I need for both axis to use said scale.

Any chance this enhancement can be ported to the latest version?

The graph I'm working on can be found here http://irken.codebeta.net/plot.php

Member

dnschnur commented Sep 28, 2012

From lmuri...@codebeta.net on March 11, 2012 21:00:20
Wanted to follow up on this Enhancement request.
So far I've found that the modified code provided in the 2nd comment does it's job well and have modified it myself a bit more in order to allow for both axis to use the logarithmic scale as I need for both axis to use said scale.

Any chance this enhancement can be ported to the latest version?

The graph I'm working on can be found here http://irken.codebeta.net/plot.php

@dnschnur

This comment has been minimized.

Show comment Hide comment
@dnschnur

dnschnur Sep 28, 2012

Member

From dnsch...@gmail.com on July 11, 2012 01:29:17
The recent move of time-axis support into its own plugin is an excellent example for a log-axis plugin.

Member

dnschnur commented Sep 28, 2012

From dnsch...@gmail.com on July 11, 2012 01:29:17
The recent move of time-axis support into its own plugin is an excellent example for a log-axis plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment