Node cards — a whole record drawn as the node

Sometimes the node is the record: a header, a photo, every property as a label: value row, a couple of badges, an overprinted stamp. A dossier, in other words. The engine knows nothing about dossiers — you map your own records onto a card spec, and it draws them.

There are two tiers, and they read the same node. Pick per use, or run the raster tier for every node and the DOM tier for the selected one.

Raster tier — NodeCardLayer DOM tier — api.cards
What it is pixels rasterised into an atlas and drawn in the scene live HTML positioned over the canvas
Scales with the graph yes optional (scale)
Composites with the scene yes — edges run behind it, it dims with focus/context, it is pickable no — it sits above the canvas
Text pixels real, selectable text
Links, inputs, scrolling no yes
Good for hundreds of cards a handful

The raster tier

import { GraphCanvas, NodeCardLayer } from '@kineviz/gl';

<GraphCanvas data={graph} nodeCloud edgeCloud>
  <NodeCardLayer
    filter={(n) => n.category === 'Person'}
    card={(n) => ({
      title: String(n.properties?.name ?? n.id),
      subtitle: String(n.properties?.caseId ?? ''),
      image: n.properties?.photo as string,
      badges: ['watchlist'],
      stamp: 'CLASSIFIED',
      fields: Object.entries(n.properties ?? {})
        .filter(([k]) => k !== 'photo')
        .map(([label, value]) => ({ label, value: String(value) })),
    })}
    aspect={1.5}
    sizeFactor={9}
  />
</GraphCanvas>

One texture, one draw call, hundreds of cards. card returns null to leave a node without one; filter bounds which nodes the layer touches at all.

The card spec

Field Draws as
title the headline, in the accent band
subtitle right of the headline, smaller — a category, a case id
image a photo URL, composited into the card's frame
fields rows, in order: { label, value, accent? }
badges short tags under the header band
stamp a big rotated overprint
footer a bottom strip, in the muted colour
accent a per-card accent colour, overriding the theme's

accent: true on a field draws its value in the accent colour — a flag, a risk level, a match.

Theme

theme controls colours, photo placement and metrics, all as fractions of the card height so a card looks the same at any resolution:

background, foreground, muted, accent, accentText, border (default 0.006), borderColor, photo ("left" | "top" | "none", default "left"), photoSize (default 0.34), font, labelFont, padding (0.055), header (0.15), rowHeight (0.082), rules (default true).

Panel options

The panel itself takes the same options as a media panel: shape, customSdf, radius (default 0.03), border, borderColor, tint, opacity, effects, band, bandOffset, clickable (default true), hideBuiltinNode (default true).

Sizing and budget differ: aspect defaults to 1.5, sizeFactor to 9, resolution to 320 card-height pixels (a 1.5 card is then 480×320 — raise it for crisper text, at capacity × resolution² worth of video memory), capacity to 36 cells and maxNodes to 64. Nodes past capacity draw no card.

Painting a cell yourself

paint replaces card and hands you the 2-D context for the cell:

<NodeCardLayer
  paint={(g, node, size) => {
    g.fillStyle = '#0b1220';
    g.fillRect(0, 0, size.width, size.height);
    // …draw anything
  }}
  revision={rev}        // bump to repaint — the layer cannot tell what you drew
/>

This is the door for anything the card spec cannot express, including real HTML, by rasterising an SVG foreignObject into an Image and drawing it here. Mind the caveat: external fonts and remote images inside such an SVG do not load, so inline them.

The DOM tier

api.cards puts live HTML over the graph. With placement: "center" and hideNode: true, the card is the node — an HTML node:

// a card beside a node
api.cards.set([{ nodeId: 'n1', template: 'property' }]);

// an HTML node: replaces the dot, and zooms with the graph
api.cards.set('n1', {
  template: 'dossier',
  placement: 'center',
  hideNode: true,
  scale: 6,
});

// your own markup, anchored to a world position, draggable
api.cards.set([{ position: [10, 0, 0], html: '<b>hello</b>', draggable: true }]);

api.cards.update('card:n1', { maxWidth: 420 });
api.cards.has('card:n1');
api.cards.clear('card:n1');
api.cards.clear();              // all of them

A spec needs either nodeId (the card follows the node) or position (a fixed world-space anchor); it throws otherwise. Default ids are card:<nodeId>.

Content comes from exactly one of:

  • template — a built-in: "property", "media", "list", "dossier". Any other key on the spec that is not a framing key is forwarded to the template as data.
  • html — a markup string.
  • render(node) — a function returning a string or an element; it receives the resolved node (id, category, caption, properties, image) or null.
  • element — an element you own.

Framing options: placement ("auto" | "top" | "right" | "bottom" | "left" | "center", default "auto"), offset (default [12, 0]), connector (default false), maxWidth (280), interactive (true), draggable (false), variant ("card" | "plain"), hideNode (false), scale (0), className, style.

scale is the card's width in graph units — the space node positions live in — so it zooms with the graph; 0 keeps it a fixed pixel size at any zoom. It is clamped to between 0.08 and 12 times its CSS width so a card stays legible.

See also