Skip to content
TechnologicalTurtle edited this page Jul 20, 2026 · 4 revisions

Graph

Graph class is simple (at least I hope so) class for rendering graphs.

Initialization

LibGui::Graph MyGraph(
   MyWindow, // you don't have to put this parameter here
   {100, 100}, // position
   {400, 400}, // desired size
   &myData,   // vector<float> pointer to data source
   roboto      // font
);

Usage

// create your data vector
std::vector<float> myData = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};

// create graph
LibGui::Graph MyGraph({100, 100}, {400, 400}, &myData, roboto);

while (!MyWindow.ShouldClose())
{
   MyWindow.Draw();

   MyGraph.Render();

   MyWindow.PushDraw();
}

Warning

If you update your datasource, don't forget to also update your graph by calling Update() function.

Methods

void Update()

Updates graph to new version of datasource. Don't worry about using it, as it only takes $O(N)$.

void Render()

Renders graph.

bool Rect_OnMouseEnter(Vec2 anchor)

Returns if mouse cursor is on this graph, ignore anchor parameter, as it's override of RectangleInput::Rect_OnMouseEnter.

Properties

Type Name Description
std::vector<float>* data_source pointer to a vector holding source data
—————————— —————————— ——————————
float scale scales whole graph
Vec2 position position of graph
Vec2 anchor center of graph
Vec2 desired_size size of graph (without padding and text)
Vec2 background_padding Is added with desired size (and some more stuff), to get size of background.
Vec2 finalSize Final size of graph.
—————————— —————————— ——————————
Color lineColor color of data line in graph
Color textColor color of text
Color infoLineColor color of support lines
Color backgroundColor background color
—————————— —————————— ——————————
bool anyText Should Render function render labels in the graph?
float fontSize text size
int textLeftOffset how much space is between labels and graph
float infoLineDelta every [how much?] value should be rendered support line

Yes I used m-dashes here, now I'm officially AI. :(

Clone this wiki locally