Build a radial tree into an element, creating the SVG root when needed.
Module graphic.hypertree/create | Type constructible helper (not a module descriptor, not a graphicModules member) | Source packages/front/graphic/anim/src/hypertree/create.js | Deps the shared helper runtime, graphic.hypertree, graphic.svgApply | Worker-safe no
Descriptor
There is no descriptor. createHypertree(rootEl, opts) acquires the shared
runtime (registerDeep of the graphic.hypertree descriptor and its whole deps
closure), resolves graphic.hypertree and graphic.svgApply, prepares the SVG
root and constructs the tree. It composes; it touches no descriptor.
API
| Export | Signature | Description |
|---|---|---|
createHypertree |
(rootEl: Element, opts: HypertreeHelperOptions) => HypertreeHandle |
Build the tree under rootEl. |
opts is HypertreeOptions plus tree (a TreeNode or a forest array,
required). tree is stripped; the rest is forwarded verbatim to the
Hypertree constructor (see hypertree/hypertree).
The helper adds no other option.
HypertreeHandle:
| Member | Meaning |
|---|---|
instance |
The live Hypertree with its full public API (focus, focusSync, focusId, node, rootId, el, …). |
root |
The SVG root the tree was built into: the supplied one, or the element the helper created. |
dispose() |
Idempotent teardown: disposes the instance, removes the built <g> and, when the helper created the root, that root, then releases its share of the runtime. |
Examples
const carto = createHypertree(document.querySelector('#carto'), {
tree: { id: 'root', children: [{ id: 'a' }, { id: 'b' }] },
radius: 400,
onFocus: (id) => console.log('focused', id),
});
carto.instance.focus('a');
carto.dispose();
Notes
- SVG-root recipe: a
rootElalready in the SVG namespace (an<svg>or<g>) is used as is, never resized or re-attributed. Any other element is a container: the helper creates an<svg>withcreateElementNS, setspreserveAspectRatio="xMidYMid meet", appends it, and after construction setsviewBox="0 0 2R 2R"whereRis read from the live layout (the root node'sx), so it fits the radius in force. The container owns the CSS size. - Throws:
createHypertree: rootEl is required;createHypertree: opts.tree is required; plus everyHypertreeconstructor error, propagated unchanged. On a constructor failure the helper removes the root it inserted and releases its runtime share, leaving nothing behind. - A caller-supplied root is left in place after
dispose(), emptied of this tree. - The runtime is shared across calls and with
createPageflip(onegraphic.scheduler), and reference-counted: the lastdispose()releases it. - Not Worker-safe (element-anchored).
See also
- hypertree/hypertree — the module and its options
- helpers/shared-runtime — the shared runtime
- main — the public entry that exports the helper
- hypertree guide — the long form