Skip to content

Commit a160255

Browse files
committed
avoid repeated colors in donuts
1 parent 41f5cb6 commit a160255

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/main/resources/static/charts.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,22 @@ function donutChart(objectName, data) {
7878
});
7979

8080
function createColorArray(length) {
81-
let array = [];
82-
while (array.length < length) {
83-
array = array.concat([
84-
"#54ca76",
85-
"#f5c452",
86-
"#f2637f",
87-
"#9261f3",
88-
"#31a4e6",
89-
"#55cbcb",
90-
]);
91-
}
81+
82+
const colors = [
83+
"#54ca76",
84+
"#f5c452",
85+
"#f2637f",
86+
"#9261f3",
87+
"#31a4e6",
88+
"#55cbcb"
89+
];
90+
91+
let array = [...Array(length).keys()].map(i => colors[i % colors.length]);
92+
93+
// avoid first and last colors being the same
94+
if (length % colors.length === 1)
95+
array[length - 1] = colors[1];
96+
9297
return array;
9398
}
9499

0 commit comments

Comments
 (0)