npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-svgpathplayer

v2.0.3

Published

React component for animating an SVG path and/or a series of SVG paths.

Downloads

8

Readme

build status bitHound Score Dependency Status license semantic-release GitHub license

react-svgpathplayer

Description/Features

This player component loads an SVG image as it's child element using Snap.svg. It has two modes of operation: play/pause animation of a path element and/or forward/backward display of path elements contained in a parent element ("stepped" path or "stepping").

An SVG marker can also be specified to follow the leading end of the the path during animation and to be positioned at the end of stepped paths.

The player is configured by supplying CSS selector strings for the animated path, parent element of stepped segments, and marker. These strings are supplied to SnapSVG's select method and are applied only to the SVG element in the DOM. CSS class selectors are recommended if multiple players will be used on a single page; if ids are used in SVG images they must be globally unique to the page.

The presence/absence of path and segments properties enables/disables their respective control buttons and display sections.

The player's controls can be hidden and the path can be animated once or looped repeatedly. See the demo for configuration examples.

Usage

As a Component Within a React Application

See the demo for example usage of this component and the composition of the SVG images.

Install the component:

npm install react-svgpathplayer

Unfortunately, Snap.svg doesn't integrate well with the npm infrastructure; it is easiest to just includes it in the HTML or take a look at the demoConfig in the webpack.config.babel.js file.

Include the component in the application, provide it's props, and render it:

import SVGPathPlayer from 'react-svgpathplayer';
require('./images/pathsegments.svg');


export default class Demo extends React.Component {
    render() {
        let props = {svg:'./images/pathsegments.svg',
                     path:'.dog-path-0',
                     segments:'.dog-path-segments-0',
                     marker:'.dog',
                     units:'yd',
                     scale:1/36.0,
                     loading:true,
                     time:10236};
         return (<SVGPathPlayer {...props}/>);
    }
}

As a JavaScript Component

See the demo using this component in a plain HTML/JS file.

A UMD build for use directly in the browser is available via CDN at https://npmcdn.com/react-svgpathplayer@latest/dist/react-svgpathplayer.min.js, https://npmcdn.com/react-svgpathplayer@latest/dist/react-svgpathplayer.js with corresponding map files.

You'll need to include all the dependencies:

<body>
<div id="player"/>
...
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg-min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
  <!-- host it locally: -->
  <script src="./react-svgpathplayer.min.js"></script>
  <!-- or use the npmcdn: -->
  <script src="https://npmcdn/react-svgpathplayer@latest/dist/react-svgpathplayer.min.js"></script>
  <script>
    var props1 = {svg:"./images/pathsegments.svg", path:".dog-path-0", segments:".dog-path-segments-0", marker:".dog", units:"yd", scale:1/36.0, loading:true, time:10236};
    ReactDOM.render(React.createElement(SVGPathPlayer, props1), document.getElementById('player'));
  </script>
</body>
...

Developers

  • Linting - npm run lint - Runs ESLint.
  • Developing - npm start - Runs the development server at localhost:8080 and use Hot Module Replacement. You can override the default host and port through env (HOST, PORT).
  • Testing - npm test - Runs a single pass through the tests and writes coverage to build directory.
  • TDD - npm run tdd - watches for file changes and re-runs tests/coverage

License

react-svgpathplayer is available under the MIT license. See LICENSE for more details.