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

mk-svg-tree

v0.2.4

Published

draw a directory tree using svg

Downloads

8

Readme

mk-svg-tree

安装
使用方法
实例方法
事件
内置样式
效果图

INSTALL

Using npm:

  npm install mk-svg-tree

  import mkTree from 'mk-svg-tree'
  import 'mk-svg-tree/dist/tree.css'

Using cdn:

  <script src="https://unpkg.com/mk-svg-tree/dist/tree.js"></script>
  <link rel="stylesheet" href="https://unpkg.com/mk-svg-tree/dist/tree.css">

USAGE

  <div id="tree"></div>
  
  let mk_tree = new mkTree({
    container:'tree',
    parameter:{
      node_margin: 5,
      node_field: 'title',
      icon_margin: 5,
      child_field: 'children',
      expand_icon: 'icon-plus-square-fill',
      collapse_icon: 'icon-minus-square-fill',
      directory_open_icon: 'icon-folder-open',
      directory_close_icon: 'icon-folder1',
      leaf_node_icon: 'icon-file'
    },
    data:[]
  })

container:一个可以嵌入svg的容器,可以传入容器id或者DOM元素.省略时默认是id为tree的容器

parameter:构造参数。 不传时取默认值

  node_margin: 节点间的上下间距 默认: 5  

  icon_margin: 图标间隔 默认: 5  

  node_field: 节点显示的字段名 默认: 'title'

  child_field: 子节点字段名 默认: 'children'

  expand_icon: 展开图标  

  collapse_icon: 收起图标  

  directory_open_icon: 目录展开时的图标  

  directory_close_icon: 目录收起时的图标  

  leaf_node_icon: 叶子节点图标  

data:必填。要展示的数据。

Method

  mk_tree.Init(data) // 数据更新,重新渲染

  mk_tree.expandAll() // 一键展开

  mk_tree.collaspseAll() // 一键收起

回到顶部

Event

nodeclick: 节点点击事件,参数是当前节点和其在父元素下的位置。 例如:

  mk_tree.addEventListener('nodeclick',(node,index)=>{
    /** dosomething */
  })

expandChange:展开收起事件,参数是当前展开/收起的节点数据和状态。例如:

  mk_tree.addEventListener('expandChange',(...args)=>{
    /** dosomething */
  })

BUILT-IN STYLE

/* 节点 */
.inner-group {
  user-select: none;
}

/* 节点字体 */
.tree-text {
  fill: #333;
  font-size: 14px;
}

/* 节点背景 */
.tree-rect {
  fill: transparent;
}

/* 选中节点背景 */
.inner-group.active-node .tree-rect {
  fill: #BAE7FF;
}

/* 选中节点字体 */
.inner-group.active-node .tree-text {
  fill: #fff;
}

/* 节点:hover背景 */
.inner-group:not(.active-node):hover .tree-rect {
  fill: #E6F7FF;
}

/* 节点:hover字体 */
.inner-group:not(.active-node):hover .tree-text {
  fill: #333;
}

/* 线条样式 */
.tree-line {
  stroke: #52AFF8;
  stroke-width: 1;
  stroke-dasharray: 1, 1;
}

/* 图标样式 */
.tree-icon-icon-plus-square-fill,
.tree-icon-icon-minus-square-fill,
.tree-icon-icon-folder-open,
.tree-icon-icon-folder1,
.tree-icon-icon-file {
  fill: #4A90E2;
}

/* 子节点 */
.tree-group.active-group .child-group {
  animation: group_animation 0.2s linear;
}

@keyframes group_animation {
  0% {
    opacity: 0;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    opacity: 1;
  }
}

回到顶部

NOTICE

节点图标若想使用自定义图标 使用SVG symbol. 传入id给对应的参数

EFFECT

20190527095843.png