progressbar.js
repository·master·Indexed 27 days ago
https://github.com/kimmobrunfeldt/progressbar.jsA lightweight library for creating responsive, animated SVG progress bars. It supports built-in shapes like Circle, SemiCircle, and Line, as well as custom SVG paths via ProgressBar.Path. The library features customizable animation parameters including easing functions, duration, and a tweening engine using from, to, and step parameters for dynamic transitions.
What's inside progressbar.js
- ProgressBar.js is a library for creating responsive and slick progress bars using animated SVG paths. It supports built-in shapes or allows you to define custom paths. Animations can be customized to suit specific design requirements.
Run tests in Sauce Labs using Karma
masterTo run tests across multiple browsers in Sauce Labs, use Karma via Grunt. This requires setting up your Sauce Labs credentials as environment variables.
Set environment variables:
SAUCE_USERNAMESAUCE_ACCESS_KEY
Run tests:
- Run all browsers:
grunt karma - Run a specific set of browsers for faster results:
grunt karma:sauce0
- Run all browsers:
Install progressbar.js
masterYou can install progressbar.js using bower, npm, or by manually including the files from thedist/directory in your project.Load progressbar.js module
masterProgressBar.js is distributed as a UMD module and can be loaded using CommonJS, AMD, or as a global variable.
// CommonJS const ProgressBar = require('progressbar.js') const line = new ProgressBar.Line('#container'); // AMD require.config({ paths: {'progressbar': '../bower_components/progressbar.js/dist/progressbar'} }); define(['progressbar'], function(ProgressBar) { var line = new ProgressBar.Line('#container'); }); // Global variable (if no module loader is used) // progressbar.js exposes window.ProgressBar var line = new ProgressBar.Line('#container');Access SVG paths in embedded <object> tags
masterIf your SVG is loaded via an
<object>tag rather than being inline in the HTML, you must wait for the object to load before accessing the path. You can then access the path via thecontentDocumentproperty.var heart = document.getElementById('heart'); heart.addEventListener('load', function() { var path = new ProgressBar.Path(heart.contentDocument.querySelector('#heart-path'), { duration: 300 }); });Run tests locally with Grunt or Testem
masterTests are written using Mocha and expect.js. You can run them quickly using Grunt, which utilizes Testem to execute tests in Chrome.
- Run all tests:
grunt test
If you want to use
testemdirectly:testem: Serves a testing page to connect any browser.testem ci: Runs tests in all available/detected local browsers.testem ci -R dot -l chrome: Runs tests in Chrome using dot reporting.
grunt test # Or using testem directly testem ci -R dot -l chrome- Run all tests:
Create custom animations using from, to, and step
masterCustom animations are achieved by using the
from,to, andstepparameters. The tweening engine interpolates values betweenfromandtoover time, calling thestepfunction for every frame.There is a distinction between defining these parameters during initialization versus during an
.animate()call:Initialization approach: Defines the animation properties when the progress bar is first created.
.animate()approach: Defines the animation properties at the moment the animation is triggered, allowing for dynamic transitions.// Pass in initialization var bar = new ProgressBar.Line('#container', { from: { color: '#000 '}, to: { color: '#888 '}, step: function(state, bar, attachment) { bar.path.setAttribute('stroke', state.color); } }); // Pass in .animate() call var bar = new ProgressBar.Line('#container', { step: function(state, bar, attachment) { bar.path.setAttribute('stroke', state.color); } }); var opts = { from: { color: '#000 '}, to: { color: '#888'} }; bar.animate(0.5, opts);Release a new version
masterReleases are automated via Grunt. Before releasing, ensure all files are committed, tests pass, and
jshintreports no errors.- Commit and push all changes.
- Run
npm testto verify local tests and linters. - Ensure Sauce Labs tests pass.
- Run the release command. By default, this performs a
patchrelease.
To specify a different version bump, use one of the following:
grunt release:majorgrunt release:minorgrunt release:patch(default)
npm test grunt release:majorAccess ProgressBar.js documentation and examples
masterYou can find comprehensive resources for ProgressBar.js at the following locations:
- Official Documentation: hosted at readthedocs.org
- Demos & Examples: kimmobrunfeldt.github.io/progressbar.js
- Interactive Playground: Try in JSFiddle
- API Reference: Shape and API documentation
- React Integration: Use react-progressbar.js for progress bars in React applications.
Set up a local development environment
masterTo develop on ProgressBar.js, install the necessary global npm tools and then use the provided npm scripts to run the development server and watch for changes.
Install global dependencies:
watchifybrowserifymocha(for testing)testem(for testing)
Run the development environment:
- Use
npm run devfor a shortcut to start development. - Alternatively, manually:
cd local-devand serve the folder, then rungrunt watchfrom the project root to watchsrc/progressbar.jsfor changes.
- Use
npm install npm install -g watchify npm install -g browserify npm install -g mocha npm install -g testem # Shorter way to start development npm run devDevelop documentation locally
masterThe documentation is built using
mkdocsand is written in Markdown. To view the documentation site locally:- Install
mkdocsand the requirements listed inpip-requirements.txt. - Run
mkdocs serveto start the local documentation server.
- Install
Ensure IE 11 compatibility
masterTo support IE 11, you must include ES6 polyfills in your
index.html.<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>