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

Fix instanceof checks with constructor name comparison #431

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcos2872
Copy link

applying getPosition corrections when using pie chart

The problem occurs at the getPositioner function.

function getPositioner(el) {
    if (el instanceof chart_js.ArcElement) {
      return positioners.arc;
    }
    if (el instanceof chart_js.PointElement) {
      return positioners.point;
    }
    if (el instanceof chart_js.BarElement) {
      return positioners.bar;
    }
    return positioners.fallback;
  }

In this function when using Pie or Doughnut charts at the first if should return but it happens that the condition el instanceof chart_js.ArcElement isn't evaluated to true, because chart_js (that is require(chart.js)) is not equal to the chart.js which calling this plugin.

As a workaround I rewrite that function as below and it works fine.

function getPositioner(el) {
    if (el.constructor.name === 'ArcElement') {
      return positioners.arc;
    }
    if (el.constructor.name === 'PointElement') {
      return positioners.point;
    }
    if (el.constructor.name === 'BarElement') {
      return positioners.bar;
    }
    return positioners.fallback;
  }

Reference: #141

The changes show adding compiled distribution files for a Chart.js plugin that adds data label capabilities. The plugin enables showing labels on chart elements with customizable positioning, styling, and interaction.

I suggest the following commit message:

```
Add Chart.js data labels plugin dist files

Add compiled and minified distribution files for the chartjs-plugin-datalabels
plugin which adds configurable data labels to Chart.js chart elements.
```

I included a brief message body since this introduces a significant library feature and it helps explain what the files are for. The subject follows conventional style using imperative mood, while the body provides helpful context.
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.

1 participant