gauge.html 4.5 KB

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