terelius | dc35dcd | 2016-08-01 12:03:27 -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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #include "rtc_tools/event_log_visualizer/plot_base.h" |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 15 | #include "rtc_base/checks.h" |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace plotting { |
| 19 | |
| 20 | void Plot::SetXAxis(float min_value, |
| 21 | float max_value, |
| 22 | std::string label, |
| 23 | float left_margin, |
| 24 | float right_margin) { |
| 25 | RTC_DCHECK_LE(min_value, max_value); |
| 26 | xaxis_min_ = min_value - left_margin * (max_value - min_value); |
| 27 | xaxis_max_ = max_value + right_margin * (max_value - min_value); |
| 28 | xaxis_label_ = label; |
| 29 | } |
| 30 | |
| 31 | void Plot::SetSuggestedXAxis(float min_value, |
| 32 | float max_value, |
| 33 | std::string label, |
| 34 | float left_margin, |
| 35 | float right_margin) { |
| 36 | for (const auto& series : series_list_) { |
| 37 | for (const auto& point : series.points) { |
| 38 | min_value = std::min(min_value, point.x); |
| 39 | max_value = std::max(max_value, point.x); |
| 40 | } |
| 41 | } |
| 42 | SetXAxis(min_value, max_value, label, left_margin, right_margin); |
| 43 | } |
| 44 | |
| 45 | void Plot::SetYAxis(float min_value, |
| 46 | float max_value, |
| 47 | std::string label, |
| 48 | float bottom_margin, |
| 49 | float top_margin) { |
| 50 | RTC_DCHECK_LE(min_value, max_value); |
| 51 | yaxis_min_ = min_value - bottom_margin * (max_value - min_value); |
| 52 | yaxis_max_ = max_value + top_margin * (max_value - min_value); |
| 53 | yaxis_label_ = label; |
| 54 | } |
| 55 | |
| 56 | void Plot::SetSuggestedYAxis(float min_value, |
| 57 | float max_value, |
| 58 | std::string label, |
| 59 | float bottom_margin, |
| 60 | float top_margin) { |
| 61 | for (const auto& series : series_list_) { |
| 62 | for (const auto& point : series.points) { |
| 63 | min_value = std::min(min_value, point.y); |
| 64 | max_value = std::max(max_value, point.y); |
| 65 | } |
| 66 | } |
| 67 | SetYAxis(min_value, max_value, label, bottom_margin, top_margin); |
| 68 | } |
| 69 | |
| 70 | void Plot::SetTitle(std::string title) { |
| 71 | title_ = title; |
| 72 | } |
| 73 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 74 | void Plot::AppendTimeSeries(TimeSeries&& time_series) { |
| 75 | series_list_.emplace_back(std::move(time_series)); |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 76 | } |
| 77 | |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 78 | void Plot::AppendIntervalSeries(IntervalSeries&& interval_series) { |
| 79 | interval_list_.emplace_back(std::move(interval_series)); |
| 80 | } |
| 81 | |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 82 | void Plot::AppendTimeSeriesIfNotEmpty(TimeSeries&& time_series) { |
| 83 | if (time_series.points.size() > 0) { |
| 84 | series_list_.emplace_back(std::move(time_series)); |
| 85 | } |
| 86 | } |
| 87 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 88 | } // namespace plotting |
| 89 | } // namespace webrtc |