Graph

画布上的交互式网络图:力导向、聚类和分层布局,平移与缩放,键盘导航以及节点列表。

可用框架
  • Angular: 可用
  • Vue: 可用
  • React: 可用
  • React Native: 暂不可用

用法

PeopleMeetingsNotesDocuments48 nodes · 70 links
Arrow keys move to the nearest node, Page Up and Page Down step through all of them, Enter opens the selected one, Escape clears the selection. Plus and minus zoom, 0 fits the view.
Selected: none · Opened: none

导入

ts
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.

选择器
canvas[soneGraphCanvas]
导出为
soneGraphCanvas
输入
名称类型 默认值
scene

The positioned nodes, edges, columns and clusters to draw.

GraphSceneEMPTY_GRAPH_SCENE
tones

Tone name → custom property (or `"--a, --b"` fallback chain).

Readonly<Record<string, string>>{}
selectedKeystring | nullnull
输出
名称类型
nodePick

The user picked a node with the pointer or keyboard; `null` clears.

string | null
nodeOpen

Double-click, or Enter on the picked node.

string
nodeHoverstring | null
zoomChange

Zoom in percent of the fitted view.

number
anchor

Screen 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.

选择器
sone-graph-card
输入
名称类型 默认值
anchorGraphSceneAnchor | nullnull
heading必填string—
metastring""
tone

Any CSS colour for the swatch, e.g. `var(--graph-note)`.

string"var(--graph-ink)"
squarebooleanfalse
pinnedbooleanfalse
openLabel

The text of the open action of a pinned card; `null` hides it.

string | nullnull
body

Replaces the heading and meta lines.

TemplateRef<unknown> | nullnull
bodyContextunknownnull
输出
名称类型
openvoid

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.

选择器
ng-template[soneGraphCard]

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.

选择器
sone-graph
输入
名称类型 默认值
dataSoneGraphData | nullnull
layoutSoneGraphLayout"force"
tones

Extra or overriding tones: tone name → custom property, or a `"--a, --b"` fallback chain.

SoneGraphTones{}
sizing

The radius range node sizes are mapped onto.

SoneGraphSizingSONE_GRAPH_SIZING
layerLabels

Column titles of the `layers` layout, by `layer`.

Readonly<Record<number, string>>{}
clusterLabel

The title of a `clusters` community; return `""` for none.

(cluster: SoneGraphCluster) => stringsoneGraphClusterLabel
describe

The meta line of a node's card, its list entry and its announcement.

(node: SoneGraphNode, info: SoneGraphNodeInfo) => stringsoneGraphDescribe
label

The canvas's accessible name; defaults to the node and link counts.

string | nullnull
summary

The counts in the controls panel; `""` hides them.

string | nullnull
labelsPartial<SoneGraphLabels>{}
layoutStrategy

Computes the layout elsewhere (a Web Worker); `null` lays out on the main thread.

SoneGraphLayoutStrategy | nullnull
listToggle

Shows the List button in the controls.

booleantrue
selected双向

The selected node id.

string | nullnull
showList双向

Renders the nodes as a list of buttons under the canvas.

booleanfalse
输出
名称类型
nodeOpenstring
nodeHoverstring | null
zoomChange

Zoom 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).

选择器
sone-graph-controls
输入
名称类型 默认值
label必填

Accessible name of the toolbar.

string—
zoomPct

The zoom readout, in percent of the fitted view.

number100
list

`true` / `false` shows the list toggle pressed / not pressed; `null` hides it.

boolean | nullnull
labelsPartial<SoneGraphControlsLabels>{}
输出
名称类型
zoomInvoid
zoomOutvoid
fitvoid
listChangeboolean

SoneGraphLegendDirective指令

Marks content projected into the controls' info panel (a legend, counts).

选择器
[soneGraphLegend]