Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to select the entire summary? #21

Open
Frozenlock opened this issue Jan 30, 2013 · 10 comments
Open

Impossible to select the entire summary? #21

Frozenlock opened this issue Jan 30, 2013 · 10 comments

Comments

@Frozenlock
Copy link

For a summary of width 848, a reset (click) in the selection area will give a selection object of: max: 848.0000000000001.

However, dragging the mouse in the selection area will only give a selection of max 846.9999999999826, thus never entirely selecting the entire data set.
A selection trigger seems to give the same result: can't get up to 848.0000000000001.

@Frozenlock
Copy link
Author

(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;

@Frozenlock
Copy link
Author

Should I open an issue in Flotr2 instead of Envision?

@cesutherland
Copy link
Member

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

@Frozenlock
Copy link
Author

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!

@cesutherland
Copy link
Member

Ah, got it!

@Frozenlock
Copy link
Author

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

@cesutherland
Copy link
Member

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

@Frozenlock
Copy link
Author

Bump!

Any changes?

@Flati
Copy link

Flati commented Nov 4, 2013

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.

@Flati
Copy link

Flati commented Nov 4, 2013

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.

brendonj added a commit to wandnz/amp-web that referenced this issue Feb 24, 2017
This appears to fix the problem we are seeing where the right edge of the selected area is truncated, so that the resulting detail graph does not show the full area. Who knows what side effects this has, but the function appears to be only used for selecting on graphs.

This issue appears to be similar to what we are seeing:

    HumbleSoftware/envisionjs#21

Keep track of what is going on with this in the trac, Ticket #60.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants