5a93ae2e4bc077ced30e5cdc1eb027e5bb4a875c.svn-base 2.4 KB

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