Billy-Sheppard / chart-js-rs

Rust Chart.js connector crate
https://billy-sheppard.github.io/chart-js-rs/examples/index.html
Apache License 2.0
25 stars 8 forks source link

Added `Chart.update()` functionality #14

Closed Billy-Sheppard closed 8 months ago

Billy-Sheppard commented 8 months ago

Example uses update on scatter chart.

DDtKey commented 8 months ago

The API looks exactly the way I would like it to 🚀 Thank you for supporting this!

Just one question, is it possible to make to_chart(self) not self-consuming, i.e to_chart(&self)? (btw, it also corresponds to self-convertion clippy lint)

Of course, in any case, we serialize the data and send it to JS, but this makes it possible to avoid some extra allocations, for example, if I just want to add new data points, without building a new dataset and/or cloning

Not critical though, provided API in the PR is totally enough for my use-cases, thanks 🙏

Billy-Sheppard commented 8 months ago

The reason its not &self is to generally avoid having a version of the struct in rust out of sync with what was sent to the JS. E.g. in theory you should always run ChartExt::get() to get your chart every time you make a change, as things like render_mutate may or may not cause side effects after the fact. I suppose it should be into_chart() to fit with clippy.

DDtKey commented 8 months ago

Makes sense to me