terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 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 | |
terelius | 59c1ad5 | 2016-07-28 09:21:26 -0700 | [diff] [blame] | 21 | enum PlotStyle { LINE_GRAPH, BAR_GRAPH }; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 22 | |
| 23 | struct TimeSeriesPoint { |
| 24 | TimeSeriesPoint(float x, float y) : x(x), y(y) {} |
| 25 | float x; |
| 26 | float y; |
| 27 | }; |
| 28 | |
| 29 | struct TimeSeries { |
| 30 | TimeSeries() = default; |
| 31 | TimeSeries(TimeSeries&& other) |
| 32 | : label(std::move(other.label)), |
| 33 | style(other.style), |
| 34 | points(std::move(other.points)) {} |
| 35 | TimeSeries& operator=(TimeSeries&& other) { |
| 36 | label = std::move(other.label); |
| 37 | style = other.style; |
| 38 | points = std::move(other.points); |
| 39 | return *this; |
| 40 | } |
| 41 | |
| 42 | std::string label; |
| 43 | PlotStyle style; |
| 44 | std::vector<TimeSeriesPoint> points; |
| 45 | }; |
| 46 | |
| 47 | // This is basically a struct that represents of a general graph, with axes, |
| 48 | // title and one or more data series. We make it a class only to document that |
| 49 | // it also specifies an interface for the draw()ing objects. |
| 50 | class Plot { |
| 51 | public: |
| 52 | virtual ~Plot() {} |
| 53 | virtual void draw() = 0; |
| 54 | |
| 55 | float xaxis_min; |
| 56 | float xaxis_max; |
| 57 | std::string xaxis_label; |
| 58 | float yaxis_min; |
| 59 | float yaxis_max; |
| 60 | std::string yaxis_label; |
| 61 | std::vector<TimeSeries> series; |
| 62 | std::string title; |
| 63 | }; |
| 64 | |
| 65 | class PlotCollection { |
| 66 | public: |
| 67 | virtual ~PlotCollection() {} |
| 68 | virtual void draw() = 0; |
| 69 | virtual Plot* append_new_plot() = 0; |
| 70 | |
| 71 | protected: |
| 72 | std::vector<std::unique_ptr<Plot> > plots; |
| 73 | }; |
| 74 | |
| 75 | } // namespace plotting |
| 76 | } // namespace webrtc |
| 77 | |
| 78 | #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_BASE_H_ |