Skip to content

Schema Visualization

The Schema Visualization component renders an interactive entity-relationship diagram (ERD) of your cube schemas. It shows cubes as cards with their measures, dimensions, and time dimensions, connected by relationship edges.

The schema visualization requires two optional peer dependencies:

Terminal window
npm install @xyflow/react elkjs

These packages are not bundled with drizzle-cube — they are loaded on demand only when the component is rendered. If they are not installed, a helpful fallback message is displayed.

import { CubeProvider, SchemaVisualization } from 'drizzle-cube/client'
import 'drizzle-cube/client/styles.css'
function SchemaPage() {
return (
<CubeProvider apiOptions={{ apiUrl: '/api/cubejs-api/v1' }} token={token}>
<SchemaVisualization height="calc(100vh - 100px)" />
</CubeProvider>
)
}

Enable the schema diagram button in the AnalysisBuilder results panel via the showSchemaDiagram feature flag:

<CubeProvider
apiOptions={{ apiUrl: '/api/cubejs-api/v1' }}
token={token}
features={{ showSchemaDiagram: true }}
>
<AnalysisBuilder />
</CubeProvider>

When enabled, a diagram icon button appears in the results panel toolbar. Clicking it toggles the schema visualization overlay, where you can:

  • Click measures to toggle them as metrics in the query builder
  • Click dimensions to toggle them as breakdowns
  • See highlighted fields that are currently selected in the query
PropTypeDefaultDescription
classNamestring''Additional CSS classes for the container
heightstring | number'100%'Height of the visualization container
onFieldClick(cubeName, fieldName, fieldType) => voidCallback when a field row is clicked
highlightedCubesstring[]Cube names to highlight (accent border + ring)
highlightedFieldsstring[]Field names to highlight (e.g. ['Employees.count'])
searchTermstringExternal search term (hides built-in search bar)

The component uses ELK.js (Eclipse Layout Kernel) with the layered algorithm to automatically position nodes. ELK calculates optimal placement considering edge connections, using per-edge ports to spread connections along node sides for clean routing.

React Flow’s native bezier curves handle edge rendering, producing smooth paths between nodes.

Drag any cube card to reposition it. Positions are automatically saved to localStorage and restored on the next visit. Right-click the canvas and select Auto Layout to reset to the computed layout.

The built-in search bar (shown when no external searchTerm prop is provided) filters across all cube names, field names, and titles. Matching fields are highlighted while non-matching fields are dimmed.

Each cube is rendered as a card with collapsible sections:

  • Measures — with amber indicator dot
  • Time Dimensions — with blue indicator dot
  • Dimensions — with green indicator dot

Sections with many fields scroll internally (mouse wheel works inside the card without zooming the canvas). The header shows the total field count and a summary badge (e.g. 9M 11D).

Edges display the relationship type between cubes:

SymbolRelationship
1:1hasOne
1:MhasMany
M:MbelongsToMany

Edge labels also show the join field mappings (e.g. id → employeeId).

The visualization fully supports dark mode through the drizzle-cube theming system. Section headers use subtle color tints that adapt to the current surface color.

Wire up field clicks to your own logic:

<SchemaVisualization
height="600px"
onFieldClick={(cubeName, fieldName, fieldType) => {
console.log(`Clicked ${fieldType}: ${cubeName}.${fieldName}`)
// Add to query, show details, etc.
}}
highlightedFields={['Employees.count', 'Employees.name']}
/>

Provide an external search term to hide the built-in search bar and control filtering externally:

const [search, setSearch] = useState('')
<input value={search} onChange={e => setSearch(e.target.value)} />
<SchemaVisualization searchTerm={search} />

”Schema Visualization requires additional packages”

Section titled “”Schema Visualization requires additional packages””

Install the optional dependencies:

Terminal window
npm install @xyflow/react elkjs

Clear saved positions from localStorage:

localStorage.removeItem('drizzle-cube-erd-node-positions')

Then refresh. The component will compute a fresh auto-layout.

This can happen when using saved positions from a previous layout. Right-click the canvas and select Auto Layout to recompute positions with ELK’s edge-aware algorithm.