Skip to main content

PlottingSVG::SVGScalebar

PlottingSVG::SVGScalebar

Decoration that draws a horizontal scale bar in pixel space. More…

#include <SVGScalebar.hpp>

Inherits from PlottingSVG::SVGDecoration

Public Functions

Name
SVGScalebar(int scalebar_length, float time_range_start, float time_range_end)
Build a scalebar for a fixed length in time units over a visible time interval.
void setCorner(ScalebarCorner corner)
Choose which canvas corner anchors the scalebar group.
void setPadding(int pixels)
Inset from the relevant canvas edges when placing the bar (pixels).
void setBarThickness(int pixels)
Stroke width of the main horizontal bar (stroke-width on the bar <line>).
void setTickHeight(int pixels)
Total extent of each end tick along the axis perpendicular to the bar (pixels).
void setLabelFontSize(int pixels)
Font size for the numeric label (font-size on the <text> element).
void setStrokeColor(std::string hex)
Stroke color for the bar and ticks (SVG stroke attribute value).
void setLabelFillColor(std::string hex)
Fill color for the numeric label (SVG fill attribute value).
virtual std::vector< std::string > render(int canvas_width, int canvas_height) const override
Emit the bar, two end ticks, and centered numeric label as SVG element strings.

Additional inherited members

Public Functions inherited from PlottingSVG::SVGDecoration

Name
virtual ~SVGDecoration() =default

Detailed Description

class PlottingSVG::SVGScalebar;

Decoration that draws a horizontal scale bar in pixel space.

Bar length in pixels is scalebar_length * (canvas_width / visible_time_span), matching [PlottingSVG::createScalebarSVG](/api_generated/Namespaces/namespacePlottingSVG.md#function-createscalebarsvg) / legacy DataViewer export: full canvas width represents time_range_end - time_range_start.

Public Functions Documentation

function SVGScalebar

explicit SVGScalebar(
    int scalebar_length,
    float time_range_start,
    float time_range_end
)

Build a scalebar for a fixed length in time units over a visible time interval.

Parameters:

  • scalebar_length Extent of the bar in time units (label shows this integer as text).
  • time_range_start Start of the visible time window (same units as the plot time axis).
  • time_range_end End of the visible time window; must be strictly after time_range_start for [render()](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md#function-render) to emit elements.

Precondition:

  • time_range_end > time_range_start with a finite positive difference if callers expect non-empty output from [render()](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md#function-render) (enforcement: none) [IMPORTANT]
  • time_range_start and time_range_end are finite values so the stored span behaves as a normal numeric interval (enforcement: none) [LOW] — non-finite values make [render()](/api_generated/Classes/classPlottingSVG_1_1SVGScalebar.md#function-render) return an empty vector in typical cases but are not asserted
  • scalebar_length != 0 if the bar should have non-zero pixel length for typical ranges (enforcement: none) [LOW]

Postcondition: Length and time endpoints match the arguments; style and corner use defaults until setters run.

function setCorner

void setCorner(
    ScalebarCorner corner
)

Choose which canvas corner anchors the scalebar group.

Parameters:

  • corner Anchor corner for layout.

Precondition: None (all enum values are handled).

function setPadding

void setPadding(
    int pixels
)

Inset from the relevant canvas edges when placing the bar (pixels).

Parameters:

  • pixels Padding used by corner layout (distance from edges).

Precondition: pixels >= 0 so “inset from edge” matches the intended geometry (enforcement: none) [IMPORTANT]

function setBarThickness

void setBarThickness(
    int pixels
)

Stroke width of the main horizontal bar (stroke-width on the bar <line>).

Parameters:

  • pixels Thickness in pixels.

Precondition: pixels > 0 for a visible bar stroke (enforcement: none) [LOW]

function setTickHeight

void setTickHeight(
    int pixels
)

Total extent of each end tick along the axis perpendicular to the bar (pixels).

Parameters:

  • pixels Tick height (half above and half below the bar centerline).

Precondition: pixels >= 0 for non-inverted tick geometry (enforcement: none) [LOW]

function setLabelFontSize

void setLabelFontSize(
    int pixels
)

Font size for the numeric label (font-size on the <text> element).

Parameters:

  • pixels Size in pixels.

Precondition: pixels > 0 for readable text (enforcement: none) [LOW]

function setStrokeColor

void setStrokeColor(
    std::string hex
)

Stroke color for the bar and ticks (SVG stroke attribute value).

Parameters:

  • hex Color string (e.g. #000000); invalid values yield invalid SVG (enforcement: none) [LOW]

function setLabelFillColor

void setLabelFillColor(
    std::string hex
)

Fill color for the numeric label (SVG fill attribute value).

Parameters:

  • hex Color string (e.g. #000000); invalid values yield invalid SVG (enforcement: none) [LOW]

function render

virtual std::vector< std::string > render(
    int canvas_width,
    int canvas_height
) const override

Emit the bar, two end ticks, and centered numeric label as SVG element strings.

Parameters:

  • canvas_width SVG viewport width in pixels.
  • canvas_height SVG viewport height in pixels.

Precondition:

  • canvas_width > 0 and canvas_height > 0 for non-empty output (enforcement: runtime_check)
  • time_range_end - time_range_start must be finite and strictly positive for non-empty output (enforcement: runtime_check)
  • Layout is not clipped by the implementation: very large bar length in pixels or negative padding may draw outside the viewBox (enforcement: none) [LOW]

Postcondition:

  • Returns an empty vector if canvas_width, canvas_height, or the stored time span fail the runtime checks above.
  • Otherwise returns exactly four strings: main bar <line>, left tick <line>, right tick <line>, and label <text> (decimal text is scalebar_length).
  • Does not throw.

Reimplements: PlottingSVG::SVGDecoration::render


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