Skip to content

Bug #442 - Border Color #462

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
17 changes: 10 additions & 7 deletions angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,18 @@
var dataset = {
labels: labels,
datasets: [{
data: data,
backgroundColor: colors.map(function (color) {
return color.pointBackgroundColor;
}),
hoverBackgroundColor: colors.map(function (color) {
return color.backgroundColor;
})
data: data
}]
};
colors.map(function (color) {
Object.keys(color).forEach(function (key) {
var d = dataset.datasets[0][key];
if (d === undefined) {
d = dataset.datasets[0][key] = []
}
d.push(color[key])
});
});
if (datasetOverride) {
angular.merge(dataset.datasets[0], datasetOverride);
}
Expand Down
17 changes: 10 additions & 7 deletions dist/angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,18 @@
var dataset = {
labels: labels,
datasets: [{
data: data,
backgroundColor: colors.map(function (color) {
return color.pointBackgroundColor;
}),
hoverBackgroundColor: colors.map(function (color) {
return color.backgroundColor;
})
data: data
}]
};
colors.map(function (color) {
Copy link
Owner

@jtblin jtblin Aug 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map returns a newly created array which is not needed here, so use forEach instead.

Object.keys(color).forEach(function (key) {
Copy link
Owner

@jtblin jtblin Aug 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.keys(color) is going to loop through all the properties of the colors object and create an array from the keys. Doing that on each color iteration is not super efficient, it would be better to have the keys in a constant so that we don't need to repeat that on every iteration (the keys from the color object don't change).

var d = dataset.datasets[0][key];
if (d === undefined) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to test for undefined is typeof d === 'undefined'. Personally I prefer the short handler: if (! d) d = dataset.datasets[0][key] = [].

d = dataset.datasets[0][key] = []
}
d.push(color[key])
});
});
if (datasetOverride) {
angular.merge(dataset.datasets[0], datasetOverride);
}
Expand Down
Binary file modified dist/angular-chart.js.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/angular-chart.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-chart.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/fixtures/51-pie-update-colours.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
$scope.labels = ['Series A', 'Series B'];
$scope.data = [65, 59];
$scope.colors = [{ // red
backgroundColor: 'rgba(247,70,74,0.2)',
backgroundColor: 'rgba(247,70,74,1)',
borderColor: 'rgba(247,70,74,1)',
pointBackgroundColor: 'rgba(247,70,74,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(247,70,74,0.8)'
},
{ // green
backgroundColor: 'rgba(70,191,189,0.2)',
backgroundColor: 'rgba(70,191,189,1)',
borderColor: 'rgba(70,191,189,1)',
pointBackgroundColor: 'rgba(70,191,189,1)',
pointBorderColor: '#fff',
Expand Down
Binary file modified test/fixtures/54-not-enough-colours.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/charts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/dataset-override.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.