GithubHelp home page GithubHelp logo

Comments (7)

ppcmetrics-thp avatar ppcmetrics-thp commented on September 25, 2024

I could fix it by adding following lines to Exporting.ts#L1216:

const chartHeightFactor = chart.chartHeight / options.exporting.sourceHeight;
const chartWidthFactor = chart.chartWidth / options.exporting.sourceWidth;
options.annotations.forEach((annotation, index) => {
    if (
        typeof annotation.labels[0] !== 'undefined' &&
        typeof chart.annotations[index]?.labels[0]?.options !== 'undefined'
    ) {
        annotation.labels[0].x = chart.annotations[index].labels[0].options.x * chartWidthFactor;
        annotation.labels[0].y = chart.annotations[index].labels[0].options.y * chartHeightFactor;
    }
});

Since I don't think this is the right place in the code to fix the bug, I waited to submit a pull request.

from highcharts.

karolkolodziej avatar karolkolodziej commented on September 25, 2024

Hi @ppcmetrics-thp!
Thank you for reporting the issue!

Your suggestion seems to be valid, thank you for that!

from highcharts.

ppcmetrics-thp avatar ppcmetrics-thp commented on September 25, 2024

Hi @karolkolodziej , but is this really the right place to fix the bug? Isn't there an update function in the annotation module which needs to be fixed instead of the export function?

from highcharts.

ppcmetrics-thp avatar ppcmetrics-thp commented on September 25, 2024

@karolkolodziej When preparing the pull request I'm getting following error in VS Code:
Property 'annotations' does not exist on type 'ChartComposition'.ts(2339)
This error comes from the line:
typeof chart.annotations[index]?.labels[0]?.options !== 'undefined'

I suppose this error would fail the defined GitHub actions. Could you show me please how I can avoid this error?

Changing the line like following doesn't solve the problem:
typeof chart?.annotations[index]?.labels[0]?.options !== 'undefined'

from highcharts.

karolkolodziej avatar karolkolodziej commented on September 25, 2024

We have this thing called AnnotationChart and this should be used to properly access the type.

Altho as I think about it, putting annotation-related code into the exporting module isn't ideal. It looks like a good workaround but maybe there is a better place for the fix.

from highcharts.

pawelfus avatar pawelfus commented on September 25, 2024

Possible workarounds:

Workaround 1:

https://jsfiddle.net/BlackLabel/yazgf9xj/

Snippet:

Highcharts.Annotation.prototype.onMouseUp = function() {
  const chart = this.chart,
    annotation = this.target || this,
    annotationsOptions = chart.options.annotations,
    index = chart.annotations.indexOf(annotation);
  this.removeDocEvents();

  // annotationsOptions[index] = annotation.options;
}

Workaround 2:
https://jsfiddle.net/BlackLabel/yazgf9xj/2/

Highcharts.Annotation.prototype.onMouseUp = function() {
  const chart = this.chart,
    annotation = this.target || this,
    annotationsOptions = chart.options.annotations,
    index = chart.annotations.indexOf(annotation);
  this.removeDocEvents();
  
  annotation.options.labels = annotation.labels.map(label => label.options);
  annotation.options.shapes = annotation.shapes.map(shape => shape.options);

  annotationsOptions[index] = annotation.options;
}

from highcharts.

ppcmetrics-thp avatar ppcmetrics-thp commented on September 25, 2024

Thank you for the fix!

from highcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.