Skip to content

Idetik ​

The entry point of an Idetik application.

An Idetik instance owns the renderer and the chunk manager and drives the render loop for the viewports it is given. Each viewport pairs a camera and its controls with a stack of layers and draws into a region of the shared canvas. Layers in all viewports stream chunks through the same manager under a single memory budget.

ts
const source = await OmeZarrImageSource.fromHttp({ url });

const layer = new ImageLayer({
  source,
  sliceCoords: { t: 0, z: 0, c: [0] },
});

const camera = new OrthographicCamera({
  left: 0,
  right: 1024,
  top: 0,
  bottom: 1024,
});

const canvas = document.querySelector<HTMLCanvasElement>('canvas')!;
const idetik = new Idetik({
  canvas,
  viewports: [new Viewport({
    domElement: canvas,
    camera,
    layers: [layer],
    cameraControls: new PanZoomControls(camera),
  })],
});

idetik.start();

Constructor ​

Creates an Idetik runtime for the given canvas.

ts
new Idetik(params): Idetik;
ParameterDescription
params: IdetikPropsInitialization properties.

Types ​

Overlay ​

An object updated once per animation frame after any drawing.

Overlays drive HUD elements that live outside the canvas such as scale bars, time indicators, or memory readouts.

ts
const chunkReadout: Overlay = {
  update(idetik) {
    div.textContent = `${idetik.stats.memory.cpuChunkCount} chunks`;
  },
};

idetik.addOverlay(chunkReadout);
PropertyDescription
update: (idetik) => voidCalled every animation frame, including when drawing is skipped.

IdetikProps ​

Initialization properties for constructing an Idetik instance.

PropertyDescription
canvas: HTMLCanvasElementThe canvas element to render into.
viewports?: Viewport[]Viewports to render at startup.
overlays?: Overlay[]Overlays to run each frame.
showStats?: booleanShows an FPS meter. Defaults to false.
memoryLimitMB?: numberMemory budget for chunk data. Defaults to 2048.
maxConcurrentRequests?: numberMax in-flight chunk requests. Defaults to 8.
maxGpuUploadsPerUpdate?: numberMax GPU texture uploads per frame. Defaults to 4.

Properties ​

canvas ​

The canvas element the renderer draws into.

ts
readonly canvas: HTMLCanvasElement;

overlays ​

The registered overlays that update once per frame in order.

ts
readonly overlays: Overlay[];

stats ​

Runtime, memory, queue, chunk, and rendered-object statistics.

ts
readonly stats: Stats;

Accessors ​

width number ​

The width of the rendering surface in pixels.

ts
get width(): number;

height number ​

The height of the rendering surface in pixels.

ts
get height(): number;

viewports readonly Viewport[] ​

The viewports in render order.

ts
get viewports(): readonly Viewport[];

running boolean ​

Whether the render loop is running.

ts
get running(): boolean;

Methods ​

getViewport() Viewport | undefined ​

Finds a viewport by its id.

ts
getViewport(id): Viewport | undefined;
ParameterDescription
id: stringThe id given in the viewport's definition.

addViewport() Viewport ​

Adds a viewport at runtime.

ts
addViewport(viewport): Viewport;
ParameterDescription
viewport: ViewportThe viewport to add.

removeViewport() boolean ​

Removes a previously added viewport.

ts
removeViewport(viewport): boolean;
ParameterDescription
viewport: ViewportThe viewport to remove.

addOverlay() void ​

Registers an overlay that updates once per frame.

ts
addOverlay(overlay): void;
ParameterDescription
overlay: OverlayThe overlay to add.

removeOverlay() boolean ​

Removes a previously added overlay.

ts
removeOverlay(overlay): boolean;
ParameterDescription
overlay: OverlayThe overlay to remove.

setMemoryLimitMB() void ​

Sets the memory budget for chunk data at runtime.

ts
setMemoryLimitMB(memoryLimitMB): void;
ParameterDescription
memoryLimitMB: numberThe new budget in megabytes.

requestRender() void ​

Explicitly requests a draw on the next animation frame while running, even if no internal state has changed.

ts
requestRender(): void;

start() Idetik ​

Starts the render loop and connects input handlers.

ts
start(): Idetik;

stop() void ​

Stops the render loop and disconnects input handlers.

ts
stop(): void;

Released under the MIT License