d3-composer
d3-composer consists of two primary concepts: functional chart components and a grid system based on CSS grid.
Functional chart components
A functional chart component approach is used throughout d3-composer and allows complex charts to be composed out of simple, reusable chart components. These match closely to built-in d3 components and can be used with the standard approach of selection.call(...)
.
{ // ...} { ; // ...} // or ;
Grid system
d3-composer uses a grid-template
approach (see: A Complete Guide to Grid for details) for laying out selections for chart components.
; const grid = ; // For size = { width: 600, height: 400 }://// grid = {// title: { x: 0, y: 0, width: 600, height: 50 },// y_axis: { x: 0, y: 50, width: 50, height: 300 },// chart: { x: 50, y: 50, width: 550, height: 300 },// x_axis: { x: 50, y: 350, width: 550, height: 50 }// }
Usage
For npm / yarn, npm install d3-composer
or yarn add d3-composer
. Otherwise, you can use unpkg to download the latest release: <script src="https://unpkg.com/d3-composer"></script>
and reference d3-composer with the d3c
global.
Example
;; { const data = xScale yScale } = options; const grid = ; xScale; yScale; ;} const svg = ; ;
Examples
Live examples on observablehq:
API
@d3-composer/grid
- template - Create grid from template
@d3-composer/svg
- chart - SVG chart wrapper with sizing and responsive options
- layout - Create
g
layers from grid - layer - Create named
g
layer - series - Create series layers
- stack - Create stacked layers
- vstack - Create vertically stacked layers
- hstack - Create horizontally stacked layers
- line - Line chart
- bars - Bars chart
- scatter - Scatter chart
- area - Area chart
- labels - Labels component
- axisTop - Top-oriented axis component
- axisRight - Right-oriented axis component
- axisBottom - Bottom-oriented axis component
- axisLeft - Left-oriented axis component
- text - Text component
- legend - Legend component
- gridlines - Gridlines component
- symbolLine - Line symbol
- measure - Measurement helper
- interpolatePath - Interpolate path
d
- translateXY - Translate helper for x,y
@d3-composer/utils
- toStyle - convert to style string
- toMargin - convert to margin array
- passthrough - create data passthrough
- array - wrap given value as array
- fn - ensure given value is a function
- seriesExtent - determine extent of series data
- Size - size local
- Area - area local
- Series - series local
Development
- Install:
yarn
oryarn install
(d3-composer uses yarn workspaces) - Test:
yarn test
- Build:
yarn build
- Version:
npx lerna version VERSION
- Publish:
npx lerna publish from-package --otp ######