BaseClass
Provides shared configuration, event handling, and locale management inherited by all d3plus classes.
Reference
Section titled “Reference”BaseClass supplies the fluent API shared by every class: config() for deep-merging a settings object (with RESET to restore defaults), on() for event handlers, locale() for translations and number formats, and translate() for localized strings. A subclass only has to define getter/setter methods; config() discovers and calls them.
import {BaseClass} from "@d3plus/core";
class Widget extends BaseClass {
constructor() {
super();
this._size = 10;
}
// Getter/setter pairs are what config() drives: no argument reads, one writes.
size(_) {
return arguments.length ? ((this._size = _), this) : this._size;
}
}
const widget = new Widget().config({size: 20, locale: "es-ES"});
widget.size();
widget.on("click", d => console.log(d));
Configuration
import {BaseClass} from "@d3plus/core";
classNamestring|array.<string>|undefinedCSS classes added to the outermost element this chart or component draws into, next to its fixed d3plus classes, so page CSS can target it: a chart's root
<svg class="d3plus-viz">(its<canvas>with the Canvas renderer) and a standalone component's<svg>. Takes a space-separated string or an array. A new value replaces the classes the previous one added; unset adds none. Tooltips take their owntooltipConfig.className.colorDefaultscolordefaultsconfigOverrides the default colors used when assigning fills from data and choosing legible text colors:
darkandlight(the text colors picked for contrast against a background),missing(null/undefined values),on/off(true/falsevalues),sequential(the anchor hue for magnitude ramps), andscale(the categorical palette, given as a d3 ordinal scale or an array of colors). Keys are merged into the current defaults, and a Viz passes its overrides down to the shapes and components it draws.configd3plusconfigMethods that correspond to the key/value pairs and returns this class.
localestring|objectThe locale used for all text and number formatting. Supports the locales defined in d3plus-format. The locale can be a complex Object, a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale.
onstringEvent listener for the specified event typenames. Mirrors the core d3-selection behavior.
parentunknownParent config used by the wrapper.
shapeConfigd3plusconfigConfiguration object with key/value pairs applied as method calls on each shape.
translatefunctionDefines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.