什么是 Movk Sigma
sigma.js 是一个 WebGL 图渲染引擎,graphology 是与之配套的图数据结构。两者都是命令式的原生 JavaScript 库:建实例、改数据、调 refresh()、手动清理。
Movk Sigma 把这套流程包成 Vue 组件与 composables——数据变化自动增量同步、相机与选中状态成为响应式引用、覆盖层跟随画布定位、实例生命周期跟着组件走。
设计原则
封装是加法,不是围墙。 库没覆盖的原生能力,用户必须仍然能用:
useSigma()返回原生Sigma与Graph实例,不包 Proxy、不做代理settings整体透传给 sigma,不逐字段枚举、不过滤未知键,上游新增配置立即可用- 数据双通道:传
data由库做增量 diff,传graph则库完全不碰数据,只负责渲染与生命周期 - 渲染程序、布局、控件全都可以绕过,库不劫持画布
- 不 re-export 上游,
sigma与graphology保持 peer 依赖,不夹带第二份实例 styles与用户自带的nodeReducer/edgeReducer都原样进构造选项,库内规则只在其后叠加,不会顶掉你的声明
能力概览
一个最小例子
<script lang="ts" setup>
import type { SerializedGraph } from 'graphology-types'
const data: SerializedGraph = {
attributes: {},
options: { type: 'mixed', multi: false, allowSelfLoops: true },
nodes: [
{ key: '1', attributes: { label: 'Node 1', x: 0, y: 0, size: 1, color: 'blue' } },
{ key: '2', attributes: { label: 'Node 2', x: 5, y: 10, size: 1, color: 'red' } },
{ key: '3', attributes: { label: 'Node 3', x: 10, y: 0, size: 1, color: 'green' } }
],
edges: [
{ source: '1', target: '2', attributes: { size: 1 } },
{ source: '2', target: '3', attributes: { size: 1 } },
{ source: '3', target: '1', attributes: { size: 1 } }
]
}
</script>
<template>
<SigmaGraph :data="data" />
</template>
useSigma() 是 inject,所有 composable 都必须在 SigmaGraph 子树内调用。因此消费上下文的部分总是一个独立子组件——这也正是真实应用的结构。