Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.charting._color"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.charting._color"] = true;
3
dojo.provide("dojox.charting._color");
4
 
5
dojox.charting._color={};
6
dojox.charting._color.fromHsb=function(/* int */hue, /* int */saturation, /* int */brightness){
7
	//	summary
8
	//	Creates an instance of dojo.Color based on HSB input (360, %, %)
9
	hue=Math.round(hue);
10
	saturation=Math.round((saturation/100)*255);
11
	brightness=Math.round((brightness/100)*255);
12
 
13
	var r, g, b;
14
	if(saturation==0){
15
		r=g=b=brightness;
16
	} else {
17
		var tint1=brightness,
18
			tint2=(255-saturation)*brightness/255,
19
			tint3=(tint1-tint2)*(hue%60)/60;
20
		if(hue<60){ r=tint1, g=tint2+tint3, b=tint2; }
21
		else if(hue<120){ r=tint1-tint3, g=tint1, b=tint2; }
22
		else if(hue<180){ r=tint2, g=tint1, b=tint2+tint3; }
23
		else if(hue<240){ r=tint2, g=tint1-tint3, b=tint1; }
24
		else if(hue<300){ r=tint2+tint3, g=tint2, b=tint1; }
25
		else if(hue<360){ r=tint1, g=tint2, b=tint1-tint3; }
26
	}
27
 
28
	r=Math.round(r); g=Math.round(g); b=Math.round(b);
29
	return new dojo.Color({ r:r, g:g, b:b });
30
};
31
 
32
dojox.charting._color.toHsb=function(/* int|Object|dojo.Color */ red, /* int? */ green, /* int? */blue){
33
	//	summary
34
	//	Returns the color in HSB representation (360, %, %)
35
	var r=red,g=green,b=blue;
36
	if(dojo.isObject(red)){
37
		r=red.r,g=red.g,b=red.b;
38
	}
39
	var min=Math.min(r,g,b);
40
	var max=Math.max(r,g,b);
41
	var delta=max-min;
42
 
43
	var hue=0, saturation=(max!=0?delta/max:0), brightness=max/255;
44
	if(saturation==0){ hue=0; }
45
	else {
46
		if(r==max){ hue=((max-b)/delta)-((max-g)/delta); }
47
		else if(g==max){ hue=2+(((max-r)/delta)-((max-b)/delta)); }
48
		else { hue=4+(((max-g)/delta)-((max-r)/delta)); }
49
		hue/=6;
50
		if(hue<0) hue++;
51
	}
52
 
53
	hue=Math.round(hue*360);
54
	saturation=Math.round(saturation*100);
55
	brightness=Math.round(brightness*100);
56
	return {
57
		h:hue, s:saturation, b:brightness,
58
		hue:hue, saturation:saturation, brightness:brightness
59
	};	//	Object
60
};
61
 
62
}