Keeping opacity in [0, 1] #623

Open
dumbledad opened this Issue Sep 26, 2012 · 2 comments

Comments

Projects
None yet
1 participant
@dumbledad

Here's a code block (lines 5140 to 5144, i.e. inside the setFillAndStroke function)

        opacity = mmin(mmax(opacity, 0), 1);
        params["stroke-width"] == null && (width = a["stroke-width"]);
        params["stroke-width"] && (stroke.weight = width);
        width && width < 1 && (opacity *= width) && (stroke.weight = 1);
        stroke.opacity = opacity;

The first line ensures that the variable 'opacity' lies in the range [0, 1] and the last line relies on that. But if the variable 'width' is negative the penultimate line breaks the restriction. I am seeing the JavaScript error message:

Unhandled exception at line 5144, column 13 in raphael.js
0x80048270 - JavaScript runtime error: Arg: Fraction out of range (0 to 1 allowed)

because on that penultimate line width == -0.2898198634532889

Is it worth guarding against that by ensuring '0 <= width < 1' before 'opacity *= width'?

@dumbledad

This comment has been minimized.

Show comment Hide comment
@dumbledad

dumbledad Sep 26, 2012

BTW 'width' is set on the line before the block I quoted (5139):

    var width = (toFloat(params["stroke-width"]) || 1) * .75; 

I need to debug my code to find out why params["stroke-width"] is being passed in as -0.3864264846043852 but that's where the negative opacity error is coming from.

BTW 'width' is set on the line before the block I quoted (5139):

    var width = (toFloat(params["stroke-width"]) || 1) * .75; 

I need to debug my code to find out why params["stroke-width"] is being passed in as -0.3864264846043852 but that's where the negative opacity error is coming from.

@dumbledad

This comment has been minimized.

Show comment Hide comment
@dumbledad

dumbledad Sep 26, 2012

It looks like the problem's coming from line 2927:

                    set[attr] = now;

in the Raphael animation code. That's setting stroke-width to negative values. Is there a way to ensure your animation function does not take attributes negative?

It looks like the problem's coming from line 2927:

                    set[attr] = now;

in the Raphael animation code. That's setting stroke-width to negative values. Is there a way to ensure your animation function does not take attributes negative?

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