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 idetik = new Idetik({
  canvas: document.querySelector('canvas')!,
  viewports: [{
    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 ​

QueueStats ​

A snapshot of the chunk request queue.

PropertyDescription
pending: numberNumber of requests waiting to start.
running: numberNumber of requests currently in flight.

ChunkStats ​

A snapshot of chunk demand and GPU residency.

Requested counts include prefetch. When the memory limit cannot hold every requested chunk, some are never fetched and resident stays below requested.

PropertyDescription
sources: readonly SourceChunkStats[]Cache state per source.
viewports: readonly ViewportChunkStats[]Loading progress per viewport. Viewports without chunked layers are omitted.

SourceChunkStats ​

Cache state for one source, combined across all of its views.

PropertyDescription
source: ChunkSourceThe source the counts describe.
requested: numberChunks requested by any view, visible or prefetch, at any LOD. A chunk requested by several views counts once. The budget may defer fetching.
resident: numberHow many of requested are on the GPU and drawable.
timepoints: objectThe same counts by timepoint index, the position along the source's time axis rather than the world t coordinate. A timepoint is fully loaded for every view of the source when its two counts are equal.
timepoints.requested: Uint32Arrayrequested[t] is the chunks requested at timepoint index t.
timepoints.resident: Uint32Arrayresident[t] is how many of requested[t] are on the GPU.

ViewportChunkStats ​

Loading progress for one viewport, summed across its chunked layers.

PropertyDescription
viewportId: stringThe viewport the counts describe.
requested: numberVisible and prefetch chunks at any LOD, including the fallback LOD drawn while the current one loads.
resident: numberHow many of requested are on the GPU.
current: objectThe same counts excluding fallback and prefetch: chunks visible at each layer's current LOD and timepoint. The viewport is fully drawn at its selected LOD when these are equal.
current.requested: numberChunks visible at each layer's current LOD and timepoint.
current.resident: numberHow many of requested are on the GPU.

Overlay ​

An object updated once per frame after all viewports have rendered.

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.memoryStats.cpuChunkCount} chunks`;
  },
};

idetik.addOverlay(chunkReadout);
PropertyDescription
update: (idetik) => voidCalled once per rendered frame.

IdetikProps ​

Initialization properties for constructing an Idetik instance.

PropertyDescription
canvas: HTMLCanvasElementThe canvas element to render into.
viewports?: ViewportProps[]Viewport definitions to create 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.

MemoryStats ​

A snapshot of the runtime's memory usage.

PropertyDescription
cpuChunkBytes: numberBytes of chunk data held in CPU memory.
cpuChunkCount: numberNumber of chunks held in CPU memory.
gpuTextureBytes: numberBytes of texture data resident on the GPU.
gpuTextureCount: numberNumber of textures resident on the GPU.
jsHeapUsedBytes?: numberUsed JS heap in bytes.
jsHeapLimitBytes?: numberJS heap size limit in bytes.

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[];

Accessors ​

chunkQueueStats QueueStats ​

Counts of queued and in-flight chunk requests.

ts
get chunkQueueStats(): QueueStats;

chunkStats ChunkStats ​

Chunk demand and GPU residency per source, by timepoint, and loading progress per viewport. Each read walks every view's chunk states and returns a new snapshot, so poll it at the rate you need rather than every frame.

ts
get chunkStats(): ChunkStats;

memoryStats MemoryStats ​

A snapshot of current CPU/GPU/JS heap memory usage.

ts
get memoryStats(): MemoryStats;

renderedObjects number ​

The number of objects drawn in the last rendered frame.

ts
get renderedObjects(): number;

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(props): Viewport;
ParameterDescription
props: ViewportPropsThe viewport definition. The element defaults to the canvas and must be unique across viewports.

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.

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