| 1 |
<!DOCTYPE HTML> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<head> |
| 10 |
<title>goog.ui.Gauge</title> |
| 11 |
<link rel="stylesheet" href="css/demo.css"> |
| 12 |
<style> |
| 13 |
.type { font-size:14px; font-weight:bold; font-family:arial; background-color:#f7f7f7; text-align:center } |
| 14 |
</style> |
| 15 |
<script src="../base.js"></script> |
| 16 |
<script> |
| 17 |
goog.require('goog.dom'); |
| 18 |
goog.require('goog.graphics'); |
| 19 |
goog.require('goog.graphics.Font'); |
| 20 |
goog.require('goog.graphics.LinearGradient'); |
| 21 |
goog.require('goog.graphics.SolidFill'); |
| 22 |
goog.require('goog.graphics.Stroke'); |
| 23 |
goog.require('goog.ui.Gauge'); |
| 24 |
goog.require('goog.ui.GaugeTheme'); |
| 25 |
</script> |
| 26 |
<script> |
| 27 |
|
| 28 |
var CustomGaugeTheme = function() { |
| 29 |
} |
| 30 |
goog.inherits(CustomGaugeTheme, goog.ui.GaugeTheme); |
| 31 |
|
| 32 |
CustomGaugeTheme.prototype.getInternalBorderFill = function(cx, cy, r) { |
| 33 |
return new goog.graphics.SolidFill("#8080ff"); |
| 34 |
} |
| 35 |
|
| 36 |
CustomGaugeTheme.prototype.getExternalBorderFill = function(cx, cy, r) { |
| 37 |
return new goog.graphics.SolidFill("#8080c0"); |
| 38 |
} |
| 39 |
|
| 40 |
CustomGaugeTheme.prototype.getInternalBorderStroke = function() { |
| 41 |
return new goog.graphics.Stroke(2, "#ffff00"); |
| 42 |
} |
| 43 |
|
| 44 |
CustomGaugeTheme.prototype.getMajorTickStroke = function() { |
| 45 |
return new goog.graphics.Stroke(2, "#ffffff"); |
| 46 |
} |
| 47 |
|
| 48 |
CustomGaugeTheme.prototype.getHingeStroke = function() { |
| 49 |
return new goog.graphics.Stroke(1, "#00a000"); |
| 50 |
} |
| 51 |
|
| 52 |
CustomGaugeTheme.prototype.getHingeFill = function(cx, cy, r) { |
| 53 |
return new goog.graphics.SolidFill("#00c000"); |
| 54 |
} |
| 55 |
|
| 56 |
CustomGaugeTheme.prototype.getNeedleStroke = function() { |
| 57 |
return new goog.graphics.Stroke(1, "#008040"); |
| 58 |
} |
| 59 |
|
| 60 |
CustomGaugeTheme.prototype.getNeedleFill = function(cx, cy, r) { |
| 61 |
return new goog.graphics.SolidFill("#008040", 0.7); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
var interactiveGauge; |
| 66 |
|
| 67 |
function setupGauges() { |
| 68 |
var gauge = new goog.ui.Gauge(120, 120); |
| 69 |
gauge.setValue(33); |
| 70 |
gauge.render(document.getElementById('basic')); |
| 71 |
|
| 72 |
var gauge = new goog.ui.Gauge(200, 200); |
| 73 |
gauge.addBackgroundColor(50, 60, goog.ui.Gauge.RED); |
| 74 |
gauge.addBackgroundColor(35, 50, goog.ui.Gauge.YELLOW); |
| 75 |
gauge.addBackgroundColor(15, 25, goog.ui.Gauge.GREEN); |
| 76 |
gauge.setMinimum(15); |
| 77 |
gauge.setMaximum(60); |
| 78 |
gauge.setTicks(3, 6); |
| 79 |
gauge.setValue(40); |
| 80 |
gauge.setTitleBottom("RPM"); |
| 81 |
gauge.render(document.getElementById('colors')); |
| 82 |
|
| 83 |
|
| 84 |
interactiveGauge = new goog.ui.Gauge(300, 200); |
| 85 |
interactiveGauge.addBackgroundColor(0, 30, goog.ui.Gauge.RED); |
| 86 |
interactiveGauge.addBackgroundColor(75, 90, goog.ui.Gauge.YELLOW); |
| 87 |
interactiveGauge.addBackgroundColor(90, 100, goog.ui.Gauge.RED); |
| 88 |
interactiveGauge.setTitleTop("CPU Utilization"); |
| 89 |
interactiveGauge.setTicks(5, 2); |
| 90 |
interactiveGauge.setMajorTickLabels(['Idle', '20%', '40%', '60%', '80%', 'Argh']); |
| 91 |
setValue(); |
| 92 |
interactiveGauge.render(document.getElementById('interactive')); |
| 93 |
|
| 94 |
var gauge = new goog.ui.Gauge(200, 200); |
| 95 |
gauge.setMinimum(-30); |
| 96 |
gauge.setMaximum(30); |
| 97 |
gauge.setTicks(10, 0); |
| 98 |
gauge.setValue(20); |
| 99 |
var theme = new CustomGaugeTheme(); |
| 100 |
gauge.setTheme(theme); |
| 101 |
gauge.render(document.getElementById('customcolors')); |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
function setValue() { |
| 106 |
var sv = document.getElementById("v1").value |
| 107 |
var v = parseInt(sv, 10); |
| 108 |
if (isNaN(v)) { |
| 109 |
v = 0; |
| 110 |
} |
| 111 |
interactiveGauge.setValue(v, v + "%"); |
| 112 |
} |
| 113 |
</script> |
| 114 |
|
| 115 |
</head> |
| 116 |
|
| 117 |
<body> |
| 118 |
<h1>goog.ui.Gauge</h1> |
| 119 |
<h2>Note: This component requires vector graphics support</h2> |
| 120 |
<table border="1"> |
| 121 |
<tr valign="top"> |
| 122 |
<td class="type"> |
| 123 |
Basic |
| 124 |
</td> |
| 125 |
<td class="type"> |
| 126 |
Background colors, title. custom ticks |
| 127 |
</td> |
| 128 |
<td class="type"> |
| 129 |
Value change, formatted value, tick labels |
| 130 |
</td> |
| 131 |
<td class="type"> |
| 132 |
Custom colors |
| 133 |
</td> |
| 134 |
</tr> |
| 135 |
<tr> |
| 136 |
<td style="width: 120px"> |
| 137 |
<span id="basic"></span> |
| 138 |
</td> |
| 139 |
<td style="width: 200px"> |
| 140 |
<span id="colors"></span> |
| 141 |
</td> |
| 142 |
<td style="width: 300px"> |
| 143 |
<span id="interactive"></span> |
| 144 |
<center> |
| 145 |
<input type="text" size="3" value="22" id="v1" /> |
| 146 |
<input type="button" onclick="setValue()" value="Set" /> |
| 147 |
</center> |
| 148 |
</td> |
| 149 |
<td style="width: 200px"> |
| 150 |
<span id="customcolors"></span> |
| 151 |
</td> |
| 152 |
</tr> |
| 153 |
</table> |
| 154 |
<script> |
| 155 |
setupGauges(); |
| 156 |
</script> |
| 157 |
</body> |
| 158 |
</html> |