MCPcopy
hub / github.com/airbnb/visx

github.com/airbnb/visx @v4.0.0 sqlite

repository ↗ · DeepWiki ↗ · release v4.0.0 ↗
1,109 symbols 3,564 edges 1,013 files 31 documented · 3%
README

visx

visx is a collection of reusable low-level visualization components. visx combines the power of d3 to generate your visualization with the benefits of react for updating the DOM.

[!IMPORTANT] visx v4 is the current stable release and requires React 18 or 19.

bash npm install @visx/shape

Upgrading from v3? See the visx 4 migration guide.

Docs Gallery Changelog Migration

Usage

Let's make a simple bar graph.

First we'll install the relevant packages:

npm install --save @visx/mock-data @visx/group @visx/shape @visx/scale

import React from 'react';
import { letterFrequency } from '@visx/mock-data';
import { Group } from '@visx/group';
import { Bar } from '@visx/shape';
import { scaleLinear, scaleBand } from '@visx/scale';

// We'll use some mock data from `@visx/mock-data` for this.
const data = letterFrequency;

// Define the graph dimensions and margins
const width = 500;
const height = 500;
const margin = { top: 20, bottom: 20, left: 20, right: 20 };

// Then we'll create some bounds
const xMax = width - margin.left - margin.right;
const yMax = height - margin.top - margin.bottom;

// Accessors
const getLetter = (d) => d.letter;
const getFrequency = (d) => d.frequency * 100;

// And then scale the graph by our data
const xScale = scaleBand({
  range: [0, xMax],
  round: true,
  domain: data.map(getLetter),
  padding: 0.4,
});
const yScale = scaleLinear({
  range: [yMax, 0],
  round: true,
  domain: [0, Math.max(...data.map(getFrequency))],
});

// Finally we'll embed it all in an SVG
function BarGraph() {
  return (
    <svg width={width} height={height}>
      {data.map((d) => {
        const letter = getLetter(d);
        const barHeight = yMax - (yScale(getFrequency(d)) ?? 0);
        return (
          <Group key={`bar-${letter}`}>
            <Bar
              x={xScale(letter)}
              y={yMax - barHeight}
              height={barHeight}
              width={xScale.bandwidth()}
              fill="#fc2e1c"
            />
          </Group>
        );
      })}
    </svg>
  );
}

For more examples using visx, check out the gallery.

Motivation

Goal

The goal is to create a library of components you can use to make both your own reusable chart library or your slick custom one-off chart. visx is largely unopinionated and is meant to be built upon. Keep your bundle sizes down and use only the packages you need.

How?

Under the hood, visx is using d3 for the calculations and math. If you're creating your own awesome chart library on top of visx, it's easy to create a component api that hides d3 entirely. Meaning your team could create charts as easily as using reusable react components.

But why?

Mixing two mental models for updating the DOM is never a good time. Copy and pasting d3 code into useEffect() is just that. This collection of components lets you easily build your own reusable visualization charts or library without having to learn d3. No more selections or enter()/exit()/update().

FAQ

  1. What does visx stand for?

visx stands for visualization components.

  1. Do you plan on supporting animation/transitions?

A common criticism of visx is it doesn't have animation baked in, but this was a conscious choice. It's a powerful feature to not bake it in.

Imagine your app already bundles react-motion, adding a hypothetical @visx/animation is bloat. Since visx is react, it already supports all react animation libs.

Charting libraries are like style guides. Each org or app will eventually want full control over their own implementation.

visx makes this easier for everyone. No need to reinvent the wheel each time.

more info: https://github.com/airbnb/visx/issues/6

  1. Do I have to use every package to make a chart?

nope! pick and choose the packages you need.

  1. Can I use this to create my own library of charts for my team?

Please do.

  1. Does visx work with preact?

yup! alias react + react-dom to preact/compat. For visx v4, configure your package manager to satisfy the React 18/19 peer dependency range.

  1. I like using d3.

Me too.

Development

Please see CONTRIBUTING.md

:v:

MIT

Extension points exported contracts — how you extend this code

Config (Interface)
(no doc)
packages/visx-voronoi/src/voronoi.ts
TooltipWithZIndexProps (Interface)
(no doc)
packages/visx-tooltip/test/useTooltipInPortal.test.tsx
AxisStyle (Interface)
(no doc)
packages/visx-xychart/src/types/theme.ts
TransformMatrix (Interface)
(no doc)
packages/visx-zoom/src/types.ts
WordsWithWidth (Interface)
(no doc)
packages/visx-text/src/types.ts
WordcloudProps (Interface)
(no doc)
packages/visx-wordcloud/src/Wordcloud.tsx
ParsedFeature (Interface)
(no doc)
packages/visx-geo/src/projections/Projection.tsx
TemporalScaleConfig (Interface)
(no doc)
packages/visx-scale/src/types/ScaleConfig.ts

Core symbols most depended-on inside this repo

keys
called by 49
packages/visx-xychart/src/classes/DataRegistry.ts
render
called by 48
packages/visx-demo/src/pages/_document.tsx
isValidNumber
called by 35
packages/visx-xychart/src/typeguards/isValidNumber.ts
size
called by 35
packages/visx-wordcloud/src/types.ts
attachDocGenInfo
called by 30
packages/visx-demo/src/utils/getDocGenInfo.ts
getDataContext
called by 29
packages/visx-xychart/test/mocks/getDataContext.ts
get
called by 29
packages/visx-xychart/src/classes/DataRegistry.ts
createScale
called by 26
packages/visx-scale/src/createScale.ts

Shape

Function 907
Interface 115
Method 53
Class 34

Languages

TypeScript100%

Modules by API surface

packages/visx-wordcloud/src/types.ts20 symbols
scripts/generateDocs.ts17 symbols
packages/visx-zoom/src/util/matrix.ts9 symbols
packages/visx-demo/src/sandboxes/visx-xychart/ExampleControls.tsx9 symbols
packages/visx-demo/src/sandboxes/visx-stats/Example.tsx8 symbols
packages/visx-demo/src/sandboxes/visx-shape-line-radial/Example.tsx8 symbols
packages/visx-demo/src/sandboxes/visx-brush/Example.tsx8 symbols
scripts/performRelease/performLernaRelease.ts7 symbols
packages/visx-xychart/src/classes/DataRegistry.ts7 symbols
packages/visx-event/src/typeGuards.ts7 symbols
packages/visx-demo/src/sandboxes/visx-wordcloud/Example.tsx7 symbols
packages/visx-demo/src/sandboxes/visx-shape-pie/Example.tsx7 symbols

Dependencies from manifests, versioned

@babel/cli7.26.4 · 1×
@babel/core7.26.0 · 1×
@babel/eslint-parser7.25.9 · 1×
@babel/plugin-transform-modules-commonjs7.22.5 · 1×
@babel/preset-env7.29.7 · 1×
@babel/preset-react7.26.3 · 1×
@babel/preset-typescript7.26.0 · 1×
@babel/runtime7.8.4 · 1×
@juggle/resize-observer3.3.1 · 1×
@octokit/openapi-types18.0.0 · 1×
@octokit/rest18.1.0 · 1×
@react-spring/web10.0.3 · 1×

For agents

$ claude mcp add visx \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact