Giter Site home page Giter Site logo

s.arrow's Introduction

s.arrow

SVG arrow for simplesvg. I noticed I was duplicating code a lot, so extracted this into a module.

usage

General case:

var arrow = require('s.arrow');
// svgRoot is a parent dom element.
var ui = arrow(svgRoot);
ui.stoke('orangered');
var from = {x: 0, y: 0};
var to = { x: 42, y: 42};
ui.render(from, to);

Usage with ngraph.svg:

var render = require('ngraph.svg');
var arrow = require('s.arrow');
var svg = render.svg;
var renderer = render(graph);

// use circles for nodes:
renderer.node(createNode).placeNode(placeNode);
// render arrows, and stop precisely at intersection with circle:
renderer.link(createLink).placeLink(placeLink);

function createNode() {
  var ui = svg('circle', {
    r: 10, // radius 10, we will use later
    fill: 'deepskyblue'
  });
  return ui;
}

function placeNode(ui, pos) {
  ui.attr('transform', 'translate(' + pos.x + ',' + pos.y + ')');
}

function createLink() {
  var ui = arrow(renderer.svgRoot);
  ui.stroke('#5A5D6E');
  return ui;
}

function placeLink(ui, from, to, link) {
  ui.render(
    arrow.intersectCircle(from, to, 10), // from
    arrow.intersectCircle(to, from, 10) // to
  );
}

I know, it's too much code. Please let me know how would you make it simpler.

install

With npm do:

npm install s.arrow

license

MIT

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.