Chromium Code Reviews| Index: webrtc/tools/event_log_visualizer/plot_base.h |
| diff --git a/webrtc/tools/event_log_visualizer/plot_base.h b/webrtc/tools/event_log_visualizer/plot_base.h |
| index 925dcecf3db1546cc684ff5d5b0500f101670713..f665c677898604a7d4cd68cc2074c04e401a2d33 100644 |
| --- a/webrtc/tools/event_log_visualizer/plot_base.h |
| +++ b/webrtc/tools/event_log_visualizer/plot_base.h |
| @@ -10,11 +10,14 @@ |
| #ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |
| #define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |
| +#include <algorithm> |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| +#include "webrtc/base/checks.h" |
| + |
| namespace webrtc { |
| namespace plotting { |
| @@ -44,32 +47,90 @@ struct TimeSeries { |
| std::vector<TimeSeriesPoint> points; |
| }; |
| -// This is basically a struct that represents of a general graph, with axes, |
| +// This is basically a struct that represents a general graph, with axes, |
| // title and one or more data series. We make it a class only to document that |
|
danilchap
2016/07/26 10:52:46
Comment probably need an update too: This struct b
terelius
2016/07/26 17:37:38
Done.
|
| // it also specifies an interface for the draw()ing objects. |
| class Plot { |
|
danilchap
2016/07/26 10:52:46
may be add plot_base.cc and move implementation th
terelius
2016/07/26 17:37:38
Done.
|
| public: |
| virtual ~Plot() {} |
| - virtual void draw() = 0; |
| - |
| - float xaxis_min; |
| - float xaxis_max; |
| - std::string xaxis_label; |
| - float yaxis_min; |
| - float yaxis_max; |
| - std::string yaxis_label; |
| - std::vector<TimeSeries> series; |
| - std::string title; |
| + virtual void Draw() = 0; |
| + |
| + void SetXAxis(float min, |
| + float max, |
| + std::string label, |
| + float left_margin = 0, |
|
danilchap
2016/07/26 10:52:46
it doesn't look like you use default arguments (i.
terelius
2016/07/26 17:37:38
They are not used right now, but just setting the
|
| + float right_margin = 0) { |
|
danilchap
2016/07/26 10:52:46
margin doesn't use same units as min/max. It might
terelius
2016/07/26 17:37:38
I added comments indicating that the margins are m
|
| + xaxis_min_ = min - left_margin * (max - min); |
| + xaxis_max_ = max + right_margin * (max - min); |
| + xaxis_label_ = label; |
| + } |
| + |
| + void SetSuggestedXAxis(float min, |
| + float max, |
| + std::string label, |
| + float left_margin = 0, |
| + float right_margin = 0) { |
| + for (auto& series : series_list_) { |
|
danilchap
2016/07/26 10:52:46
const auto& here and next line
terelius
2016/07/26 17:37:38
Done.
|
| + for (auto& point : series.points) { |
| + min = std::min(min, point.x); |
|
danilchap
2016/07/26 10:52:46
std::min as function and min as variable in same l
terelius
2016/07/26 17:37:38
Done.
|
| + max = std::max(max, point.x); |
| + } |
| + } |
| + RTC_DCHECK(max >= min); |
|
danilchap
2016/07/26 10:52:46
RTC_DCHECK_LE(min, max);
and have this check in Se
terelius
2016/07/26 17:37:38
Done.
|
| + xaxis_min_ = min - left_margin * (max - min); |
|
danilchap
2016/07/26 10:52:46
may be call SetXAxis instead of duplicating the co
terelius
2016/07/26 17:37:38
Done.
|
| + xaxis_max_ = max + right_margin * (max - min); |
| + xaxis_label_ = label; |
| + } |
| + |
| + void SetYAxis(float min, |
| + float max, |
| + std::string label, |
| + float bottom_margin = 0, |
| + float top_margin = 0) { |
| + yaxis_min_ = min - bottom_margin * (max - min); |
| + yaxis_max_ = max + top_margin * (max - min); |
| + yaxis_label_ = label; |
| + } |
| + |
| + void SetSuggestedYAxis(float min, |
| + float max, |
| + std::string label, |
| + float bottom_margin = 0, |
| + float top_margin = 0) { |
| + for (auto& series : series_list_) { |
| + for (auto& point : series.points) { |
| + min = std::min(min, point.y); |
| + max = std::max(max, point.y); |
| + } |
| + } |
| + RTC_DCHECK(max >= min); |
| + yaxis_min_ = min - bottom_margin * (max - min); |
| + yaxis_max_ = max + top_margin * (max - min); |
| + yaxis_label_ = label; |
| + } |
| + |
| + void SetTitle(std::string title) { title_ = title; } |
| + |
| + std::vector<TimeSeries> series_list_; |
|
danilchap
2016/07/26 10:52:46
Why rename this variable to _list when it is not e
terelius
2016/07/26 17:37:38
This variable is a collection of TimeSeries object
|
| + |
| + protected: |
|
danilchap
2016/07/26 10:52:46
either make it private, or update CL description t
terelius
2016/07/26 17:37:38
Can't be private. Updated CL description.
|
| + float xaxis_min_; |
| + float xaxis_max_; |
| + std::string xaxis_label_; |
| + float yaxis_min_; |
| + float yaxis_max_; |
| + std::string yaxis_label_; |
| + std::string title_; |
| }; |
| class PlotCollection { |
| public: |
| virtual ~PlotCollection() {} |
| - virtual void draw() = 0; |
| - virtual Plot* append_new_plot() = 0; |
| + virtual void Draw() = 0; |
| + virtual Plot* AppendNewPlot() = 0; |
| protected: |
| - std::vector<std::unique_ptr<Plot> > plots; |
| + std::vector<std::unique_ptr<Plot> > plots_; |
| }; |
| } // namespace plotting |