index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>gauge.js</title>
  5. <meta name="description" content="100% native and cool looking animated JavaScript/CoffeeScript gauge">
  6. <meta name="viewport" content="width=1024, maximum-scale=1">
  7. <meta property="og:image" content="http://bernii.github.com/gauge.js/assets/preview.jpg?v=1" />
  8. <link rel="shortcut icon" href="favicon.ico">
  9. <meta http-equiv="X-UA-Compatible" content="IE=7" />
  10. <link href="assets/bootstrap.min.css" type="text/css" rel="stylesheet">
  11. <link href="assets/main.css?v=5" type="text/css" rel="stylesheet">
  12. <link href='http://fonts.googleapis.com/css?family=Amaranth:400,700|Just+Another+Hand' rel='stylesheet' type='text/css'>
  13. <link href="assets/prettify.css" type="text/css" rel="stylesheet">
  14. <link rel="stylesheet" type="text/css" href="assets/fd-slider/fd-slider.css?v=2">
  15. <link rel="stylesheet" type="text/css" href="assets/fd-slider/fd-slider-tooltip.css">
  16. <script type="text/javascript" src="assets/prettify.js"></script>
  17. <script type="text/javascript" src="assets/jscolor.js"></script>
  18. <!--[if lt IE 9]><script type="text/javascript" src="assets/excanvas.compiled.js"></script><![endif]-->
  19. </head>
  20. <body>
  21. <div id="logo">
  22. <h1>gauge.js</h1>
  23. <h2>100% native and cool looking animated JavaScript/CoffeeScript gauge</h2>
  24. <div id="its-coffee">coffee</div>
  25. <div id="strike-it"></div>
  26. <!--
  27. <div id="mask">
  28. <div id="dot"></div>
  29. </div>
  30. -->
  31. </div>
  32. <a id="ribbon" href="http://github.com/bernii/gauge.js"></a>
  33. <div id="content">
  34. <div id="download">
  35. <a href="dist/gauge.coffee" class="btn btn-primary btn-large">gauge.coffee</a>
  36. <a href="dist/gauge.min.js" class="btn btn-large">gauge.min.js</a>
  37. </div>
  38. <div id="example" class="gauge">
  39. <h2>Example</h2>
  40. <h4>Variant selection</h4>
  41. <ul class="horiz-list" id="type-select">
  42. <li class="active" type="gauge"><canvas width=100 height=50 id="select-1"></canvas></li>
  43. <li type="donut"><canvas width=80 height=40 id="select-2"></canvas></li>
  44. </ul>
  45. <div id="preview">
  46. <canvas width=220 height=70 id="canvas-preview"></canvas>
  47. <div id="preview-textfield"></div>
  48. </div>
  49. <form id="opts" class="opts">
  50. <h4>Options:</h4>
  51. <label>Current Val:</label><input type="text" name="currval" min="0" max="3000" step="25" value="1244"><br>
  52. <label>Anim speed:</label><input type="text" name="animationSpeed" min="1" max="128" step="1" value="32"><br><br>
  53. <label>Angle:</label><input id="input-angle" type="text" name="angle" min="0" max="50" step="1" value="15"><br>
  54. <label>Line width:</label><input id="input-line-width" type="text" name="lineWidth" min="0" max="70" value="44"><br>
  55. <label>Ptr length:</label><input id="input-ptr-len" type="text" name="pointer.length" min="0" max="100" value="90"><br>
  56. <label>Ptr color:</label><input id="input-ptr-color" type="text" class="color" name="pointer.color" value="000000"><br>
  57. <label>Ptr stroke:</label><input id="input-ptr-stroke" type="text" name="pointer.strokeWidth" min="0" max="300" value="35"><br>
  58. <label>Font size:</label><input id="input-font-size" type="text" name="fontSize" min="0" max="100" value="41"><br>
  59. <label>Color start:</label><input type="text" name="colorStart" class="color" value="6FADCF"><br>
  60. <label>Color stop:</label><input type="text" name="colorStop" class="color" value="8FC0DA"><br>
  61. <label>Background:</label><input type="text" name="strokeColor" class="color" value="E0E0E0"><br>
  62. </form>
  63. <br clear="left">
  64. <input type="checkbox" id="share">
  65. <label for="share">
  66. <b>Share it!</b> If checked, the option values will be stored in the URL so that you can easily share your settings.
  67. </label>
  68. </div>
  69. <h2>Features</h2>
  70. <ul>
  71. <li>No images, no external CSS - pure canvas</li>
  72. <li>No dependencies (jQuery is <a href="#jquery">supported</a>, but not required)</li>
  73. <li>Highly configurable</li>
  74. <li>Resolution independent</li>
  75. <li>Animated guage value changes (!)</li>
  76. <li>Works in all major browsers</li>
  77. <li>MIT License</li>
  78. </ul>
  79. <h2 id="usage">Usage</h2>
  80. <pre class="prettyprint">
  81. var opts = {
  82. lines: <span id="opt-lines" class="lit">12</span>, // The number of lines to draw
  83. angle: <span id="opt-angle" class="lit">7</span>, // The length of each line
  84. lineWidth: <span id="opt-lineWidth" class="lit">5</span>, // The line thickness
  85. pointer: {
  86. length: <span id="opt-pointer-length" class="lit">10</span>, // The radius of the inner circle
  87. strokeWidth: <span id="opt-pointer-strokeWidth" class="lit">0</span>, // The rotation offset
  88. color: '<span id="opt-pointer-color" class="lit">#000000</span>' // Fill color
  89. },
  90. limitMax: '<span id="opt-limitMax" class="lit">false</span>', // If true, the pointer will not go past the end of the gauge
  91. colorStart: '<span id="opt-colorStart" class="lit">0</span>', // Colors
  92. colorStop: '<span id="opt-colorStop" class="lit">0</span>', // just experiment with them
  93. strokeColor: '<span id="opt-strokeColor" class="lit">0</span>', // to see which ones work best for you
  94. generateGradient: true
  95. };
  96. var target = document.getElementById('foo'); // your canvas element
  97. var gauge = new <span id="class-code-name" class="typ">Gauge</span>(target).setOptions(opts); // create sexy gauge!
  98. gauge.maxValue = <span id="opt-maxval" class="lit">3000</span>; // set max gauge value
  99. gauge.animationSpeed = <span id="opt-animationSpeed" class="lit">3000</span>; // set animation speed (32 is default value)
  100. gauge.set(<span id="opt-currval" class="lit">1500</span>); // set actual value
  101. </pre>
  102. <p>
  103. The <code>Gauge</code> class handles drawing on canvas and starts the animation.
  104. </p>
  105. <h2 id="advanced-options">Advanced options</h2>
  106. <ul>
  107. <li>
  108. <b>Percentage color</b>
  109. <p>If you want to control how Gauge behavaes in relation to the displayed value you can use the Guage option called <b>percentColors</b>. To use it add following entry to the options:
  110. <pre class="prettyprint">
  111. percentColors = [[0.0, "#a9d70b" ], [0.50, "#f9c802"], [1.0, "#ff0000"]];
  112. </pre>
  113. see working example at <a href="http://jsfiddle.net/berni/Yb4d7/">JSFiddle</a></p>
  114. </li>
  115. </ul>
  116. <h3 id="jquery">jQuery plugin</h3>
  117. <p>
  118. Gauge.js does not require jQuery. Anyway, if you use jQuery you may use the following plugin:
  119. </p>
  120. <pre class="prettyprint">
  121. $.fn.gauge = function(opts) {
  122. this.each(function() {
  123. var $this = $(this),
  124. data = $this.data();
  125. if (data.gauge) {
  126. data.gauge.stop();
  127. delete data.gauge;
  128. }
  129. if (opts !== false) {
  130. data.gauge = new Gauge(this).setOptions(opts);
  131. }
  132. });
  133. return this;
  134. };
  135. </pre>
  136. <h2>Supported browsers</h2>
  137. <img src="assets/browsers.png">
  138. <p>
  139. Gauge.js has been (not yet!) successfully tested in the following browsers:
  140. <ul>
  141. <li>Chrome</li>
  142. <li>Safari 3.2+</li>
  143. <li>Firefox 3.5+</li>
  144. <li>IE 9</li>
  145. <li>Opera 10.6+</li>
  146. <li>Mobile Safari (iOS 3.2+)</li>
  147. <li>Android 2.3+</li>
  148. </ul>
  149. </p>
  150. <h2>Changes</h2>
  151. <h3 id="v1.2.1">Version 1.2.1 (9.03.2014)</h3>
  152. <ul>
  153. <li>Proper handling of color params <a href="https://github.com/bernii/gauge.js/issues/47">issue #47</a>.</li>
  154. <li>Moved percentage color to example/docs + <a href="http://jsfiddle.net/berni/Yb4d7/">JSFiddle</a></li>
  155. </ul>
  156. <h3 id="v1.2">Version 1.2 (16.08.2012)</h3>
  157. <ul>
  158. <li>Prototype chain fix. See <a href="https://github.com/bernii/gauge.js/issues/7">issue #7</a>.</li>
  159. <li>Refactored code a bit to make it more flexible. Default class that has some extra features like gradient shadows is called Donut while more flexible one (for devs) is called BaseDonut - use it if you would don't need extra automatic stuff.</li>
  160. <li>Ability to scale gauges (requested via email) - example at <a href="http://jsfiddle.net/7Z2z2/">JSFiddle</a></li>
  161. </ul>
  162. <h3 id="v1.1">Version 1.1 (15.08.2012)</h3>
  163. <ul>
  164. <li>Fixed color picker <a href="https://github.com/bernii/gauge.js/issues/2">bug</a> in FF & Opera</li>
  165. <li>Added a shadow option. See <a href="https://github.com/bernii/gauge.js/pull/5">issue #5</a>.</li>
  166. <li>Added multiple pointer option (requested via email). This needed some code refactoring. No demo for it yet. Use array of values to check it ex. gauge.set([44, 554]);</li>
  167. <li>Added wrapper for formatting text output <a href="https://github.com/bernii/gauge.js/issues/4">issue #4</a>.</li>
  168. </ul>
  169. <h3 id="v1.0">Version 1.0 (27.6.2012)</h3>
  170. <ul>
  171. <li>Initial release</li>
  172. </ul>
  173. <h2>Contact</h2>
  174. <p id="contact">
  175. <img width="57" height="57" src="http://www.gravatar.com/avatar/429e77b5fd1904a032be360339e0bf74">
  176. If you encounter any problems, please use the <a href="https://github.com/bernii/gauge.js/issues">GitHub issue tracker</a>.<br>
  177. If you like gauge.js and use it in the wild, let me know.<br>
  178. If you want to contact me, drop me a message <a href="mailto:bkobos+githubp@extensa.pl">via email</a><br>
  179. </p>
  180. </div>
  181. <div id="footer">
  182. <a class="github" href="http://github.com">Hosted on GitHub</a>
  183. </div>
  184. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  185. <script type="text/javascript" src="assets/fd-slider/fd-slider.js"></script>
  186. <script src="dist/gauge.js"></script>
  187. <script>
  188. prettyPrint();
  189. function update() {
  190. var opts = {};
  191. $('.opts input[min], .opts .color').each(function() {
  192. var val = $(this).hasClass("color") ? this.value : parseFloat(this.value);
  193. if($(this).hasClass("color")){
  194. val = "#" + val;
  195. }
  196. if(this.name.indexOf("lineWidth") != -1 ||
  197. this.name.indexOf("angle") != -1 ||
  198. this.name.indexOf("pointer.length") != -1){
  199. val /= 100;
  200. }else if(this.name.indexOf("pointer.strokeWidth") != -1){
  201. val /= 1000;
  202. }
  203. $('#opt-' + this.name.replace(".", "-")).text(val);
  204. if(this.name.indexOf(".") != -1){
  205. var elems = this.name.split(".");
  206. var tmp_opts = opts;
  207. for(var i=0; i<elems.length - 1; i++){
  208. if(!(elems[i] in tmp_opts)){
  209. tmp_opts[elems[i]] = {};
  210. }
  211. tmp_opts = tmp_opts[elems[i]];
  212. }
  213. tmp_opts[elems[elems.length - 1]] = val;
  214. }else if($(this).hasClass("color")){
  215. // color picker is removing # from color values
  216. opts[this.name] = "#" + this.value
  217. $('#opt-' + this.name.replace(".", "-")).text("#" + this.value);
  218. }else{
  219. opts[this.name] = val;
  220. }
  221. if(this.name == "currval"){
  222. // update current demo gauge
  223. demoGauge.set(parseInt(this.value));
  224. AnimationUpdater.run();
  225. }
  226. });
  227. $('#opts input:checkbox').each(function() {
  228. opts[this.name] = this.checked;
  229. $('#opt-' + this.name).text(this.checked);
  230. });
  231. demoGauge.animationSpeed = opts.animationSpeed;
  232. opts.generateGradient = true;
  233. demoGauge.setOptions(opts);
  234. demoGauge.ctx.clearRect(0, 0, demoGauge.ctx.canvas.width, demoGauge.ctx.canvas.height);
  235. demoGauge.render();
  236. if ($('#share').is(':checked')) {
  237. window.location.replace('#?' + $('form').serialize());
  238. }
  239. }
  240. function initGauge(){
  241. document.getElementById("class-code-name").innerHTML = "Gauge";
  242. demoGauge = new Gauge(document.getElementById("canvas-preview"));
  243. demoGauge.setTextField(document.getElementById("preview-textfield"));
  244. demoGauge.maxValue = 3000;
  245. demoGauge.set(1244);
  246. };
  247. function initDonut(){
  248. document.getElementById("class-code-name").innerHTML = "Donut";
  249. demoGauge = new Donut(document.getElementById("canvas-preview"));
  250. demoGauge.setTextField(document.getElementById("preview-textfield"));
  251. demoGauge.maxValue = 3000;
  252. demoGauge.set(1244);
  253. };
  254. $(function() {
  255. var params = {};
  256. var hash = /^#\?(.*)/.exec(location.hash);
  257. if (hash) {
  258. $('#share').prop('checked', true);
  259. $.each(hash[1].split(/&/), function(i, pair) {
  260. var kv = pair.split(/=/);
  261. params[kv[0]] = kv[kv.length-1];
  262. });
  263. }
  264. $('.opts input[min], #opts .color').each(function() {
  265. var val = params[this.name];
  266. if (val !== undefined) this.value = val;
  267. this.onchange = update;
  268. });
  269. $('.opts input[name=currval]').mouseup(function(){
  270. AnimationUpdater.run();
  271. });
  272. $('.opts input:checkbox').each(function() {
  273. this.checked = !!params[this.name];
  274. this.onclick = update;
  275. });
  276. $('#share').click(function() {
  277. window.location.replace(this.checked ? '#?' + $('form').serialize() : '#!');
  278. });
  279. $("#type-select li").click(function(){
  280. $("#type-select li").removeClass("active")
  281. $(this).addClass("active");
  282. var type = $(this).attr("type");
  283. if(type=="donut"){
  284. initDonut();
  285. $("input[name=lineWidth]").val(10);
  286. $("input[name=fontSize]").val(24);
  287. $("input[name=angle]").val(35);
  288. $("input[name=colorStart]").val("6F6EA0")[0].color.importColor();
  289. $("input[name=colorStop]").val("C0C0DB")[0].color.importColor();
  290. $("input[name=strokeColor]").val("EEEEEE")[0].color.importColor();
  291. fdSlider.disable('input-ptr-len');
  292. fdSlider.disable('input-ptr-stroke');
  293. $("#input-ptr-color").prop('disabled', true);
  294. selectGaguge1.set(1);
  295. selectGaguge2.set(3000);
  296. }else{
  297. initGauge();
  298. $("input[name=lineWidth]").val(44);
  299. $("input[name=fontSize]").val(41);
  300. $("input[name=angle]").val(15);
  301. $("input[name=colorStart]").val("6FADCF")[0].color.importColor();
  302. $("input[name=colorStop]").val("8FC0DA")[0].color.importColor();
  303. $("input[name=strokeColor]").val("E0E0E0")[0].color.importColor();
  304. fdSlider.enable('input-ptr-len');
  305. fdSlider.enable('input-ptr-stroke');
  306. $("#input-ptr-color").prop('disabled', false);
  307. selectGaguge1.set(3000);
  308. selectGaguge2.set(1) ;
  309. }
  310. fdSlider.updateSlider('input-line-width');
  311. fdSlider.updateSlider('input-font-size');
  312. fdSlider.updateSlider('input-angle');
  313. $("#example").removeClass("donut, gauge").addClass(type);
  314. update();
  315. });
  316. selectGaguge1 = new Gauge(document.getElementById("select-1"));
  317. selectGaguge1.maxValue = 3000;
  318. selectGaguge1.set(1552);
  319. selectGaguge2 = new Donut(document.getElementById("select-2"));
  320. selectGaguge2.maxValue = 3000;
  321. selectGaguge2.set(1844);
  322. initGauge();
  323. update();
  324. });
  325. </script>
  326. <script type="text/javascript">
  327. var _gaq = _gaq || [];
  328. _gaq.push(['_setAccount', 'UA-11790841-11']);
  329. _gaq.push(['_trackPageview']);
  330. (function() {
  331. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  332. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  333. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  334. })();
  335. </script>
  336. </body>
  337. </html>