/src/com/google/maps/extras/gradients/ValueColorGradient.as

http://gmaps-utility-library-flash.googlecode.com/ · ActionScript · 98 lines · 54 code · 12 blank · 32 comment · 0 complexity · e69667a2653e4dd82839f3656d7f5c43 MD5 · raw file

  1. /**
  2. * Copyright 2009 Google Inc.
  3. * Licensed under the Apache License, Version 2.0:
  4. * http://www.apache.org/licenses/LICENSE-2.0
  5. */
  6. package com.google.maps.extras.gradients {
  7. import flash.errors.IllegalOperationError;
  8. import com.google.maps.Color;
  9. /**
  10. * ValueColorGradient is an internal class that's used by GradientControl
  11. * objects for storing final gradient lists. Certain functions are declared
  12. * public only so that the subclasses could have them public too.
  13. *
  14. * @author Simon Ilyushchenko
  15. */
  16. public class ValueColorGradient extends Range {
  17. /**
  18. * Class constructor
  19. */
  20. function ValueColorGradient() {
  21. super(this);
  22. }
  23. /**
  24. * Apply the scaling calculations to translate the specfied number
  25. * into a color within this object's range.
  26. */
  27. public function colorForValue(someValue:Number):Number {
  28. var valueDict:Object = getValueDict();
  29. var rgbColorDict:Object = getRgbColorDict();
  30. var r:Number = GradientUtil.linearScale(
  31. valueDict, rgbColorDict['r'], someValue);
  32. var g:Number = GradientUtil.linearScale(
  33. valueDict, rgbColorDict['g'], someValue);
  34. var b:Number = GradientUtil.linearScale(
  35. valueDict, rgbColorDict['b'], someValue);
  36. var result:Color = new Color(0);
  37. result.setRGB(r, g, b);
  38. return result.rgb;
  39. }
  40. // Percentage values are not used with ValueColorGradients
  41. /**
  42. * @throws flash.errors.IllegalOperationError Always.
  43. */
  44. public override function get minPercent():Number {
  45. throw new IllegalOperationError(
  46. "ValueColorGradient can't specify percentages.");
  47. }
  48. /**
  49. * @throws flash.errors.IllegalOperationError Always.
  50. */
  51. public override function set minPercent(someValue:Number):void {
  52. throw new IllegalOperationError(
  53. "ValueColorGradient can't specify percentages.");
  54. }
  55. /**
  56. * @throws flash.errors.IllegalOperationError Always.
  57. */
  58. public override function get maxPercent():Number {
  59. throw new IllegalOperationError(
  60. "ValueColorGradient can't specify percentages.");
  61. }
  62. /**
  63. * @throws flash.errors.IllegalOperationError Always.
  64. */
  65. public override function set maxPercent(someValue:Number):void {
  66. throw new IllegalOperationError(
  67. "ValueColorGradient can't specify percentages.");
  68. }
  69. function containsValue(someValue:Number):Boolean {
  70. return someValue < maxValue;
  71. }
  72. protected function numFlatGradients():int {
  73. return 1;
  74. }
  75. protected function flatGradientAt(i:int):ValueColorGradient {
  76. return this;
  77. }
  78. public override function toString():String {
  79. return ([
  80. "ValueColorGradient: ",
  81. "value: " + minValue.toString() + " - " + maxValue.toString(),
  82. "color: " + rgbColorDictString()
  83. ]).join(", ");
  84. }
  85. }
  86. }