Skip to content

PureRenderer

PureRenderer renders a single read-only chart from a visualization specification. It has minimal UI — no toolbar, no chart tabs, no field list. This makes it ideal for embedding charts in dashboards, articles, or any context where you want a static visualization.

import { PureRenderer } from '@kanaries/graphic-walker';

When to Use

ComponentInteractiveToolbarMultiple ChartsField List
GraphicWalkerFull editingYesYesYes
GraphicRendererView onlyYesYesNo
PureRendererView onlyNoNoNo

Use PureRenderer when you need to display a chart with the smallest possible footprint.

Props

Local Mode (Client-Side Data)

PropTypeRequiredDescription
rawDataIRow[]YesArray of data records.
type'local'NoExplicitly set local mode (default).

Remote Mode (Server-Side Data)

PropTypeRequiredDescription
computationIComputationFunctionYesComputation function for server-side processing.
type'remote'YesMust be set to 'remote'.

Visualization State

PropTypeRequiredDescription
visualStateDraggableFieldStateYesField encodings (rows, columns, color, size, etc.).
visualConfigIVisualConfigNewYesVisualization configuration (aggregation, geom type, coord system).
visualLayoutIVisualLayoutNoLayout configuration (size, stack mode, formatting). Falls back to visualConfig if not provided.

Appearance Props

PropTypeDefaultDescription
appearance'media' | 'light' | 'dark''media'Dark mode setting.
vizThemeConfigIThemeKey | GWGlobalConfigundefinedChart theme.
uiThemeIUIThemeConfigundefinedCustom UI colors.
overrideSize{ mode: 'auto' | 'fixed' | 'full'; width: number; height: number }undefinedOverride size from the spec.
scalesIChannelScalesundefinedCustom scale configurations.

Other Props

PropTypeDescription
namestringChart name (used in export).
classNamestringCSS class for the root element.
localestringLocale for number/date formatting. Defaults to 'en-US'.
disableCollapsebooleanDisable collapsible chart container.

Examples

Local Mode

import { PureRenderer } from '@kanaries/graphic-walker';
import type { DraggableFieldState, IVisualConfigNew, IVisualLayout } from '@kanaries/graphic-walker';
 
const data = [
  { category: 'A', value: 100 },
  { category: 'B', value: 200 },
  { category: 'C', value: 150 },
];
 
const visualState: DraggableFieldState = {
  dimensions: [],
  measures: [],
  rows: [{ fid: 'value', name: 'Value', analyticType: 'measure', semanticType: 'quantitative' }],
  columns: [{ fid: 'category', name: 'Category', analyticType: 'dimension', semanticType: 'nominal' }],
  color: [],
  opacity: [],
  size: [],
  shape: [],
  theta: [],
  radius: [],
  longitude: [],
  latitude: [],
  geoId: [],
  details: [],
  filters: [],
  text: [],
};
 
const visualConfig: IVisualConfigNew = {
  defaultAggregated: true,
  geoms: ['bar'],
  coordSystem: 'generic',
  limit: -1,
};
 
const visualLayout: IVisualLayout = {
  showTableSummary: false,
  stack: 'stack',
  showActions: false,
  interactiveScale: false,
  zeroScale: true,
  size: { mode: 'auto', width: 600, height: 400 },
  format: {},
  resolve: {},
};
 
function ChartEmbed() {
  return (
    <PureRenderer
      rawData={data}
      visualState={visualState}
      visualConfig={visualConfig}
      visualLayout={visualLayout}
    />
  );
}

Remote Mode

import { PureRenderer } from '@kanaries/graphic-walker';
import type { IComputationFunction } from '@kanaries/graphic-walker';
 
const computation: IComputationFunction = async (payload) => {
  const res = await fetch('/api/query', {
    method: 'POST',
    body: JSON.stringify(payload),
    headers: { 'Content-Type': 'application/json' },
  });
  return res.json();
};
 
function RemoteChart() {
  return (
    <PureRenderer
      type="remote"
      computation={computation}
      visualState={visualState}
      visualConfig={visualConfig}
      visualLayout={visualLayout}
    />
  );
}

With Fixed Size

<PureRenderer
  rawData={data}
  visualState={visualState}
  visualConfig={visualConfig}
  overrideSize={{ mode: 'fixed', width: 400, height: 300 }}
/>

Extracting State from GraphicWalker

You can get the visualState, visualConfig, and visualLayout from a GraphicWalker instance using storeRef, then pass them to PureRenderer:

import { useRef } from 'react';
import { GraphicWalker, PureRenderer } from '@kanaries/graphic-walker';
import type { VizSpecStore } from '@kanaries/graphic-walker';
 
function App() {
  const storeRef = useRef<VizSpecStore>(null);
 
  const handleExport = () => {
    if (!storeRef.current) return;
    const chart = storeRef.current.exportCurrentChart();
    // chart contains encodings, config, layout
    // Pass these to PureRenderer elsewhere
  };
 
  return <GraphicWalker data={data} fields={fields} storeRef={storeRef} />;
}