BREAKING Tree shakable standalone library#1801
BREAKING Tree shakable standalone library#1801santam85 merged 7 commits intovalor-software:masterfrom
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. |
santam85
left a comment
There was a problem hiding this comment.
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.
It's not mandatory to use the directive in a standalone component right? Should we make that explicit?
| import {AnyObject} from "chart.js/dist/types/basic"; | ||
|
|
||
| export const builtInDefaults = { | ||
| export const builtInDefaults :AnyObject= { |
There was a problem hiding this comment.
Isn't there a more restrictive type we could use for defaults in Chart.js?
There was a problem hiding this comment.
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.
Can you please also add a config example with a custom registerables list as you did in the docs app?
|
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)
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ng2-charts](https://github.com/valor-software/ng2-charts) | [`^5.0.3` -> `^6.0.0`](https://renovatebot.com/diffs/npm/ng2-charts/5.0.4/6.0.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>valor-software/ng2-charts (ng2-charts)</summary> ### [`v6.0.0`](https://github.com/valor-software/ng2-charts/releases/tag/v6.0.0) [Compare Source](valor-software/ng2-charts@v5.0.4...v6.0.0) #### What’s Changed - BREAKING Tree shakable standalone library ([#​1801](valor-software/ng2-charts#1801)) [@​PowerKiKi](https://github.com/PowerKiKi) Users must import the library in standalone mode - BREAKING drop hardcoded and generated colors ([#​1806](valor-software/ng2-charts#1806)) [@​PowerKiKi](https://github.com/PowerKiKi) Users must migrate to the Colors [plugin](https://www.chartjs.org/docs/latest/general/colors.html) from Chart.js for color generation - Angular 17 ([#​1757](valor-software/ng2-charts#1757)) [@​santam85](https://github.com/santam85) Angular 17 is the minimum version for v6 - Target ES2022 as is done in Angular 17 new projects ([#​1802](valor-software/ng2-charts#1802)) [@​PowerKiKi](https://github.com/PowerKiKi) - Enforce prettier in CI ([#​1804](valor-software/ng2-charts#1804)) [@​PowerKiKi](https://github.com/PowerKiKi) - Drop CHANGELOG.md ([#​1805](valor-software/ng2-charts#1805)) [@​PowerKiKi](https://github.com/PowerKiKi) - Migrate to new control flow syntax ([#​1827](valor-software/ng2-charts#1827)) [@​PowerKiKi](https://github.com/PowerKiKi) - Make defaults type safe ([#​1836](valor-software/ng2-charts#1836)) [@​Cselt](https://github.com/Cselt) - chore(deps-dev): bump [@​types/node](https://github.com/types/node) from 20.11.23 to 20.11.24 ([#​1857](valor-software/ng2-charts#1857)) [@​dependabot](https://github.com/dependabot) - chore(deps-dev): bump [@​types/node](https://github.com/types/node) from 20.11.20 to 20.11.21 ([#̴...

The library is standalone and tree-shakable, so it introduces the following breaking changes:
NgChartsModulemust 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: