Library to generate SVG Path with Javascript?

≯℡__Kan透↙ 提交于 2019-12-10 18:05:50

问题


I'm using Raphaël for my SVG rendering needs. But I find the Path syntax a little low-level.

So does anyone know a nice wrapper/library for Javascript that allows something like this:

var pathStr = move (10, 10).draw (5, 5)
var path = paper.path(pathStr)

回答1:


It may not be 100% complete, but this looks sort of like what you're looking for:

https://github.com/DmitryBaranovskiy/raphael/blob/cuttingedge/plugins/raphael.path.methods.js




回答2:


I strongly recommend d3.js.

Creating a path that represents an hexagon and moving it 10px in each direction is as simple as this:

var svg = d3.select('body')
    .append('svg:svg')
    .attr('width', 1000)
    .attr('height', 1000);

svg.append('svg:path')
    .attr('d', 'M' + [
        [850, 75], [958, 137.5], [958, 262.5], 
        [850, 325], [742, 262.6], [742, 137.5]
    ].join('L') + 'Z')
    .attr('transform', 'translate(10, 10)');

It uses selectors that work closely to those found in jQuery.

Quoting the author:

D3 does not provide a new graphical representation—unlike Processing, Raphaël, or Protovis, there is no new vocabulary of marks to learn. Instead, you build directly on standards such as CSS3, HTML5 and SVG.



来源:https://stackoverflow.com/questions/4441451/library-to-generate-svg-path-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!