Cyprobar is a light-weight javascript library that provides you a seamless way of creating circular progress bars. All you need to do is call a function, provide preference and cyprobar will take over from there.
<script src="https://cdn.jsdelivr.net/npm/cyprobar@1.0.0/dist/cyprobar.js"></script>
npm i cyprobar
If you are using imports, use the following to import Cyprobar
import CPB from 'cyprobar'
To create the circular progress bar, call the draw method and pass in an object of your preference for the circular progress bar.
CPB.draw({ elementClass: "example" })
The above will create a circular progress bar with default preference.
CPB.draw({ elementClass: "example" }).
Below are all the properties that can be passed in the object argument of the draw() method.
Properties | Function | Default Value | Possible Values |
---|---|---|---|
value | sets the value of the indicator and the center text | 0 | 0 - maxValue |
maxValue | sets the maximum value of the progress bar | 100 | any value |
valueUnit | sets the unit in the center text | % | any unit (%, pt, cm etc.) |
valueFont | sets the font-family of the center text | monospace | any browser font or font-stack |
valueFontSize | sets the font size of the center text | 60 | 10 - 100 |
barSize | sets progress bar size | 200 | 0 - 1000 |
indicatorSize | sets the width of the indicator | 15 | 0 - 40 |
trackSize | sets the with of the track | 15 | 0 - 40 |
indicatorCap | sets how the ends of the indicator should look | acute-square | acute-square, square, round |
barBgColor | sets inner background color | grey | any browser color or useGradient (default is used unless set) |
trackColor | sets track color | #eee | any browser color or useGradient (default is used unless set) |
indicatorColor | sets indicator color | black | any browser color or useGradient (default is used unless set) |
valueColor | sets background color | black | any browser color or useGradient (default is used unless set) |
barBgOpacity | sets background opacity | 0 | 0 - 1 |
valueOpacity | sets the opacity of the center text | 1 | 0 - 1 |
setText | sets a text for the center text other than the given value | CBP | any text |
useText | replaces the center text with the set text | 0 | true or false (boolean) |
setGradient | sets a gradient that can be used by any property that takes in a color value | [ ['rgba(0, 0, 0, 1)', 0], ['rgba(0, 0, 0, 0.5)', 50], ['rgba(0, 0, 0, 0.2)', 100] ] | multi-dimension array of colors and their corresponding stops |
Let's play around with the values in the above table.
To use a gradient on any property that takes in any browser color value, assign a value of useGradient. Gradients should be set using the setGradient property, if no gradient is set and the useGradient is called the default gradient will be used.
To set a gradient, pass in a multi-dimensional array of the colors you want in the gradient and their corresponding stops to the setGradient property.
Eg. The setGradient value should be in the below format.
[
["color1", "stop1"],
["color1", "stop1"],
["color3", "stop3"]
]
NB. The color value must come first before the stop value. Stop values range from 0 to 100.
By default, the center text comprises of the given value and unit. To use a certain text instead of the default, assign the text to the setText property and set the useText property to true. The useText property should only take in a boolean value.