OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | 10 #ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |
11 #define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | 11 #define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |
12 | 12 |
13 #include <algorithm> | |
13 #include <memory> | 14 #include <memory> |
14 #include <string> | 15 #include <string> |
15 #include <utility> | 16 #include <utility> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
19 #include "webrtc/base/checks.h" | |
20 | |
18 namespace webrtc { | 21 namespace webrtc { |
19 namespace plotting { | 22 namespace plotting { |
20 | 23 |
21 enum PlotStyle { LINE_GRAPH, BAR_GRAPH }; | 24 enum PlotStyle { LINE_GRAPH, BAR_GRAPH }; |
22 | 25 |
23 struct TimeSeriesPoint { | 26 struct TimeSeriesPoint { |
24 TimeSeriesPoint(float x, float y) : x(x), y(y) {} | 27 TimeSeriesPoint(float x, float y) : x(x), y(y) {} |
25 float x; | 28 float x; |
26 float y; | 29 float y; |
27 }; | 30 }; |
28 | 31 |
29 struct TimeSeries { | 32 struct TimeSeries { |
30 TimeSeries() = default; | 33 TimeSeries() = default; |
31 TimeSeries(TimeSeries&& other) | 34 TimeSeries(TimeSeries&& other) |
32 : label(std::move(other.label)), | 35 : label(std::move(other.label)), |
33 style(other.style), | 36 style(other.style), |
34 points(std::move(other.points)) {} | 37 points(std::move(other.points)) {} |
35 TimeSeries& operator=(TimeSeries&& other) { | 38 TimeSeries& operator=(TimeSeries&& other) { |
36 label = std::move(other.label); | 39 label = std::move(other.label); |
37 style = other.style; | 40 style = other.style; |
38 points = std::move(other.points); | 41 points = std::move(other.points); |
39 return *this; | 42 return *this; |
40 } | 43 } |
41 | 44 |
42 std::string label; | 45 std::string label; |
43 PlotStyle style; | 46 PlotStyle style; |
44 std::vector<TimeSeriesPoint> points; | 47 std::vector<TimeSeriesPoint> points; |
45 }; | 48 }; |
46 | 49 |
47 // This is basically a struct that represents of a general graph, with axes, | 50 // This is basically a struct that represents a general graph, with axes, |
48 // title and one or more data series. We make it a class only to document that | 51 // 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.
| |
49 // it also specifies an interface for the draw()ing objects. | 52 // it also specifies an interface for the draw()ing objects. |
50 class Plot { | 53 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.
| |
51 public: | 54 public: |
52 virtual ~Plot() {} | 55 virtual ~Plot() {} |
53 virtual void draw() = 0; | 56 virtual void Draw() = 0; |
54 | 57 |
55 float xaxis_min; | 58 void SetXAxis(float min, |
56 float xaxis_max; | 59 float max, |
57 std::string xaxis_label; | 60 std::string label, |
58 float yaxis_min; | 61 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
| |
59 float yaxis_max; | 62 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
| |
60 std::string yaxis_label; | 63 xaxis_min_ = min - left_margin * (max - min); |
61 std::vector<TimeSeries> series; | 64 xaxis_max_ = max + right_margin * (max - min); |
62 std::string title; | 65 xaxis_label_ = label; |
66 } | |
67 | |
68 void SetSuggestedXAxis(float min, | |
69 float max, | |
70 std::string label, | |
71 float left_margin = 0, | |
72 float right_margin = 0) { | |
73 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.
| |
74 for (auto& point : series.points) { | |
75 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.
| |
76 max = std::max(max, point.x); | |
77 } | |
78 } | |
79 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.
| |
80 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.
| |
81 xaxis_max_ = max + right_margin * (max - min); | |
82 xaxis_label_ = label; | |
83 } | |
84 | |
85 void SetYAxis(float min, | |
86 float max, | |
87 std::string label, | |
88 float bottom_margin = 0, | |
89 float top_margin = 0) { | |
90 yaxis_min_ = min - bottom_margin * (max - min); | |
91 yaxis_max_ = max + top_margin * (max - min); | |
92 yaxis_label_ = label; | |
93 } | |
94 | |
95 void SetSuggestedYAxis(float min, | |
96 float max, | |
97 std::string label, | |
98 float bottom_margin = 0, | |
99 float top_margin = 0) { | |
100 for (auto& series : series_list_) { | |
101 for (auto& point : series.points) { | |
102 min = std::min(min, point.y); | |
103 max = std::max(max, point.y); | |
104 } | |
105 } | |
106 RTC_DCHECK(max >= min); | |
107 yaxis_min_ = min - bottom_margin * (max - min); | |
108 yaxis_max_ = max + top_margin * (max - min); | |
109 yaxis_label_ = label; | |
110 } | |
111 | |
112 void SetTitle(std::string title) { title_ = title; } | |
113 | |
114 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
| |
115 | |
116 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.
| |
117 float xaxis_min_; | |
118 float xaxis_max_; | |
119 std::string xaxis_label_; | |
120 float yaxis_min_; | |
121 float yaxis_max_; | |
122 std::string yaxis_label_; | |
123 std::string title_; | |
63 }; | 124 }; |
64 | 125 |
65 class PlotCollection { | 126 class PlotCollection { |
66 public: | 127 public: |
67 virtual ~PlotCollection() {} | 128 virtual ~PlotCollection() {} |
68 virtual void draw() = 0; | 129 virtual void Draw() = 0; |
69 virtual Plot* append_new_plot() = 0; | 130 virtual Plot* AppendNewPlot() = 0; |
70 | 131 |
71 protected: | 132 protected: |
72 std::vector<std::unique_ptr<Plot> > plots; | 133 std::vector<std::unique_ptr<Plot> > plots_; |
73 }; | 134 }; |
74 | 135 |
75 } // namespace plotting | 136 } // namespace plotting |
76 } // namespace webrtc | 137 } // namespace webrtc |
77 | 138 |
78 #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | 139 #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |
OLD | NEW |