blob: 7ff4ef9c2cdff464bfa4778ac312f3ce0970b033 [file] [log] [blame]
tereliusdc35dcd2016-08-01 12:03:27 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_tools/event_log_visualizer/plot_base.h"
tereliusdc35dcd2016-08-01 12:03:27 -070012
13#include <algorithm>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
tereliusdc35dcd2016-08-01 12:03:27 -070016
17namespace webrtc {
18namespace plotting {
19
20void 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
31void 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
45void 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
56void 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
70void Plot::SetTitle(std::string title) {
71 title_ = title;
72}
73
philipel35ba9bd2017-04-19 05:58:51 -070074void Plot::AppendTimeSeries(TimeSeries&& time_series) {
75 series_list_.emplace_back(std::move(time_series));
terelius23c595a2017-03-15 01:59:12 -070076}
77
philipel23c7f252017-07-14 06:30:03 -070078void Plot::AppendIntervalSeries(IntervalSeries&& interval_series) {
79 interval_list_.emplace_back(std::move(interval_series));
80}
81
terelius2c8e8a32017-06-02 01:29:48 -070082void Plot::AppendTimeSeriesIfNotEmpty(TimeSeries&& time_series) {
83 if (time_series.points.size() > 0) {
84 series_list_.emplace_back(std::move(time_series));
85 }
86}
87
tereliusdc35dcd2016-08-01 12:03:27 -070088} // namespace plotting
89} // namespace webrtc