Commit 6eaeabcd authored by David Schnur's avatar David Schnur

Improve generation of color variations.

As the size of the variation increases, the resulting colors approach
white and black. To avoid this we now reset the variation when it gets
too large. This results in repeated colors, but that's much better than
a list full of whites and blacks.
parent c62cb307
...@@ -439,34 +439,32 @@ ...@@ -439,34 +439,32 @@
neededColors = maxIndex + 1; neededColors = maxIndex + 1;
} }
// Generate as many colors as necessary, using the provided // Generate the needed colors, based on the option colors
// 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;
i = 0;
while (colors.length < neededColors) {
var c;
if (options.colors.length == i) // check degenerate case
c = $.color.make(100, 100, 100);
else
c = $.color.parse(options.colors[i]);
// vary color if needed var c, colors = [], colorPool = options.colors,
var sign = variation % 2 == 1 ? -1 : 1; colorPoolSize = colorPool.length, variation = 0;
c.scale('rgb', 1 + sign * Math.ceil(variation / 2) * 0.2);
// FIXME: if we're getting to close to something else, for (i = 0; i < neededColors; i++) {
// we should probably skip this one
colors.push(c); c = $.color.parse(colorPool[i % colorPoolSize] || "#666");
++i; // Each time we exhaust the colors in the pool we adjust
if (i >= options.colors.length) { // a scaling factor used to produce more variations on
i = 0; // those colors. The factor alternates negative/positive
++variation; // to produce lighter/darker colors.
// Reset the variation after every few cycles, or else
// it will end up producing only white or black colors.
if (i % colorPoolSize == 0 && i) {
if (variation >= 0) {
if (variation < 0.5) {
variation = -variation - 0.2;
} else variation = 0;
} else variation = -variation;
} }
colors[i] = c.scale('rgb', 1 + variation);
} }
// Finalize the series options, filling in their colors // Finalize the series options, filling in their colors
......
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