npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-composer

v0.8.2

Published

grid and chart components for composing data visualizations with d3

Downloads

8

Readme

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(...).

function lines(selection, options) {
  // ...
}

function composed(selection, options) {
  lines(selection, options);
  // ...
}

composed(select('...'), { /* ... */ })

// or 

select('...').call(composed, { /* ... */ });

Grid system

d3-composer uses a grid-template approach (see: A Complete Guide to Grid for details) for laying out selections for chart components.

import { template } from 'd3-composer';

const grid = template(`
  "title title" 50
  "y_axis chart" auto
  ". x_axis" 50
  / 50 auto
`, { width: 600, height: 400 });

// 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

import { select } from 'd3';
import { template, chart, layout, series, line, axisLeft, axisBottom, text, measure } from 'd3-composer';

function lines(selection, options = {}) {
  const { data = [], xScale, yScale  } = options;

  const grid = template(`
    "title title" 50
    "y_axis chart" auto
    ". x_axis" 50
    / 50 auto
  `, measure(selection));

  xScale.range([0, grid.areas.chart.width]);
  yScale.range([grid.areas.chart.height, 0]);

  layout(selection, grid, layers => {
    axisLeft(layers.x_axis(), { scale: xScale });
    axisBottom(layers.y_axis(), { scale: yScale });
    
    line(
      series(layers.chart(), { data }),
      {
        data: series => series.values,
        x: d => xScale(d.x),
        y: d => yScale(d.y)
      }
    );
    
    text(layers.title(), { text: 'Line Chart' });
  });
}

const svg = chart(
  select('#chart'),
  { width: 600, height: 400, responsive: true }
);

lines(svg, { /* ... */ });

Examples

Live examples on observablehq:

API

@d3-composer/grid

@d3-composer/svg

@d3-composer/utils

Development

  • Install: yarn or yarn install (d3-composer uses yarn workspaces)
  • Test: yarn test
  • Build: yarn build
  • Version: npx lerna version VERSION
  • Publish: npx lerna publish from-package --otp ######