Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
js-circle-progress
Advanced tools
Responsive, accessible, animated, stylable with CSS circular progress bar available as plain (vanilla) JS and jQuery plugin.
Lightweight (less than 4kB minified and gzipped), responsive, accessible, animated, stylable with CSS circular progress bar web component.
See examples or go to the project site
There's been a major rewrite of Circle Progress. The new version is a web component (custom element), which can be used directly in HTML just like any native element. It can also be used programmatically in JavaScript.
The new version is not entirely backwards compatible with the old one. If you need the old version, you can still find it in the v0 branch.
This version is currently in beta. Any feedback is much appreciated.
New users — skip to Getting Started section below.
clockwise
and constrain
properties have been revised to anticlockwise
and unconstrained
correspondingly, which have the opposite meanings and are both false
by default..circle-progress-circle
, .circle-progress-value
, .circle-progress-text
, you can now use the ::part()
CSS selector, e. g. circle-progress::part(circle)
, circle-progress::part(value)
, circle-progress::part(text)
. See Styling section below or check the examples for details.1.2e7
, hexadecimal (0x1b4) or octal (0o10) are now properly converted. When making a property assignment (not attribute) you are advised to always pass numbers as numbers, not strings.attr
method or as property assignments. This means that if you set multiple properties at once, the constraints (such as keeping value
between min
and max
) will be applied on the new values and the component will only be updated once, which is more efficient. Once you set the properties, you can subscribe to the update if you need by awaiting the circleProgress.updateComplete
Promise.What hasn't changed?
CircleProgress
programmatically in JavaScript in the same way as before.Keep on reading for more details.
Navigate to your project directory and install the js-circle-progress
module:
$ npm install --save js-circle-progress
Import the module anywhere in your application:
import 'js-circle-progress'
This will register the circle-progress
custom element, which you can use in your html:
<circle-progress value="50" max="100"></circle-progress>
Alternatively, you can import the module in your JavaScript and use it programmatically:
import 'js-circle-progress'
// Create an instance of CircleProgress element
const cp = document.createElement('circle-progress')
or
import CircleProgress from 'js-circle-progress'
// Create an instance of CircleProgress element
const cp = new CircleProgress()
Either way you get the same CircleProgress
element.
Download the minified production version
Given you placed the downloaded file in the same folder as your HTML file, in your HTML:
<script src="circle-progress.min.js" type="module"></script>
<circle-progress value="50" max="100"></circle-progress>
In your HTML:
<script src="https://unpkg.com/js-circle-progress/dist/circle-progress.min.js" type="module"></script>
<circle-progress value="50" max="100"></circle-progress>
Important! The script is an ES module, so you need to include it with the type="module"
attribute.
There are multiple ways to set properties on Circle Progress.
Set properties on a CircleProgress
instance:
circleProgress.max = 100;
circleProgress.value = 20;
or using the chainable attr
method by passing it property key and value:
circleProgress
.attr('max', 100)
.attr('value', 20);
or options object
circleProgress.attr({
max: 100,
value: 20,
});
When using the constructor, you can pass it options object directly at initialization:
const cp = new CircleProgress({
value: 50,
max: 100,
})
Option | Type | Default | Description |
---|---|---|---|
value | Number | Indeterminate | Current value |
min | Number | 0 | Minimum value |
max | Number | 1 | Maximum value |
startAngle | Number | 0 | Starting angle in degrees. Angle of 0 points straight up. Direction depends on anticlockwise . |
anticlockwise | Boolean | false | Whether to rotate anti-clockwise (true) or clockwise (false) |
unconstrained | Boolean | false | Whether the value should be constrained between min and max . If false, values over max will be truncated to max and values under min will be set to min . |
indeterminateText | String | '?' | Text to display as the value when it is indeterminate |
textFormat | String or Function | 'horizontal' | Text layout for value, min, max. You can pass either one of the possible keywords: horizontal - value/max vertical - value is shown over max percent - value% value - only value is shown valueOnCircle - the value is painted on top of the filled region on the circle none - no text is shown. Alternatively you can provide your own function, which will be called each time progress is updated with value and max as arguments, and is expected to return a string of HTML to insert in the center of the progress circle. Attention! The string returned from your function will be inserted as HTML. Do not pass any dynamic content such as variables coming from elsewhere to avoid XSS vulnerability. |
animation | String or Function | 'easeInOutCubic' | Animation easing function. Can be a string keyword (see the table below for available easings) or 'none' .Alternatively, you can pass your own function with the signature function(time, startAngle, angleDiff, duration) .The function will be called on each animation frame with the current time (milliseconds since animation start), starting angle, difference in angle (i.e. endAngle - startAngle) and animation duration as arguments, and must return the current angle. |
animationDuration | Number | 600 | Animation duration in milliseconds |
The predefined animation easing functions:
Easing name | Easing |
---|---|
linear | Linear |
easeInQuad | Quadratic easing in |
easeOutQuad | Quadratic easing out |
easeInOutQuad | Quadratic easing in/out |
easeInCubic | Cubic easing in |
easeOutCubic | Cubic easing out |
easeInOutCubic | Cubic easing in/out |
easeInQuart | Quartic (power of 4) easing in |
easeOutQuart | Quartic easing out |
easeInOutQuart | Quartic easing in/out |
easeInQuint | Quintic (power of 5) easing in |
easeOutQuint | Quintic easing out |
easeInOutQuint | Quintic easing in/out |
easeInSine | Sinusoidal easing in |
easeOutSine | Sinusoidal easing out |
easeInOutSine | Sinusoidal easing in/out |
easeInExpo | Exponential easing in |
easeOutExpo | Exponential easing out |
easeInOutExpo | Exponential easing in/out |
easeInCirc | Circular easing in |
easeOutCirc | Circular easing out |
easeInOutCirc | Circular easing in/out |
updateComplete
A promise that resolves when the element has finished updating.
circleProgress.value = 50
circleProgress.max = 100
await circleProgress.updateComplete
// Do something when the update is complete
To customize widget's appearance, you can style its underlying SVG elements which are exposed as part
s with CSS.
The elements are:
Part | Description |
---|---|
::part(base) | The svg image. You can use this selector to scale the widget. E. g.: circle-progress::part(base) {width: 200px; height: auto;} |
::part(circle) | The entire circle (SVG circle element) |
::part(value) | The arc representing currently filled progress (SVG path element) |
::part(text) | Text controlled by textFormat option (SVG text element) |
::part(text-value) | Current value text (SVG tspan element). Appears only for textFormat values of horizontal , vertical , valueOnCircle |
::part(text-max) | Maximum value text (SVG tspan element). Appears only for textFormat values of horizontal , vertical , valueOnCircle |
You can use any SVG presentation attributes on these elements. Particularly useful are:
fill
, stroke
, stroke-width
, stroke-linecap
properties. (See examples)
The default properties are stored in CircleProgress.defaults. You can override the values, so that all instances will be created with the overridden properties.
Since Circle Progress is a Custom Element, which is natively supported by all modern browsers, it can freely be used with any framework, just like a standard HTML element.
Chrome, Firefox, Safari (starting with version 14), Edge are supported.
If you noticed a bug or want to suggest a feature or an improvement, please do not hesitate to open an issue.
If you want to contribute code, please
npm run check
and npm test
to make sure everything is ok (you can run tests in watch mode npm run test:watch
),npm start
, which will open the docs
folder in your browser,© 2018 Tigran Sargsyan
Licensed under (the MIT License)
FAQs
Responsive, accessible, animated, stylable with CSS circular progress bar available as plain (vanilla) JS and jQuery plugin.
We found that js-circle-progress demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.