Path
Creates SVG Paths based on an array of data.
Basic example
Section titled “Basic example”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,
};
Background image
Section titled “Background image”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";
activefunction|nullThe active callback function for highlighting shapes.
activeStylerecordThe style to apply to active shapes.
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.configpartialNarrowed
.config()for Path. Inherited surface fromBaseClass.config(); the override exists only to surface per-shape keys (e.g.width/heightfor Rect) in autocomplete + type checks.dataarray.<datapoint>The data array used to create shapes. A shape will be drawn for each object in the array.
hoverfunction|nullThe hover callback function for highlighting shapes on mouseover.
hoverStylerecordThe style to apply to hovered shapes.
labelConfigrecordA pass-through to the config method of the TextBox class used to create a shape's labels.
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.
selectstring|htmlelement|svgelement|nullThe SVG container element as a d3 selector or DOM element.
shapeConfigd3plusconfigConfiguration object with key/value pairs applied as method calls on each shape.
sortfunction|nullA comparator function used to sort shapes for layering order.
textureDefaultrecordA series of global texture methods to be used for all textures (ie.
{stroke: "darkorange", strokeWidth: 2}).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.