Skip to content
Snippets Groups Projects
Commit 3988be95 authored by alexisben's avatar alexisben
Browse files

fix block key figures

parent 6c05f8c7
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,7 @@ class KeyFigures { ...@@ -60,6 +60,7 @@ class KeyFigures {
loop () { loop () {
this.time = Math.min(new Date().getTime() - this.start, OPTIONS.DURATION); this.time = Math.min(new Date().getTime() - this.start, OPTIONS.DURATION);
console.log(this.time)
this.figures.forEach((figure, index) => { this.figures.forEach((figure, index) => {
this.values[index] = this.getValues(this.time, 0, this.targets[index], OPTIONS.DURATION); this.values[index] = this.getValues(this.time, 0, this.targets[index], OPTIONS.DURATION);
figure.innerHTML = this.formatValue(parseFloat(this.values[index], 10)); figure.innerHTML = this.formatValue(parseFloat(this.values[index], 10));
...@@ -67,11 +68,14 @@ class KeyFigures { ...@@ -67,11 +68,14 @@ class KeyFigures {
if (this.time < OPTIONS.DURATION) { if (this.time < OPTIONS.DURATION) {
window.requestAnimationFrame(this.loop.bind(this)); window.requestAnimationFrame(this.loop.bind(this));
} else {
this.onEnded();
} }
} }
getValues (time, from, to, duration) { getValues (time, from, to, duration) {
const decimalsLength = to.decimals(); const decimalsLength = to.decimals();
let value = KeyFigures.easeOutQuad(time, from, to, duration); let value = KeyFigures.easeOutQuad(time, from, to, duration);
if (decimalsLength) { if (decimalsLength) {
value = Math.round(value * decimalsLength * 10) / (decimalsLength * 10); value = Math.round(value * decimalsLength * 10) / (decimalsLength * 10);
...@@ -85,6 +89,12 @@ class KeyFigures { ...@@ -85,6 +89,12 @@ class KeyFigures {
return value.toLocaleString('en').replace(',', separator); return value.toLocaleString('en').replace(',', separator);
} }
onEnded() {
this.figures.forEach((figure, index) => {
figure.innerHTML = this.formatValue(this.targets[index]);
});
}
resize () { resize () {
this.figures.forEach((figure) => { this.figures.forEach((figure) => {
figure.style.minWidth = 0; figure.style.minWidth = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment