Skip to main content

PlottingSVG

PlottingSVG

Classes

Name
class PlottingSVG::SVGAxisRenderer
Renders a simple linear axis (uniform tick spacing) as SVG fragments in pixel space.
class PlottingSVG::SVGDecoration
Interface for SVG-specific decorations rendered in canvas pixel space.
class PlottingSVG::SVGScalebar
Decoration that draws a horizontal scale bar in pixel space.
class PlottingSVG::SVGGlyphRenderer
Stateless conversion from [CorePlotting::RenderableGlyphBatch]() to SVG element strings.
class PlottingSVG::SVGPolyLineRenderer
Stateless conversion from [CorePlotting::RenderablePolyLineBatch]() to SVG <polyline> strings.
class PlottingSVG::SVGRectangleRenderer
Stateless conversion from [CorePlotting::RenderableRectangleBatch]() to SVG <rect> strings.
class PlottingSVG::SVGDocument
Builds a UTF-8 SVG 1.1 document string with a full-canvas background and ordered <g> layers.
struct PlottingSVG::SVGExportParams
Canvas size and background fill for legacy DataViewer SVG export.
struct PlottingSVG::ScalebarTimeRange
Visible time window used to map “full canvas width” ↔︎ elapsed time for the scalebar.
class PlottingSVG::SVGSceneRenderer
Orchestrates [SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md) assembly, per-batch SVG renderers, and optional decorations.

Types

Name
enum class AxisPosition { Left, Bottom}
Which edge of the inner plot box the axis spine follows.
enum class ScalebarCorner { BottomRight, BottomLeft, TopRight, TopLeft}
Corner used to anchor the scalebar (horizontal bar, end ticks, and label) on the canvas.

Functions

Name
std::vector< std::string > renderSceneToSVG(CorePlotting::RenderableScene const & scene, SVGExportParams const & params)
Flatten scene batches to SVG element strings in fixed draw order.
std::string buildSVGDocument(CorePlotting::RenderableScene const & scene, SVGExportParams const & params)
Build a full SVG 1.1 document.
std::vector< std::string > createScalebarSVG(int scalebar_length, ScalebarTimeRange time_range, SVGExportParams const & params)
Bottom-right scalebar (default [SVGScalebar]() corner).
glm::vec2 transformVertexToSVG(glm::vec4 const & vertex, glm::mat4 const & mvp, int canvas_width, int canvas_height)
Apply mvp to a homogeneous world-space vertex and map the result to SVG pixel coordinates.
std::string colorToSVGHex(glm::vec4 const & color)
Convert linear RGB channels to an uppercase #RRGGBB string for SVG fill / stroke.

Types Documentation

enum AxisPosition

Enumerator Value Description
Left
Bottom

Which edge of the inner plot box the axis spine follows.

enum ScalebarCorner

Enumerator Value Description
BottomRight
BottomLeft
TopRight
TopLeft

Corner used to anchor the scalebar (horizontal bar, end ticks, and label) on the canvas.

Functions Documentation

function renderSceneToSVG

std::vector< std::string > renderSceneToSVG(
    CorePlotting::RenderableScene const & scene,
    SVGExportParams const & params
)

Flatten scene batches to SVG element strings in fixed draw order.

Precondition:

  • params.canvas_width > 0 and params.canvas_height > 0 if coordinates should match OpenGL-style NDC→pixel mapping in the sub-renderers (enforcement: none) [IMPORTANT]
  • Batch contents satisfy the preconditions of [SVGRectangleRenderer::render](/api_generated/Classes/classPlottingSVG_1_1SVGRectangleRenderer.md#function-render), [SVGPolyLineRenderer::render](/api_generated/Classes/classPlottingSVG_1_1SVGPolyLineRenderer.md#function-render), and [SVGGlyphRenderer::render](/api_generated/Classes/classPlottingSVG_1_1SVGGlyphRenderer.md#function-render) respectively (enforcement: none) [LOW]

Postcondition:

  • Returns the concatenation of per-batch renderer outputs in the order above (each batch may contribute zero or more strings).
  • Does not throw under normal allocator / string behavior.

Order: all rectangle_batches, then all poly_line_batches, then all glyph_batches. Uses scene.view_matrix and scene.projection_matrix for every batch. spatial_index, entity maps, selection, and preview fields are not read.

function buildSVGDocument

std::string buildSVGDocument(
    CorePlotting::RenderableScene const & scene,
    SVGExportParams const & params
)

Build a full SVG 1.1 document.

Precondition:

  • params.canvas_width and params.canvas_height should be positive for a conventional canvas (enforcement: none) [IMPORTANT]
  • params.background_color must be safe inside fill="…" (no ", &, <, etc.) (enforcement: none) [IMPORTANT]

Postcondition:

  • Returns a document starting with <?xml version="1.0" encoding="UTF-8" standalone="no"?>, a root <svg> with viewBox="0 0 width height", a constant <desc>[Neuralyzer](/api_generated/Namespaces/namespaceNeuralyzer.md)[DataViewer](/api_generated/Namespaces/namespaceDataViewer.md) Export</desc>, a full-viewport background <rect>, then each string from [renderSceneToSVG](/api_generated/Namespaces/namespacePlottingSVG.md#function-renderscenetosvg) on its own line with leading indentation, and a closing </svg>.
  • Does not throw under normal stream behavior.

XML declaration, root <svg>, fixed <desc>, background <rect>, then scene elements.

Implementation is string-based (not [SVGDocument](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md)); fragment strings are not XML-escaped.

function createScalebarSVG

std::vector< std::string > createScalebarSVG(
    int scalebar_length,
    ScalebarTimeRange time_range,
    SVGExportParams const & params
)

Bottom-right scalebar (default [SVGScalebar]() corner).

Precondition:

  • For non-empty output, time_range.end > time_range.start with a finite positive span, and params.canvas_width > 0, params.canvas_height > 0 (matches [SVGScalebar::render](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md#function-render) early exit) (enforcement: none) [IMPORTANT]
  • scalebar_length non-zero if the bar should have non-zero extent in typical ranges (enforcement: none) [LOW]

Postcondition:

  • Returns an empty vector when [SVGScalebar::render](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md#function-render) would return empty; otherwise the same four SVG fragments as that render (bar, ticks, label) for the default decoration configuration.
  • Does not throw under normal behavior of the callee.

horizontal bar, end ticks, numeric label.

Delegates to [SVGScalebar](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md)(scalebar_length, time_range.start, time_range.end) and render(canvas).

function transformVertexToSVG

glm::vec2 transformVertexToSVG(
    glm::vec4 const & vertex,
    glm::mat4 const & mvp,
    int canvas_width,
    int canvas_height
)

Apply mvp to a homogeneous world-space vertex and map the result to SVG pixel coordinates.

Parameters:

  • vertex Typically (x, y, 0, 1) in the same space as mvp.
  • mvp Model–view–projection matrix (column-major, GL convention).
  • canvas_width Target width in pixels.
  • canvas_height Target height in pixels.

Precondition:

  • canvas_width > 0 and canvas_height > 0 if the mapping should match the usual OpenGL viewport convention (enforcement: none) [IMPORTANT]
  • For finite pixel output, mvp * vertex and the post-divide NDC values should be finite; near-zero w skips the divide and can amplify coordinates (enforcement: none) [LOW]

Postcondition:

  • Returns {svg_x, svg_y} with components computed from the formulas above (points may lie outside the [0, width] × [0, height] range when NDC is outside [-1, 1]).
  • Does not throw.

Performs ndc = mvp * vertex, then a perspective divide when std::abs(ndc.w) > 1e-6f (if w is smaller in magnitude, x/y are not divided). Maps NDC x from [-1, 1] to [0, canvas_width] and flips y so NDC +1 is the top of the canvas (svg_y = height * (1 - ndc.y) / 2).

function colorToSVGHex

std::string colorToSVGHex(
    glm::vec4 const & color
)

Convert linear RGB channels to an uppercase #RRGGBB string for SVG fill / stroke.

Precondition: For predictable channel bytes, color.r, color.g, and color.b should be finite (enforcement: none) [LOW]

Postcondition:

  • Returns exactly seven characters: '#' plus six uppercase hexadecimal digits.
  • Does not throw under normal std::ostringstream behavior.

Each channel is clamp(channel * 255, 0, 255); values outside [0, 1] are saturated. The alpha component is not encoded (callers must emit fill-opacity / stroke-opacity separately if needed).


Updated on 2026-11-13 at 20:25:41 +0000