-
Notifications
You must be signed in to change notification settings - Fork 13
/
s-circle-progress.html
175 lines (140 loc) · 3.27 KB
/
s-circle-progress.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../paper-styles/default-theme.html">
<!--
`s-circle-progress`
Polymer-based web component displaying a circular progress bar.
@demo demo/index.html
-->
<dom-module id="s-circle-progress">
<template>
<style>
:host {
@apply(--layout-vertical);
@apply(--layout-center-center);
position: relative;
width: 64px;
height: 64px;
margin: 24px;
border-radius: 50%;
}
svg {
position: absolute;
top: 0;
left: 0;
display: none;
}
.Circle-background {
stroke: var(--s-circle-progress-bg-stroke-color, --paper-grey-100);
}
.Circle-foreground {
transition: var(--s-circle-progress-transition, stroke-dashoffset 150ms);
stroke: var(--s-circle-progress-stroke-color, --accent-color);
stroke-linecap: var(--s-circle-progress-stroke-linecap, round);
}
</style>
<svg id="circle" width="100%" height="100%">
<circle class="Circle-background"
r$="[[_radius]]"
cx$="[[_cx]]"
cy$="[[_cy]]"
fill="transparent"
stroke-width$="[[strokeWidth]]" />
<circle class="Circle-foreground"
r$="[[_radius]]"
cx$="[[_cx]]"
cy$="[[_cy]]"
fill="transparent"
stroke-width$="[[strokeWidth]]"
stroke-dasharray$="[[_dasharray]]"
stroke-dashoffset$="[[_dashoffset]]"
transform$="[[_transform]]" />
</svg>
<content></content>
</template>
<script>
Polymer({
is: 's-circle-progress',
behaviors: [
Polymer.IronResizableBehavior
],
properties: {
/**
* Value of circular progress bar.
*/
value: {
type: Number,
value: 0
},
/**
* Maximum of value.
*/
max: {
type: Number,
value: 100
},
/**
* Stroke width of circle.
*/
strokeWidth: {
type: Number,
value: 4
},
/**
* Starting angle of the progress.
*/
angle: {
type: Number,
value: -90
},
_cx: {
type: Number,
value: null
},
_cy: {
type: Number,
value: null
},
_radius: {
type: Number,
computed: '_computeRadius(_cx, _cy, strokeWidth)'
},
_transform: {
type: String,
computed: '_computeTransform(angle, _cx, _cy)'
},
_dasharray: {
type: Number,
computed: '_computeDashArray(_radius)'
},
_dashoffset: {
type: Number,
computed: '_computeDashOffset(value, max, _dasharray)'
}
},
listeners: {
"iron-resize": "_onIronResize"
},
_computeDashArray: function(radius) {
return 2 * Math.PI * radius;
},
_computeDashOffset: function(value, max, dasharray) {
return (1 - value / max) * dasharray;
},
_computeRadius: function(cx, cy, strokeWidth) {
return cx && cy ? Math.max(0, Math.min(cx, cy) - strokeWidth / 2) : 0;
},
_computeTransform: function(angle, cx, cy) {
return cx && cy ? 'rotate(' + angle + ', ' + cx + ', ' + cy + ')' : '';
},
_onIronResize: function() {
if (this.offsetWidth && this.offsetHeight) {
this._cx = this.offsetWidth / 2;
this._cy = this.offsetHeight / 2;
this.$.circle.style.display = 'block';
}
}
});
</script>
</dom-module>