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): SVGSVGElementRetrieves the root <svg> element of an RvgGraphic.
static get(visual: RvgBox): SVGRectElementRetrieves the <rect> element of a box visual.
static get(visual: RvgRectangle): SVGPolygonElementRetrieves the <polygon> element of a rectangle visual.
static get(visual: RvgPolygon): SVGPolygonElementRetrieves the <polygon> element of a polygon visual (also triangles).
static get(visual: RvgSegment): SVGLineElementRetrieves the <line> element of a segment visual.
static get(visual: RvgPolyline): SVGPolylineElementRetrieves the <polyline> element of a polyline visual.
static get(visual: RvgAnchoredText): SVGTextElementRetrieves the <text> element of a text visual.
static get(visual: RvgArc): SVGPathElementRetrieves the <path> element of an arc visual.
static get(visual: RvgCircle): SVGCircleElementRetrieves the <circle> element of a circle visual.
static get(visual: RvgShapeVisual): SVGElementRetrieves the element of any other shape visual.
static get(visual: RvgVisual): SVGElementRetrieves the element of any other visual.
iconstatic
static icon(group: RvgGroup, d: string, style?: string): RvgGroupCreates 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
dattribute of an SVG<path>. styleoptional- The visual style to apply to the icon.
Returns The icon's layer.
