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

Exercise/highcharts 2 #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Exercise/highcharts 2 #3

wants to merge 6 commits into from

Conversation

KamilKubik
Copy link
Collaborator

No description provided.

Copy link

@magdalena-gut magdalena-gut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 🎉 A small SVG rendering correction is required 📈

width: 2
});

const redCircle = this.renderer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a circle on load is not necessary when you use render as well. Try to figure out, how to add a circle only by using render event. Also, take note, that your circle is not fully responsive (you added a fixed radius value, but it should be changing as x and y)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the circle render to the render event, refactored the whole event and added the responsiveness (r parameter which I missed). Thanks!

})
.add();

this.redCircle = redCircle;
},
render() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I have only two suggestions:

  • radius is not quite responsive this way (it changes via Math.random() every time when you redraw the chart, but it should only base on the value from the chart and scale relative to the chart ( toPixels() is a good choice 🥇 )
  • if you first check that the circle doesn't exist, you avoid a few code lines

Generally, you can simplify it following way:

    events: {
      render: function() {
        const chart = this,
          yAxis = this.yAxis[0];

        if (!chart.customCircle) {
          chart.customCircle = chart.renderer
            .circle()
            .attr({
              stroke: "blue",
              "stroke-width": 3,
              fill: "none"
            })
            .add();
        }

        chart.customCircle.attr({
          x: chart.yAxis[0].center[0] + chart.plotTop,
          y: chart.yAxis[0].center[1] + chart.plotLeft,
          r: chart.yAxis[0].toPixels(chart.yAxis[0].dataMax)
        });

      }
    }

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

Successfully merging this pull request may close these issues.

2 participants