wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wPlot2D::AxisEntity Class Reference

Represents a visual axis (X or Y) in a 2D plot with optional notches and title. More...

#include <wAxisEntity.hpp>

Inheritance diagram for wPlot2D::AxisEntity:
Inheritance graph

Public Member Functions

 AxisEntity (sf::Font &font, sf::Vector2f origin, sf::Vector2f scale, sf::Vector2f offset, AxisType type, sf::Vector2f axisRange)
 Constructs an AxisEntity with a given orientation, origin, scale, and range.
virtual ~AxisEntity ()=default
 Virtual destructor.
void setColor (sf::Color color)
 Sets the color of the axis line.
void setThickness (float thickness)
 Sets the thickness of the axis line (in pixels).
void setArrowSize (float arrowSize)
 Sets the size of the arrowhead at the end of the axis.
void addTitle (const std::string &title)
 Adds a title to the axis.
void addTitle (const std::wstring &title)
 Adds a title to the axis.
void setTitleFont (const sf::Font &font)
 Sets the font of the axis title.
void setTitleCharacterSize (unsigned int size)
 Sets the character size of the axis title.
void setTitleColor (sf::Color newColor)
 Sets the color of the axis title.
void setTitleOffset (sf::Vector2f titleOffset)
 Sets a manual offset for the title position.
sf::Vector2f getTitleOffset () const
 Gets the current title offset.
void addNotches (float interval, NotchPosition position, bool hasLabels=false)
 Adds notches along the axis.
void setNotchesColor (const sf::Color &color)
 Sets the color of all notches.
void setNotchesThickness (float thickness)
 Sets the thickness of all notches.
void setNotchesLength (float newLength)
 Sets the length of all notches.
void setLabelsFont (const sf::Font &font)
 Sets the font of all labels.
void setLabelsColor (const sf::Color &color)
 Sets the color of all labels.
std::vector< sf::Vector2f > getLabelsOffset () const
 Gets the current offset of all labels.
void setLabelsOffset (sf::Vector2f offset)
 Sets a new offset for all labels.
void addLabelsOffset (sf::Vector2f delta)
 Applies an additional offset to all labels.
void setLabelsCharacterSize (unsigned int newSize)
 Sets the character size of all labels.
void setLabelsDecimalPlaces (int places)
 Sets the number of decimal places for numeric labels.
void setCustomLabels (const std::vector< std::string > &labels)
 Replaces numeric labels with a custom set of strings.
void render (sf::RenderWindow &window)
 Renders the axis (line, arrow, title, notches, labels).
Public Member Functions inherited from wEngine::Entity
 Entity ()
virtual ~Entity ()
unsigned int getEntityID () const
 Returns the unique ID associated with this entity.
void clearComponents ()
 Removes all components currently attached to the entity.
template<typename T, typename... Args>
std::shared_ptr< T > addComponent (Args &&... args)
 Adds a new component of type T to the entity.
template<typename T>
void removeComponent ()
 Removes the component of type T from the entity.
template<typename T>
bool hasComponent () const noexcept
 Checks whether the entity has a component of type T.
template<typename T>
std::shared_ptr< T > getComponent () const
 Retrieves the component of type T attached to the entity.
template<typename T>
std::shared_ptr< T > requireComponent (const std::string &context="") const
 Retrieves the component of type T and throws if it's missing.
template<typename Interface>
std::shared_ptr< Interface > getInterfaceComponent () const
 Returns the first component that implements the specified interface.

Additional Inherited Members

Static Public Member Functions inherited from wEngine::Entity
static void resetEntityIDCounter ()
 Resets the global entity ID counter to zero.

Detailed Description

Represents a visual axis (X or Y) in a 2D plot with optional notches and title.

This class manages the rendering of a coordinate axis in a Cartesian 2D system. It supports:

  • Rendering of an axis line with an arrowhead.
  • Adding notches (tick marks) with optional labels.
  • Attaching a customizable axis title.
See also
TitleEntity, LabelEntity, NotchEntity, LineEntity
Author
Wilfried Koch

Constructor & Destructor Documentation

◆ AxisEntity()

wPlot2D::AxisEntity::AxisEntity ( sf::Font & font,
sf::Vector2f origin,
sf::Vector2f scale,
sf::Vector2f offset,
AxisType type,
sf::Vector2f axisRange )

Constructs an AxisEntity with a given orientation, origin, scale, and range.

Parameters
fontReference to a font used for the title and labels.
originPixel position of the logical origin (typically from GraphicsEntity).
scaleScaling factor (pixels per logical unit).
offsetLogical displacement of the axis system.
typeAxis type (X_AXIS or Y_AXIS).
axisRangeLogical range covered by the axis (e.g., [-5, 5]).

◆ ~AxisEntity()

virtual wPlot2D::AxisEntity::~AxisEntity ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ setColor()

void wPlot2D::AxisEntity::setColor ( sf::Color color)

Sets the color of the axis line.

Parameters
colorNew axis color.
Exceptions
std::runtime_errorif ColorComponent is missing.

◆ setThickness()

void wPlot2D::AxisEntity::setThickness ( float thickness)

Sets the thickness of the axis line (in pixels).

Parameters
thicknessNew thickness (must be > 0).
Exceptions
std::invalid_argumentif thickness <= 0.
std::runtime_errorif ThicknessComponent is missing.

◆ setArrowSize()

void wPlot2D::AxisEntity::setArrowSize ( float arrowSize)

Sets the size of the arrowhead at the end of the axis.

Parameters
arrowSizeArrowhead size in pixels.

◆ addTitle() [1/2]

void wPlot2D::AxisEntity::addTitle ( const std::string & title)

Adds a title to the axis.

Parameters
titleTitle string (narrow string).

◆ addTitle() [2/2]

void wPlot2D::AxisEntity::addTitle ( const std::wstring & title)

Adds a title to the axis.

Parameters
titleTitle string (wide string).

◆ setTitleFont()

void wPlot2D::AxisEntity::setTitleFont ( const sf::Font & font)

Sets the font of the axis title.

Parameters
fontReference to an SFML font.

◆ setTitleCharacterSize()

void wPlot2D::AxisEntity::setTitleCharacterSize ( unsigned int size)

Sets the character size of the axis title.

Parameters
sizeCharacter size in pixels.

◆ setTitleColor()

void wPlot2D::AxisEntity::setTitleColor ( sf::Color newColor)

Sets the color of the axis title.

Parameters
newColorNew text color.

◆ setTitleOffset()

void wPlot2D::AxisEntity::setTitleOffset ( sf::Vector2f titleOffset)

Sets a manual offset for the title position.

Parameters
titleOffsetPixel offset applied to the title position.

◆ getTitleOffset()

sf::Vector2f wPlot2D::AxisEntity::getTitleOffset ( ) const
nodiscard

Gets the current title offset.

Returns
Offset vector in pixels.

◆ addNotches()

void wPlot2D::AxisEntity::addNotches ( float interval,
NotchPosition position,
bool hasLabels = false )

Adds notches along the axis.

Parameters
intervalLogical spacing between notches (> 0).
positionPlacement relative to axis (Center, Above, Below).
hasLabelsIf true, labels are displayed for each notch.

◆ setNotchesColor()

void wPlot2D::AxisEntity::setNotchesColor ( const sf::Color & color)

Sets the color of all notches.

Parameters
colorNew notch color.

◆ setNotchesThickness()

void wPlot2D::AxisEntity::setNotchesThickness ( float thickness)

Sets the thickness of all notches.

Parameters
thicknessNew thickness in pixels.

◆ setNotchesLength()

void wPlot2D::AxisEntity::setNotchesLength ( float newLength)

Sets the length of all notches.

Parameters
newLengthNew length in pixels.

◆ setLabelsFont()

void wPlot2D::AxisEntity::setLabelsFont ( const sf::Font & font)

Sets the font of all labels.

Parameters
fontReference to an SFML font.

◆ setLabelsColor()

void wPlot2D::AxisEntity::setLabelsColor ( const sf::Color & color)

Sets the color of all labels.

Parameters
colorNew text color.

◆ getLabelsOffset()

std::vector< sf::Vector2f > wPlot2D::AxisEntity::getLabelsOffset ( ) const
nodiscard

Gets the current offset of all labels.

Returns
Vector of offsets (one per label).

◆ setLabelsOffset()

void wPlot2D::AxisEntity::setLabelsOffset ( sf::Vector2f offset)

Sets a new offset for all labels.

Parameters
offsetOffset vector in pixels.

◆ addLabelsOffset()

void wPlot2D::AxisEntity::addLabelsOffset ( sf::Vector2f delta)

Applies an additional offset to all labels.

Parameters
deltaDelta offset in pixels.

◆ setLabelsCharacterSize()

void wPlot2D::AxisEntity::setLabelsCharacterSize ( unsigned int newSize)

Sets the character size of all labels.

Parameters
newSizeCharacter size in pixels.

◆ setLabelsDecimalPlaces()

void wPlot2D::AxisEntity::setLabelsDecimalPlaces ( int places)

Sets the number of decimal places for numeric labels.

Parameters
placesDigits after decimal point (>= 0).

◆ setCustomLabels()

void wPlot2D::AxisEntity::setCustomLabels ( const std::vector< std::string > & labels)

Replaces numeric labels with a custom set of strings.

Parameters
labelsVector of user-defined label strings.

◆ render()

void wPlot2D::AxisEntity::render ( sf::RenderWindow & window)

Renders the axis (line, arrow, title, notches, labels).

Parameters
windowTarget render window.

The documentation for this class was generated from the following files: