OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 #ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | |
11 #define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | |
12 | |
13 #include <memory> | |
14 #include <string> | |
15 #include <utility> | |
16 #include <vector> | |
17 | |
18 namespace webrtc { | |
19 namespace plotting { | |
20 | |
21 enum PlotStyle { | |
22 LINE_GRAPH, | |
23 LINE_DOT_GRAPH, | |
24 BAR_GRAPH, | |
25 LINE_STEP_GRAPH, | |
26 DOT_GRAPH | |
27 }; | |
28 | |
29 struct TimeSeriesPoint { | |
30 TimeSeriesPoint(float x, float y) : x(x), y(y) {} | |
31 float x; | |
32 float y; | |
33 }; | |
34 | |
35 struct TimeSeries { | |
36 TimeSeries() = default; | |
37 TimeSeries(const char* label, PlotStyle style) : label(label), style(style) {} | |
38 TimeSeries(const std::string& label, PlotStyle style) | |
39 : label(label), style(style) {} | |
40 TimeSeries(TimeSeries&& other) | |
41 : label(std::move(other.label)), | |
42 style(other.style), | |
43 points(std::move(other.points)) {} | |
44 TimeSeries& operator=(TimeSeries&& other) { | |
45 label = std::move(other.label); | |
46 style = other.style; | |
47 points = std::move(other.points); | |
48 return *this; | |
49 } | |
50 | |
51 std::string label; | |
52 PlotStyle style; | |
53 std::vector<TimeSeriesPoint> points; | |
54 }; | |
55 | |
56 // A container that represents a general graph, with axes, title and one or | |
57 // more data series. A subclass should define the output format by overriding | |
58 // the Draw() method. | |
59 class Plot { | |
60 public: | |
61 virtual ~Plot() {} | |
62 | |
63 // Overloaded to draw the plot. | |
64 virtual void Draw() = 0; | |
65 | |
66 // Sets the lower x-axis limit to min_value (if left_margin == 0). | |
67 // Sets the upper x-axis limit to max_value (if right_margin == 0). | |
68 // The margins are measured as fractions of the interval | |
69 // (max_value - min_value) and are added to either side of the plot. | |
70 void SetXAxis(float min_value, | |
71 float max_value, | |
72 std::string label, | |
73 float left_margin = 0, | |
74 float right_margin = 0); | |
75 | |
76 // Sets the lower and upper x-axis limits based on min_value and max_value, | |
77 // but modified such that all points in the data series can be represented | |
78 // on the x-axis. The margins are measured as fractions of the range of | |
79 // x-values and are added to either side of the plot. | |
80 void SetSuggestedXAxis(float min_value, | |
81 float max_value, | |
82 std::string label, | |
83 float left_margin = 0, | |
84 float right_margin = 0); | |
85 | |
86 // Sets the lower y-axis limit to min_value (if bottom_margin == 0). | |
87 // Sets the upper y-axis limit to max_value (if top_margin == 0). | |
88 // The margins are measured as fractions of the interval | |
89 // (max_value - min_value) and are added to either side of the plot. | |
90 void SetYAxis(float min_value, | |
91 float max_value, | |
92 std::string label, | |
93 float bottom_margin = 0, | |
94 float top_margin = 0); | |
95 | |
96 // Sets the lower and upper y-axis limits based on min_value and max_value, | |
97 // but modified such that all points in the data series can be represented | |
98 // on the y-axis. The margins are measured as fractions of the range of | |
99 // y-values and are added to either side of the plot. | |
100 void SetSuggestedYAxis(float min_value, | |
101 float max_value, | |
102 std::string label, | |
103 float bottom_margin = 0, | |
104 float top_margin = 0); | |
105 | |
106 // Sets the title of the plot. | |
107 void SetTitle(std::string title); | |
108 | |
109 // Add a new TimeSeries to the plot. | |
110 void AppendTimeSeries(TimeSeries&& time_series); | |
111 | |
112 // Add a new TimeSeries to the plot if the series contains contains data. | |
113 // Otherwise, the call has no effect and the timeseries is destroyed. | |
114 void AppendTimeSeriesIfNotEmpty(TimeSeries&& time_series); | |
115 | |
116 protected: | |
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_; | |
124 std::vector<TimeSeries> series_list_; | |
125 }; | |
126 | |
127 class PlotCollection { | |
128 public: | |
129 virtual ~PlotCollection() {} | |
130 virtual void Draw() = 0; | |
131 virtual Plot* AppendNewPlot() = 0; | |
132 | |
133 protected: | |
134 std::vector<std::unique_ptr<Plot> > plots_; | |
135 }; | |
136 | |
137 } // namespace plotting | |
138 } // namespace webrtc | |
139 | |
140 #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ | |
OLD | NEW |