Skip to content

Commit

Permalink
BREAKING drop hardcoded and generated colors (#1806)
Browse files Browse the repository at this point in the history
`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)
  • Loading branch information
PowerKiKi authored Feb 10, 2024
1 parent 1a070c9 commit 7fd1407
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 133 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ changes to start using the library right away.
4. Provide a configuration, typically in your `main.ts`:

```typescript
import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts';
import { provideCharts, withDefaultRegisterables } from 'ng2-charts';

bootstrapApplication(AppComponent, {
providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())],
providers: [provideCharts(withDefaultRegisterables())],
}).catch((err) => console.error(err));
```

Expand All @@ -80,10 +80,10 @@ changes to start using the library right away.
Or in your AppModule:

```typescript
import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts';
import { provideCharts, withDefaultRegisterables } from 'ng2-charts';

@NgModule({
providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())],
providers: [provideCharts(withDefaultRegisterables())],
bootstrap: [AppComponent],
})
export class AppModule {}
Expand Down Expand Up @@ -248,9 +248,8 @@ documentation

### Colors

The library comes with a set of predefined default colors (which are exported as `baseColors`). If there are more
datasets than colors, colors are generated randomly. You can specify custom colors by following
these [instructions](https://www.chartjs.org/docs/latest/general/colors.html).
By default, this library uses the colors as [defined by Chart.js](https://www.chartjs.org/docs/latest/general/colors.html#default-color-palette).
If you need more control on colors, eg: generating colors on the fly, see [the advanced color palettes](https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes).

### Dynamic Theming

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions apps/ng2-charts-demo/src/app/landing/landing.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ <h2>API</h2>
```typescript
import &#123;
provideCharts,
withColorGenerator,
withDefaultRegisterables,
&#125; from 'ng2-charts';

bootstrapApplication(AppComponent, &#123;
providers: [
provideCharts(withDefaultRegisterables(), withColorGenerator()),
provideCharts(withDefaultRegisterables()),
],
&#125;).catch((err) => console.error(err));
```
Expand Down
8 changes: 2 additions & 6 deletions apps/ng2-charts-demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import {
import { bootstrapApplication } from '@angular/platform-browser';
import { LanguageFn } from 'highlight.js';
import { HIGHLIGHT_OPTIONS } from 'ngx-highlightjs';
import {
provideCharts,
withColorGenerator,
withDefaultRegisterables,
} from 'ng2-charts';
import { provideCharts, withDefaultRegisterables } from 'ng2-charts';
import { LandingComponent } from './app/landing/landing.component';
import { LineChartComponent } from './app/line-chart/line-chart.component';
import { BarChartComponent } from './app/bar-chart/bar-chart.component';
Expand Down Expand Up @@ -96,7 +92,7 @@ bootstrapApplication(AppComponent, {
providers: [
provideMarkdown({ loader: HttpClient }),
provideAnimations(),
provideCharts(withDefaultRegisterables(), withColorGenerator(), {
provideCharts(withDefaultRegisterables(), {
defaults: {
// For consistent rendering across CI and local envs
font: { family: 'Arial' },
Expand Down
13 changes: 6 additions & 7 deletions libs/ng2-charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ changes to start using the library right away.
4. Provide a configuration, typically in your `main.ts`:

```typescript
import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts';
import { provideCharts, withDefaultRegisterables } from 'ng2-charts';

bootstrapApplication(AppComponent, {
providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())],
providers: [provideCharts(withDefaultRegisterables())],
}).catch((err) => console.error(err));
```

Expand All @@ -80,10 +80,10 @@ changes to start using the library right away.
Or in your AppModule:

```typescript
import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts';
import { provideCharts, withDefaultRegisterables } from 'ng2-charts';

@NgModule({
providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())],
providers: [provideCharts(withDefaultRegisterables())],
bootstrap: [AppComponent],
})
export class AppModule {}
Expand Down Expand Up @@ -248,9 +248,8 @@ documentation

### Colors

The library comes with a set of predefined default colors (which are exported as `baseColors`). If there are more
datasets than colors, colors are generated randomly. You can specify custom colors by following
these [instructions](https://www.chartjs.org/docs/latest/general/colors.html).
By default, this library uses the colors as [defined by Chart.js](https://www.chartjs.org/docs/latest/general/colors.html#default-color-palette).
If you need more control on colors, eg: generating colors on the fly, see [the advanced color palettes](https://www.chartjs.org/docs/latest/general/colors.html#advanced-color-palettes).

### Dynamic Theming

Expand Down
1 change: 0 additions & 1 deletion libs/ng2-charts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
export * from './lib/ng-charts.provider';
export * from './lib/base-chart.directive';
export * from './lib/theme.service';
export * from './lib/base-colors';
14 changes: 0 additions & 14 deletions libs/ng2-charts/src/lib/base-colors.ts

This file was deleted.

87 changes: 0 additions & 87 deletions libs/ng2-charts/src/lib/get-colors.ts

This file was deleted.

9 changes: 0 additions & 9 deletions libs/ng2-charts/src/lib/ng-charts.provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { InjectionToken } from '@angular/core';
import { ChartComponentLike, registerables } from 'chart.js';
import { merge } from 'lodash-es';
import { builtInDefaults } from './get-colors';
import { AnyObject } from 'chart.js/dist/types/basic';

export const NG_CHARTS_CONFIGURATION =
Expand All @@ -26,14 +25,6 @@ export function withDefaultRegisterables(): NgChartsConfiguration {
return { registerables: registerables };
}

/**
* Provide predefined default colors (which are exported as `baseColors`), and then, if there are more
* datasets than colors, colors are generated randomly.
*/
export function withColorGenerator(): NgChartsConfiguration {
return { defaults: builtInDefaults };
}

/**
* Provide configuration for ngCharts. In most cases, you have to pass it some registerables. So either
* `withDefaultRegisterables()`, or a custom list of registerables tailored to your needs to reduce bundle size.
Expand Down

0 comments on commit 7fd1407

Please sign in to comment.