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

to-planar-graph

v3.0.1

Published

Given a graph with a graph with a non planar embedding, make changes to this graph so that it becomes planar.

Downloads

2

Readme

To Planar Graph

This library aims to solve the following problem;

Given a graph embedded in a 2d coordinate space, and the embedding is not planar, make changes to the graph such that after the changes the graph is planar. The Changes that will be made conform to the following

  1. Do not change the position of any of the vertices.
  2. Do not change the positions or directions of any of the edges.

The changes may;

  1. Add new vertices at intersection points of edges.
  2. Re route edges that cross over vertices.

Installation

npm install --save to-planar-graph

Usage


import { toPlanarGraph } from "to-planar-graph";

/**
 * Nodes are defined as a coordinate position. Their "id" used
 * in edges is their index in the input
 * 
 * You can see more examples in the tests.
 */
const nodes: Array<[number, number]> = [
    [10, 10],
    [70, 50],
    [80, 70],
    ...
]

/**
 * Edges are defined by [source id, target id]
 */
const edges: Array<[number, number]> = [
    [0, 1],
    [1, 3],
    [1, 2],
    ...
]

const threshold = 5;

const result = toPlanarGraph(nodes, edges, threshold)

About the "Threshold"

Consider the following graph as input

The graph is clearly not planar. We could say this because of one of two reasons

  1. The edge B->E intersects the edge A->C
  2. The edge B->E intersects the vertex C

Now in the first scenario we would create a new vertex F, and then create the path B->F->E and A->F->C

But this may not be very good when we display our graph visually, even if logically it may be correct. We would end up with a graph where a vertex overlaps another.

To avoid this we can check each intersection for its proximity to a vertex, this is what the threshold describes. If a vertex is found within threshold the new edges will be routed through the edge that is within the threshold distance.

It is suggested that the size of this threshold is the radius of the display size of the vertices in your coordinate system. For example if you show your vertices as 10 pixel squares a sensible threshold may be 5 (pixels).

Acknowledgements

The intersections are performed using the Bentley-Ottmann algorithm from the isect library, its very cool and fast too

I built this library for use alongside planar-face-discovery