square.js
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Square shaped progress bar
var Progress = require('./progress');
var utils = require('./utils');
var Square = function Square(container, options) {
this._pathTemplate =
'M 0,{halfOfStrokeWidth}' +
' L {width},{halfOfStrokeWidth}' +
' L {width},{width}' +
' L {halfOfStrokeWidth},{width}' +
' L {halfOfStrokeWidth},{strokeWidth}';
this._trailTemplate =
'M {startMargin},{halfOfStrokeWidth}' +
' L {width},{halfOfStrokeWidth}' +
' L {width},{width}' +
' L {halfOfStrokeWidth},{width}' +
' L {halfOfStrokeWidth},{halfOfStrokeWidth}';
Progress.apply(this, arguments);
};
Square.prototype = new Progress();
Square.prototype.constructor = Square;
Square.prototype._pathString = function _pathString(opts) {
var w = 100 - opts.strokeWidth / 2;
return utils.render(this._pathTemplate, {
width: w,
strokeWidth: opts.strokeWidth,
halfOfStrokeWidth: opts.strokeWidth / 2
});
};
Square.prototype._trailString = function _trailString(opts) {
var w = 100 - opts.strokeWidth / 2;
return utils.render(this._trailTemplate, {
width: w,
strokeWidth: opts.strokeWidth,
halfOfStrokeWidth: opts.strokeWidth / 2,
startMargin: (opts.strokeWidth / 2) - (opts.trailWidth / 2)
});
};
module.exports = Square;