class RVG · Core

Svg

SVG-specific access: the underlying SVG DOM element of a graphic, a group, or a visual (get), and icons drawn from SVG path data (icon).

Polylines, polygons (also rectangles and triangles), boxes, segments, circles, arcs and texts get their specific element type (an arc is a <path>). Other visuals get SVGElement.

Example

// From a graphic (RvgGraphic) — returns the root <svg> element
const svgRoot = Svg.get(graphic);       // SVGSVGElement

// From a group
const gEl = Svg.get(group);             // SVGGElement

// From a specific visual
const rect = Svg.get(box);              // SVGRectElement
rect.setAttribute("rx", "4");
const ring = Svg.get(circle);           // SVGCircleElement
const path = Svg.get(arc);              // SVGPathElement

Static methods

getstatic

static get(visual: RvgGraphic): SVGSVGElement

Retrieves the root <svg> element of an RvgGraphic.

static get(visual: RvgGroup): SVGGElement

Retrieves the <g> element backing an RvgGroup.

static get(visual: RvgBox): SVGRectElement

Retrieves the <rect> element of a box visual.

static get(visual: RvgRectangle): SVGPolygonElement

Retrieves the <polygon> element of a rectangle visual.

static get(visual: RvgPolygon): SVGPolygonElement

Retrieves the <polygon> element of a polygon visual (also triangles).

static get(visual: RvgSegment): SVGLineElement

Retrieves the <line> element of a segment visual.

static get(visual: RvgPolyline): SVGPolylineElement

Retrieves the <polyline> element of a polyline visual.

static get(visual: RvgAnchoredText): SVGTextElement

Retrieves the <text> element of a text visual.

static get(visual: RvgArc): SVGPathElement

Retrieves the <path> element of an arc visual.

static get(visual: RvgCircle): SVGCircleElement

Retrieves the <circle> element of a circle visual.

static get(visual: RvgShapeVisual): SVGElement

Retrieves the element of any other shape visual.

static get(visual: RvgVisual): SVGElement

Retrieves the element of any other visual.

iconstatic

static icon(group: RvgGroup, d: string, style?: string): RvgGroup

Creates an icon from SVG path data, as a layer of the group.

The path data use the 24 × 24 grid of Material Design icons (coordinates from 0 to 24, as in @mdi/js). Inside the layer, the icon has size 1 and is centred on the origin, so the layer's anchor places it: the anchor's position is the icon's centre, its direction turns the icon, and the direction's length is the icon's size. The anchor starts at (0, 0) with direction (24, 0): an upright icon of size 24 at the group's origin.

The style sets the classes or the inline style of the layer; the path inherits fill, stroke and fill-rule from it. Leave the size and position to the anchor: a CSS transform on the layer replaces the anchor's.

The path data are set once. To switch between icons, create one for each and show one with visible.

To place an icon of size 16 centred 30 px below a point, write the anchor: Pins.withOrientation(Points.moveDown(point, 30), [16, 0], icon.anchor).

group
The group the icon's layer is created in.
d
The path data, in the format of the d attribute of an SVG <path>.
style optional
The visual style to apply to the icon.

Returns The icon's layer.