API: primitives (@fragiola/flow-react, @fragiola/flow-vue, @fragiola/flow-svelte, @fragiola/flow-angular)
MiniMap
MiniMap draws a small map of every node and of what the root shows; with minimap(), a drag on it pans the flow and its wheel zooms.
MiniMap comes from @fragiola/flow-react/minimap (@fragiola/flow-vue/minimap), with the minimap() feature it needs. It
renders an SVG of width × height pixels inside Flow.Root, outside Flow.Viewport, whose
view box is the engine's minimap-view: every node, and the view the root shows. By default it
draws a MiniMapNode per node, then the MiniMapMask; a children function receives the view
(MinimapView) to draw your own. With minimap({ pannable, zoomable }) (both true by default) a
press or a drag on it pans the flow and its wheel zooms it. Place it and name it yourself.
import { Flow } from "@fragiola/flow-react";
import { MiniMap, MiniMapMask, MiniMapNode, minimap } from "@fragiola/flow-react/minimap";
const features = [minimap()] as const;
<Flow.Root<Types, typeof features> features={features} defaultNodes={nodes} className="relative size-full">
<Flow.Viewport>…</Flow.Viewport>
<MiniMap width={180} height={130} role="img" aria-label="Minimap" className="absolute right-3 bottom-3">
{(view) => (
<>
{view.nodes.map((node) => (
<MiniMapNode key={node.nodeId} nodeId={node.nodeId} className="fill-gray-300" />
))}
<MiniMapMask className="fill-black/10" />
</>
)}
</MiniMap>
</Flow.Root>;Grab, wheel speed and clicks
By default a press on the minimap centres the view there and a drag moves the view with the
pointer. A drag maps the pointer through the minimap's view box as it was at the press, so a drag
that changes the flow's bounds does not rescale under the pointer. inversePan makes a drag move
the view the other way, as grabbing the flow itself, and a press then does not centre it.
zoomStep sets how fast its wheel zooms (10, the default, is the flow's own wheel; 20 twice
as fast). Both default to minimap()'s options, and are sent to the
engine as the minimap's part options (engine.adapter.setPartOptions("minimap", "", …)): one set
per root, so several minimaps on one root share one set of options: the last to set them wins, and
removing one of them clears them (the others fall back to minimap()'s options until they set
theirs again).
A tap on the minimap (a press released without dragging) is the engine's minimap-click, with the
flow point under the pointer on that minimap: centre the view there with an animation, add a node
there. The event names the tapped minimap (element), so with several minimaps on one root only
the tapped one's callback runs. The root
captures the pointer at every press, so a DOM click listener on the minimap's element hears
nothing: use the minimap's own callback.
import { useFlow } from "@fragiola/flow-react";
import { MiniMap } from "@fragiola/flow-react/minimap";
/** Rendered inside Flow.Root: grab the map to move the flow, tap it to glide there. */
export function Map() {
const { engine } = useFlow();
return (
<MiniMap
inversePan
zoomStep={20}
onClick={(_event, point) => engine.run("center-on", { ...point, duration: 300 })}
role="img"
aria-label="Minimap"
/>
);
}onClick(event, point) gets the DOM MouseEvent and the flow point.
Props
MiniMapProps extends the common primitive props and
every SVG attribute of an svg but children.
| prop | type | default | description |
|---|---|---|---|
width | number | 200 | its width, in pixels |
height | number | 150 | its height, in pixels |
inversePan | boolean | minimap()'s (false) | a drag moves the view the other way (as grabbing the flow), and a press does not centre it |
zoomStep | number | minimap()'s (10) | how fast its wheel zooms: 10 is the flow's own wheel, 20 twice as fast |
onClick | (event: MouseEvent, point: XY) => void | none | a tap on it (the engine's minimap-click), with the flow point under the pointer on the minimap (Vue: the click event; Svelte: onclick; Angular: the minimapClick output, the whole event) |
children | ReactNode | ((view: MinimapView) => ReactNode) | a MiniMapNode per node, then the MiniMapMask | what it draws, in flow coordinates |
State
MiniMapState, what className, style and render receive:
| field | type | description |
|---|---|---|
view | MinimapView | the nodes, the view and the mask, in flow coordinates (engine reads) |
Data attributes
| attribute | value |
|---|---|
data-flow-part | "minimap" |
Structural style
width and height (attributes and style), viewBox from minimap-view.