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-data-join

v6.0.3

Published

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

Downloads

45,962

Readme

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.