chartjs / chartjs-plugin-annotation

Annotation plugin for Chart.js
MIT License
603 stars 325 forks source link

Label from line annotation disappear after once being outside the visible area. #789

Closed mbehr1 closed 2 years ago

mbehr1 commented 2 years ago

It seems that due to https://github.com/chartjs/chartjs-plugin-annotation/blob/eee842cb5181bdebcb29b23a6a8e4891f6c0c30f/src/types/line.js#L93

element.elements[0].options.display is set to false and never set back to the orig. value if the line annotation e.g. with zoom/pan is moved once out of the "inside" area.

Is this by design/intended? Is there any workaround? I tried setting display back to true in e.g. the "enter" callback and that works but only if I access element.elements[0]... directly. enter: ({ element }, event) => {
element.elements[0].options.display=true; element.label.options.display=true; // <- this works as well return true; }

tested with version v2.0.0

stockiNail commented 2 years ago

element.elements[0].options.display is set to false and never set back to the orig. value if the line annotation e.g. with zoom/pan is moved once out of the "inside" area.

Let me do some additional tests but should work with zoom/pan.

I tried setting display back to true in e.g. the "enter" callback and that works but only if I access element.elements[0]... directly. enter:

({ element }, event) => { 
 element.elements[0].options.display=true; 
 element.options.label.display=true; // <- this seems not to be sufficient 
 return true; 
}

tested with version v2.0.0

To change the options of the label, you have to access to the label element, by element.label.options. The element.options.label are not used at runtime.

mbehr1 commented 2 years ago

To change the options of the label, you have to access to the label element, by element.label.options. The element.options.label are not used at runtime.

Thx. Now setting element.label.options.display=true; works as well as workaround.

mbehr1 commented 2 years ago

@stockiNail thx a lot! I can confirm it's fixed 👍 (any rough indication when 2.0.1 might be released?)

stockiNail commented 2 years ago

I can confirm it's fixed 👍

Glad to hear it!

(any rough indication when 2.0.1 might be released?)

Not yet. @LeeLenaleee what do you think?

LeeLenaleee commented 2 years ago

There are not really any bugs open that are clear and can be solved now so I guess we can bump the version to 2.0.1

stockiNail commented 2 years ago

@mbehr1 version 2.0.1 has been published.

mbehr1 commented 2 years ago

@stockiNail thx a lot! Really appreciate the fast reaction/response!