Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Graph

A line graph plotter. More...

#include <klang.h>

+ Inheritance diagram for klang::Graph:

Public Member Functions

template<typename... Args>
Graphoperator<< (Function< Args... > &function)
 Plot the given function for x plus additional arguments.
 
size_t capacity () const
 
void clear ()
 
Graphoperator() (double min, double max)
 
Graphoperator() (double x_min, double x_max, double y_min, double y_max)
 
Graph::Series & operator[] (int index)
 
const Graph::Series & operator[] (int index) const
 
 operator Series & ()
 
void plot (Generic::Function< SIGNAL, Args... > &function)
 Plot the given Function.
 
void plot (TYPE(*function)(TYPE))
 Plot the given function of x.
 
void plot (FUNCTION f, VALUES... values)
 Plot the given function for x plus additional arguments.
 
void add (TYPE y)
 Add a data point (incrementing x)
 
void add (const Point pt)
 Add a data point.
 
Graphoperator+= (TYPE y)
 Add a data point (incrementing x)
 
Graphoperator+= (const Point pt)
 Add a data point.
 
Graphoperator+= (std::initializer_list< Point > values)
 Plot the given data points.
 
Graphoperator<< (Function< Args... > &function)
 Plot the given function for x plus additional arguments.
 
Graphoperator<< (TYPE &in)
 
Graphoperator<< (const TYPE &in)
 
const Axes & getAxes () const
 
void getAxes (Axes &axes) const
 
const Data & getData () const
 
bool isDirty () const
 
void setDirty (bool dirty)
 
void truncate (unsigned int count)
 

Protected Attributes

Axes axes
 
Data data
 
bool dirty
 

Detailed Description

Definition at line 2042 of file klang.h.

Member Function Documentation

◆ add() [1/2]

void klang::Generic::Graph< SIZE >::add ( const Point pt)
inlineinherited

Definition at line 1864 of file klang.h.

◆ add() [2/2]

void klang::Generic::Graph< SIZE >::add ( TYPE y)
inlineinherited

Definition at line 1862 of file klang.h.

1862{ data[0].add(y); dirty = true; }

◆ capacity()

size_t klang::Generic::Graph< SIZE >::capacity ( ) const
inlineinherited

Definition at line 1637 of file klang.h.

1637{ return SIZE; }

◆ clear()

void klang::Generic::Graph< SIZE >::clear ( )
inlineinherited

Definition at line 1759 of file klang.h.

1759 {
1760 dirty = true;
1761 axes.clear();
1762 for (int s = 0; s < GRAPH_SERIES; s++)
1763 data[s].clear();
1764 data.clear();
1765 }

◆ getAxes() [1/2]

const Axes & klang::Generic::Graph< SIZE >::getAxes ( ) const
inlineinherited

Definition at line 1901 of file klang.h.

1901{ return axes; }

◆ getAxes() [2/2]

void klang::Generic::Graph< SIZE >::getAxes ( Axes & axes) const
inlineinherited

Definition at line 1904 of file klang.h.

1904 {
1905 if (!axes.x.valid()) {
1906 axes.x.clear();
1907 for (int s = 0; s < GRAPH_SERIES; s++)
1908 axes.x.from(data[s], &Point::x);
1909 if (!axes.y.valid() && axes.y.max != 0)
1910 axes.y.min = 0;
1911 }
1912 if (!axes.y.valid()) {
1913 axes.y.clear();
1914 for (int s = 0; s < GRAPH_SERIES; s++)
1915 axes.y.from(data[s], &Point::y);
1916 if (!axes.y.valid() && axes.y.max != 0)
1917 axes.y.min = 0;
1918 }
1919 }

◆ getData()

const Data & klang::Generic::Graph< SIZE >::getData ( ) const
inlineinherited

Definition at line 1921 of file klang.h.

1921{ return data; }

◆ isDirty()

bool klang::Generic::Graph< SIZE >::isDirty ( ) const
inlineinherited

Definition at line 1922 of file klang.h.

1922{ return dirty; }

◆ operator Series &()

klang::Generic::Graph< SIZE >::operator Series & ( )
inlineinherited

Definition at line 1812 of file klang.h.

1812 {
1813 dirty = true;
1814 return data[0];
1815 }

◆ operator()() [1/2]

Graph & klang::Generic::Graph< SIZE >::operator() ( double min,
double max )
inlineinherited

Definition at line 1790 of file klang.h.

1790 {
1791 dirty = true;
1792 axes.x.min = min; axes.x.max = max;
1793 return *this;
1794 }
TYPE1 max(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:215
TYPE1 min(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:212

◆ operator()() [2/2]

Graph & klang::Generic::Graph< SIZE >::operator() ( double x_min,
double x_max,
double y_min,
double y_max )
inlineinherited

Definition at line 1805 of file klang.h.

1805 {
1806 dirty = true;
1807 axes.x.min = x_min; axes.x.max = x_max;
1808 axes.y.min = y_min; axes.y.max = y_max;
1809 return *this;
1810 }

◆ operator+=() [1/3]

Graph & klang::Generic::Graph< SIZE >::operator+= ( const Point pt)
inlineinherited

Definition at line 1870 of file klang.h.

1870{ add(pt); return *this; }

◆ operator+=() [2/3]

Graph & klang::Generic::Graph< SIZE >::operator+= ( std::initializer_list< Point > values)
inlineinherited

Definition at line 1885 of file klang.h.

1885 {
1886 for (const auto& value : values)
1887 add(value);
1888 return *this;
1889 }

◆ operator+=() [3/3]

Graph & klang::Generic::Graph< SIZE >::operator+= ( TYPE y)
inlineinherited

Definition at line 1868 of file klang.h.

1868{ add(y); return *this; }

◆ operator<<() [1/4]

Graph & klang::Generic::Graph< SIZE >::operator<< ( const TYPE & in)
inlineinherited

Definition at line 1898 of file klang.h.

1898{ add(in); return *this; } // without/after processing

◆ operator<<() [2/4]

Graph & klang::Generic::Graph< SIZE >::operator<< ( Function< Args... > & function)
inlineinherited

Definition at line 1892 of file klang.h.

1892 {
1893 plot(function.with());
1894 return *this;
1895 }
void plot(Generic::Function< SIGNAL, Args... > &function)
Definition klang.h:1819

◆ operator<<() [3/4]

Graph & klang::Generic::Graph< SIZE >::operator<< ( TYPE & in)
inlineinherited

Definition at line 1897 of file klang.h.

1897{ add(in); return *this; } // with processing

◆ operator<<() [4/4]

template<typename... Args>
Graph & klang::Graph::operator<< ( Function< Args... > & function)
inline

Definition at line 2047 of file klang.h.

2047 {
2048 plot(function.with());
2049 return *this;
2050 }

◆ operator[]() [1/2]

Graph::Series & klang::Generic::Graph< SIZE >::operator[] ( int index)
inlineinherited

Definition at line 1796 of file klang.h.

1796 {
1797 dirty = true;
1798 return data[index];
1799 }

◆ operator[]() [2/2]

const Graph::Series & klang::Generic::Graph< SIZE >::operator[] ( int index) const
inlineinherited

Definition at line 1801 of file klang.h.

1801 {
1802 return data[index];
1803 }

◆ plot() [1/3]

void klang::Generic::Graph< SIZE >::plot ( FUNCTION f,
VALUES... values )
inlineinherited

Definition at line 1847 of file klang.h.

1847 {
1848 thread_local static Function fun(f);
1849 Graph::Series* series = Graph::data.find((void*)fun);
1850 if (!series)
1851 series = Graph::data.add();
1852 if (series) {
1853 dirty = true;
1854 if (!axes.x.valid())
1855 axes.x = { -1, 1 };
1856 series->plot(fun.with(values...), axes.x);
1857 }
1858 }
Function() -> Function< signal, Args... >
void add(const TYPE &item)
Add the specified item to the end of the array.
Definition klang.h:249
Series * find(void *function)
Definition klang.h:1782

◆ plot() [2/3]

void klang::Generic::Graph< SIZE >::plot ( Generic::Function< SIGNAL, Args... > & function)
inlineinherited

Definition at line 1819 of file klang.h.

1819 {
1820 Graph::Series* series = Graph::data.find((void*)function);
1821 if (!series)
1822 series = Graph::data.add();
1823 if (series) {
1824 dirty = true;
1825 if (!axes.x.valid())
1826 axes.x = { -1, 1 };
1827 series->plot(function, axes.x);
1828 }
1829 }

◆ plot() [3/3]

void klang::Generic::Graph< SIZE >::plot ( TYPE(* function )(TYPE))
inlineinherited

Definition at line 1833 of file klang.h.

1833 {
1834 Graph::Series* series = Graph::data.find((void*)function);
1835 if (!series)
1836 series = Graph::data.add();
1837 if (series) {
1838 dirty = true;
1839 if (!axes.x.valid())
1840 axes.x = { -1, 1 };
1841 series->plot(function, axes.x);
1842 }
1843 }

◆ setDirty()

void klang::Generic::Graph< SIZE >::setDirty ( bool dirty)
inlineinherited

Definition at line 1923 of file klang.h.

1923{ Graph::dirty = dirty; }

◆ truncate()

void klang::Generic::Graph< SIZE >::truncate ( unsigned int count)
inlineinherited

Definition at line 1925 of file klang.h.

1925 {
1926 if (count < data.count)
1927 data.count = count;
1928
1929 for (int s = 0; s < GRAPH_SERIES; s++)
1930 if (count < data[s].count)
1931 data[s].count = count;
1932 }

Member Data Documentation

◆ axes

Axes klang::Generic::Graph< SIZE >::axes
protectedinherited

Definition at line 1935 of file klang.h.

◆ data

Data klang::Generic::Graph< SIZE >::data
protectedinherited

Definition at line 1936 of file klang.h.

◆ dirty

bool klang::Generic::Graph< SIZE >::dirty
protectedinherited

Definition at line 1937 of file klang.h.