Reusable visualization library
The reusable visualization library is the @redash/viz package. It gives Redash product surfaces one shared way to edit and display query data as charts, tables, maps, and other visual forms. The package keeps visualization behavior separate from product screens while allowing those screens to supply app settings and data.
Library boundary
The library turns a common data shape into a visualization editor or a rendered result. A visualization receives columns and rows plus saved options, then produces either a preview that can change those options or a display for users.
The main package boundary is exposed by viz-lib/…/index.ts. Product code can use the package's Renderer, Editor, visualization registry, shared data shape, and settings update function. The package also supports direct imports from its transpiled lib output for shared components.
Visualization catalog
The catalog maps a visualization type to its name, option defaults, renderer, editor, and optional dashboard sizing rules. viz-lib/…/registeredVisualizations.ts registers the supported types at package load time.
| Visualization group | User-facing purpose |
|---|---|
| Chart and box plot | Show numeric data as plotted series and statistical views |
| Counter and details | Highlight a value or present selected row details |
| Table and pivot | Let users inspect rows or summarize them by dimensions |
| Funnel and cohort | Show stage progress or grouped change over time |
| Map and choropleth | Place values or regions on geographic views |
| Sankey and sunburst | Show flow or hierarchy relationships |
| Word cloud | Show the relative weight of words |
The registry selects a default type for new visualizations and creates the initial record that product code can save. Deprecated types remain distinct from active choices so existing data can still resolve without becoming the default for new work.
Rendering interface
The Renderer is the shared display entry point. It uses the selected type to resolve that visualization's option rules and renderer, then places the result behind an error boundary so a rendering fault is contained within the visualization area.
The renderer accepts a data object with columns and rows, the visualization name, and options. It may also receive content before or after the visualization, which lets a product surface place controls such as filters around the result.
The following flow shows how a product surface supplies data and options to the library and receives a display result.
flowchart LR
A[Query result] --> B[Product surface]
B --> C[Filtered data and saved options]
C --> D[Shared Renderer]
D --> E[Type registry]
E --> F[Type option rules]
F --> G[Visualization renderer]
G --> H[Chart or view]
Geographic rendering
The choropleth renderer turns geographic feature data into a bounded map view. It colors regions from their data values and can add a legend plus formatted tooltips and popups. User map movement remains separate from bounds supplied by the product, while resize events restore a suitable view without replacing a user's chosen position.
References: viz-lib/…/initChoropleth.tsx• L51-84 viz-lib/…/initChoropleth.tsx• L99-145 viz-lib/…/initChoropleth.tsx• L156-231
The table renderer provides the row-inspection form of this interface. It shows only configured visible columns and uses shared column display rules for cell values. Users can search columns marked for search, sort by one or more headers, and move through paged rows. A change to the incoming data or table columns clears the current sort so the view stays aligned with the new result.
References: viz-lib/…/Renderer.tsx• L17-63 viz-lib/…/Renderer.tsx• L86-142 viz-lib/…/utils.tsx• L53-138 viz-lib/…/utils.tsx• L141-189
Editing interface
The Editor is the shared configuration entry point. It resolves the same type registry as the renderer, applies the type's option rules, and passes changes back through onOptionsChange.
Editors can group related controls into tabs and can hide controls that do not apply to the current option set. For example, chart editors expose axis and series controls for standard charts but use a smaller control set for custom or pie charts. This keeps the editing contract consistent while allowing each visualization to fit its own choices.
References: viz-lib/…/Editor.tsx• L1-80 viz-lib/…/registeredVisualizations.ts• L1-160 viz-lib/…/index.tsx• L14-58
Reusable editor components
Shared editor components give different visualization editors the same controls and interaction rules. They cover color choice, labeled form controls, column settings, and drag-based ordering, so a change in one editor follows the same user model as a change in another.
Column and series editors use the shared sorting behavior to let users reorder saved configuration. The color picker supports preset or typed colors, while shared display helpers cover values such as dates, numbers, booleans, links, and nulls. JSON views can expand nested values, and HTML content is sanitized before it is shown.
References: viz-lib/…/index.tsx• L64-175 viz-lib/…/index.tsx• L122-193 viz-lib/…/ColumnEditor.tsx• L27-114 viz-lib/…/value-format.tsx• L15-121 viz-lib/…/HtmlContent.tsx• L1-19 viz-lib/…/sanitize.ts• L1-25
Chart sizing
The Plotly chart sizing path keeps a chart aligned with its container while preserving space for an enabled legend. It changes the chart layout when the container size changes and leaves the layout untouched during repeated checks of the same size, so a horizontal legend does not lose its reserved space.
Legend placement adapts to the available width. Automatic placement puts the legend below a narrow chart and beside a wider chart, while an explicit below setting always uses the lower position. The sizing path measures the legend when it is below the plot so the chart and legend share the available height.
References: viz-lib/…/updateChartSize.ts• L17-139 viz-lib/…/updateChartSize.test.ts• L3-32
Visualization data and display settings
The library treats visualization data as columns plus row objects. Column types and display modes support common table and detail views, including text, numbers, dates, booleans, links, images, and JSON. These shared column views keep value display consistent across visualizations.
The library also holds shared settings for formats, null values, boolean labels, links, help triggers, map definitions, and chart display. A product surface updates these settings before it renders an editor or result. The settings therefore adapt the library to product configuration without changing each visualization's interface.
Chart data is then shaped for the selected visual form. Standard charts map columns into series, while pie charts group values into slices and heatmaps arrange values into a grid. Maps group rows into geographic points or regions, and flow views turn staged rows into links or a hierarchy.
References: viz-lib/…/prop-types.ts• L1-46 viz-lib/…/index.ts• L1-120 viz-lib/…/visualizationsSettings.tsx• L1-160 viz-lib/…/preparePieData.ts• L98-135 viz-lib/…/prepareHeatmapData.ts• L107-127 viz-lib/…/prepareData.ts• L4-35 viz-lib/…/initSankey.ts• L134-171 viz-lib/…/initSunburst.ts• L115-128
Product surface integration
Redash query and dashboard surfaces use the library as a rendering service rather than reimplementing each visualization. client/…/visualizationComponents.jsx connects product links, help controls, client formats, and map data to the library settings before exposing wrapped editor and renderer components.
The query result surface combines query data with local and global filters before it calls the renderer. The visualization editor uses the registry to create or load a type, sends filtered data to both the editor and its live preview, and saves the resulting name and options through the product service. Dashboard widgets also read type sizing rules from the registry so the visual form fits its grid space.
This relationship connects the library to the broader dashboards and visualizations model. The product owns query results, saved records, filters, and layout. The library owns the visual meaning of a type and the controls needed to configure it.
References: client/…/visualizationComponents.jsx• L1-180 client/…/VisualizationRenderer.jsx• L1-180 client/…/EditVisualizationDialog.jsx• L1-220 client/…/widget.js• L1-180
Build outputs
The package produces two related outputs. The Babel build transpiles source files to lib and emits type declarations. The Webpack build creates the browser bundle dist/redash-visualizations.js as a UMD library and processes styles and image assets.
The package exposes the browser bundle as its main entry and publishes the dist and lib outputs. The transpiled output uses CommonJS for consumers such as client tests. The browser bundle keeps React, React DOM, Lodash, and Ant Design outside the bundle. React 18 and Ant Design are peer requirements, so the product supplies those shared runtimes.
The package provides separate type-check, declaration, build, watch, and test commands. The root client build runs the library Babel build before it bundles the product. Local development can watch the library and product in parallel, so changes to visualization code can flow into the client without a separate package release. See development build and test tooling for the wider build path.
References: viz-lib/package.json• L1-19 viz-lib/package.json• L27-32 viz-lib/package.json• L74-77 viz-lib/package.json• L106-145 viz-lib/.babelrc• L1-24 viz-lib/webpack.config.js• L6-71 viz-lib/tsconfig.json• L1-25 package.json• L1-180
Test structure
The library tests data preparation, option behavior, editor controls, render output, and shared value views. Jest runs in a browser-like DOM with Testing Library, fixed but advancing fake time, mocked media queries, and CSS or Less import stubs.
Tests provide three useful kinds of protection:
- Data tests check that rows and options become the expected chart or metric input.
- Component tests check that editors expose the right controls and renderers preserve key display behavior such as column order, filtering, pagination, and empty data handling.
- Interaction tests check shared controls such as drag sorting with mouse, touch, and keyboard input.
The package exposes type-check, build, and test scripts. The root product test path also includes the library in coverage and builds the library during install and product builds.
References: viz-lib/package.json• L6-19 viz-lib/package.json• L106-137 viz-lib/…/mocks.js• L1-21 viz-lib/…/testUtils.ts• L1-43 viz-lib/…/GridSettings.test.tsx• L1-180 viz-lib/…/ColumnsSettings.test.tsx• L1-180 viz-lib/…/updateChartSize.test.ts• L1-32 viz-lib/…/sortable.test.tsx• L43-180
Change checklist
When these files or sections are changed, remember to consider these:
- A new or renamed registry type must stay aligned with saved visualization type values and the product's type selector.
- Changes to the shared data shape or option normalization must be checked in both the editor preview and the dashboard or query renderer.
- Changes to shared settings must be checked against the product wrapper that copies client configuration and supplies map assets.
- Changes to visualization sizing fields must be checked against dashboard widget placement and resize limits.
- Changes to Plotly chart sizing or legend placement must preserve the distinction between a real container resize and a repeated size check.
- Changes to choropleth bounds or map updates must preserve the difference between product-provided bounds, user movement, and container resize.
- Changes to package entry points or build outputs must be checked against the root client build and direct
@redash/vizorlibimports. - Table changes to column visibility, search eligibility, sorting, or pagination must preserve the table options used by saved visualizations and the row data shape supplied by product surfaces.
- Changes to chart or table display rules must preserve the saved option format used by existing visualizations.
- Changes to custom chart execution or its enable setting must preserve the product's boundary for user-supplied chart code.
- Changes to HTML, map tooltip, or map popup content must keep the shared sanitization path in place.
- Changes to sortable editor items must preserve position-based indexes and the old-to-new index callback contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A product passes an unknown visualization type | The shared editor or renderer cannot resolve the type-specific behavior | Keep saved type values aligned with registeredVisualizations |
| A renderer receives data without the required columns or rows shape | The selected visualization can fail before it can display a result | Preserve the shared data contract at query-result and preview boundaries |
| A choropleth receives invalid geographic features or no usable map definition | The map has no regions to draw or cannot show the configured geography | Validate geographic data and supply map assets through the product settings wrapper |
| A choropleth update replaces a user's view while the map is focused or resized | The map jumps away from the user's selected area | Keep product bounds, user movement, and resize handling distinct |
| A table receives changed columns while retaining an old sort state | Rows can appear ordered by fields that no longer match the visible result | Reset table sorting when table options or result columns change |
| A repeated size check reapplies the raw container height after a horizontal legend was measured | The chart loses space reserved for the legend | Skip layout changes when the container dimensions are unchanged |
| Custom chart code runs without the product enable setting | User-supplied code can run where the product does not allow it | Keep the custom chart option and product setting aligned |
The library bundle or transpiled lib output is stale | Product imports can use old visualization behavior or fail to resolve generated files | Run the library build as part of product install and build flows |
| Saved chart or table options are replaced without normalization | Older records can lose defaults or stop matching current controls | Keep type option rules responsible for merging defaults and compatibility values |
| User HTML reaches a view outside the shared sanitizer | A tooltip, popup, or content view can display unsafe markup | Route HTML through sanitize before it reaches the DOM or map layer |
| A sortable item does not pass through the required sortable element boundary | Drag actions can report the wrong item or fail to update order | Keep item indexes and drag handles tied to the sortable container contract |
Key files
| File | Why to read it |
|---|---|
| viz-lib/README.md | Shows package use, supported visualization types, shared data, and product-supplied settings |
| viz-lib/…/index.ts | Shows the package's public exports |
| viz-lib/…/registeredVisualizations.ts | Explains type registration, default selection, and new visualization records |
| viz-lib/…/Renderer.tsx | Shows the shared path from a type and data object to a protected display |
| viz-lib/…/Editor.tsx | Shows the shared path from a type and data object to configuration controls |
| viz-lib/…/prop-types.ts | Defines the common visualization and data boundary |
| viz-lib/…/visualizationsSettings.tsx | Defines settings that product surfaces can adapt |
| viz-lib/…/initChoropleth.tsx | Shows the geographic rendering boundary, map view behavior, and cleanup contract |
viz-lib/src/visualizations/chart/ | Illustrates a chart with data display and a multi-part editor |
| viz-lib/…/updateChartSize.ts | Shows how a Plotly chart responds to container resizing and legend placement |
| viz-lib/…/Renderer.tsx | Illustrates table search, sorting, pagination, and handling of changing data |
viz-lib/src/visualizations/shared/columns/ | Shows common value display rules shared by table-like views |
| viz-lib/…/index.tsx | Shows the shared ordering behavior used by chart and column editors |
| viz-lib/…/sanitize.ts | Shows the safety boundary for HTML content |
| viz-lib/package.json | Defines package scripts, peer requirements, published outputs, and test scope |
viz-lib/.babelrc | Defines the transpiled module format and source aliases |
| viz-lib/tsconfig.json | Defines strict type checking and declaration output |
| viz-lib/webpack.config.js | Defines the browser bundle and asset processing boundary |
| client/…/visualizationComponents.jsx | Shows how the product supplies settings and wraps library entry points |
| client/…/VisualizationRenderer.jsx | Shows how query results and filters reach a visualization renderer |
| client/…/EditVisualizationDialog.jsx | Shows how type choice, live preview, and saved options reach the library |
| client/…/widget.js | Shows how registry sizing rules affect dashboard widget layout |