-
Notifications
You must be signed in to change notification settings - Fork 328
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
Annotations that are following current Y values should not overlap #895
Comments
@davidnir1 may I ask you if you are using annotations or the annotations you are referring to are the tooltip labels? If you are using annotation plugin, can you share a sample? |
@davidnir1 anyway, if you are using the annotation plugin, the labels can be overlapped. |
Hi, in this example you reffered to i`m not sure what is x,x2, y,y2 ,Here is an example on how we add annotation (using annotations plugin): which means I can only control yValue for the location of the annotation, however I find it difficult to identify collisions because I have cases of multiple y scales whos values are totally different and yet there may be collision between the annotations because the chart is normalized. |
@KseniaKeren you are right writing that it is not simple. |
@KseniaKeren sorry, I forgot to explain better the above doubt. See elements diagrams:
|
@stockiNail Thank you very much for the explanation ,your thorough explanations and thoughtful suggestions have greatly improved my understanding. also I wanted to see the elements x2 y2 values but when I print the annotation element to the console these are the fields I have |
@KseniaKeren I think you are still using the annotation plugin version1.x. |
@davidnir1 @KseniaKeren here is a codepen with a sample how to avoid label overlapping: https://codepen.io/stockinail/pen/xxQKPKv |
@stockiNail Thank you very much, I looked into the code and it seems to be very helpful for us. Also I updated our version and now we indeed have the beforeDraw hook. a challenge we encountered now is about how to access other annotations in the chart. I wonder if there is a way to access them in the chart context that comes as a parameter to the beforeDraw hook? we cannot use the custom plugin you written cause our annotations are always shown the only thing we change in the app is the x value (kind of progress bar of a clip that constantly moving) , so we cannot seem to find a way to access all other annotations. We used to access them via chart.options.plugins.annotation.annotations[i] in order to change the yValue each time the current x changed, but this is the inner propeties of the annotation and they do not include the x x2 y y2 properties. |
@KseniaKeren to get all annotation elements there is a "private" method which can be removed if and when #892 will be approved and merged. // get annotation plugin instance
import annotationPlugin from 'chartjs-plugin-annotation';
....
const myLineChart = new Chart(ctx, config);
// get all annotation elements
const elements = annotationPlugin.getAnnotations(myLineChart); If you cannot wait for that PR, you can have a look to the discussion (previously mentioned) #880 (reply in thread) where the sample is using the private and undocumented function. |
@KseniaKeren the PR (#892) mentioned above was merged and new release has been published. |
Feature Proposal
When two plots have very close Y values, the annotations are overlapping and can hide each other, for example in our app:
Possible Implementation
Instead of overlapping, they should be on top of each other (ordered by y values), for example (source):
Thanks!
The text was updated successfully, but these errors were encountered: