2020-04-06 05:00:42 +00:00
|
|
|
#ifndef __NCPP_PLOT_HH
|
|
|
|
#define __NCPP_PLOT_HH
|
|
|
|
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "NCAlign.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
|
|
|
class Plane;
|
|
|
|
|
|
|
|
class NCPP_API_EXPORT Plot : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-04-11 22:20:11 +00:00
|
|
|
static ncplot_options default_options;
|
2020-04-06 05:00:42 +00:00
|
|
|
|
|
|
|
public:
|
2020-04-11 22:20:11 +00:00
|
|
|
explicit Plot (Plane *plane, const ncplot_options *opts = nullptr)
|
2020-04-06 05:00:42 +00:00
|
|
|
: Plot (reinterpret_cast<ncplane*>(plane), opts)
|
|
|
|
{}
|
|
|
|
|
2020-04-11 22:20:11 +00:00
|
|
|
explicit Plot (Plane const* plane, const ncplot_options *opts = nullptr)
|
2020-04-06 05:00:42 +00:00
|
|
|
: Plot (const_cast<Plane*>(plane), opts)
|
|
|
|
{}
|
|
|
|
|
2020-04-11 22:20:11 +00:00
|
|
|
explicit Plot (Plane &plane, const ncplot_options *opts = nullptr)
|
2020-04-06 05:00:42 +00:00
|
|
|
: Plot (reinterpret_cast<ncplane*>(&plane), opts)
|
|
|
|
{}
|
|
|
|
|
2020-04-11 22:20:11 +00:00
|
|
|
explicit Plot (Plane const& plane, const ncplot_options *opts = nullptr)
|
2020-04-06 05:00:42 +00:00
|
|
|
: Plot (const_cast<Plane*>(&plane), opts)
|
|
|
|
{}
|
|
|
|
|
2020-04-23 07:52:07 +00:00
|
|
|
explicit Plot (ncplane *plane, const ncplot_options *opts = nullptr,
|
|
|
|
uint64_t miny = 0, uint64_t maxy = 0)
|
2020-04-06 05:00:42 +00:00
|
|
|
{
|
|
|
|
if (plane == nullptr)
|
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
|
2020-04-23 07:52:07 +00:00
|
|
|
plot = ncuplot_create (plane, opts == nullptr ? &default_options : opts, miny, maxy);
|
2020-04-06 05:00:42 +00:00
|
|
|
if (plot == nullptr)
|
|
|
|
throw init_error ("notcurses failed to create a new plot");
|
|
|
|
}
|
|
|
|
|
|
|
|
~Plot ()
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
2020-04-23 07:52:07 +00:00
|
|
|
ncuplot_destroy (plot);
|
2020-04-06 05:00:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool add_sample(uint64_t x, uint64_t y) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-23 07:52:07 +00:00
|
|
|
return error_guard (ncuplot_add_sample (plot, x, y), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
2020-04-06 05:00:42 +00:00
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool set_sample(uint64_t x, uint64_t y) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-23 07:52:07 +00:00
|
|
|
return error_guard (ncuplot_set_sample (plot, x, y), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
2020-04-06 05:00:42 +00:00
|
|
|
|
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
|
|
|
|
private:
|
2020-04-23 07:52:07 +00:00
|
|
|
ncuplot *plot;
|
2020-04-06 05:00:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|