Skip to content

Refactor graph types to classes. #355

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

Merged
merged 1 commit into from
May 25, 2025

Conversation

mauriciopoppe
Copy link
Owner

Having classes instead of plain objects allows having aliases for known graph types, it also allows the addition of new graphs if they follow the same structure as other graph types.

Example of the new API:

functionPlot({
  target: '#playground',
  data: [
    functionPlot.interval({ fn: 'x^2' }),
    functionPlot.scatter({ fn: 'sin(x)', nSamples: 50 }),
    functionPlot.polyline({ fn: 'x^3' }),
    functionPlot.text({ text: 'foo', location: [1, 2] })
  ]
})

The existing object API is still supported and transformed into the classes, moving forward, the class API is preferred.

Having classes instead of plain objects allows having
aliases for known graph types, it also allows the addition
of new graphs if they follow the same structure as other
graph types.

Example of the new API:

```javascript
functionPlot({
  target: '#playground',
  data: [
    functionPlot.interval({ fn: 'x^2' }),
    functionPlot.scatter({ fn: 'sin(x)', nSamples: 50 }),
    functionPlot.polyline({ fn: 'x^3' }),
    functionPlot.text({ text: 'foo', location: [1, 2] })
  ]
})
```

The existing object API is still supported and transformed into
the classes, moving forward, the class API is preferred.
@mauriciopoppe mauriciopoppe merged commit 651aa08 into master May 25, 2025
4 checks passed
@mauriciopoppe mauriciopoppe deleted the refactor-graph-types-to-classes branch May 25, 2025 21:19
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