Graph
画布上的交互式网络图:力导向、聚类和分层布局,平移与缩放,键盘导航以及节点列表。
Angular: 可用 Vue: 可用 React: 可用 React Native: 暂不可用
用法
<div class="demo-stack" style="width: 100%">
<sone-segmented [options]="layouts" [(value)]="mode" ariaLabel="Graph layout" />
<sone-graph
style="--sone-graph-height: 460px"
[data]="data"
[layout]="layout()"
[layerLabels]="kinds"
[describe]="describe"
[(selected)]="selected"
(nodeOpen)="opened.set($event)"
>
<span soneGraphLegend class="graph-demo-key">
@for (k of kinds; track k; let i = $index) {
<span><i [style.background]="'var(--graph-' + tones[i] + ')'"></i>{{ k }}</span>
}
</span>
</sone-graph>
<span style="color: var(--text-secondary); font-size: var(--font-size-sm)">
Selected: {{ selected() ?? "none" }} · Opened: {{ opened() ?? "none" }}
</span>
</div>导入
import {
SoneGraphCanvasDirective,
SoneGraphCardComponent,
SoneGraphCardTemplateDirective,
SoneGraphComponent,
SoneGraphControlsComponent,
SoneGraphLegendDirective,
} from "@surface-one/angular/graph";API 参考
SoneGraphCanvasDirective指令
The canvas part of `<sone-graph>`: binds a `GraphScene` to the framework-free `SoneGraphEngine`. The engine (and with it `getContext`, `matchMedia` and the observers) is created after the first render, so the directive is SSR-safe. Use it on its own when you build the scene yourself.
| 名称 | 类型 | 默认值 |
|---|---|---|
sceneThe positioned nodes, edges, columns and clusters to draw. | GraphScene | EMPTY_GRAPH_SCENE |
tonesTone name → custom property (or `"--a, --b"` fallback chain). | Readonly<Record<string, string>> | {} |
selectedKey | string | null | null |
| 名称 | 类型 |
|---|---|
nodePickThe user picked a node with the pointer or keyboard; `null` clears. | string | null |
nodeOpenDouble-click, or Enter on the picked node. | string |
nodeHover | string | null |
zoomChangeZoom in percent of the fitted view. | number |
anchorScreen position of the hovered (else the picked) node, for a floating card. | GraphSceneAnchor | null |
SoneGraphCardComponent组件
The node card of a graph. Floating, it sits above (or below, near the top edge) the node at `anchor` and ignores the pointer; `pinned`, it docks to the bottom-left corner and offers the `openLabel` action. `data-node-x` / `data-node-y` expose the node's on-screen position for tests.
| 名称 | 类型 | 默认值 |
|---|---|---|
anchor | GraphSceneAnchor | null | null |
heading必填 | string | — |
meta | string | "" |
toneAny CSS colour for the swatch, e.g. `var(--graph-note)`. | string | "var(--graph-ink)" |
square | boolean | false |
pinned | boolean | false |
openLabelThe text of the open action of a pinned card; `null` hides it. | string | null | null |
bodyReplaces the heading and meta lines. | TemplateRef<unknown> | null | null |
bodyContext | unknown | null |
| 名称 | 类型 |
|---|---|
open | void |
SoneGraphCardTemplateDirective指令
`<ng-template soneGraphCard let-node let-pinned="pinned">` replaces the body of the node card (title + meta); the card's position and its Open action stay.
SoneGraphComponent组件
An interactive network diagram on a Canvas 2D: `force`, `clusters` (communities with hulls) or `layers` (one column per `layer`) layouts; drag to pan, wheel to zoom at the cursor, click to select and highlight the neighbourhood, double-click or Enter to open; full keyboard support with spoken selections, an optional node list, and colours read from the theme tokens.
| 名称 | 类型 | 默认值 |
|---|---|---|
data | SoneGraphData | null | null |
layout | SoneGraphLayout | "force" |
tonesExtra or overriding tones: tone name → custom property, or a `"--a, --b"` fallback chain. | SoneGraphTones | {} |
sizingThe radius range node sizes are mapped onto. | SoneGraphSizing | SONE_GRAPH_SIZING |
layerLabelsColumn titles of the `layers` layout, by `layer`. | Readonly<Record<number, string>> | {} |
clusterLabelThe title of a `clusters` community; return `""` for none. | (cluster: SoneGraphCluster) => string | soneGraphClusterLabel |
describeThe meta line of a node's card, its list entry and its announcement. | (node: SoneGraphNode, info: SoneGraphNodeInfo) => string | soneGraphDescribe |
labelThe canvas's accessible name; defaults to the node and link counts. | string | null | null |
summaryThe counts in the controls panel; `""` hides them. | string | null | null |
labels | Partial<SoneGraphLabels> | {} |
layoutStrategyComputes the layout elsewhere (a Web Worker); `null` lays out on the main thread. | SoneGraphLayoutStrategy | null | null |
listToggleShows the List button in the controls. | boolean | true |
selected双向The selected node id. | string | null | null |
showList双向Renders the nodes as a list of buttons under the canvas. | boolean | false |
| 名称 | 类型 |
|---|---|
nodeOpen | string |
nodeHover | string | null |
zoomChangeZoom in percent of the fitted view. | number |
SoneGraphControlsComponent组件
The overlay toolbar of a graph: an info panel (legend, counts — projected) and Fit / zoom out / zoom readout / zoom in, plus an optional list toggle. One tab stop; arrow keys, Home and End move between the buttons (WAI-ARIA toolbar).
| 名称 | 类型 | 默认值 |
|---|---|---|
label必填Accessible name of the toolbar. | string | — |
zoomPctThe zoom readout, in percent of the fitted view. | number | 100 |
list`true` / `false` shows the list toggle pressed / not pressed; `null` hides it. | boolean | null | null |
labels | Partial<SoneGraphControlsLabels> | {} |
| 名称 | 类型 |
|---|---|
zoomIn | void |
zoomOut | void |
fit | void |
listChange | boolean |
SoneGraphLegendDirective指令
Marks content projected into the controls' info panel (a legend, counts).