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

@icos-react/graph

v0.1.2

Published

D3 力导向关联图谱组件:矩形碰撞 + 8 方向标签 + 引导线

Readme

@xuanwu/graph

基于 D3 v7 的 React 关联图谱组件,适用于事件-人-地-物等节点关系可视化场景。

核心能力:

  • 力导向布局 (d3-force) + 自定义矩形 forceCollide,节点外接矩形不重叠
  • 8 方向标签贪心避让 + 超阈值自动绘制引导线,保证标签也尽量不遮挡
  • 中心节点锚定 + forceRadial 软分层,可贴近"中心-多环"视觉
  • SVG 渲染,支持 zoom / pan / 节点拖拽 + 钉住 / 双击解除
  • 主题可替换:内置 default / platformMain / screenCommand 三套,业务可透传自定义

安装

本地开发(推荐)在工作区中使用 file: 引用:

// 消费端 package.json
{
  "dependencies": {
    "@xuanwu/graph": "file:../graph-component"
  }
}

使用

import { RelationGraph } from "@xuanwu/graph";
import { platformMainTheme } from "@xuanwu/graph/themes/platform-main";

<RelationGraph
  nodes={[
    { id: "c", label: "中心事件", type: "event", isCenter: true },
    { id: "v1", label: "小轿车", type: "vehicle", depth: 2 },
  ]}
  edges={[{ id: "e1", source: "c", target: "v1", label: "关联" }]}
  theme={platformMainTheme}
  force={{ radialStrength: 0.3, radialStep: 120 }}
  draggable
  onNodeClick={(n) => console.log(n)}
/>;

迁移指引(已完成)

platform-main

  • src/utils/chat/KnowledgeGraph.tsx 改为 <RelationGraph/> 的轻封装。
    • 保留原 API:{ title, nodes, edges, layoutScale }ChatProvider 不变。
    • 依然使用原 PNG 资源(src/utils/chat/assets/kg-*.png),通过 createPlatformMainTheme(assets) 注入主题。
    • 中心识别沿用"isCenter > type==='event' > nodes[0]";depth 映射:event→1vehicle/person/material→2video→3
    • 小图 416x416 + 点击全屏 Portal 放大,Esc 关闭。
  • package.json 新增依赖:"@xuanwu/graph": "file:../graph-component"

screen-command

  • 两份 EventRelationship 合并为单一实现:
    • src/components/Event/components/EventRelationship/index.tsx —— 新实现
    • src/components/Event/eventWorkbench/EventDetail/Relationship/index.tsx —— re-export 壳
    • g6Node.ts 已删除。
  • RadarNodeType 由数值 enum 改为字符串 enum(字面量仍保留业务 typo orgnization),配合 radarTreeToGraph 转为 {nodes, edges}
  • 主题:createScreenCommandTheme(assets),沿用原 SVG 资源(icon-g6-node-bg.svgicon-event.svg 等)。
  • defaultCollapsedDepth=2,近似原 collapse-expand 行为,通过双击节点展开/折叠。
  • @antv/g6 仍在 DispatchGraph(派单流程图)使用,非关联图谱范围,保留依赖。如后续改造 DispatchGraph,可一并移除。

核心算法

PLAN 中 4.x 节。关键文件:

  • src/layouts/force.ts:力组合
  • src/anti-occlusion/rect-collide.ts:自定义矩形碰撞
  • src/anti-occlusion/label-placement.ts:8 方向贪心 + 引导线

开发

pnpm install
pnpm dev        # 运行 example 调试
pnpm build      # 产出 dist