comparison rhodecode/public/js/rhodecode.js @ 1465:ef31d0c6bae9 beta

Added smart color generator to rhodecode.js
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 12 Sep 2011 02:24:52 +0300
parents 9d9e491e2a21
children 974d6193b61a
comparison
equal deleted inserted replaced
1464:31ed19b1fdb9 1465:ef31d0c6bae9
41 41
42 // Replace the prototype property 42 // Replace the prototype property
43 return format; 43 return format;
44 44
45 }(); 45 }();
46
47
48 /**
49 * SmartColorGenerator
50 *
51 *usage::
52 * var CG = new ColorGenerator();
53 * var col = CG.getColor(key); //returns array of RGB
54 * 'rgb({0})'.format(col.join(',')
55 *
56 * @returns {ColorGenerator}
57 */
58 function ColorGenerator(){
59 this.GOLDEN_RATIO = 0.618033988749895;
60 this.CURRENT_RATIO = 0.22717784590367374 // this can be random
61 this.HSV_1 = 0.75;//saturation
62 this.HSV_2 = 0.95;
63 this.color;
64 this.cacheColorMap = {};
65 };
66
67 ColorGenerator.prototype = {
68 getColor:function(key){
69 if(this.cacheColorMap[key] !== undefined){
70 return this.cacheColorMap[key];
71 }
72 else{
73 this.cacheColorMap[key] = this.generateColor();
74 return this.cacheColorMap[key];
75 }
76 },
77 _hsvToRgb:function(h,s,v){
78 if (s == 0.0)
79 return [v, v, v];
80 i = parseInt(h * 6.0)
81 f = (h * 6.0) - i
82 p = v * (1.0 - s)
83 q = v * (1.0 - s * f)
84 t = v * (1.0 - s * (1.0 - f))
85 i = i % 6
86 if (i == 0)
87 return [v, t, p]
88 if (i == 1)
89 return [q, v, p]
90 if (i == 2)
91 return [p, v, t]
92 if (i == 3)
93 return [p, q, v]
94 if (i == 4)
95 return [t, p, v]
96 if (i == 5)
97 return [v, p, q]
98 },
99 generateColor:function(){
100 this.CURRENT_RATIO = this.CURRENT_RATIO+this.GOLDEN_RATIO;
101 this.CURRENT_RATIO = this.CURRENT_RATIO %= 1;
102 HSV_tuple = [this.CURRENT_RATIO, this.HSV_1, this.HSV_2]
103 RGB_tuple = this._hsvToRgb(HSV_tuple[0],HSV_tuple[1],HSV_tuple[2]);
104 function toRgb(v){
105 return ""+parseInt(v*256)
106 }
107 return [toRgb(RGB_tuple[0]),toRgb(RGB_tuple[1]),toRgb(RGB_tuple[2])];
108
109 }
110 }
111
112
113
114
46 115
47 /** 116 /**
48 * GLOBAL YUI Shortcuts 117 * GLOBAL YUI Shortcuts
49 */ 118 */
50 var YUC = YAHOO.util.Connect; 119 var YUC = YAHOO.util.Connect;