scatter 0.1.0
Plot.hpp
1/*
2 * Copyright (C) Tobias Löw (tobi.loew@protonmail.ch)
3 *
4 * This file is part of Scatter
5 *
6 * Scatter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Scatter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Scatter. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <functional>
23#include <memory>
24#include <scatter/Figure.hpp>
25#include <scatter/PlotOptions.hpp>
26#include <string>
27
28namespace scatter
29{
30 // forward declarations
31 class Renderer;
32 class Transform;
33 class Figure;
34 class Point;
35 class Ellipse;
36 class Arrow;
37 class PlotBase;
38 class Axis;
39 class Legend;
40
46 class Plot : public std::enable_shared_from_this<Plot>
47 {
48 public:
53 Plot() = delete;
54
59 virtual ~Plot();
60
69 bool save(const std::string &file, const FigureOptions &options = FigureOptions());
70
77
85 template <class T, class... Args>
86 typename T::Options *add(Args &&...args)
87 {
88 plots_.push_back(std::make_unique<T>(args...));
89
90 return dynamic_cast<T *>(plots_.back().get())->options();
91 }
92
93 private:
95 friend void Figure::save(const std::string &);
96
103 Plot(const std::string &title, const PlotOptions &options);
104
114 void render(Renderer &renderer, const Point &origin, const double &width, const double &height);
115
116 private:
118 std::vector<std::unique_ptr<PlotBase>> plots_;
119
121 std::unique_ptr<Axis> axis_;
122
124 std::unique_ptr<Legend> legend_;
125
127 PlotOptions options_;
128
129 public:
131 typedef std::shared_ptr<Plot> Ptr;
132
141
150 static Plot::Ptr create(const std::string &title, const PlotOptions &options = PlotOptions());
151 };
152
153} // namespace scatter
[brief description]
Definition FigureOptions.hpp:32
void save(const std::string &file)
save the Figure to the given file
[brief description]
Definition PlotOptions.hpp:36
main class for creating plots
Definition Plot.hpp:47
Plot()=delete
delete default constructor in order to enforce using Plot::create
static Plot::Ptr create(const std::string &title, const PlotOptions &options=PlotOptions())
create a new Plot
bool save(const std::string &file, const FigureOptions &options=FigureOptions())
save the plot to the given filepath
std::shared_ptr< Plot > Ptr
typedef for convenience
Definition Plot.hpp:131
static Plot::Ptr create(const PlotOptions &options=PlotOptions())
create a new Plot
virtual ~Plot()
destructor
PlotOptions & options()
[brief description]
T::Options * add(Args &&...args)
[brief description]
Definition Plot.hpp:86
[brief description]
Definition Point.hpp:29
[brief description]
Definition Renderer.hpp:38