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

Annotations label edit makes the text dissapear #19042

Closed
kamil-musialowski opened this issue May 24, 2023 · 1 comment · Fixed by #19067
Closed

Annotations label edit makes the text dissapear #19042

kamil-musialowski opened this issue May 24, 2023 · 1 comment · Fixed by #19067

Comments

@kamil-musialowski
Copy link
Contributor

kamil-musialowski commented May 24, 2023

Actual behaviour

After adding the label annotation and editing it through annotations GUI (even without changing any parameters) makes the text inside the label disappear.

Live demo with steps to reproduce

https://jsfiddle.net/BlackLabel/hd49nfum/

Click on the TXT icon to add the simple label to the chart
Click on the label
Click the pencil icon to edit it
Click save button (you don't have to change any data)

Product version

Highstock 11.0.1 (latest)

Internal note

Regression, last working version 10.3.3

@pawelfus
Copy link
Contributor

Workaround:

Demo: https://jsfiddle.net/BlackLabel/hd49nfum/2/

Plugin:

(function(H) {
  H._modules['Extensions/Annotations/NavigationBindings.js'].prototype.fieldsToOptions = function(
    fields,
    config
  ) {
    H.objectEach(fields, (value, field) => {
      const parsedValue = parseFloat(value),
        path = field.split('.'),
        pathLength = path.length - 1;

      // If it's a number (not "format" options), parse it:
      if (
        H.isNumber(parsedValue) &&
        !value.match(/px|em/g) &&
        !field.match(/format/g)
      ) {
        value = parsedValue;
      }

      // Remove values like 0
      if (value !== 'undefined') {
        let parent = config;

        path.forEach((name, index) => {
          const nextName = H.pick(path[index + 1], '');

          if (pathLength === index) {
            // Last index, put value:
            (parent)[name] = value;
          } else if (!(parent)[name]) {
            // Create middle property:
            (parent)[name] = nextName.match(/\d/g) ? [] : {};
            parent = (parent)[name];
          } else {
            // Jump into next property
            parent = (parent)[name];
          }
        });
      }
    });
    return config;
  }
})(Highcharts);

Internal note:
Bug in regexp - missing em in the regexp here: !value.match(/px/g)

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

Successfully merging a pull request may close this issue.

3 participants