Skip to content

Commit

Permalink
Added value event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhus committed Mar 14, 2017
1 parent 183ea9c commit 0eefbf1
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
96 changes: 96 additions & 0 deletions examples/value-event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gauge Test</title>
<link rel="stylesheet" href="../fonts/fonts.css">
<script src="../gauge.min.js"></script>
</head>
<body style="background: #fff">

<button onclick="animateGauges()">Animate</button>

<canvas id="canvasPressure"></canvas>

<script>
var gaugePressure = new RadialGauge({
renderTo: 'canvasPressure',
width: 300,
height: 300,
units: "1010 hPa",
startAngle: 70,
ticksAngle: 220,
colorPlate: "#ffffff",
colorUnits: "#3CA7DB",
colorNumbers: "#3CA7DB",
needleType: "arrow",
needleStart: 0,
needleEnd: 75,
needleWidth: 4,
needleCircleSize: 10,
needleCircleInner: false,
needleCircleOuter: true,
needleShadow: false,
colorNeedle: "#3CA7DB",
colorNeedleEnd: "#2698CE",
colorNeedleCircleOuter: "#3CA7DB",
colorNeedleCircleOuterEnd: "#3CA7DB",
// barWidth: 5,
// colorBarProgress: '#3CA7DB',
// colorBar: '#A8D3D5',

colorMajorTicks: ["#A8D3D5", "#ffffff", "#ffffff", "#ffffff", "#ffffff",
"#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#A8D3D5"],
colorMinorTicks: "#ffffff",

// Вопрос в мин и макс значениях, при этих значениях анимация не работает
minValue: 975,
maxValue: 1045,

majorTicks: ["","980","","990","","1000","","1010","","1020","","1030","","1040",""],
minorTicks: "10",
strokeTicks: true,

highlights: [
{
"from": 974.75,
"to": 1045.25,
"color": "#A8D3D5"
}
],
//
highlightsWidth: 25,
numbersMargin: 12,
animation: true,
animationRule: "linear",
valueBox: false,
borders: false,
borderShadowWidth: 0,
value: 1010,
animateOnInit: true,
animatedValue: true

}).draw();

var timers = [];

function animateGauges() {
document.gauges.forEach(function(gauge) {
timers.push(setInterval(function() {
gauge.value = Math.random() *
(gauge.options.maxValue - gauge.options.minValue) +
gauge.options.minValue;
}, gauge.animation.duration + 50));
});
}

window.addEventListener('load', function() {
document.gauges.forEach(function(gauge) {
gauge.on('value', function(value) {
gauge.update({ units: parseInt(value, 10) + ' hPa' });
});
});
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion gauge.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gauge.min.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion lib/BaseGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,19 @@ export default class BaseGauge extends EventEmitter {
this.emit('animationStart');

this.animation.animate(percent => {
let newValue = fromValue + (value - fromValue) * percent;

this.options.animatedValue &&
this.emit('value', newValue, this.value);

this.options.value = fromValue + (value - fromValue) * percent;

this.draw();

this.emit('animate', percent, this.options.value);
this.emit('animate', percent, this.value);
}, () => {
if (this._value !== undefined) {
this.emit('value', this._value, this.value);
this.options.value = this._value;
delete this._value;
}
Expand All @@ -260,6 +266,7 @@ export default class BaseGauge extends EventEmitter {
}

else {
this.emit('value', value, this.value);
this.options.value = value;
this.draw();
}
Expand Down

0 comments on commit 0eefbf1

Please sign in to comment.