Skip to content

Tooltips not showing on scroll (Firefox & IE) #3

@uBaze

Description

@uBaze

In the changes proposed by @peachananr in #2 there was a small problem. If you scroll on Firefox and IE, the tooltips does not appear or with some shift. After some search, it seems that e.scrollTop property is not supported if a doctype is present.

I replaced :

function getPosition(e) {
        var xPosition = 0;
        var yPosition = 0;

        while(e) {
            xPosition += (e.offsetLeft - e.scrollLeft + e.clientLeft);
            yPosition += (e.offsetTop - e.scrollTop + e.clientTop);
            e = e.offsetParent;
        }
        return { x: xPosition, y: yPosition };
    }

    context.canvas.onmousemove = function(e) {
        if(chart.tooltips.length > 0) {
            chart.savedState = chart.savedState == null ? context.getImageData(0,0,context.canvas.width,context.canvas.height) : chart.savedState;
            var rendered = 0;
            for(var i in chart.tooltips) {
                var position = getPosition(context.canvas),
                    mx = e.x - position.x,
                    my = e.y - position.y;
                if(chart.tooltips[i].inRange(mx,my)) {
                    chart.tooltips[i].render(mx,my);
                    rendered++;
                }
            }
            if(rendered == 0) {
                context.putImageData(chart.savedState,0,0);
            }
        }
    }

with this

    function getPosition(e) {
        var xPosition = 0;
        var yPosition = 0;

        while(e) {
            xPosition += (e.offsetLeft - window.pageXOffset + e.clientLeft);
            yPosition += (e.offsetTop - window.pageYOffset + e.clientTop);
            e = e.offsetParent;
        }
        return { x: xPosition, y: yPosition };
    }

    context.canvas.onmousemove = function(e) {

        if(chart.tooltips.length > 0) {
            chart.savedState = chart.savedState == null ? context.getImageData(0,0,context.canvas.width,context.canvas.height) : chart.savedState;
            var rendered = 0;
            for(var i in chart.tooltips) {
                var position = getPosition(context.canvas),
                    mx = (e.clientX) - position.x - window.pageXOffset,
                    my = (e.clientY) - position.y - window.pageYOffset;

                if(chart.tooltips[i].inRange(mx,my)) {
                    chart.tooltips[i].render(mx,my);
                    rendered++;
                }
            }
            if(rendered == 0) {
                context.putImageData(chart.savedState,0,0);
            }
        }
    }

Hope it help.

Cheers.

Val

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions