Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dist/
node_modules/
package-lock.json
*.swp
/.vs
/.gitignore
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ All available options are listed below.
| `fillAlpha` | `number` | `0.5` | The transparency value for the line fill color. Must be a number between `0.0` (fully transparent) and `1.0` (no transparency).
| `scheme` | <code>string&#124;string[]</code> | `'brewer.Paired12'` | Color scheme name that is any of [Color Chart](https://nagix.github.io/chartjs-plugin-colorschemes/colorchart.html). It also accepts an array of color strings, which is primarily for ES modules. [more...](#usage-in-es6-as-module)
| `reverse` | `boolean` | `false` | If set to `true`, the order of the colors in the selected scheme is reversed.
| `override` | `boolean` | `false` | If set to `true`, the specified color scheme will override the existing color options. If `false`, it is only applied when no color setting exists. [more...](#overriding-existing-color-settings)
| `overrideExisting` | `boolean` | `false` | If set to `true`, the specified color scheme will override the existing color options. If `false`, it is only applied when no color setting exists. [more...](#overriding-existing-color-settings)
| `custom` | `function` | `undefined` | A function that takes a copy of the color string array for `scheme` in order to extend the predefined scheme colors. [more...](#custom-function)

### Overriding Existing Color Settings

By default, this plugin doesn't apply a color scheme if any color options are already specified. This may cause a problem if you are using a third party library such as [ng-charts](https://valor-software.com/ng2-charts/), which automatically applies default color settings. In that case, the existing color settings can be overridden by setting the `override` option to `true`.
By default, this plugin doesn't apply a color scheme if any color options are already specified. This may cause a problem if you are using a third party library such as [ng-charts](https://valor-software.com/ng2-charts/), which automatically applies default color settings. In that case, the existing color settings can be overridden by setting the `overrideExisting` option to `true`.

### `custom`-Function

Expand Down
1,210 changes: 1,210 additions & 0 deletions dist/chartjs-plugin-colorschemes.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"test": "test"
},
"devDependencies": {
"chart.js": "~2.8.0",
"eslint-config-chartjs": "^0.1.0",
"chart.js": "~3.7.1",
"eslint-config-chartjs": "^0.3.0",
"eslint-plugin-es": "^1.4.0",
"eslint-plugin-html": "^5.0.3",
"gulp": "^4.0.0",
Expand All @@ -63,6 +63,6 @@
"yargs": "^13.2.2"
},
"peerDependencies": {
"chart.js": ">= 2.5.0 < 3"
"chart.js": ">= 3 < 4"
}
}
7 changes: 4 additions & 3 deletions src/plugins/plugin.colorschemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginBase.plugins.colorschemes = {
scheme: 'brewer.Paired12',
fillAlpha: 0.5,
reverse: false,
override: false
overrideExisting: false
};

function getScheme(scheme) {
Expand Down Expand Up @@ -59,7 +59,7 @@ var ColorSchemesPlugin = {
var scheme = getScheme(options.scheme);
var fillAlpha = options.fillAlpha;
var reverse = options.reverse;
var override = options.override;
var override = options.overrideExisting;
var custom = options.custom;
var schemeClone, customResult, length, colorIndex, color;

Expand Down Expand Up @@ -181,6 +181,7 @@ var ColorSchemesPlugin = {
}
};

Chart.plugins.register(ColorSchemesPlugin);
const registerPlugin = Chart.register || Chart.plugins.register;
registerPlugin(ColorSchemesPlugin);

export default ColorSchemesPlugin;
8 changes: 4 additions & 4 deletions test/fixtures/plugin.colorschemes/chart-bar-fillAlpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 4
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
x: {display: false},
y: {display: false}
},
plugins: {
legend: {display:false},
title: {display:false},
colorschemes: {
scheme: 'brewer.Accent3',
fillAlpha: 0.2
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-bar-fillAlpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/fixtures/plugin.colorschemes/chart-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 4
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
x: {display: false},
y: {display: false}
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3',
fillAlpha: 1
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/plugin.colorschemes/chart-bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 30
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
x: {display: false},
y: {display: false}
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3'
}
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-bubble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/fixtures/plugin.colorschemes/chart-doughnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default {
}]
},
options: {
legend: false,
title: false,
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent6'
}
Expand Down
11 changes: 6 additions & 5 deletions test/fixtures/plugin.colorschemes/chart-horizontal-bar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
config: {
type: 'horizontalBar',
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4, 5],
datasets: [{
Expand All @@ -12,16 +12,17 @@ export default {
}]
},
options: {
legend: false,
title: false,
indexAxis: 'y',
layout: {
padding: 4
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
x: {display: false},
y: {display: false}
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3'
}
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-horizontal-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/fixtures/plugin.colorschemes/chart-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 4
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
x: {display: false},
y: {display: false}
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3'
}
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/fixtures/plugin.colorschemes/chart-pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default {
}]
},
options: {
legend: false,
title: false,
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent6'
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/plugin.colorschemes/chart-polar-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default {
}]
},
options: {
legend: false,
title: false,
scale: {
display: false
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent6'
}
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-polar-area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/fixtures/plugin.colorschemes/chart-radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 4
},
scale: {
display: false
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3'
}
Expand Down
Binary file modified test/fixtures/plugin.colorschemes/chart-radar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/fixtures/plugin.colorschemes/chart-scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export default {
}]
},
options: {
legend: false,
title: false,
layout: {
padding: 4
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
xAxes: {display: false},
yAxes: {display: false}
},
plugins: {
legend: false,
title: false,
colorschemes: {
scheme: 'brewer.Accent3'
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jasmine.triggerMouseEvent = utils.triggerMouseEvent;
beforeEach(function() {
jasmine.addMatchers(matchers);

Chart.helpers.merge(Chart.defaults.global, {
Chart.helpers.merge(Chart.defaults, {
animation: false,
legend: {display: false},
responsive: false,
Expand Down