-
Notifications
You must be signed in to change notification settings - Fork 571
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
BREAKING Tree shakable standalone library #1801
Conversation
The library is standalone and tree-shakable, so it introduces the following breaking changes: - All usage of `NgChartsModule` must be replaced by `provideNgCharts()` (and `withDefaultRegisterables()` and optionally `withColorGenerator()`)
Thanks @PowerKiKi , I agree all the schematics are overkill, I am not opposed to remove the generation ones. As a compromise, we could probably keep a single one with a type parameter to generate a new chart? IIRC the color generation feature is now something directly supported from Chart.js (https://www.chartjs.org/docs/latest/general/colors.html#default-color-palette) so we could potentially rework that option to include/exclude the extra registrable. |
I'll remove all of them then. Because generating hardcoded values does not bring much value, and we already have well documented usages that can be copy-pasted on https://valor-software.com/ng2-charts/
I assumed that the hardcoded colors from this lib (which differ from chart.js values), and the generated colors, were something that should be kept. But if that is not the case, and we agree that colors will change in this release, then I agree it would make more sense to drop it entirely and instead recommend something like https://github.com/kurkle/chartjs-plugin-autocolors. Would that be ok with you ? |
Rather than suggesting en external library ('autocolor' from https://github.com/kurkle/chartjs-plugin-autocolors) I would prefer using the built-in one already present in Chart.js. It should be possible to test it in our lib by adding these defaults:
and for the charts:
|
Actually the built-in So what should we do ? drop and recommend that |
My opinion is we should:
This can be part of a separate PR too though... |
Instead you should either create components manually or use the directive directly in one of your existing components.
This is ready for review (and merge). I'll address the color thing in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thanks for the help!
Can you take care of updating the changelog as well for the library please? That way we can start tracking the breaking changes for 6.0.0
libs/ng2-charts/README.md
Outdated
// In your App's module: | ||
imports: [NgChartsModule]; | ||
@Component({ | ||
standalone: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not mandatory to use the directive in a standalone component right? Should we make that explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented in 7b0bfa8
|
||
export const builtInDefaults = { | ||
export const builtInDefaults :AnyObject= { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a more restrictive type we could use for defaults in Chart.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish, but unfortunately Chart.js typing is quite loose for that method:
README.md
Outdated
|
||
bootstrapApplication(AppComponent, { | ||
providers: [ | ||
provideCharts(withDefaultRegisterables(), withColorGenerator()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also add a config example with a custom registerables list as you did in the docs app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 0d894e5
I did everything you asked, except updating CHANGELOG.md, because that file was not kept up to for 4.0.1, 4.0.2, 4.1.0, 4.1.1, 5.0.0, 5.0.1, 5.0.2, 5.0.3 and 5.0.4. I'd rather not do that 😅. Instead I would suggest to delete CHANGELOG.md and only use GitHub releases, which are up-to-date and easily generated. I know it's slightly less convenient for users, but CHANGELOG.md maintenance is a pain. And i'd rather have a systematically up-to-date non-file changelog in GitHub, rather than incomplete CHANGELOG.md file. |
Because that file was not kept up to for 4.0.1, 4.0.2, 4.1.0, 4.1.1, 5.0 .0, 5.0.1, 5.0.2, 5.0.3 and 5.0.4. Instead, we will keep using GitHub auto-generated release notes. As discussed in valor-software#1801 (comment)
IMHO this is ready to be merged. Would you like me to rebase/squash ? |
Because that file was not kept up to for 4.0.1, 4.0.2, 4.1.0, 4.1.1, 5.0 .0, 5.0.1, 5.0.2, 5.0.3 and 5.0.4. Instead, we will keep using GitHub auto-generated release notes. As discussed in #1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in valor-software#1801 (comment)
`builtInDefaults` and `baseColors` were dropped. That means that colors will change to be the default as defined by Chart.js, and we will no longer generate colors on the fly. If you need this kind of features, see https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes As discussed in #1801 (comment)
The library is standalone and tree-shakable, so it introduces the following breaking changes:
NgChartsModule
must be replaced byprovideNgCharts()
(andwithDefaultRegisterables()
and optionallywithColorGenerator()
)@santam85, this is a draft to transform the library into a pure standalone lib. My goal was to be standalone and tree shakable, hence the introduction of
withColorGenerator()
(which I'd like to avoid in my own projects).It is still WIP, because I didn't do much for schematics. I see they are a lot of them to add each possible chart. IMHO that is a bit overkill, and I'd drop support for adding chart entirely. And instead, I'd only keep adding the library to an existing standalone project (not a module project). It is a severe breaking change, but would reduce maintenance drastically. WDYT ?
tl;dr: new usage is like: