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

Custom Tooltips - X coordinate unpredictable for points in second half of dataset #2636

Closed
elzii opened this issue May 25, 2016 · 18 comments
Closed

Comments

@elzii
Copy link

elzii commented May 25, 2016

JSBin here:

http://jsbin.com/beguzuveki/1/edit?js,output

To demonstrate, hover over the point in for JUNE, then JULY

It looks like a product of the default tooltip styling where the caret is situated to the left/right, but I'm unsure how to resolve for this custom implementation

@elzii
Copy link
Author

elzii commented May 25, 2016

@etimberg This is actually for version 2.x, experiencing it in 2.0.2 specifically.

@elzii
Copy link
Author

elzii commented May 25, 2016

I'm able to circumvent the issue by commenting out

this.determineAlignment(tooltipSize)

on line 11604 in Chart.bundle.js though I suspect a more elegant solution is possible.

I'm also setting

Chart.defaults.global.tooltips.yAlign = 'left';
Chart.defaults.global.tooltips.xAlign = 'center';

@etimberg
Copy link
Member

I think it's the alignment settings but I'll give it some debugging

@elzii
Copy link
Author

elzii commented Jun 8, 2016

Running into further issues even with that line commented out. Here is a screenshot to demonstrate.

chartjs

Using a simple 1px red vertical line to debug. How can I reliably get the x coord that is at the center of the point? The x value seems to vary - I'm not sure why, perhaps based on the actual value of the point.

It makes achieving the following style quite difficult:

rce0wry

Is it possible for them to be evenly spaced?

@delcon
Copy link

delcon commented Aug 23, 2016

I think the Label Version 2.x should be kept for this bug.
This bug originated in V1 and continues to be unsolved.
@elzii did you find a workaround for this?

@seven-plus
Copy link

I am also experiencing this issue in v2.3.0.

Has anyone found a workaround/fix?

@elzii ?

Thanks.

@etimberg
Copy link
Member

@elzii you can probably compute the correct point using the alignment options and the given point until a PR can fix this.

I will likely add something to fix this as part of my tooltip work in v2.4 hence why this is targeted to v2.4

@delcon
Copy link

delcon commented Sep 29, 2016

my workaround is using a custom hover function and get the correct values from it.
This should get you going:

chartoptions{ hover:{ onHover: function(e){console.log(e)} } }

lookout for _view.x and _view.y

@seven-plus
Copy link

Thank you for the responses, it is much appreciated.

Due to time pressure I had to revert to the standard tooltip.

@divinitas-art
Copy link

Hi, onHover objects has no x a y coordinates, Is there any other way to do the positioning, I can stick easily with original tooltips but when I change the tooltip using custom: fucntion() - like adding some lines, the position is screwed up... Please some help, this is really annoying, we have such a great feature to do custom tooltips but we have no chance to position them right? I dont believe it, there must be a easy way to do this for sure...

@divinitas-art
Copy link

I moved
if (changed && opts.custom) {
opts.custom.call(me, model);
}

in front of
// We need to determine alignment of
var tooltipSize = me.getTooltipSize(model);
me.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas

in chart.js and everything works just as expected... is there a reason this is not done ? because i tested most of graphs a made with this and it works just great...

@sambruggeman
Copy link

sambruggeman commented Oct 10, 2016

@StealthyDamn the position is indeed correct when you move that if statement but in our code the tooltip doesn't dissapear anymore except for when we hover another item that has the tooltip(then that one sticks), are you seeing the same behavior?

I've added a check in the custom tooltip function if the tooltip is aligned left or right.

var position = $(this._chart.canvas)[0].getBoundingClientRect();            
if (tooltip.xAlign) {
  if (tooltip.xAlign == 'right') {
    tooltipEl.css({
      left: (position.width/2+position.left+tooltip.x-34) + 'px' //where 34 is arbitrary value cfr your tooltip's width
    });
  } else {
    tooltipEl.css({
      left: position.left + tooltip.x + 'px'
    });
  }
}

@divinitas-art
Copy link

@sambruggeman no, I am using the latest version with that modificatin and tooltips are dssapearing correctly.

@sambruggeman
Copy link

sambruggeman commented Oct 10, 2016

@StealthyDamn weird, I've also updated to latest version and still have the issue.. either way my addition above fixes the problem for us without going in the chart.js .. not sure if it's actually working as intended or if this is an actual bug ..

@divinitas-art
Copy link

@sambruggeman I dont know, maybe it is happeining only with some options or so, I use pretty big code to generate the graphs, many options changed.

@etimberg
Copy link
Member

@sambruggeman's solution is the best way to deal with this until we expose the top left of the tooltip regardless of the alignment. This is currently targeted to v2.4 (next release) and will be fixed soon. We will likely add some new properties to expose the (left, top) which can be used

@divinitas-art
Copy link

okay, nice, I will stick with my solution since it works and i have my code around it, but will upgrade as soon as 2.4 will come out. I am always sticking with latest version since the charts.js development is great, every new version is much better and I love that.

@etimberg
Copy link
Member

Fixed in #3472 see the new caretX and caretY properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

7 participants