Skip to content

isMouseOver Calculated Incorrectly for path Elements, Leading to Closing Powertip #135

Open
@speedplane

Description

@speedplane

Powertip's isMouseOver function does not properly calculate the height of SVG elements, which causes it to determine that the mouse is not over an object when it really is.

The reason for this is that getBoundingClientRect does not include the height of stroke-width in its calculation. I fixed this with the following monkey-hack:

    function isMouseOver(element) {
        // use getBoundingClientRect() because jQuery's width() and height()
        // methods do not work with SVG elements
        // compute width/height because those properties do not exist on the object
        // returned by getBoundingClientRect() in older versions of IE
        var elementPosition = element.offset(),
            elementBox = element[0].getBoundingClientRect(),
            elementWidth = elementBox.right - elementBox.left,
            elementHeight = elementBox.bottom - elementBox.top;

        // Add stroke width to paths
        var (element[0].tagName == 'path') {
            var stroke = window.getComputedStyle(element[0])
                .getPropertyValue("stroke-width");
            if (stroke && stroke.length && parseFloat(stroke) > 0) {
                    elementHeight += parseFloat(stroke)
            }
        }

        return session.currentX >= elementPosition.left &&
            session.currentX <= elementPosition.left + elementWidth &&
            session.currentY >= elementPosition.top &&
            session.currentY <= elementPosition.top + elementHeight;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSoftware defects or other problems that should be fixed.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions