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

auto-layouter

v0.0.2

Published

Graph layout and routing for JavaScript

Downloads

6

Readme

Auto Layouter

Auto Layouter 是一个提供图布局算法和自动布线算法的JavaScript库。

目录

特性

布局算法

  • [x] 分层布局

布线算法

  • [x] 正交路由
  • [x] 曼哈顿路由
  • [x] 切比雪夫路由

安装

npm install auto-layouter
  • ES Module

    import * as al from 'auto-layouter'
  • CommonJS

    const al = require('auto-layouter/dist/auto-layouter.cjs')
  • Browser

    <script src="auto-layouter/dist/auto-layouter.min.js" />

使用

示例:

import { layered, chebyshev} from 'auto-layouter'

const graph = {
  nodes: [
    {id: 'A', width: 100, height: 40},
    {id: 'B', width: 100, height: 40},
    {id: 'C', width: 100, height: 40},
    {id: 'D', width: 100, height: 40}
  ],
  edges: [
    {v: 'A', w: 'B'},
    {v: 'A', w: 'C'},
    {v: 'B', w: 'D'},
    {v: 'C', w: 'D'},
  ]
}
// 分层布局
layered(graph)


const from = {
  x: graph.nodes[0].x + graph.nodes[0].width,
  y: graph.nodes[0].y + graph.nodes[0].height / 2,
  direction: 'right'
}
const to = {
  x: graph.nodes[1].x,
  y: graph.nodes[1].y + graph.nodes[1].height / 2,
  direction: 'left'
}

// 布线算法
const points = chebyshev(from, to, graph.nodes)

API

布局算法

  • layered(graph, [option])

    分层布局算法。直接使用dagrejs实现。 传入graph之后,将会把节点的位置信息(即xy)直接赋给graph.nodes中的每个元素。

    参数:

    名称| 类型 | 描述 --|--|-- graph | Object | 图的数据,包含顶点和边 option | Object | 与dagre中的graph配置信息一直

    graph的数据结构为:

    type graph = {
      nodes: Array<{
        id: string, // 节点唯一id
        width: number,
        height: number
      }>,
      edges: Array<{
        v: string, // 起点
        w: string // 终点
      }>
    }

自动布线算法

  • orthogonal(from, to, [option])

    基于正交线的算法。根据起点和终点的方向求出一个或者两个正交线,此算法不会避开障碍。

    • 参数:

      名称| 类型 | 描述 --|--|-- from | Point | 起点 to | Point | 终点 option | Object| 配置信息

    • 点的数据结构:

      type Point = {
        x: number,
        y: number,
        direction: enum // 点的方向,可选值为 up|right|down|left|mid, 其中起点方向不能为mid
      }
    • option可选值:

      名称| 类型 | 默认值 | 描述 | --|--|-- | -- extensionCord | number | 10 | 点的延长线

    • 返回值:

      Array<Point>, 从起点到终点的所有控制点集合。

  • manhattan(from, to, boxes, [option])

    基于曼哈顿距离的算法。采用A*搜索算法(A-star search algorithm)实现。其中启发式函数就是曼哈顿距离(Manhattan distance), 即,路径的搜索方向为上下左右四个方向。

    • 参数:

      名称| 类型 | 描述 --|--|-- from | Point | 起点 to | Point | 终点 boxes | Array | 网格地图上的障碍物 option | Object| 配置信息

    • boxes中的元素的数据结构

      type Box = {
        x: number,
        y: number,
        width: number,
        height: number
      }
    • option可选值:

      名称| 类型 | 默认值 | 描述 | --|--|-- | -- step | number | 10 | 搜索的步进长度

    • 返回值:

      Array<Point>, 从起点到终点的所有控制点集合。

  • chebyshev(from, to, boxes, [option])

    也是采用A*搜索算法(A-star search algorithm)实现。不过启发式函数为切比雪夫距离(Chebyshev distance),即,路径的搜索方向增长到了8个,增加了4个对角线方向。参数和返回值同上。

  • euclidean(from, to, boxes, [option])

    也是采用A*搜索算法(A-star search algorithm)实现。不过启发式函数为欧几里得距离(Euclidean distance)。