index.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Gauges</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  7. <meta name="HandheldFriendly" content="True" />
  8. <meta name="MobileOptimized" content="480" />
  9. <meta name="viewport"
  10. content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  11. <meta name="apple-mobile-web-app-capable" content="yes" />
  12. <meta name="theme-color" content="#2f434e" />
  13. <meta http-equiv="cleartype" content="on" />
  14. <link rel="stylesheet" href="index.css" />
  15. <link rel="stylesheet" href="dark.css" />
  16. <style>
  17. .example {
  18. overflow: auto;
  19. padding: 10px;
  20. box-sizing: border-box;
  21. clear: both;
  22. }
  23. .example > .code, .example > .display {
  24. box-sizing: border-box;
  25. padding: 10px;
  26. }
  27. .example > .code {
  28. }
  29. .example > .display {
  30. text-align: center;
  31. overflow: auto;
  32. padding: 20px 0;
  33. overflow: hidden;
  34. }
  35. .example > .display {
  36. }
  37. pre {
  38. padding: 0;
  39. margin: 0;
  40. }
  41. @media only screen and (min-device-width: 768px) {
  42. .example > .code {
  43. width: 65%;
  44. }
  45. .example > .display {
  46. width: 35%;
  47. }
  48. .example > .code {
  49. float: left;
  50. }
  51. .example > .display {
  52. float: right;
  53. padding: 10px;
  54. }
  55. }
  56. </style>
  57. <script type="text/javascript" src="highlight.pack.js"> </script>
  58. <script>hljs.initHighlightingOnLoad();</script>
  59. </head>
  60. <body>
  61. <h2>SVG Gauge</h2>
  62. <h4>Minimalistic, zero dependency animated gauge widget</h4>
  63. <p>
  64. All the guages are styled via CSS. See gauge-test.css for styling for each of these gauges
  65. below.
  66. </p>
  67. <div class="example">
  68. <div class="code">
  69. <pre>
  70. <code class="html">
  71. &lt;!-- Unstyled gauge (All defaults) --&gt;
  72. &lt;div id="gauge0" class="gauge-container"&gt;&lt;/div&gt;
  73. </code>
  74. <code class="javascript">
  75. var gauge0 = Gauge(document.getElementById("gauge0"));
  76. </code>
  77. </pre>
  78. </div>
  79. <div class="display">
  80. <div id="gauge0" class="gauge-container"></div>
  81. </div>
  82. </div>
  83. <div class="example">
  84. <div class="code">
  85. <pre>
  86. <code class="html"> &lt;div id="gauge1" class="gauge-container"&gt;&lt;/div&gt;</code>
  87. <code class="javascript">
  88. var gauge1 = Gauge(
  89. document.getElementById("gauge1"),
  90. {
  91. max: 100,
  92. dialStartAngle: -90,
  93. dialEndAngle: -90.001,
  94. value: 100,
  95. label: function(value) {
  96. return Math.round(value) + "/" + this.max;
  97. }
  98. }
  99. );
  100. </code>
  101. </pre>
  102. </div>
  103. <div class="display">
  104. <div id="gauge1" class="gauge-container one"></div>
  105. </div>
  106. </div>
  107. <div class="example">
  108. <div class="code">
  109. <pre>
  110. <code class="html">
  111. &lt;div id="gauge2" class="gauge-container two"&gt;&lt;/div&gt;
  112. </code>
  113. <code class="javascript">
  114. var gauge2 = Gauge(
  115. document.getElementById("gauge2"),
  116. {
  117. min: -100,
  118. max: 100,
  119. dialStartAngle: 180,
  120. dialEndAngle: 0,
  121. value: 50,
  122. viewBox: "0 0 100 57",
  123. color: function(value) {
  124. if(value < 20) {
  125. return "#5ee432";
  126. }else if(value < 40) {
  127. return "#fffa50";
  128. }else if(value < 60) {
  129. return "#f7aa38";
  130. }else {
  131. return "#ef4655";
  132. }
  133. }
  134. }
  135. );
  136. </code>
  137. </pre>
  138. </div>
  139. <div class="display">
  140. <div id="gauge2" class="gauge-container two"></div>
  141. </div>
  142. </div>
  143. <div class="example">
  144. <div class="code">
  145. <pre>
  146. <code class="html">
  147. &lt;div id="gauge3" class="gauge-container three"&gt;&lt;/div&gt;
  148. </code>
  149. <code class="javascript">
  150. var gauge3 = Gauge(
  151. document.getElementById("gauge3"),
  152. {
  153. max: 100,
  154. value: 50
  155. }
  156. );
  157. </code>
  158. </pre>
  159. </div>
  160. <div class="display">
  161. <div id="gauge3" class="gauge-container three"></div>
  162. </div>
  163. </div>
  164. <div class="example">
  165. <div class="code">
  166. <pre>
  167. <code class="html">
  168. &lt;div id="gauge4" class="gauge-container four"&gt;&lt;/div&gt;
  169. </code>
  170. <code class="javascript">
  171. var gauge4 = Gauge(
  172. document.getElementById("gauge4"),
  173. {
  174. max: 100,
  175. dialStartAngle: 180,
  176. dialEndAngle: -90,
  177. viewBox: "0 0 57 57",
  178. value: 50
  179. }
  180. );
  181. </code>
  182. </pre>
  183. </div>
  184. <div class="display">
  185. <div id="gauge4" class="gauge-container four"></div>
  186. </div>
  187. </div>
  188. <div class="example">
  189. <div class="code">
  190. <pre>
  191. <code class="html">
  192. &lt;div id="gauge5" class="gauge-container five"&gt;&lt;/div&gt;
  193. </code>
  194. <code class="javascript">
  195. var gauge5 = Gauge(
  196. document.getElementById("gauge5"),
  197. {
  198. max: 200,
  199. dialStartAngle: 0,
  200. dialEndAngle: -180,
  201. viewBox: "0 35 100 100",
  202. value: 50
  203. }
  204. );
  205. </code>
  206. </pre>
  207. </div>
  208. <div class="display">
  209. <div id="gauge5" class="gauge-container five"></div>
  210. </div>
  211. </div>
  212. <div class="example">
  213. <div class="code">
  214. <pre>
  215. <code class="html">
  216. &lt;div id="gauge6" class="gauge-container six"&gt;&lt;/div&gt;
  217. </code>
  218. <code class="javascript">
  219. var gauge6 = Gauge(
  220. document.getElementById("gauge6"),
  221. {
  222. max: 100,
  223. dialStartAngle: 90.01,
  224. dialEndAngle: 89.99,
  225. dialRadius: 150,
  226. showValue: false,
  227. value: 50,
  228. }
  229. );
  230. </code>
  231. </pre>
  232. </div>
  233. <div class="display">
  234. <div id="gauge6" class="gauge-container six"></div>
  235. </div>
  236. </div>
  237. <script type="text/javascript" src="../src/gauge.js"> </script>
  238. <script>
  239. var pad = function(tar) {}
  240. var gauge0 = Gauge(document.getElementById("gauge0"));
  241. var gauge1 = Gauge(
  242. document.getElementById("gauge1"),
  243. {
  244. max: 100,
  245. dialStartAngle: -90,
  246. dialEndAngle: -90.001,
  247. value: 100,
  248. label: function(value) {
  249. return (Math.round(value * 100) / 100) + "/" + this.max;
  250. }
  251. }
  252. );
  253. var gauge2 = Gauge(
  254. document.getElementById("gauge2"),
  255. {
  256. min: -100,
  257. max: 100,
  258. dialStartAngle: 180,
  259. dialEndAngle: 0,
  260. value: 50,
  261. viewBox: "0 0 100 57",
  262. color: function(value) {
  263. if(value < 20) {
  264. return "#5ee432";
  265. }else if(value < 40) {
  266. return "#fffa50";
  267. }else if(value < 60) {
  268. return "#f7aa38";
  269. }else {
  270. return "#ef4655";
  271. }
  272. }
  273. }
  274. );
  275. var gauge3 = Gauge(
  276. document.getElementById("gauge3"),
  277. {
  278. max: 100,
  279. value: 50
  280. }
  281. );
  282. var gauge4 = Gauge(
  283. document.getElementById("gauge4"),
  284. {
  285. max: 100,
  286. dialStartAngle: 180,
  287. dialEndAngle: -90,
  288. viewBox: "0 0 60 60",
  289. value: 50
  290. }
  291. );
  292. var gauge5 = Gauge(
  293. document.getElementById("gauge5"),
  294. {
  295. max: 200,
  296. dialStartAngle: 0,
  297. dialEndAngle: -180,
  298. viewBox: "0 35 100 100",
  299. value: 50
  300. }
  301. );
  302. var gauge6 = Gauge(
  303. document.getElementById("gauge6"),
  304. {
  305. max: 100,
  306. dialStartAngle: 90.01,
  307. dialEndAngle: 89.99,
  308. dialRadius: 15,
  309. showValue: false,
  310. value: 100
  311. }
  312. );
  313. (function loop() {
  314. var value1 = Math.random() * 100,
  315. value2 = Math.random(),
  316. value3 = Math.random() * 100,
  317. value4 = Math.random() * 100,
  318. value5 = Math.random() * 200;
  319. gauge0.setValue(value1, 1);
  320. gauge1.setValueAnimated(value1, 1);
  321. gauge2.setValueAnimated(50 - value1, 3);
  322. gauge3.setValueAnimated(value3, 1.5);
  323. gauge4.setValueAnimated(value4, 2);
  324. gauge5.setValueAnimated(value5, 1);
  325. gauge6.setValueAnimated(value1, 1);
  326. window.setTimeout(loop, 4000);
  327. })();
  328. </script>
  329. </body>
  330. </html>