Commit c62cb307 authored by David Schnur's avatar David Schnur

Optimize and tidy up calculation of neededColors.

parent f1f599f6
...@@ -416,31 +416,36 @@ ...@@ -416,31 +416,36 @@
} }
function fillInSeriesOptions() { function fillInSeriesOptions() {
var i;
// collect what we already got of colors var neededColors = series.length, maxIndex = 0, i;
var neededColors = series.length,
usedColors = [], // Subtract the number of series that already have fixed
assignedColors = []; // colors from the number we need to generate.
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
var sc = series[i].color; var sc = series[i].color;
if (sc != null) { if (sc != null) {
--neededColors; neededColors--;
if (typeof sc == "number") if (typeof sc == "number" && sc > maxIndex) {
assignedColors.push(sc); maxIndex = sc;
else }
usedColors.push($.color.parse(series[i].color));
} }
} }
// we might need to generate more colors if higher indices // If any of the user colors are numeric indexes, then we
// are assigned // need to generate at least as many as the highest index.
for (i = 0; i < assignedColors.length; ++i) {
neededColors = Math.max(neededColors, assignedColors[i] + 1); if (maxIndex > neededColors) {
neededColors = maxIndex + 1;
} }
// produce colors as needed // Generate as many colors as necessary, using the provided
// colors as a base and alternatingly increasing/decreasing
// their luminosity in steps that grow smaller each time we
// hit the edge of the color space.
var colors = [], variation = 0; var colors = [], variation = 0;
i = 0; i = 0;
while (colors.length < neededColors) { while (colors.length < neededColors) {
var c; var c;
...@@ -464,7 +469,8 @@ ...@@ -464,7 +469,8 @@
} }
} }
// fill in the options // Finalize the series options, filling in their colors
var colori = 0, s; var colori = 0, s;
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment