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

@d3fc/d3fc-group

v3.0.1

Published

A utility for manipulating CSV / TSV data to allow rendering of grouped series.

Downloads

30,057

Readme

d3fc-group

A utility for manipulating CSV / TSV data to allow rendering of grouped series.

Main D3FC package

Installation

npm install @d3fc/d3fc-group

API Reference

General API

The d3-dsv package provides a number of utilities for parsing delimiter-separated values, such as comma-separated (CSV) or tab-separated (TSV). Given a DSV input these parsers produce an array of objects, with properties that correspond to the columns.

For example, using a subset of the data from this D3 example, a simple CSV is parsed as follows:

const data = d3.csvParse(
    `State,Under 5 Years,5 to 13 Years
    AL,310,552
    AK,52,85
    AZ,515,828`);

Resulting in the following structure:

[
   {'State': 'AL', 'Under 5 Years': '310', '5 to 13 Years': '552' },
   {'State': 'AK', 'Under 5 Years': '52', '5 to 13 Years': '85' },
   {'State': 'AZ', 'Under 5 Years': '515', '5 to 13 Years': '828' }
];

The group component takes this structure and manipulates it into a form that is more appropriate for rendering each row as an individual series within a grouped chart.

Here is how the group component can be applied to the above output:

const group = fc.group()
  .key('State');
const grouped = group(data);

The default group orientation is 'vertical', which creates a 'series' for each of the columns, other than the one which represents the key. With this example, a vertical group is as follows:

[
  [["AL", 310], ["AK", 52], ["AZ", 515]],
  [["AL", 552], ["AK", 85], ["AZ", 828]]
]

This structure very similar to the output of d3.stack and is suitable for rendering grouped series, in this case grouping by state.

The key for each series is available as series.key and the input data element for each point is available as point.data.

const group = fc.group()
  .key('State');
const grouped = group(data);
// [
//   [["AL", 310], ["AK", 52], ["AZ", 515]],
//   [["AL", 552], ["AK", 85], ["AZ", 828]]
// ]

// each series has a key property
grouped[0].key // 'Under 5 Years'
grouped[1].key // '5 to 13 Years'

// and each data element has a data property:
grouped[0][0].data //  {'State': 'AL', 'Under 5 Years': '310', '5 to 13 Years': '552' }

You can also perform a horizontal grouping, as illustrated in the following example:

const group = fc.group()
  .orient('horizontal')
  .key('State');
const grouped = group(data);

Which creates a series for each row, in this case allowing grouping by age-band:

[
  [["Under 5 Years", 310], ["5 to 13 Years", 552]],
  [["Under 5 Years", 52 ], ["5 to 13 Years", 85 ]],
  [["Under 5 Years", 515], ["5 to 13 Years", 828]]
]

API

# fc.group()

Constructs a new group generator with the default settings.

# group.key(keyValue)

If keyValue is specified, sets the name of the column within the DSV data that represents the key. If keyValue is not specified, returns the current key.

# group.value(valueFunc)

If valueFunc is specified, sets the accessor function used to obtain the value for a specific row / column. If valueFunc is not specified, returns the current accessor.

The accessor is invoked each time the group component obtains the value for a cell. The valueFunc(row, column) function is invoked with the current row (as supplied by the DSV parser) and the name of the column. The default implementation of this accessor function coerces all cell values to be Number instances.

# group.orient(orientation)

If orientation is specified, sets the orientation of the group operation. If orientation is not specified, returns the current orientation.