Giter VIP home page Giter VIP logo

Comments (10)

Frozenlock avatar Frozenlock commented on August 15, 2024

(Please keep in mind that I've never written any JS... I could be totally mistaken.)

After investigation I believe this is caused by the boundX function in selection.js (from Flotr2).

function boundX(x, graph) {
  return Math.min(Math.max(0, x), graph.plotWidth - 1);
}

The selection is set to a maximum of width - 1. In my case summary.api.flotr.selection.selection.second.x is maxed at 847, instead of the initial width of 848.

The interesting part is how this maxed width is then multiplied with the axis scale:

 setSelection: function(area, preventEvent){
    var options = this.options,
      xa = this.axes.x,
      ya = this.axes.y,
      vertScale = ya.scale,
      hozScale = xa.scale,
      selX = options.selection.mode.indexOf('x') != -1,
      selY = options.selection.mode.indexOf('y') != -1,
      s = this.selection.selection;

    this.selection.clearSelection();

    s.first.y  = boundY((selX && !selY) ? 0 : (ya.max - area.y1) * vertScale, this);
    s.second.y = boundY((selX && !selY) ? this.plotHeight - 1: (ya.max - area.y2) * vertScale, this);
    s.first.x  = boundX((selY && !selX) ? 0 : (area.x1 - xa.min) * hozScale, this);
    s.second.x = boundX((selY && !selX) ? this.plotWidth : (area.x2 - xa.min) * hozScale, this);

    this.selection.drawSelection();
    if (!preventEvent)
      this.selection.fireSelectEvent();
  },

Yet the scale in Axis.js isn't based on the width -1, but rather on the width/length directly:

 setScale : function () {
    var
      length = this.length,
      max = this.max,
      min = this.min,
      offset = this.offset,
      orientation = this.orientation,
      options = this.options,
      logarithmic = options.scaling === LOGARITHMIC,
      scale;

    if (logarithmic) {
      scale = length / (log(max, options.base) - log(min, options.base));
    } else {
      scale = length / (max - min);
    }
    this.scale = scale;

from envisionjs.

Frozenlock avatar Frozenlock commented on August 15, 2024

Should I open an issue in Flotr2 instead of Envision?

from envisionjs.

cesutherland avatar cesutherland commented on August 15, 2024

Could you please fork this with your reproduction? http://jsfiddle.net/cesutherland/LurmY/49/

from envisionjs.

Frozenlock avatar Frozenlock commented on August 15, 2024

The same behavior is already present in this jsfiddle.
Here is a comparison of the selections one can make on the left and right side.

left-selection
Complete selection up to the 'touching' point.

right-selection
The two lines never meet!

from envisionjs.

cesutherland avatar cesutherland commented on August 15, 2024

Ah, got it!

from envisionjs.

Frozenlock avatar Frozenlock commented on August 15, 2024

Would you prefer if i opened this as a Flotr2 issue?

from envisionjs.

cesutherland avatar cesutherland commented on August 15, 2024

Thank you, no... it's an issue en the envision data processing. I'll take a look at it. Maybe off-by-1 heh...

from envisionjs.

Frozenlock avatar Frozenlock commented on August 15, 2024

Bump!

Any changes?

from envisionjs.

Flati avatar Flati commented on August 15, 2024

I have found this issue in my project as well.
I collected some data that might help you:

# of points # of points missing px width of chart
5012 4 1356
5012 8 712
3313 2 1356
3313 5 712
1528 1 1356
1528 2 712

As you can see with the data above, it seems to be an off-by-one error.
((# of points missing) / (# of points)) * (px width of chart) is always close to 1.

I also tried this with a few smaller examples, (all the way down to 2 data points). The last data point was always missing when I tried to select some area.

As mentioned above, by @Frozenlock , when I click the summary list to reset the selection, the whole data pool is displayed.

from envisionjs.

Flati avatar Flati commented on August 15, 2024

I have found the off-by-one error to be in flotr2.js function called boundX.
The implementation of the function is:
return Math.min(Math.max(0, x), graph.plotWidth - 1);
where it should be:
return Math.min(Math.max(0, x), graph.plotWidth);

This is in line # 4117 in the envision.js file.

After some testing on my charts, this seems to cause no error and fixes all my problems.
I will submit a pull request when I am able.

from envisionjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.