|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | + <title>Gauge Test</title> |
| 6 | + <script src="../gauge.min.js"></script> |
| 7 | + <style>body { |
| 8 | + padding: 0; |
| 9 | + margin: 0; |
| 10 | + background: #fff |
| 11 | + }</style> |
| 12 | +</head> |
| 13 | +<body> |
| 14 | + |
| 15 | +<button onclick="animateGauges()">Animate</button> |
| 16 | +<button onclick="stopGaugesAnimation()">Stop animation</button> |
| 17 | + |
| 18 | +<hr> |
| 19 | + |
| 20 | +<canvas data-type="radial-gauge" |
| 21 | + data-min-value="0" |
| 22 | + data-max-value="360" |
| 23 | + data-major-ticks="N,NE,E,SE,S,SW,W,NW,N" |
| 24 | + data-minor-ticks="22" |
| 25 | + data-ticks-angle="360" |
| 26 | + data-start-angle="180" |
| 27 | + data-stroke-ticks="false" |
| 28 | + data-highlights="false" |
| 29 | + data-color-plate="#222" |
| 30 | + data-color-major-ticks="#f5f5f5" |
| 31 | + data-color-minor-ticks="#ddd" |
| 32 | + data-color-numbers="#ccc" |
| 33 | + data-color-needle="rgba(240, 128, 128, 1)" |
| 34 | + data-color-needle-end="rgba(255, 160, 122, .9)" |
| 35 | + data-value-box="false" |
| 36 | + data-value-text-shadow="false" |
| 37 | + data-color-circle-inner="#fff" |
| 38 | + data-color-needle-circle-outer="#ccc" |
| 39 | + data-needle-circle-size="15" |
| 40 | + data-needle-circle-outer="false" |
| 41 | + data-needle-type="line" |
| 42 | + data-needle-start="75" |
| 43 | + data-needle-end="99" |
| 44 | + data-needle-width="3" |
| 45 | + data-borders="true" |
| 46 | + data-border-inner-width="0" |
| 47 | + data-border-middle-width="0" |
| 48 | + data-border-outer-width="10" |
| 49 | + data-color-border-outer="#ccc" |
| 50 | + data-color-border-outer-end="#ccc" |
| 51 | + data-color-needle-shadow-down="#222" |
| 52 | + data-animation-target="plate" |
| 53 | + data-animation-duration="1500" |
| 54 | + data-animation-rule="linear" |
| 55 | + data-width="500" |
| 56 | + data-height="500" |
| 57 | + data-units="ᵍ" |
| 58 | + data-value="0" |
| 59 | +></canvas> |
| 60 | + |
| 61 | +<canvas data-type="linear-gauge" |
| 62 | + data-width="160" |
| 63 | + data-height="600" |
| 64 | + data-border-radius="0" |
| 65 | + data-borders="0" |
| 66 | + data-bar-begin-circle="false" |
| 67 | + data-title="Temperature" |
| 68 | + data-units="°C" |
| 69 | + data-minor-ticks="10" |
| 70 | + data-value="99" |
| 71 | + data-major-ticks="0,10,20,30,40,50,60,70,80,90,100" |
| 72 | + data-tick-side="right" |
| 73 | + data-number-side="right" |
| 74 | + data-needle-side="right" |
| 75 | + data-animation-rule="bounce" |
| 76 | + data-animation-duration="750" |
| 77 | + data-bar-stroke-width="5" |
| 78 | + data-value-box-border-radius="0" |
| 79 | + data-value-text-shadow="false" |
| 80 | + data-color-plate="#eee" |
| 81 | +></canvas> |
| 82 | + |
| 83 | +<script> |
| 84 | +function domReady(handler) { |
| 85 | + if (/comp|inter|loaded/.test((window.document || {}).readyState + '')) |
| 86 | + return handler(); |
| 87 | + |
| 88 | + if (window.addEventListener) |
| 89 | + window.addEventListener('DOMContentLoaded', handler, false); |
| 90 | + |
| 91 | + else if (window.attachEvent) |
| 92 | + window.attachEvent('onload', handler); |
| 93 | +} |
| 94 | + |
| 95 | +if (!Array.prototype.forEach) { |
| 96 | + Array.prototype.forEach = function(cb) { |
| 97 | + var i = 0, s = this.length; |
| 98 | + for (; i < s; i++) { |
| 99 | + cb && cb(this[i], i, this); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +document.fonts && document.fonts.forEach(function(font) { |
| 105 | + font.loaded.then(function() { |
| 106 | + if (font.family.match(/Led/)) { |
| 107 | + document.gauges.forEach(function(gauge) { |
| 108 | + gauge.update(); |
| 109 | + }); |
| 110 | + } |
| 111 | + }); |
| 112 | +}); |
| 113 | + |
| 114 | +var timers = []; |
| 115 | + |
| 116 | +function animateGauges() { |
| 117 | + document.gauges.forEach(function(gauge) { |
| 118 | + timers.push(setInterval(function() { |
| 119 | + gauge.value = Math.random() * |
| 120 | + (gauge.options.maxValue - gauge.options.minValue) / 4 + |
| 121 | + gauge.options.minValue / 4; |
| 122 | + }, gauge.animation.duration + 50)); |
| 123 | + }); |
| 124 | +} |
| 125 | + |
| 126 | +function stopGaugesAnimation() { |
| 127 | + timers.forEach(function(timer) { |
| 128 | + clearInterval(timer); |
| 129 | + }); |
| 130 | +} |
| 131 | + |
| 132 | +domReady(function() { |
| 133 | + document.gauges.forEach(function(gauge) { |
| 134 | + var type = gauge.canvas.element.getAttribute('data-type'); |
| 135 | + |
| 136 | + gauge.on('beforeNeedle', function() { |
| 137 | + console.log(type + ': drawing needle!'); |
| 138 | + }); |
| 139 | + |
| 140 | + gauge.on('beforePlate', function() { |
| 141 | + console.log(type + ': drawing plate!'); |
| 142 | + }); |
| 143 | + }); |
| 144 | +}); |
| 145 | +</script> |
| 146 | + |
| 147 | +</html> |
0 commit comments