BioDynaMo  v1.05.119-a4ff3934
line_graph.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 #ifndef CORE_ANALYSIS_LINE_GRAPH_H_
15 #define CORE_ANALYSIS_LINE_GRAPH_H_
16 
17 #include <string>
18 #include <unordered_map>
19 #include <vector>
20 #include "core/real_t.h"
21 #include "core/util/root.h"
22 
23 class TCanvas;
24 class TMultiGraph;
25 class TLegend;
26 class TGraph;
27 class TStyle;
28 
29 namespace bdm {
30 namespace experimental {
31 
32 class TimeSeries;
33 
36 class LineGraph {
37  public:
39  LineGraph(const TimeSeries* ts, const std::string& title = "",
40  const std::string& xaxis_title = "",
41  const std::string& yaxis_title = "", bool legend = true,
42  TStyle* style = nullptr, int width = 700, int height = 500);
43 
44  ~LineGraph();
45 
51  TGraph* Add(const std::string& ts_name, const std::string& legend_name = "",
52  const char* add_mg_options = "L", short line_color = 1,
53  float line_color_alpha = 1.0, short line_style = 1,
54  short line_width = 1, short marker_color = 1,
55  float marker_color_alpha = 1.0, short marker_style = 1,
56  float marker_size = 1, short fill_color = 0,
57  float fill_color_alpha = 1.0, short fill_style = 1000);
58 
59  void SetLegendPos(real_t x1, real_t y1, real_t x2, real_t y2);
65  void SetLegendPosNDC(real_t x1, real_t y1, real_t x2, real_t y2);
66 
67  void SetMultiGraphDrawOption(const std::string& s);
68 
69  void Draw(const char* canvas_draw_option = "");
70 
71  void SaveAs(const std::string& filenpath_wo_extension,
72  const std::vector<std::string>& extensions);
73 
74  void Update();
75 
76  TCanvas* GetTCanvas();
77  TMultiGraph* GetTMultiGraph();
78  TLegend* GetTLegend();
79  const std::vector<TGraph*>& GetTGraphs(const std::string& ts_name) const;
80  TStyle* GetTStyle();
81 
82  private:
83  const TimeSeries* ts_ = nullptr;
84  std::string mg_draw_option_ = "A";
85  TCanvas* c_ = nullptr;
86  TMultiGraph* mg_ = nullptr;
87  TLegend* l_ = nullptr;
88  TStyle* s_ = nullptr;
89  std::unordered_map<std::string, std::vector<TGraph*>> id_tgraphs_map_;
90 };
91 
92 } // namespace experimental
93 } // namespace bdm
94 
95 #endif // CORE_ANALYSIS_TIME_SERIES_H_
bdm::experimental::LineGraph::SaveAs
void SaveAs(const std::string &filenpath_wo_extension, const std::vector< std::string > &extensions)
Definition: line_graph.cc:145
bdm::experimental::LineGraph::Add
TGraph * Add(const std::string &ts_name, const std::string &legend_name="", const char *add_mg_options="L", short line_color=1, float line_color_alpha=1.0, short line_style=1, short line_width=1, short marker_color=1, float marker_color_alpha=1.0, short marker_style=1, float marker_size=1, short fill_color=0, float fill_color_alpha=1.0, short fill_style=1000)
Definition: line_graph.cc:59
bdm::experimental::LineGraph::LineGraph
LineGraph(const TimeSeries *ts, const std::string &title="", const std::string &xaxis_title="", const std::string &yaxis_title="", bool legend=true, TStyle *style=nullptr, int width=700, int height=500)
Definition: line_graph.cc:31
bdm::experimental::LineGraph::mg_draw_option_
std::string mg_draw_option_
Definition: line_graph.h:84
bdm::experimental::LineGraph::l_
TLegend * l_
Definition: line_graph.h:87
bdm
Definition: agent.cc:39
bdm::experimental::LineGraph::c_
TCanvas * c_
Definition: line_graph.h:85
bdm::experimental::LineGraph::GetTStyle
TStyle * GetTStyle()
Definition: line_graph.cc:181
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::experimental::LineGraph::GetTLegend
TLegend * GetTLegend()
Definition: line_graph.cc:167
bdm::experimental::LineGraph
Definition: line_graph.h:36
bdm::experimental::LineGraph::SetMultiGraphDrawOption
void SetMultiGraphDrawOption(const std::string &s)
Definition: line_graph.cc:156
bdm::experimental::LineGraph::SetLegendPos
void SetLegendPos(real_t x1, real_t y1, real_t x2, real_t y2)
Definition: line_graph.cc:115
bdm::experimental::LineGraph::GetTCanvas
TCanvas * GetTCanvas()
Definition: line_graph.cc:161
bdm::experimental::LineGraph::SetLegendPosNDC
void SetLegendPosNDC(real_t x1, real_t y1, real_t x2, real_t y2)
Definition: line_graph.cc:130
bdm::experimental::LineGraph::s_
TStyle * s_
Definition: line_graph.h:88
root.h
bdm::experimental::LineGraph::Update
void Update()
Definition: line_graph.cc:184
bdm::experimental::LineGraph::GetTGraphs
const std::vector< TGraph * > & GetTGraphs(const std::string &ts_name) const
Definition: line_graph.cc:170
bdm::experimental::TimeSeries
Definition: time_series.h:123
bdm::experimental::LineGraph::ts_
const TimeSeries * ts_
Definition: line_graph.h:83
bdm::experimental::LineGraph::id_tgraphs_map_
std::unordered_map< std::string, std::vector< TGraph * > > id_tgraphs_map_
Definition: line_graph.h:89
real_t.h
bdm::experimental::LineGraph::Draw
void Draw(const char *canvas_draw_option="")
Definition: line_graph.cc:109
bdm::experimental::LineGraph::GetTMultiGraph
TMultiGraph * GetTMultiGraph()
Definition: line_graph.cc:164
bdm::experimental::LineGraph::~LineGraph
~LineGraph()
Definition: line_graph.cc:50
bdm::experimental::LineGraph::mg_
TMultiGraph * mg_
Definition: line_graph.h:86