Skip to content

Commit

Permalink
added onAnimationEnd event hook
Browse files Browse the repository at this point in the history
  • Loading branch information
toorshia committed Mar 25, 2016
1 parent 2c9a638 commit 0bca41e
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ JustGage is a handy JavaScript plugin for generating and animating nice & cl

###Update log

######March 25, 2016.
* **onAnimationEnd** - callback function after gauge animation ends
- demo at http://justgage.com/examples/animation-events-hooks.html

######February 3, 2016.
* **minTxt & maxTxt** - Show custom min and max text - https://github.com/toorshia/justgage/issues/193

Expand Down
106 changes: 106 additions & 0 deletions examples/animation-events-hooks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8" />
<title>Animation events hooks</title>
<meta name="viewport" content="width=device-width">
<style>
.wrapper {
position: relative;
width: 320px;
height: 240px;
margin: 50px auto 0 auto;
padding-bottom: 30px;
clear: both;
}

.box {
float: left;
width: 100%;
height: 100%;
box-sizing: border-box;
}

.container {
width: 320px;
margin: 0 auto;
text-align: center;
}

.gauge {
width: 320;
height: 240px;
}

button {
margin: 30px 5px 0 2px;
padding: 16px 40px;
border-radius: 5px;
font-size: 18px;
border: none;
background: #34aadc;
color: white;
cursor: pointer;
}

p {
padding: 10px;
font-family: 'Arial';
}

#log {
color: #ccc;
}
</style>
</head>

<body>
<div class="wrapper">
<div class="box">
<div id="g1" class="gauge"></div>
</div>
</div>
<div class="container">
<button type="button" id="gauge_refresh">Refresh Gauge</button>
<p>After every animation end, function will log it below.</p>
<p id="log"></p>
</div>
<script src="../raphael-2.1.4.min.js"></script>
<script src="../justgage.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {

var g1 = new JustGage({
id: 'g1',
value: 45,
min: 0,
max: 100,
symbol: '%',
pointer: true,
pointerOptions: {
toplength: -15,
bottomlength: 10,
bottomwidth: 12,
color: '#8e8e93',
stroke: '#ffffff',
stroke_width: 3,
stroke_linecap: 'round'
},
gaugeWidthScale: 0.6,
counter: true,
onAnimationEnd: function() {
console.log('animation ended');
var log = document.getElementById('log');
log.innerHTML = log.innerHTML + 'Animation just ended.<br/>';
}
});

document.getElementById('gauge_refresh').addEventListener('click', function() {
g1.refresh(getRandomInt(0, 100));
});
});
</script>
</body>

</html>
24 changes: 13 additions & 11 deletions examples/custom-value-renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,25 @@
max: 100,
title: "Target",
label: "temperature",
textRenderer: customValue
pointer: true,
textRenderer: function(val) {
if (val < 50) {
return 'Cold';
} else if (val > 50) {
return 'Hot';
} else if (val === 50) {
return 'OK';
}
},
onAnimationEnd: function() {
console.log('f: onAnimationEnd()');
}
});

document.getElementById('gg1_refresh').addEventListener('click', function() {
gg1.refresh(getRandomInt(0, 100));
return false;
});

function customValue(val) {
if (val < 50) {
return 'low';
} else if (val > 50) {
return 'high';
} else if (val === 50) {
return 'ideal';
}
}
});
</script>
</body>
Expand Down
8 changes: 6 additions & 2 deletions justgage.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ JustGage = function(config) {
// function applied before rendering text
textRenderer: kvLookup('textRenderer', config, dataset, null),

// onAnimationEnd: func
// function applied after animation is done
onAnimationEnd: kvLookup('onAnimationEnd', config, dataset, null),

// gaugeWidthScale : float
// width of the gauge element
gaugeWidthScale: kvLookup('gaugeWidthScale', config, dataset, 1.0),
Expand Down Expand Up @@ -826,7 +830,7 @@ JustGage = function(config) {
obj.config.donut,
obj.config.reverse
]
}, obj.config.startAnimationTime, obj.config.startAnimationType);
}, obj.config.startAnimationTime, obj.config.startAnimationType, obj.config.onAnimationEnd);

if (obj.config.pointer) {
obj.needle.animate({
Expand Down Expand Up @@ -936,7 +940,7 @@ JustGage.prototype.refresh = function(val, max) {
obj.config.reverse
],
"fill": color
}, obj.config.refreshAnimationTime, obj.config.refreshAnimationType);
}, obj.config.refreshAnimationTime, obj.config.refreshAnimationType, obj.config.onAnimationEnd);

if (obj.config.pointer) {
obj.needle.animate({
Expand Down

0 comments on commit 0bca41e

Please sign in to comment.