HTML lifecycle, styling, and migration
Host size
relation-graph uses the host’s actual dimensions. A host with no height produces no visible graph:
html, body {height: 100%; margin: 0;}
#graph {width: 100%; height: 100%; min-height: 360px;}
ResizeObserver handles host changes. After revealing a hidden tab, collapsed panel, or dialog, call graph.refresh(), moveToCenter(), or zoomToFit() if the layout system did not trigger ResizeObserver.
Multiple instances
const leftGraph = await createRelationGraph('#left-graph', leftConfig);
const rightGraph = await createRelationGraph('#right-graph', rightConfig);
Each instance owns independent DOM, events, state, and plugins. Do not pass a node object from one instance into another; copy JSON data instead.
Teardown
const stop = graph.subscribe('selection', updateBusinessPanel);
const unregisterPort = registerConnectTarget(graph, port, portOptions);
function unmount() {
stop();
unregisterPort();
graph.destroy();
}
The graph cleans up plugins and official helpers. Business-owned global listeners, timers, and requests still need explicit cleanup.
Styling
The HTML platform uses regular DOM, so application CSS can override it directly:
#graph .relation-graph {
--rg-node-color: #ffffff;
--rg-node-border-color: #64748b;
--rg-line-color: #94a3b8;
--rg-toolbar-hover-bg-color: rgba(15, 23, 42, 0.08);
}
#graph .rg-node-peel[data-id="critical"] > .rg-node {
border-color: #dc2626;
}
Prefer node/line data, renderer classes, and CSS variables. Do not depend on undocumented deep DOM ordering.
Migrating an older project
The retired packages, Shadow Root main component, and custom child element family are no longer provided. Migration steps:
- Uninstall the old package and install
@relation-graph/html@3.1.2. - Remove the auto-registering script and all
rg-*child component tags. - Create an instance in a regular container with
createRelationGraph(). - Move options and data to
config.optionsandconfig.data. - Replace instance retrieval through
onReadywith the factory Promise. - Move behavioral events to
config.events; userg:*DOM events for read-only observation. - Replace node, line, and expand slots with
renderers. - Replace background/canvas/view slots with
layers. - Replace toolbar, MiniView, and editor elements with
uior official plugins. - Replace connection-target elements with
registerConnectTarget().
| Retired capability | HTML replacement |
|---|---|
| Main tag | createRelationGraph(host, config); optional single light-DOM tag |
onReady detail |
await createRelationGraph() |
| Node/line slots | renderers.node, renderers.line, renderers.lineLabel |
| Expand-button slot | renderers.nodeExpandButton |
| Background/canvas/view slots | layers |
| Toolbar and MiniView elements | ui.toolbar, ui.miniView |
| Editing elements | ui.editing |
| Connection-target element | registerConnectTarget() |
| Store-change event | subscribe(domain, listener) |
Legacy example URLs redirect to /examples/<id>/html, but application code should move to the html platform name. Retired npm packages receive no new releases or security fixes.
Troubleshooting
- Blank graph: verify host height and
style.css. - 404 or CORS: use fixed distribution URLs and serve the page over HTTP.
- Custom HTML appears as text: return a DOM Node, or use
trustedHTML()only for trusted static content. - Toolbar/MiniView is absent: verify both plugin installation under
uiand the matching coreshow*option. - Duplicate mount error: destroy the previous instance first.
Back to HTML Startup.