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

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

Closed
uBaze opened this issue Mar 27, 2013 · 0 comments
Closed

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

uBaze opened this issue Mar 27, 2013 · 0 comments

Comments

@uBaze
Copy link

uBaze commented Mar 27, 2013

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

Regaddi pushed a commit that referenced this issue Mar 29, 2013
@Regaddi Regaddi closed this as completed Mar 29, 2013
Regaddi pushed a commit that referenced this issue Mar 29, 2013
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

2 participants