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

pixi-relationship

v0.0.2

Published

pixi.js to relationship

Downloads

6

Readme

pixi-relationship

使用 pixijs 实现关系图谱效果: Demo

Use

npm install pixi-relationship --save
import PixiRelationship from 'pixi-relationship'
import data from '../test.json'

const app = new PixiRelationship({
  containerID: "container",
  backgroundColor: 0xceefff,
  placeholderImg: require("../images/test.jpg"),
  onClick: data => {
    console.log("onClick:", data);
    alert(JSON.stringify(data))
  },
  data: {
    links: data.links,
    nodes: data.nodes,
    linksColors: [0x71b7ff, 0x509838, 0xfd8888, 0xfff36a]
  },
});

app.init();
// app.destroy();

API

初始化参数说明

| 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | containerID | 容器ID | string | "pixi-relationship" | | | applicationOptions | PIXI.Application初始化参数 | PIXI.Application options | | | | backgroundRoundColor | 背景色值 | 0x... number | 0xceefff | | | | nameStyle | 名称的样式 | (options) => PIXI.TextStyle | ... | | | borderColor | 边框色值 | 0x... number | 0x000000 | | borderColorHover | 边框Hover色值 | 0x... number | 0x598dff | | | linksColors | 连线色值对象(对应data中的type) | Array<...> | Object | [0x71b7ff, 0x509838, 0xfd8888, 0xfff36a] | | linksTypeLabel | 连线色值对象说明 | Array<...> | Object | ['爱情', '亲情', '友情'] | | | placeholderImg | 默认占位图 | string | | | onClick | 点击card事件 | | | | | data | 数据源 | | | |

注意事项:

data 数据源格式要求

{
  "links": [
    {
      "from": "2636106",
      "name": "丈夫",
      "to": "432415",
      "type": 0
    },
    {
      "from": "432415",
      "name": "妻子",
      "to": "2636106",
      "type": 0
    }
    // 注意关系都是单向的,所以2个nodes之间的关系应该有2个links
    ...
  ],
  "nodes": [
    {
      "id": "2636106",
      "img": "http://...",
      "level": 0, // 0 表示第一层, 1 表示第二层, 2表示第三层
      "name": "陈希"
    }
    ...
  ]
}

linksColors 对象需要对应 data 中的 links type,如:

linksColors = [0x71b7ff, 0x509838, 0xfd8888, 0xfff36a];
data = {
  links: [
    {
      from: "2636106",
      name: "test",
      to: "432415",
      type: 0 // 此type值,连线颜色使用 linksColors[0] 
    }
  ],
  ...
}

or 

linksColors = {
  t1: 0x71b7ff, 
  t2: 0x509838
};
data = {
  links: [
    {
      from: "2636106",
      name: "test",
      to: "432415",
      type: "t1" // 此type值,连线颜色使用 linksColors["t1"] 
    }
  ],
  ...
}

linksTypeLabel 同上,若不传,则不显示 label。

方法

继承于 PIXI.Application 对象。

app.init() // 初始化

app.destroy() // 销毁

app.resizeViewport() // 重置viewport

License

ISC