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

raphael-svg-import-classic

v0.3.1

Published

Import SVG files to Raphel

Downloads

120

Readme

Raphaël SVG Import plugin

What is it?

An extension to the Raphael Vector Library. It enables Raphael to import raw SVG data.

Fork Notes

This is a fork of raphael.svg-import. When the original raphael-svg-import reached 0.0.3, a major backwards-incompatible change was introduced. Instead of parsing SVG documents, it used regular expressions. This was undesirable for several reasons:

  • Used regular expressions to parse XML. Rebuilding something that browsers can do natively.
  • Loss of document structure. Groups (<g>) are lost.
  • Additional steps needed to load a svg file.

Usage

See demo.html for the full example. Use AJAX to retrieve your SVG file as an XML document. Then use importSVG() to convert the SVG into a raphael.js set:

jQuery(document).ready(function(){
  jQuery.ajax({
    type: "GET",
    url: "assets/demo.svg",
    dataType: "xml",
    success: function(svgXML) {
      var paper = Raphael(10, 10, 800, 600);
      var newSet = paper.importSVG(svgXML);
    }
  });
});

If you want the Raphael paper dimensions to automatically match the SVG:

jQuery(document).ready(function(){
  jQuery.ajax({
    type: "GET",
    url: "assets/demo.svg",
    dataType: "xml",
    success: function(svgXML) {
      var root = svgXML.getElementsByTagName('svg')[0].getAttribute('viewBox').split(' ');
      var width = root[2],
          height = root[3];
      var paper = Raphael(width, height);
      var newSet = paper.importSVG(svgXML);
    }
  });
});

If you want to import the SVG from an element within the page you can access to the element:

<svg id="mysvg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="500px" height="500px" viewBox="0 0 500 500" enable-background="new 0 0 500 500" xml:space="preserve">
	<circle opacity="0.3" fill="#FF0000" enable-background="new" cx="251.5" cy="255.5" r="179"/>
</svg>

And you can access to the svg element by its id:

var paper = Raphael(10, 10, 500, 500);
var newSet = paper.importSVG(document.getElementById('mysvg'));

In the assets folder a demo.svg file is provided. Nothing fancy but it gives you a starting point.

Dependencies

Contributing to Raphael SVG Import Classic

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • You can contribute a broken test case without a fix

Testing

Qunit

Open tests/qunit.html in your targeted browers. A command line version can be run based on webkit with grunt qunit. A hosted version can be found here.

Visual

Open tests/visual_tests.html in your targeted browsers. A hosted version can be found here.

Old IE testing

Follow the same instructions as above IE. When looking at the Qunit test in IE, all tests will fail, but the output should look the same as other browsers.

From the command line

$ grunt test
Running "jshint:all" (jshint) task
>> 2 files lint free.

Running "qunit:all" (qunit) task
Testing tests/qunit.html .............OK
>> 20 assertions passed (57ms)

Done, without errors

Copyright

Copyright (c) 2015 Chris Chang Original Raphael SVG Import Copyright (c) 2009 Wout Fierens See LICENSE.txt for further details.

Final Notes

I've tried keeping all the files as close to the original as possible. So there are lots of files not relevant to this fork in the tree.

There is a bug in the minified version of of Raphael.js that most people use. It's best to just grab the uncompressed source and minify it yourself.