Skip to content

Commit

Permalink
Improper value set after animation bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhus committed Dec 2, 2016
1 parent 991e4dd commit 7f8745d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion examples/issue-63.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Gauge Test</title>
<script src="../gauge.min.js"></script>
<style>body {
padding: 0;
padding: 20px;
margin: 0;
background: #fff
}</style>
Expand All @@ -15,6 +15,9 @@
<a href="#" onclick="gaugePS.value=570">570</a>
<a href="#" onclick="gaugePS.value=583">583</a>
<a href="#" onclick="gaugePS.value=830">830</a>

<hr>

<canvas id="gauge-ps"></canvas>

<script>
Expand Down
4 changes: 2 additions & 2 deletions 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.

32 changes: 24 additions & 8 deletions lib/BaseGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,11 @@ export default class BaseGauge extends EventEmitter {
* @param {number} value
*/
set value(value) {
value = parseFloat(value);

if (isNaN(value) || !isFinite(value)) {
value = this.options.minValue;
}
value = BaseGauge.ensureValue(value, this.options.minValue);

let fromValue = this.options.value;

if (value === this.options.value) return;
if (value === fromValue) return;

if (this.options.animation) {
/**
Expand All @@ -237,8 +233,11 @@ export default class BaseGauge extends EventEmitter {

this.emit('animate', percent, this.options.value);
}, () => {
this.options.value = this._value;
delete this._value;
if (this._value !== undefined) {
this.options.value = this._value;
delete this._value;
}

this.draw();
this.emit('animationEnd');
});
Expand Down Expand Up @@ -368,6 +367,23 @@ export default class BaseGauge extends EventEmitter {

new DomObserver({}, element.tagName, type).process(element);
}

/**
* Ensures value is proper number
*
* @param {*} value
* @param {number} min
* @return {number}
*/
static ensureValue(value, min = 0) {
value = parseFloat(value);

if (isNaN(value) || !isFinite(value)) {
value = parseFloat(min) || 0;
}

return value;
}
}


Expand Down
3 changes: 2 additions & 1 deletion lib/RadialGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ export default class RadialGauge extends BaseGauge {
* @param {number} value
*/
set value(value) {
value = BaseGauge.ensureValue(value, this.options.minValue);

if (this.options.animation &&
this.options.ticksAngle === 360 &&
this.options.useMinPath
Expand All @@ -821,7 +823,6 @@ export default class RadialGauge extends BaseGauge {
return super.value;
}

/* */
/**
* Triggering gauge render on a canvas.
*
Expand Down
2 changes: 1 addition & 1 deletion test-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7f8745d

Please sign in to comment.