| 1 |
// Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
|
| 16 |
/** |
| 17 |
* @fileoverview The color theme used by a gauge (goog.ui.Gauge). |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
goog.provide('goog.ui.GaugeTheme'); |
| 22 |
|
| 23 |
|
| 24 |
goog.require('goog.graphics.LinearGradient'); |
| 25 |
goog.require('goog.graphics.SolidFill'); |
| 26 |
goog.require('goog.graphics.Stroke'); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* A class for the default color theme for a Gauge. |
| 32 |
* Users can extend this class to provide a custom color theme, and apply the |
| 33 |
* custom color theme by calling {@link goog.ui.Gauge#setTheme}. |
| 34 |
* @constructor |
| 35 |
* @final |
| 36 |
*/ |
| 37 |
goog.ui.GaugeTheme = function() {}; |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Returns the stroke for the external border of the gauge. |
| 42 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 43 |
*/ |
| 44 |
goog.ui.GaugeTheme.prototype.getExternalBorderStroke = function() { |
| 45 |
return new goog.graphics.Stroke(1, '#333333'); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the fill for the external border of the gauge. |
| 51 |
* @param {number} cx X coordinate of the center of the gauge. |
| 52 |
* @param {number} cy Y coordinate of the center of the gauge. |
| 53 |
* @param {number} r Radius of the gauge. |
| 54 |
* @return {!goog.graphics.Fill} The fill to use. |
| 55 |
*/ |
| 56 |
goog.ui.GaugeTheme.prototype.getExternalBorderFill = function(cx, cy, r) { |
| 57 |
return new goog.graphics.LinearGradient( |
| 58 |
cx + r, cy - r, cx - r, cy + r, '#f7f7f7', '#cccccc'); |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
/** |
| 63 |
* Returns the stroke for the internal border of the gauge. |
| 64 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 65 |
*/ |
| 66 |
goog.ui.GaugeTheme.prototype.getInternalBorderStroke = function() { |
| 67 |
return new goog.graphics.Stroke(2, '#e0e0e0'); |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the fill for the internal border of the gauge. |
| 73 |
* @param {number} cx X coordinate of the center of the gauge. |
| 74 |
* @param {number} cy Y coordinate of the center of the gauge. |
| 75 |
* @param {number} r Radius of the gauge. |
| 76 |
* @return {!goog.graphics.Fill} The fill to use. |
| 77 |
*/ |
| 78 |
goog.ui.GaugeTheme.prototype.getInternalBorderFill = function(cx, cy, r) { |
| 79 |
return new goog.graphics.SolidFill('#f7f7f7'); |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Returns the stroke for the major ticks of the gauge. |
| 85 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 86 |
*/ |
| 87 |
goog.ui.GaugeTheme.prototype.getMajorTickStroke = function() { |
| 88 |
return new goog.graphics.Stroke(2, '#333333'); |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* Returns the stroke for the minor ticks of the gauge. |
| 94 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 95 |
*/ |
| 96 |
goog.ui.GaugeTheme.prototype.getMinorTickStroke = function() { |
| 97 |
return new goog.graphics.Stroke(1, '#666666'); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
/** |
| 102 |
* Returns the stroke for the hinge at the center of the gauge. |
| 103 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 104 |
*/ |
| 105 |
goog.ui.GaugeTheme.prototype.getHingeStroke = function() { |
| 106 |
return new goog.graphics.Stroke(1, '#666666'); |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
/** |
| 111 |
* Returns the fill for the hinge at the center of the gauge. |
| 112 |
* @param {number} cx X coordinate of the center of the gauge. |
| 113 |
* @param {number} cy Y coordinate of the center of the gauge. |
| 114 |
* @param {number} r Radius of the hinge. |
| 115 |
* @return {!goog.graphics.Fill} The fill to use. |
| 116 |
*/ |
| 117 |
goog.ui.GaugeTheme.prototype.getHingeFill = function(cx, cy, r) { |
| 118 |
return new goog.graphics.LinearGradient( |
| 119 |
cx + r, cy - r, cx - r, cy + r, '#4684ee', '#3776d6'); |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
/** |
| 124 |
* Returns the stroke for the gauge needle. |
| 125 |
* @return {!goog.graphics.Stroke} The stroke to use. |
| 126 |
*/ |
| 127 |
goog.ui.GaugeTheme.prototype.getNeedleStroke = function() { |
| 128 |
return new goog.graphics.Stroke(1, '#c63310'); |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
/** |
| 133 |
* Returns the fill for the hinge at the center of the gauge. |
| 134 |
* @param {number} cx X coordinate of the center of the gauge. |
| 135 |
* @param {number} cy Y coordinate of the center of the gauge. |
| 136 |
* @param {number} r Radius of the gauge. |
| 137 |
* @return {!goog.graphics.Fill} The fill to use. |
| 138 |
*/ |
| 139 |
goog.ui.GaugeTheme.prototype.getNeedleFill = function(cx, cy, r) { |
| 140 |
// Make needle a bit transparent so that text underneeth is still visible. |
| 141 |
return new goog.graphics.SolidFill('#dc3912', 0.7); |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
/** |
| 146 |
* Returns the color for the gauge title. |
| 147 |
* @return {string} The color to use. |
| 148 |
*/ |
| 149 |
goog.ui.GaugeTheme.prototype.getTitleColor = function() { |
| 150 |
return '#333333'; |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
/** |
| 155 |
* Returns the color for the gauge value. |
| 156 |
* @return {string} The color to use. |
| 157 |
*/ |
| 158 |
goog.ui.GaugeTheme.prototype.getValueColor = function() { |
| 159 |
return 'black'; |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
/** |
| 164 |
* Returns the color for the labels (formatted values) of tick marks. |
| 165 |
* @return {string} The color to use. |
| 166 |
*/ |
| 167 |
goog.ui.GaugeTheme.prototype.getTickLabelColor = function() { |
| 168 |
return '#333333'; |
| 169 |
}; |