github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/colors/chart_colors.go (about) 1 // Package colors contains some simple RGB color scheme 2 // for the chart package; it can vary the shade of a given color. 3 package colors 4 5 import "fmt" 6 7 var GraphColors [][]uint8 8 9 // http://ksrowell.com/blog-visualizing-data/2012/02/02/optimal-colors-for-graphs/ 10 var Colors = [][]uint8{ 11 []uint8{114, 147, 203}, 12 []uint8{225, 151, 76}, 13 []uint8{132, 186, 91}, 14 []uint8{211, 94, 96}, 15 16 []uint8{128, 133, 133}, 17 []uint8{144, 103, 157}, 18 []uint8{171, 104, 87}, 19 []uint8{204, 194, 15}, 20 21 []uint8{57, 106, 177}, 22 []uint8{218, 124, 48}, 23 []uint8{62, 150, 81}, 24 []uint8{204, 37, 41}, 25 26 []uint8{83, 81, 84}, 27 []uint8{107, 76, 154}, 28 []uint8{146, 36, 40}, 29 []uint8{148, 139, 61}, 30 } 31 32 func init() { 33 GraphColors = Colors 34 35 // colorizer := Colorizer(1) 36 // for i := 0; i < 5; i++ { 37 // pf("%v \n", colorizer()) 38 // } 39 40 } 41 42 func PreventOverFlow(base uint8, summand int) uint8 { 43 44 if int(base)+summand < 0 { 45 return uint8(0) 46 } 47 if int(base)+summand > 255 { 48 return uint8(255) 49 } 50 51 if summand > 0 { 52 return base + uint8(summand) 53 } else { 54 return base - uint8(-summand) 55 } 56 57 } 58 59 func AlternatingColorShades(idxColor int, idx int) string { 60 61 idxCol := (idxColor + 4) % len(Colors) 62 63 const step = 25 64 const steps = 4 65 variation := 0 66 67 idx = idx % steps // revolve 68 69 // alternate even - uneven 70 if idx%2 == 0 { 71 variation = (idx + 0) * step 72 } else { 73 variation = (idx + 2) * step // stronger distincting between alternating elements 74 } 75 76 // %x is the hex format, %2.2x makes padding zeros 77 col := fmt.Sprintf("%2.2x%2.2x%2.2x", 78 PreventOverFlow(Colors[idxCol][0], variation), 79 PreventOverFlow(Colors[idxCol][1], variation), 80 PreventOverFlow(Colors[idxCol][2], variation), 81 ) 82 83 return col 84 85 }