@d3fc/d3fc-group

中文文档
3.0.1发布于 2020/07/14MITESM + CJS零依赖近 30 天下载 6.1万

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

原始使用文档
文档目录4 节
  1. Installation
  2. API Reference
  3. General API
  4. API

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.

版本与发布记录

@d3fc/d3fc-group 共发布 13 个版本,首次发布于 2018/08/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.1latest2020/07/146 年前
3.0.02020/04/166 年前
2.0.102019/11/286 年前
2.0.92019/09/047 年前
2.0.82019/08/127 年前
2.0.72019/05/287 年前

关于 @d3fc/d3fc-group 的常见问题

@d3fc/d3fc-group 是什么?

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

如何安装 @d3fc/d3fc-group?

在项目目录运行 npm install @d3fc/d3fc-group,或使用 pnpm add / yarn add / bun add。

@d3fc/d3fc-group 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/d3fc__d3fc-group 是否存在。

@d3fc/d3fc-group 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@d3fc/d3fc-group 可以商用吗?

@d3fc/d3fc-group 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d3fc/d3fc-group 的下载量有多少?

根据 npm 官方下载统计,@d3fc/d3fc-group 在 2026/10/11 – 2026/11/09 这 30 天内被下载 61,340 次,日均约 2,045 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@d3fc/d3fc-group 还在维护吗?

最新版本 3.0.1 发布于 2020/07/14(6 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。