• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure Javascript alternative to path.getPointAtLength(t) and getTotalLength() functions. Works with Canvas & Node

Build Status Coverage Status

svg-path-properties

Pure Javascript alternative to getPointAtLength(t) and getTotalLength() functions. Works with Canvas objects and when Node

JavaScript can access to path elements properties in a browser, such as its length and the point at a given length. Unfortunately, this can't be achieved using a Canvas element or when working with node. This library can be used to replace this need. It has no dependencies on other JavaScript libraries.

INSTALL

To use with npm, just type

npm install svg-path-properties

You can use it int he browser directly by including svg-path-properties.min.js from the dist directory

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

USAGE

The available methods are:

const path = require("svg-path-properties");
const properties = new path.svgPathProperties("M0,100 Q50,-50 100,100 T200,100");
const length = properties.getTotalLength();
const point = properties.getPointAtLength(200);
const tangent = properties.getTangentAtLength(200);
const allProperties = properties.getPropertiesAtLength(200);
const parts = properties.getParts();

Node:

const path = require("svg-path-properties");
const properties = new path.svgPathProperties("M0,100 Q50,-50 100,100 T200,100");

Including it from an import:

import { svgPathProperties } from "svg-path-properties";
const properties = new svgPathProperties("M0,100 Q50,-50 100,100 T200,100");

Including the script in the browser

Once the script tag has been included,

const properties = new svgPathProperties.svgPathProperties("M0,100 Q50,-50 100,100 T200,100");

Using new

Since svgPathProperties is a class, using new is the correct way to initilize it. For backwards compatibility reasons, the object can be get without it:

const properties = svgPathProperties("M0,100 Q50,-50 100,100 T200,100");

Some usage examples

Typescript

The TypeScript declaration file is available too, since version 0.5.0 From version 1.0.0, the whole library has been rewritten using TypeScript, and the types are auto-generated.

CREDITS

Some parts of the code are taken from other libraries or questions at StackOverflow:

For Bézier curves:

For path parsing:

More Repositories

1

BasemapTutorial

A Basemap tutorial for ReadTheDocs
Python
100
star
2

d3-composite-projections

Set of d3 projections for showing countries distant lands together
JavaScript
98
star
3

geoexamples

Files from the geoexamples.blogspot.com blog
JavaScript
96
star
4

raster-marching-squares

Draw your raster data directly in your browser
JavaScript
42
star
5

introduccion-python-geoespacial

Introducción a Python para usos geoespaciales
Python
13
star
6

d3-raster-tools-docs

JavaScript
10
star
7

raster-streamlines

Create GeoJSON streamlines from a u and v raster fields.
JavaScript
10
star
8

obsidian-cooklang

TypeScript
7
star
9

supabase-svelte

Real time Svelte + Supabase example
JavaScript
5
star
10

simple

next-i18next simplest example to be deployed at zeit now
JavaScript
2
star
11

comarques

Test per endevinar les comarques / Catalan comarques quiz
2
star
12

RainOrSnowFeyn

Testing Rain or snow with QLattice
Jupyter Notebook
1
star
13

sapper-i18n

Basic example to use Sapper with i18n
JavaScript
1
star
14

Mapas-web-interactivos-con-D3js

Introducción a la creación de mapas usando el Framework D3.js Jornadas SIGTE2015
1
star
15

js-raob

JavaScript library to read and make calculations from radiosonde data
JavaScript
1
star
16

svelte-overpass

Playing with Svelte and the Overpass API
Svelte
1
star
17

rxpyexample

Sample code for the blog post
Python
1
star
18

simplest-node-authentication

Simplest working node authentication wothout database, to be used to start new projects
JavaScript
1
star
19

rveciana.github.io

GeoExamples blog
JavaScript
1
star
20

sigte2018

Slides and examples for the sigte2018 talk
1
star
21

sigte2017-d3-composite-projections

Slides for the 2017 Jornadas SIGTE about d3-composite-projections
JavaScript
1
star