0.0.2 • Published 5 years ago

pixi-relationship v0.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

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容器IDstring"pixi-relationship"
applicationOptionsPIXI.Application初始化参数PIXI.Application options
backgroundRoundColor背景色值0x... number0xceefff
nameStyle名称的样式(options) => PIXI.TextStyle...
borderColor边框色值0x... number0x000000
borderColorHover边框Hover色值0x... number0x598dff
linksColors连线色值对象(对应data中的type)Array<...> | Object0x71b7ff, 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