Skip to content

Whisker

Creates SVG whiskers based on an array of data: a line from each point in a given direction, capped with an endpoint shape.

A single whisker drawn from x/y, extended length pixels in the orient direction and capped with an endpoint marker.

const config = {
  data: [{id: "a", x: 300, y: 160}],
  x: d => d.x,
  y: d => d.y,
  length: 90,
  orient: "vertical",
};

endpoint names the shape drawn at the far end of each whisker (Rect or Circle, per datum here) and endpointConfig styles each kind; orient takes top, right, bottom, or left. Box plots build their whiskers from exactly these settings.

const config = {
  data: [
    {id: "a", x: 120, y: 160, endpoint: "Rect", orient: "top"},
    {id: "b", x: 260, y: 160, endpoint: "Circle", orient: "top"},
    {id: "c", x: 400, y: 160, endpoint: "Rect", orient: "right"},
    {id: "d", x: 540, y: 160, endpoint: "Circle", orient: "bottom"},
  ],
  endpoint: d => d.endpoint,
  endpointConfig: {Circle: {r: 7}, Rect: {width: 24, height: 6}},
  length: 80,
  orient: d => d.orient,
  x: d => d.x,
  y: d => d.y,
};

Configuration

import {Whisker} from "@d3plus/core";

Extends BaseClass.

activefunction | null

The active highlight state for all sub-shapes in this Whisker.

classNamestring | array.<string> | undefined

CSS 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 own tooltipConfig.className.

colorDefaultscolordefaultsconfig

Overrides the default colors used when assigning fills from data and choosing legible text colors: dark and light (the text colors picked for contrast against a background), missing (null/undefined values), on/off (true/false values), sequential (the anchor hue for magnitude ramps), and scale (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.

configpartial

Narrowed .config() for Whisker. Inherited surface from BaseClass.config(); the override exists only to surface per-shape keys (e.g. width/height for Rect) in autocomplete + type checks.

dataarray.&lt;datapoint&gt;

The data array used to create shapes.

endpointConfigrecord

Configuration object for each endpoint.

hoverfunction | null

The hover highlight state for all sub-shapes in this Whisker.

lineConfigrecord

Configuration object for the line shape.

localestring | object

The 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.

onstring

Event listener for the specified event typenames. Mirrors the core d3-selection behavior.

parentunknown

Parent config used by the wrapper.

renderfunction

Draws the whisker.

selectstring | htmlelement | svgelement | null

The SVG container element for this visualization. 3 selector or DOM element.

shapeConfigd3plusconfig

Configuration object with key/value pairs applied as method calls on each shape.

translatefunction

Defines 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.