Skip to content

DiagramSpec

DiagramSpec describes a diagram as a set of elements and the relations between them. It's the input to olliDiagram.

ts
interface DiagramSpec {
  elements: DiagramElement[];
  relations: DiagramRelation[];
  title?: string;
  description?: string;
}
PropertyTypeRequiredDescription
elementsDiagramElement[]yesThe individual items in the diagram.
relationsDiagramRelation[]yesHow elements relate to each other.
titlestringnoDisplay name for the diagram root.
descriptionstringnoExplanatory text appended after the title in screen reader output.

DiagramElement

ts
interface DiagramElement {
  id: string;
  label: string;
  description?: string;
  kind?: string;
  connector?: boolean;
}
PropertyTypeRequiredDescription
idstringyesUnique identifier. Referenced by relations.
labelstringyesShort display name — becomes displayName on the hyperedge.
descriptionstringnoExplanatory text appended after the label in screen reader output.
kindstringnoElement category (e.g., "component", "adapter"). Surfaced by the elementKind token.
connectorbooleannoIf true, the element is treated as a connector (e.g., an arrow or wire) rather than a primary element. Connectors without structural parents are only reachable through referential relations.

DiagramPayload

When the lowerer converts elements and relations into hyperedges, each edge carries a DiagramPayload:

ts
interface DiagramPayload {
  sourceRelation?: DiagramRelation;
  sourceElement?: DiagramElement;
}

Element edges have sourceElement set. Relation edges have sourceRelation set. The payload is used by tokens and predicate providers to generate descriptions and selections.

Example

ts
import { olliDiagram } from 'olli';

const spec: DiagramSpec = {
  title: 'Pulley system',
  elements: [
    { id: 'rope', label: 'Rope', kind: 'component' },
    { id: 'wheel', label: 'Wheel', kind: 'component' },
    { id: 'axle', label: 'Axle', kind: 'component' },
    { id: 'weight', label: 'Weight', kind: 'component' },
  ],
  relations: [
    { kind: 'containment', id: 'pulley', container: 'wheel', contents: ['axle'], label: 'Pulley' },
    { kind: 'connection', id: 'c1', endpoints: ['rope', 'wheel'], semantic: 'wraps-around' },
    { kind: 'connection', id: 'c2', endpoints: ['rope', 'weight'], semantic: 'attaches-to' },
  ],
};

const handle = olliDiagram(spec, document.getElementById('tree')!);

Next

Released under the BSD-3-Clause License.