-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressbar.js
106 lines (101 loc) · 3.11 KB
/
Progressbar.js
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
import Component from "./Component.js"
export default class ProgressBar extends Component {
constructor() {
super()
this.maxValue = 0
this.currentValue = 0
this.mainColor = "#747574"
this.progressColor = "#a4a6a5"
this.isInverted = false
this.isVertical = false
}
setInverted() {
this.isInverted = true
return this
}
setVertical() {
this.isVertical = true
return this
}
decoration1(size) {
//arrow x coords
let leftX = 0 * size.x
let midX = (6.5 / 10.5) * size.x
let rightX = 1 * size.x
//arrow y coords
let topY = 0 * size.y
let topMidY = (2.5 / 7) * size.y
let midY = 0.5 * size.y
let bottomMidY = (4.5 / 7) * size.y
let bottomY = 1 * size.y
return {
"clip-path": `polygon(${leftX}px ${topMidY}px, ${midX}px ${topMidY}px, ${midX}px ${topY}px, ${rightX}px ${midY}px, ${midX}px ${bottomY}px, ${midX}px ${bottomMidY}px, ${leftX}px ${bottomMidY}px )`,
}
}
decoration1inside = this.decoration1
setMaxValue(value) {
this.maxValue = value
return this
}
update(value) {
this.currentValue = value
let progress =
(this.isInverted
? (this.currentValue == 0 ? 0 : this.maxValue - this.currentValue) /
this.maxValue
: this.currentValue / this.maxValue) * 100
if (this.isVertical) this.insideContainer.style.height = progress + "%"
else this.insideContainer.style.width = progress + "%"
return this
}
createContainer() {
this.container = document.createElement("div")
this.container.style.display = "none"
this.container.style.position = "absolute"
this.container.style.pointerEvents = true ? "all" : "none"
this.container.disableContextMenu()
this.insideContainer = document.createElement("div")
this.insideContainer.style.display = "block"
this.insideContainer.style.position = "absolute"
if (this.isVertical) this.insideContainer.style.width = "100%"
else this.insideContainer.style.height = "100%"
this.insideContainer.style.pointerEvents = true ? "all" : "none"
this.insideContainer.disableContextMenu()
this.container.appendChild(this.insideContainer)
return this
}
applyProgressColor() {
this.insideContainer.style.background = this.progressColor
return this
}
setProgressColor(color) {
this.progressColor = color
if (this.isBuilt) this.applyProgressColor()
return this
}
applyMainColor() {
this.container.style.background = this.mainColor
return this
}
setMainColor(color) {
this.mainColor = color
if (this.isBuilt) this.applyMainColor()
return this
}
build() {
super.build()
this.applyProgressColor()
this.applyMainColor()
return this
}
applyDecoration() {
super.applyDecoration()
if (this[`decoration${this.decoration}inside`])
this.insideContainer.applyStyle(
this[`decoration${this.decoration}inside`](
this.size.multiply(this.getPixelSize()),
this.position.multiply(this.getPixelSize())
)
)
}
}