Skip to content

Commit

Permalink
add padding and precision
Browse files Browse the repository at this point in the history
  • Loading branch information
zbryikt committed May 22, 2019
1 parent b9edce4 commit bde313f
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 76 deletions.
20 changes: 15 additions & 5 deletions dist/loading-bar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/loading-bar.min.js

Large diffs are not rendered by default.

Binary file modified dist/loading-bar.zip
Binary file not shown.
18 changes: 14 additions & 4 deletions lib/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ wrap = function(content){
"set-dim": true,
"aspect-ratio": "xMidYMid",
"min": 0,
"max": 100
"max": 100,
"precision": 0,
"padding": undefined
};
config["preset"] = root.attr("data-preset") || option["preset"];
if (config.preset != null) {
Expand Down Expand Up @@ -369,6 +371,9 @@ wrap = function(content){
d = Math.max.apply(null, ['stroke-width', 'stroke-trail-width', 'fill-background-extrude'].map(function(it){
return config[it];
})) * 1.5;
if (config["padding"] != null) {
d = +config["padding"];
}
svg.attrs({
viewBox: [box.x - d, box.y - d, box.width + d * 2, box.height + d * 2].join(" ")
});
Expand Down Expand Up @@ -591,16 +596,21 @@ wrap = function(content){
return -c * 0.5 * (t * (t - 2) - 1) + b;
},
handler: function(time, doTransition){
var ref$, min, max, dv, dt, dur, v, p, node, style, box, dir;
var ref$, min, max, prec, dv, dt, dur, v, p, node, style, box, dir;
doTransition == null && (doTransition = true);
if (this.time.src == null) {
this.time.src = time;
}
ref$ = [config["min"], config["max"]], min = ref$[0], max = ref$[1];
ref$ = [config["min"], config["max"], 1 / config["precision"]], min = ref$[0], max = ref$[1], prec = ref$[2];
ref$ = [this.value.des - this.value.src, (time - this.time.src) * 0.001, +config["duration"] || 1], dv = ref$[0], dt = ref$[1], dur = ref$[2];
v = doTransition
? Math.round(this.ease(dt, this.value.src, dv, dur))
? this.ease(dt, this.value.src, dv, dur)
: this.value.des;
if (config.precision) {
v = Math.round(v * prec) / prec;
} else if (doTransition) {
v = Math.round(v);
}
v >= min || (v = min);
v <= max || (v = max);
text.textContent = v;
Expand Down
Loading

0 comments on commit bde313f

Please sign in to comment.