Skip to content

applyConfig

Merges the supplied config objects over a fresh {select: node} target, routes any <field> + <field>Format pairs to their loader methods, then applies whatever remains via instance.config(). Shared by every d3plus framework wrapper so this routing lives in exactly one place.

What every framework wrapper does with the props it receives: merge the config objects left to right (later ones win, undefined entries are skipped) over {select: container}, then hand the result to the instance’s config().

import {applyConfig} from "@d3plus/dom";
applyConfig(viz, container, {width: 300, title: "Default title"}, undefined, {width: 400, legend: false});
// viz.config({select: container, width: 400, title: "Default title", legend: false})

A data-like field paired with its <field>Format function (data/dataFormat, and likewise nodes, links, and topojson) is routed to the matching loader method, which takes the formatter as its second argument, and both keys are removed before the rest goes through config().

import {applyConfig} from "@d3plus/dom";
applyConfig(viz, container, {data: "/data/fruits.csv", dataFormat: rows => rows.slice(0, 3), groupBy: "name"});
// viz.data("/data/fruits.csv", rows => rows.slice(0, 3))
// viz.config({select: container, groupBy: "name"})

Parameters

import {applyConfig} from "@d3plus/dom";
instancerequiredD3plusInstance

A d3plus class instance.

noderequiredElement

The DOM element the visualization renders into (its select).

configsrequiredArray.&lt;Record | undefined&gt;

One or more config objects, merged left-to-right (later objects win); undefined/null entries are ignored.