accessor
Wraps an object key in a simple accessor function.
Basic example
Section titled “Basic example”Turns a key into the function d => d[key]. Every chart config that accepts “a key or an accessor” (groupBy, x, y, sum, label, …) runs string values through this, so the rest of the pipeline only ever deals with functions.
import {accessor} from "@d3plus/core";
accessor("id")({id: "alpha", value: 3});
accessor("value")({id: "alpha", value: 3});
[{id: "alpha"}, {id: "beta"}, {id: "gamma"}].map(accessor("id"));
Default value
Section titled “Default value”A second argument is returned whenever the key is undefined on a row, which is how optional config such as x or y fall back to 0 for rows missing the field.
import {accessor} from "@d3plus/core";
accessor("missing")({id: "alpha"});
accessor("missing", "n/a")({id: "alpha"});
accessor("value", 0)({id: "alpha", value: 3});
Parameters
import {accessor} from "@d3plus/core";