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 🙏

© 2026 – Pkg Stats / Ryan Hefner

er-canvas

v0.1.1

Published

一个无第三方依赖,使用canvas实现的简单数据库表关系图绘制工具

Downloads

7

Readme

er-canvas

一个无第三方依赖,使用canvas实现的简单数据库表关系图绘制工具

预览

B.gif

安装

npm i -d er-canvas

使用

webpack

import 'er-canvas/dist/index.css';
import ErCanvas from 'er-canvas';

let er = new ErCanvas(document.querySelector('#app'), {
  width: 1600,
  height: 1200,
  onContextmenu(e, target) {
    console.log(target);
  },
  onSelectLine(line) {
    console.log(line)
  },
  onSelectTable(table) {
    console.log(table)
  },
  tables: [{
    id: 'frb',
    name: '用户表',
    fields: Array(20).fill(1).map((t, i) => {
      return {
        id: 'frbfield' + i,
        name: '字段' + i,
      };
    }),
    top: 0,
    left: 0,
    width: 100,
    height: 100,
  }, {
    id: 'cyb',
    name: '信息表',
    fields: [
      {
        id: 'cybfield1',
        name: '字段1',
      },
      {
        id: 'cybfield2',
        name: '字段2',
      },
    ],
    top: 0,
    left: 300,
    width: 100,
    height: 100,
  }],
  lines: [{
    form: 'frbfield1',
    to: 'cybfield1',
  }],
})

浏览器

<!DOCTYPE html>
<html lang="">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="stylesheet" href="./index.css">
</head>
<style>
  html, body {
    margin: 0;
    padding: 0;
  }
</style>
<body>
<button onclick="addTable()">增加一张表</button>
<button onclick="addLine()">增加一条线</button>
<button onclick="removeTable()">删除表</button>
<button onclick="removeLine()">删除线</button>

<div id="app" class="er" style="width: 800px;height:600px" tabindex="999"></div>
<div id="message"></div>
<script src="./index.js"></script>
<script>
  window.er = new ErCanvas(document.querySelector('#app'), {
    width: 1600,
    height: 1200,
    onContextmenu(e, target) {
      console.log(target);
    },
    onSelectLine(line) {
      if (line) {
        document.querySelector('#message').innerText = '当前选中的线:' + line.form.options.name + '->' + line.to.options.name;
      }
//    alert(line.form.id);
    },
    onSelectTable(table) {
      if (table) {
        document.querySelector('#message').innerText = '当前选中的表:' + table.options.name;
      }
//    alert(line.form.id);
    },
    tables: [{
      id: 'frb',
      name: '用户表',
      fields: Array(20).fill(1).map((t, i) => {
        return {
          id: 'frbfield' + i,
          name: '字段' + i,
        };
      }),
      top: 0,
      left: 0,
      width: 100,
      height: 100,
    }, {
      id: 'cyb',
      name: '信息表',
      fields: [
        {
          id: 'cybfield1',
          name: '字段1',
        },
        {
          id: 'cybfield2',
          name: '字段2',
        },
      ],
      top: 0,
      left: 300,
      width: 100,
      height: 100,
    }],
    lines: [{
      form: 'frbfield1',
      to: 'cybfield1',
    }],
  });

  var i = 0;

  function addTable() {
    i++;
    er.addTable({
      id: 'table' + i,
      name: '表' + i,
      fields: Array(20).fill(1).map((t, fieldInde) => {
        return {
          id: 'table' + i + 'field' + fieldInde,
          name: '字段' + fieldInde,
        };
      }),
      top: 0,
      left: 300 * ( er.tables.length ),
      width: 100,
      height: 100,
    });
  }

  function addLine() {
    er.addLine({
      form: er.tables[0].fields[0].id,
      to: er.tables[1].fields[0].id,
    });
  }

  function removeTable() {
    er.removeTable(er.tables[0].id);
  }

  function removeLine() {
    er.removeLine(er.lines[0]);
  }

</script>
</body>
</html>