@d3fc/d3fc-data-join

中文文档
6.0.3发布于 2020/09/24MITESM + CJS零依赖近 30 天下载 7.4万

A component that simplifies the D3 data join and supports the d3fc decorate pattern

原始使用文档

d3fc-data-join

A wrapper around D3's data join which simplifies some of the common problems that have been run into with our particular usage patterns, and facilitates the d3fc decorate pattern. These are not going to be universally applicable. As always it’s important to understand the abstraction and in many cases a vanilla data join may be simpler or perform better.

This blog post (Building Components with Data Join) introduces the rationale behind this component.

Main D3FC package

Installing

npm install @d3fc/d3fc-data-join

API Reference

The data-join component is a relatively lightweight wrapper around d3's selectAll/data data-join, which allows decoration of the result. This is achieved by appending the element to the enter selection before exposing it. A default transition of fade in/out is also implicitly added but can be modified.

# fc.dataJoin([element][, className])

Constructs a new data-join component instance. Optionally an element or an element and a className can be specified, this is functionally equivalent to calling their methods as defined below.

# dataJoin(selection[, data])

Invoke with a selection containing the parent element and the data to be joined.

import { dataJoin } from 'd3fc-data-join';
import { select } from 'd3-selection';

const join = dataJoin('li', 'animal');

join(select('ul'), ['Aardvark', 'Beaver', 'Cat'])
  .text(d => d);

The return value is a selection containing all new and existing nodes. Two additional methods are exposed for retrieving a selection containing only the new nodes (.enter()) and the removed nodes (.exit()).

import { dataJoin } from 'd3fc-data-join';
import { select } from 'd3-selection';

const join = dataJoin('li', 'animal');

const update = join(select('ul'), ['Aardvark', 'Beaver', 'Cat'])
  .text(d => d);

update.enter()
  .attr('data-', d => d);

If d3-transition is available, new nodes will have a fade-in transition applied and removed nodes will have a fade-out transition applied. The transition timings can be controlled from the container selection passed in or by explicitly setting transition.

import { dataJoin } from 'd3fc-data-join';
import { select } from 'd3-selection';
import { transition } from 'd3-transition';

const quickTransition = transition()
  .duration(300);

const join = dataJoin('li', 'animal');

const container = select('ul')
  .transition(quickTransition);

join(container, ['Aardvark', 'Beaver', 'Cat'])
  .text(d => d);

To disable transitions, explicitly retrieve the selection from the transition before passing it in -

import { dataJoin } from 'd3fc-data-join';
import { select } from 'd3-selection';
import { transition } from 'd3-transition';

const quickTransition = transition()
  .duration(300);

const join = dataJoin('li', 'animal');

const root = select('body')
  .transition(quickTransition);

const container = root.select('ul')
  .selection();

join(container, ['Aardvark', 'Beaver', 'Cat'])
  .text(d => d);

# dataJoin.element(element)

Sets the element name used to select elements and to create elements for insertion. Defaults to an SVG g element. See className for a description of the selector used.

# dataJoin.className(className)

Set the class name used to select elements and applied to inserted elements. Defaults to null. If set to null, only the element is used as the selector. If non-null, the selector provided to selectAll is -

`${element}.${className}`

# dataJoin.key(keyFunc)

Specifies the key function used by the data-join. Defaults to index-based. Equivalent to specifying a key argument when calling selection.data().

# dataJoin.transition(transition)

Specifies the transition to be used if an implicit transition is not supplied as the container. Defaults to null which disables transitions.

版本与发布记录

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

版本发布日期距今
6.0.3latest2020/09/246 年前
6.0.22020/09/166 年前
6.0.12020/07/146 年前
6.0.02020/04/166 年前
5.1.02020/03/196 年前
5.0.112019/11/286 年前

关于 @d3fc/d3fc-data-join 的常见问题

@d3fc/d3fc-data-join 是什么?

A component that simplifies the D3 data join and supports the d3fc decorate pattern

如何安装 @d3fc/d3fc-data-join?

在项目目录运行 npm install @d3fc/d3fc-data-join,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:d3-selection(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@d3fc/d3fc-data-join 支持 TypeScript 吗?

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

@d3fc/d3fc-data-join 支持 ESM 还是 CommonJS?

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

@d3fc/d3fc-data-join 可以商用吗?

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

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

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

@d3fc/d3fc-data-join 还在维护吗?

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