Skip to content

Path

Creates SVG Paths based on an array of data.

The d accessor reads a raw SVG path string from each datum; with fill: none and a stroke, the cubic-Bezier path renders as an open curved stroke.

const config = {
  // The default `d` accessor reads the `path` key from each datum; fill,
  // stroke and strokeWidth take constant values.
  data: [{id: "wave", path: "M40,200 C140,80 240,320 340,200 S540,80 640,200"}],
  fill: "none",
  stroke: "#cc4b4b",
  strokeWidth: 4,
};

Setting backgroundImage to a per-datum URL fills each path with an image. A Path carries no width/height, so the image is sized to the path’s exact bounding box (computed DOM-free from the d string), scaled to cover that box, and clipped to the path outline — so the landscape appears only inside the diamond (see issue #757).

const config = {
  // A diamond whose exact bounding box is the 240×240 square [200,440]×[40,280].
  data: [{id: "diamond", path: "M320,40 L440,160 L320,280 L200,160 Z"}],
  fill: "#7fb3d5",
  stroke: "#2c3e50",
  strokeWidth: 2,
  // The `backgroundImage` accessor returns a per-datum URL. A Path has no
  // width/height of its own, so the image fills the path's exact (DOM-free)
  // bounding box using `cover` and is clipped to the path itself — here a wide
  // 400×200 "landscape" is cover-cropped to the square bbox and shows only
  // through the diamond. (The `viewBox` keeps the image's aspect ratio when scaled.)
  backgroundImage:
    "data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20400%20200%22%20width%3D%22400%22%20height%3D%22200%22%3E%3Crect%20width%3D%22400%22%20height%3D%22200%22%20fill%3D%22%239ad0ec%22%2F%3E%3Ccircle%20cx%3D%22320%22%20cy%3D%2255%22%20r%3D%2228%22%20fill%3D%22%23ffd93b%22%2F%3E%3Crect%20y%3D%22150%22%20width%3D%22400%22%20height%3D%2250%22%20fill%3D%22%236ab04c%22%2F%3E%3Cpolygon%20points%3D%220%2C150%2090%2C80%20180%2C150%22%20fill%3D%22%233d7a3d%22%2F%3E%3Cpolygon%20points%3D%22140%2C150%20240%2C60%20340%2C150%22%20fill%3D%22%234c9a4c%22%2F%3E%3C%2Fsvg%3E",
};

Configuration

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

Extends Shape → BaseClass.

activefunction | null

The active callback function for highlighting shapes.

activeStylerecord

The style to apply to active shapes.

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 Path. 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. A shape will be drawn for each object in the array.

hoverfunction | null

The hover callback function for highlighting shapes on mouseover.

hoverStylerecord

The style to apply to hovered shapes.

labelConfigrecord

A pass-through to the config method of the TextBox class used to create a shape's labels.

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.

selectstring | htmlelement | svgelement | null

The SVG container element as a d3 selector or DOM element.

shapeConfigd3plusconfig

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

sortfunction | null

A comparator function used to sort shapes for layering order.

textureDefaultrecord

A series of global texture methods to be used for all textures (ie. {stroke: "darkorange", strokeWidth: 2}).

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.