Skip to main content

DataViewer::DataViewerCoordinates

DataViewer::DataViewerCoordinates

Coordinate transformation utilities for the DataViewer widget. More…

#include <DataViewerCoordinates.hpp>

Public Functions

Name
DataViewerCoordinates(CorePlotting::ViewStateData const & view_state, int width, int height, TimeFrame const * master_time_frame =[nullptr])
Construct from view state and dimensions.
DataViewerCoordinates() =default
Default constructor (creates identity-like transforms).
float canvasXToTime(float canvas_x) const
Convert canvas X coordinate to time coordinate.
float canvasXToWorldX(float canvas_x) const
Convert canvas X coordinate to world X coordinate.
float canvasYToWorldY(float canvas_y) const
Convert canvas Y coordinate to world Y coordinate.
std::pair< float, float > canvasToWorld(float canvas_x, float canvas_y) const
Convert canvas position to world coordinates.
float timeToCanvasX(float time) const
Convert time coordinate to canvas X pixel coordinate.
float worldYToCanvasY(float world_y) const
Convert world Y coordinate to canvas Y pixel coordinate.
float canvasYToAnalogValue(float canvas_y, CorePlotting::LayoutTransform const & y_transform) const
Convert canvas Y to analog data value using a layout transform.
float pixelToleranceToWorldX(float pixels) const
Convert pixel tolerance to world X (time) units.
float pixelToleranceToWorldY(float pixels) const
Convert pixel tolerance to world Y units.
CorePlotting::TimeAxisParams const & timeAxisParams() const
Get the time axis parameters.
CorePlotting::YAxisParams const & yAxisParams() const
Get the Y axis parameters.
int width() const
Get the canvas width.
int height() const
Get the canvas height.
float timeUnitsPerPixel() const
Get time units per pixel (for tolerance calculations).
float worldYUnitsPerPixel() const
Get world Y units per pixel.

Detailed Description

class DataViewer::DataViewerCoordinates;

Coordinate transformation utilities for the DataViewer widget.

Consolidates all coordinate conversion logic into a single class, reducing code duplication and ensuring consistent behavior across input handling, hit testing, and interaction management.

Public Functions Documentation

function DataViewerCoordinates

DataViewerCoordinates(
    CorePlotting::ViewStateData const & view_state,
    int width,
    int height,
    TimeFrame const * master_time_frame =nullptr
)

Construct from view state and dimensions.

Parameters:

  • view_state Current ViewStateData with time bounds and Y-axis state
  • width Canvas width in pixels
  • height Canvas height in pixels
  • master_time_frame When non-null, x_min / x_max are interpreted as [TimeFrameIndex](/api_generated/Classes/structTimeFrameIndex.md) into this frame and the time axis uses getTimeAtIndex for canvas/time mapping. When null, x_min / x_max are used directly as integer time values (legacy index semantics).

function DataViewerCoordinates

DataViewerCoordinates() =default

Default constructor (creates identity-like transforms).

function canvasXToTime

float canvasXToTime(
    float canvas_x
) const

Convert canvas X coordinate to time coordinate.

Parameters:

  • canvas_x X position in pixels (0 = left edge of canvas)

Return: Time coordinate (floating point for sub-frame precision)

Maps a pixel position on the canvas to the corresponding time value based on the current visible time range.

function canvasXToWorldX

float canvasXToWorldX(
    float canvas_x
) const

Convert canvas X coordinate to world X coordinate.

Parameters:

  • canvas_x X position in pixels

Return: World X coordinate (same as time)

For the DataViewer, world X is equivalent to time coordinate. This method is an alias for canvasXToTime for semantic clarity.

function canvasYToWorldY

float canvasYToWorldY(
    float canvas_y
) const

Convert canvas Y coordinate to world Y coordinate.

Parameters:

  • canvas_y Y position in pixels (0 = top of canvas)

Return: World Y coordinate

Maps a pixel position to world Y coordinate, accounting for:

  • Canvas origin at top-left with Y increasing downward
  • World Y increasing upward
  • Vertical pan offset

function canvasToWorld

std::pair< float, float > canvasToWorld(
    float canvas_x,
    float canvas_y
) const

Convert canvas position to world coordinates.

Parameters:

  • canvas_x X position in pixels
  • canvas_y Y position in pixels

Return: Pair of (world_x, world_y)

Convenience method that converts both X and Y in a single call.

function timeToCanvasX

float timeToCanvasX(
    float time
) const

Convert time coordinate to canvas X pixel coordinate.

Parameters:

  • time Time coordinate

Return: Canvas X position in pixels (0 = left edge)

Note: Times outside the visible range will return negative values or values greater than canvas width.

function worldYToCanvasY

float worldYToCanvasY(
    float world_y
) const

Convert world Y coordinate to canvas Y pixel coordinate.

Parameters:

  • world_y World Y coordinate

Return: Canvas Y position in pixels (0 = top)

function canvasYToAnalogValue

float canvasYToAnalogValue(
    float canvas_y,
    CorePlotting::LayoutTransform const & y_transform
) const

Convert canvas Y to analog data value using a layout transform.

Parameters:

  • canvas_y Canvas Y position in pixels
  • y_transform The LayoutTransform used for rendering the series

Return: Data value in the series’ native units

Uses the inverse of the provided Y transform to convert from canvas coordinates back to the original data space.

function pixelToleranceToWorldX

float pixelToleranceToWorldX(
    float pixels
) const

Convert pixel tolerance to world X (time) units.

Parameters:

  • pixels Tolerance in pixels

Return: Tolerance in world X (time) units

Useful for hit testing: “click within 10 pixels” becomes a time tolerance.

function pixelToleranceToWorldY

float pixelToleranceToWorldY(
    float pixels
) const

Convert pixel tolerance to world Y units.

Parameters:

  • pixels Tolerance in pixels

Return: Tolerance in world Y units

function timeAxisParams

inline CorePlotting::TimeAxisParams const & timeAxisParams() const

Get the time axis parameters.

Return: Const reference to TimeAxisParams

function yAxisParams

inline CorePlotting::YAxisParams const & yAxisParams() const

Get the Y axis parameters.

Return: Const reference to YAxisParams

function width

inline int width() const

Get the canvas width.

Return: Width in pixels

function height

inline int height() const

Get the canvas height.

Return: Height in pixels

function timeUnitsPerPixel

float timeUnitsPerPixel() const

Get time units per pixel (for tolerance calculations).

Return: Time units per pixel

function worldYUnitsPerPixel

float worldYUnitsPerPixel() const

Get world Y units per pixel.

Return: World Y units per pixel


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