@carbonplan/charts v3.1.1
carbonplan / charts
responsive reactive themeable charts
There are a lot of charting libraries for the web. Somehow, this one fills a niche that we think still exists. If nothing else, we find it useful, and will be using it ourselves! It's still super early in development, so expect lots of changes.
We're designing @carbonplan/charts
with a few goals in mind:
- built for modern
react
:arrow_upper_right: - fully responsive :left_right_arrow:
- modular and composable :recycle:
- easy to theme via
theme-ui
:sparkles: - plays great with
MDX
:tada:
It's also super light weight, depending only on react
and theme-ui
and some d3
utility packages. If there's interest we could probably factor out the theme-ui
dependency so it's optional.
background
This package is most directly inspired by pancake
, an experimental package build for svelte
. The concept motivating pancake
is that responsive charts that adapt fluidly to their containers without the need for redrawing can be built by carefully combining HTML for the chart and axes and SVG with viewBox
for the graphical elements. It's like an SVG sandwich
or pancake
. Pick your favorite food metaphor. Rich Harris described the concept super clearly in a blog post. Without knowing about pancake
, we started doing almost exactly the same thing a few months ago for our charts at CarbonPlan. There must be something to it.
However, to our knowledge, none of the existing charting libraries for JS help streamline this pattern. And pancake
is built for svelte
, whereas we're mainly using react
. That's how we got here.
Also worth mentioning that we've used vega
and vega-lite
and d3
a lot. We love them, we're taking inspiration all over the place, and even using some d3
utilities under the hood. Incredibly grateful to the developers of those tools.
usage
Here's a super simple scatter chart just to give you the idea.
import {
Chart,
Grid,
Ticks,
TickLabels,
AxisLabel,
Plot,
Scatter,
} from '@carbonplan/charts'
const ScatterChart = () => {
return (
<div style={{ width: '500px', height: '500px', padding: '64px' }}>
<Chart x={[0, 100]} y={[0, 100]}>
<Grid vertical horizontal />
<Ticks left bottom />
<TickLabels left bottom />
<AxisLabel left>Variable one</AxisLabel>
<AxisLabel bottom>Variable two</AxisLabel>
<Plot>
<Scatter
data={[
[10, 10],
[50, 50],
[90, 90],
]}
/>
</Plot>
</Chart>
</div>
)
}
This creates the following chart, shown with the light
and dark
themes of @carbonplan/theme
.
Many more examples and documentation coming soon.
development
To update a component and publish a new version, first make your changes, then follow these steps
- Increase the version number in
package.json
npm run build
npm publish
license
All the code in this repository is MIT-licensed, but we request that you please provide attribution if reusing any of our digital content (graphics, logo, articles, etc.).
about us
CarbonPlan is a nonprofit organization that uses data and science for climate action. We aim to improve the transparency and scientific integrity of climate solutions with open data and tools. Find out more at carbonplan.org or get in touch by opening an issue or sending us an email.
10 months ago
12 months ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago