I found an HBar internal error when drawing tickmarks

Share RGraph:  

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by David Cook on 28th August 2017
Hi Richard:

I've discovered two problems with HBar - and I've given you a fix here for one of those two.

Our HBar implementation allows the user to dynamically resize the iFrame containing the bar. If the user sizes the frame such that the inner value bar goes to zero in size, the browser locks up.

For sizing the vertical (eg., making the vertical size smaller until the value bar goes zero)... the error is in the:

this.DrawLabels() routine...

Specifically, in the "// Draw the X tickmarks" part of the routine, you have this...

// Draw the X tickmarks
var i=0;
for (y=this.gutterTop + (yTickGap / 2); y<=ca.height - this.gutterBottom; y+=yTickGap) {
    ...
}

The problem is that 'yTickGap' is normally +infinity, but when the value bar becomes zero, it either becomes NaN or -Infinity.

I fixed this portion of your code by wrapping your loop like this:

// Draw the X tickmarks
var i=0;
if ((yTickGap == Number.POSITIVE_INFINITY) || (isFinite(yTickGap))) {
   for (y=this.gutterTop + (yTickGap / 2); y<=ca.height - this.gutterBottom; y+=yTickGap) {
     ...
   }
}

(Basically, I wrapped your FOR loop in an IF statement)

That solves the vertical problem.

The horizontal sizing also suffers the same thing - but this is failing in RG.Background.draw(this) - which is in your common-core js which I don't have an uncompressed version of (so can't fix yet).

I'll note that Vbar suffers from similar things - but I haven't gotten there to address those yet.

Is an uncompressed version of the common-core js available?

david

Posted by Richard on 28th August 2017
Hi there,

Looking at it - it looks like this happens when there not enough space for the bars - due to the gutter sizes (top and bottom).

So if I understand correctly a check at the start of the draw() function could be done and if the canvas is too small - nothing gets rendered and the HBar just exits.

Since if the gutter sizing means that there's no space for the bars - nothing could be rendered anyway.

Or have I misunderstood?


Richard
Posted by David Cook on 28th August 2017
You are correct. However, since the user is dynamically sizing the bar they don't realize this - and if they make it too small, as I said, it locks the browser.

After my Y change that I posted, I now note that I can move it even into negative space (eg., put the vertical such that the value bar is now negative in size) - and it actually draws.

What I am trying to avoid is having the user accidentally do it. Since I can't easily compute what the size will be of that bar (to inhibit the drawing) it makes more sense to simply skip over the error condition inside your code (as I did with my IF statement).

If I download your latest version (the top download link, rather than the minimized links) - is the common.core js not minimized? (As I need to go into there to fix the Background.draw of the same problem).

david
Posted by Richard on 28th August 2017
Hi there,

I'll add a check into the draw() function then - and it just exits if there's not enough space. Things like the Bar, Line, Scatter and Waterfall might be similar.

> If I download your latest version (the top download link, rather than the minimized
> links) - is the common.core js not minimized? (As I need to go into there to fix the
> Background.draw of the same problem).

Correct - the main stable download (that I released a few days ago) isn't minimised.

www.rgraph.net/download#stable


Richard
Posted by Richard on 7th September 2017
Hi there,

I@ve been thinking about this (a bit) - and couldn't you add the check in the beforedraw event?

eg

.on('beforedraw', function (obj)
{
     // Add a check here on the canvas using obj.canvas
     //
     // alert('The new canvas width is: ' + obj.canvas.width);
})


It may not work - just musing.

Richard

Add a reply




« Back to message list