Tuesday, December 09, 2008

Yet more color stuff for charts and beyond

I can't believe I'm spelling colour the American way?!

Anyways, here's a ColorProvider I built based around the Dundas/Microsoft Chart Control - it's just got a simple iteration and raw color access API - I'm sure you'll have no problems understanding it.

See my earlier post for more info about where the Colors come from.


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace SlodgeRoutesTools
{
public class ColorProvider
{
readonly List myColors = null;
int myCurrent = -1;

public List Colors
{
get
{
return myColors;
}
}

public void Reset()
{
myCurrent = -1;
}

public Color GetNextColor()
{
myCurrent++;
myCurrent %= myColors.Count;
return myColors[myCurrent];
}

public ColorProvider(List colors)
{
myColors = colors;
}

public static ColorProvider GetColorProvider()
{
return GetColorProvider(ColorProviderPalette.Default);
}

public static ColorProvider GetColorProvider(ColorProviderPalette palette)
{
return new ColorProvider(GetColors(palette));
}

public enum ColorProviderPalette
{
Default,
Pastel,
Berry,
Fire,
SeaGreen,
EarthTones,
Excel,
GrayScale,
Chocolate,
Special,
Light


}

private static List GetColors(ColorProviderPalette palette)
{
switch (palette)
{
case ColorProviderPalette.Pastel:
return new List()
{
// pastel
Color.FromArgb(255, 135, 206, 235),
Color.FromArgb(255, 50, 205, 50),
Color.FromArgb(255, 186, 85, 211),
Color.FromArgb(255, 240, 128, 128),
Color.FromArgb(255, 70, 130, 180),
Color.FromArgb(255, 154, 205, 50),
Color.FromArgb(255, 64, 224, 208),
Color.FromArgb(255, 255, 105, 180),
Color.FromArgb(255, 240, 230, 140),
Color.FromArgb(255, 210, 180, 140),
Color.FromArgb(255, 143, 188, 139),
Color.FromArgb(255, 100, 149, 237),
Color.FromArgb(255, 221, 160, 221),
Color.FromArgb(255, 95, 158, 160),
Color.FromArgb(255, 255, 218, 185),
Color.FromArgb(255, 255, 160, 122)
};

case ColorProviderPalette.Special:
return new List()
{
// special - was originally Dundas
Color.FromArgb(255, 65, 140, 240),
Color.FromArgb(255, 252, 180, 65),
Color.FromArgb(255, 224, 64, 10),
Color.FromArgb(255, 5, 100, 146),
Color.FromArgb(255, 191, 191, 191),
Color.FromArgb(255, 26, 59, 105),
Color.FromArgb(255, 255, 227, 130),
Color.FromArgb(255, 18, 156, 221),
Color.FromArgb(255, 202, 107, 75),
Color.FromArgb(255, 0, 92, 219),
Color.FromArgb(255, 243, 210, 136),
Color.FromArgb(255, 80, 99, 129),
Color.FromArgb(255, 241, 185, 168),
Color.FromArgb(255, 224, 131, 10),
Color.FromArgb(255, 120, 147, 190)
};

case ColorProviderPalette.EarthTones:
return new List()
{
// earth tones
Color.FromArgb(255, 255, 128, 0),
Color.FromArgb(255, 184, 134, 11),
Color.FromArgb(255, 192, 64, 0),
Color.FromArgb(255, 107, 142, 35),
Color.FromArgb(255, 205, 133, 63),
Color.FromArgb(255, 192, 192, 0),
Color.FromArgb(255, 34, 139, 34),
Color.FromArgb(255, 210, 105, 30),
Color.FromArgb(255, 128, 128, 0),
Color.FromArgb(255, 32, 178, 170),
Color.FromArgb(255, 244, 164, 96),
Color.FromArgb(255, 0, 192, 0),
Color.FromArgb(255, 143, 188, 139),
Color.FromArgb(255, 178, 34, 34),
Color.FromArgb(255, 139, 69, 19),
Color.FromArgb(255, 192, 0, 0),
};
case ColorProviderPalette.Excel:
return new List()
{
// excel
Color.FromArgb(255, 153, 153, 255),
Color.FromArgb(255, 153, 51, 102),
Color.FromArgb(255, 255, 255, 204),
Color.FromArgb(255, 204, 255, 255),
Color.FromArgb(255, 102, 0, 102),
Color.FromArgb(255, 255, 128, 128),
Color.FromArgb(255, 0, 102, 204),
Color.FromArgb(255, 204, 204, 255),
Color.FromArgb(255, 0, 0, 128),
Color.FromArgb(255, 255, 0, 255),
Color.FromArgb(255, 255, 255, 0),
Color.FromArgb(255, 0, 255, 255),
Color.FromArgb(255, 128, 0, 128),
Color.FromArgb(255, 128, 0, 0),
Color.FromArgb(255, 0, 128, 128),
Color.FromArgb(255, 0, 0, 255)
};
case ColorProviderPalette.GrayScale:
return new List()
{
// grayscale
Color.FromArgb(255, 189, 189, 189),
Color.FromArgb(255, 178, 178, 178),
Color.FromArgb(255, 167, 167, 167),
Color.FromArgb(255, 156, 156, 156),
Color.FromArgb(255, 145, 145, 145),
Color.FromArgb(255, 134, 134, 134),
Color.FromArgb(255, 123, 123, 123),
Color.FromArgb(255, 112, 112, 112),
Color.FromArgb(255, 101, 101, 101),
Color.FromArgb(255, 90, 90, 90),
Color.FromArgb(255, 79, 79, 79),
Color.FromArgb(255, 68, 68, 68),
Color.FromArgb(255, 57, 57, 57),
Color.FromArgb(255, 46, 46, 46),
Color.FromArgb(255, 35, 35, 35)
};
case ColorProviderPalette.Light:
return new List()
{
// light
Color.FromArgb(255, 230, 230, 250),
Color.FromArgb(255, 255, 240, 245),
Color.FromArgb(255, 255, 218, 185),
Color.FromArgb(255, 255, 250, 205),
Color.FromArgb(255, 255, 228, 225),
Color.FromArgb(255, 240, 255, 240),
Color.FromArgb(255, 240, 248, 255),
Color.FromArgb(255, 245, 245, 245),
Color.FromArgb(255, 250, 235, 215),
Color.FromArgb(255, 224, 255, 255)
};
case ColorProviderPalette.SeaGreen:
return new List()
{
// seaGreen
Color.FromArgb(255, 46, 139, 87),
Color.FromArgb(255, 102, 205, 170),
Color.FromArgb(255, 70, 130, 180),
Color.FromArgb(255, 0, 139, 139),
Color.FromArgb(255, 95, 158, 160),
Color.FromArgb(255, 60, 179, 113),
Color.FromArgb(255, 72, 209, 204),
Color.FromArgb(255, 176, 196, 222),
Color.FromArgb(255, 143, 188, 139),
Color.FromArgb(255, 135, 206, 235)
};
case ColorProviderPalette.Berry:
return new List()
{
// berry
Color.FromArgb(255, 138, 43, 226),
Color.FromArgb(255, 186, 85, 211),
Color.FromArgb(255, 65, 105, 225),
Color.FromArgb(255, 199, 21, 133),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 138, 43, 226),
Color.FromArgb(255, 218, 112, 214),
Color.FromArgb(255, 123, 104, 238),
Color.FromArgb(255, 192, 0, 192),
Color.FromArgb(255, 0, 0, 205),
Color.FromArgb(255, 128, 0, 128)
};
case ColorProviderPalette.Fire:
return new List()
{
// fire
Color.FromArgb(255, 255, 215, 0),
Color.FromArgb(255, 255, 0, 0),
Color.FromArgb(255, 255, 20, 147),
Color.FromArgb(255, 220, 20, 60),
Color.FromArgb(255, 255, 140, 0),
Color.FromArgb(255, 255, 0, 255),
Color.FromArgb(255, 255, 255, 0),
Color.FromArgb(255, 255, 69, 0),
Color.FromArgb(255, 199, 21, 133),
Color.FromArgb(255, 221, 226, 33)
};

case ColorProviderPalette.Chocolate:
return new List()
{
// chocolate
Color.FromArgb(255, 160, 82, 45),
Color.FromArgb(255, 210, 105, 30),
Color.FromArgb(255, 139, 0, 0),
Color.FromArgb(255, 205, 133, 63),
Color.FromArgb(255, 165, 42, 42),
Color.FromArgb(255, 244, 164, 96),
Color.FromArgb(255, 139, 69, 19),
Color.FromArgb(255, 192, 64, 0),
Color.FromArgb(255, 178, 34, 34),
Color.FromArgb(255, 182, 92, 58)
};
case ColorProviderPalette.Default:
default:
return new List()
{
Color.FromArgb(255, 0, 128, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 128, 0, 128),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 255, 0, 255),
Color.FromArgb(255, 0, 128, 128),
Color.FromArgb(255, 255, 255, 0),
Color.FromArgb(255, 128, 128, 128),
Color.FromArgb(255, 0, 255, 255),
Color.FromArgb(255, 0, 0, 128),
Color.FromArgb(255, 128, 0, 0),
Color.FromArgb(255, 255, 0, 0),
Color.FromArgb(255, 128, 128, 0),
Color.FromArgb(255, 192, 192, 192),
Color.FromArgb(255, 255, 99, 71),
Color.FromArgb(255, 255, 228, 181)
};
}
}
}
}

No comments:

Post a Comment