UNPKG

@kit-data-manager/react-search-component

Version:

All-in-one component for rendering an elastic search UI for searching anything. Built-in support for visualizing related items in a graph and resolving unique identifiers.

37 lines 1.29 kB
import { toArray } from "../../lib/utils"; /** * Utilities for working with the RelationsGraph */ export class GraphNodeUtils { /** * Build a sequential graph (n:n:n:...) by passing just the identifiers of the nodes in layers. * @param type Type of the nodes (use "result" to display your resultView) * @param ids Each entry resembled one layer in the sequential graph * @example * buildSequentialGraphFromIds("result", "a", ["b", "c", "d"], "e") * // result: * // b * // / \ * // a - c - e * // \ / * // d */ static buildSequentialGraphFromIds(type, ...ids) { const nodes = []; for (let layer = 0; layer < ids.length; layer++) { const previousLayer = layer > 0 ? toArray(ids[layer - 1]) : []; const currentLayer = toArray(ids[layer]); const nextLayer = layer + 1 < ids.length ? toArray(ids[layer + 1]) : []; for (const node of currentLayer) { nodes.push({ type, id: node, in: previousLayer, out: nextLayer }); } } return nodes; } } //# sourceMappingURL=GraphNodeUtils.js.map