Code Monkey home page Code Monkey logo

snap.svg's Introduction

A JavaScript SVG library for the modern web. Learn more at snapsvg.io.

Follow us on Twitter.

Install

Learn

Use

In your HTML file, load simply by:

<script src="snap.svg-min.js"></script>

No other scripts are needed. Both the minified and uncompressed (for development) versions are in the /dist folder.

webpack

To load with webpack 2.x and 3.x, install Imports Loader (npm i -D imports-loader), and add the following to your webpack config:

module: {
  rules: [
    {
      test: require.resolve('snapsvg/dist/snap.svg.js'),
      use: 'imports-loader?this=>window,fix=>module.exports=0',
    },
  ],
},
resolve: {
  alias: {
    snapsvg: 'snapsvg/dist/snap.svg.js',
  },
},

Then, in any module you’d like to require Snap, use:

import Snap from 'snapsvg';

Build

Build Status

Snap.svg uses Grunt to build.

  • Open the terminal from the Snap.svg directory:
cd Snap.svg
  • Install its command line interface (CLI) globally:
npm install -g grunt-cli

*You might need to use sudo npm, depending on your configuration.

  • Install dependencies with npm:
npm install

*Snap.svg uses Grunt 0.4.0. You might want to read more on their website if you haven’t upgraded since a lot has changed.

  • To build the files run
grunt
  • The results will be built into the dist folder.
  • Alternatively type grunt watch to have the build run automatically when you make changes to source files.

Testing

Tests are located in test folder. To run tests, simply open test.html in there. Automatic tests use PhantomJS to scrap this file, so you can use it as a reference.

Alternatively, install PhantomJS and run command

grunt test

Contribute

git checkout -b my_branch
  • Add your changes.
  • Check that tests are passing
  • Commit your changes:
git commit -am "Added some awesome stuff"
  • Push your branch:
git push origin my_branch

Note: Pull requests to other branches than dev or without filled CLA wouldn’t be accepted.

snap.svg's People

Contributors

alexnormand avatar bitblitter avatar cantrell avatar cjgammon avatar dangodev avatar dcjones avatar dmitrybaranovskiy avatar enition avatar fmichenaud avatar fyrd avatar ibrierley avatar jadbox avatar jakeswenson avatar jameskmonger avatar kizu avatar mjamro avatar mtiller avatar nicolaspinzon avatar oslego avatar phaen avatar sbking avatar subzey avatar thomasbrierley avatar throrin19 avatar tomconroy avatar tshinnic avatar tvjg avatar vmx avatar voithos avatar yoheishimomae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snap.svg's Issues

Add missing unit tests

Looking the API docs and existing tests, the following methods still need testing and will be tracked here:

Savage

  • Savage.Matrix()
  • Savage.ajax()
  • Savage.animate()
  • Savage.animation()
  • Savage.color()
  • Savage.deg()
  • Savage.format()
  • Savage.fragment()
  • Savage.getRGB()
  • Savage.hsb()
  • Savage.hsb2rgb()
  • Savage.hsl()
  • Savage.hsl2rgb()
  • Savage.is()
  • Savage.load()
  • Savage.parse()
  • Savage.parsePathString()
  • Savage.parseTransformString()
  • Savage.pathBBox()
  • Savage.rad()
  • Savage.rgb()
  • Savage.rgb2hsb()
  • Savage.rgb2hsl()
  • Savage.select()
  • Savage.selectAll()
  • Savage.snapTo()

Savage.filter

  • Savage.filter.blur()
  • Savage.filter.brightness()
  • Savage.filter.contrast()
  • Savage.filter.grayscale()
  • Savage.filter.hueRotate()
  • Savage.filter.invert()
  • Savage.filter.saturate()
  • Savage.filter.sepia()
  • Savage.filter.shadow()

Savage.path

  • Savage.path.findDotsAtSegment()
  • Savage.path.toAbsolute()
  • Savage.path.toCubic()
  • Savage.path.toRelative()
  • Savage.path.map()
  • Savage.path.isPointInside()
  • Savage.path.intersection()

Matrix

  • Matrix.add()
  • Matrix.clone()
  • Matrix.invert()
  • Matrix.rotate()
  • Matrix.scale()
  • Matrix.split()
  • Matrix.toTransformString()
  • Matrix.translate()
  • Matrix.x()
  • Matrix.y()

Set

  • Set.clear()
  • Set.exclude()
  • Set.forEach()
  • Set.pop()
  • Set.push()
  • Set.splice()

Mina

  • mina.backin()
  • mina.backout()
  • mina.bounce()
  • mina.easein()
  • mina.easeinout()
  • mina.easeout()
  • mina.elastic()
  • mina.getById()
  • mina.linear()
  • mina.time()

Color parsing fails when using percentages

According to the API docs under Savage.getRGB(colour) it should be possible to parse colors with percentages set, like rgb(•••%, •••%, •••%) for rgb, hsl and hsb. However, all tests with strings like this appear to fail.

Create a v0.1.0 tag

Once all issues have been addressed, create a v0.1.0 tag and get Yohie the link to the zip file.

Issue with triggering .animate() from another .animate()'s callback

Came across a case where Element.animate() is not triggered from within another Element.animate()'s callback. I was able to resolve the issue by wrapping the second animate function in a setTimeout of 50ms. Appears to be a timing issue.

road_bottom.animate({x2:691.5}, 2000, function(){
    tunnel_mask_bottom_right.animate({
        y: 394,
        height:150
    }, 200);
    });

Coffee Maker fonts don't work

Check the screenshot. Please do one of the following:

  • Use a font from Typekit/Edge Web Fonts.
  • Use a font that more people have installed.

Please do not:

  • Check in the AdobeClean-Light font into this repo. (We can't do that.)

Let me know if you have questions. If you need another font, ask Yohei.
coffee_maker_fonts

The removed test should return!

Investigate why the test is not passing while the same code on the page is working perfectly.

The broken test code:

    it("Element.asPX - from em", function() {
        var rect = s.rect(0, 0, 10, '10em');
        var heightAsPx = rect.asPX("height");
        expect(heightAsPx).to.be(160); // assumes 1em = 16px, is this safe?
    });

API Reference for Matrix.add incorrect

Currently it appears as:
Matrix.add(a, b, c, d, e, f, matrix)

which based on the code should be split to accepting either a-f params or just the matrix.

Create a "demos" directory

Create a "demos" directory for the samples. Create directories for each demo so the HTML and SVG assets are together. Name the demo directories something descriptive (i.e. "map", "barista", etc.).

consider a package manager

npm / component / bower or something so that the little chunks are useful to people (and to keep yourself sane), then produce a snap build from those. Otherwise looks good! :D

Mention of sudo with npm

The README should mention that you might need to use sudo with npm, depending on your configuration.

stroke-dashoffset does not animate

following code does not animate line as it should:

var s = new Snap('100%', '100%');
myPath = s.path('M0,0c0,0,0-28.008,0-46.707S0-89,0-89');
myPath.attr({
'fill': 'none',
'stroke': 'red',
'stroke-width': 25,
'stroke-miterlimit': 10,
'stroke-linecap': 'round',
'opacity': 1,
'stroke-dasharray': "120 200",
'stroke-dashoffset': 0
});
myPath.transform('translate(100, 300)');
myPath.animate({'stroke-dashoffset': 120});

Create a "getting started" guide

Write a getting started guide for the site, and link to it from the README. It should include:

  • Getting the repo (or downloading the zip file).
  • Building it with grunt.
  • Including the library.
  • Initializing Snap.
  • Drawing a couple of shapes.
  • Animating them.

Write it up, and send it to Yohei for inclusion on the site.

Snap logo is throwing an error

Very high priority.

The snap-mascot demo isn't working. Mousing over the mascot throws this error:

Uncaught TypeError: string is not a function: snap.svg-min.js 18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.