blob: 8313beb98db115bb0f725cb35856bbbd7d6c8b4a [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 {
tereliusdc35dcd2016-08-01 12:03:27 -070018
19void Plot::SetXAxis(float min_value,
20 float max_value,
21 std::string label,
22 float left_margin,
23 float right_margin) {
24 RTC_DCHECK_LE(min_value, max_value);
25 xaxis_min_ = min_value - left_margin * (max_value - min_value);
26 xaxis_max_ = max_value + right_margin * (max_value - min_value);
27 xaxis_label_ = label;
28}
29
30void Plot::SetSuggestedXAxis(float min_value,
31 float max_value,
32 std::string label,
33 float left_margin,
34 float right_margin) {
35 for (const auto& series : series_list_) {
36 for (const auto& point : series.points) {
37 min_value = std::min(min_value, point.x);
38 max_value = std::max(max_value, point.x);
39 }
40 }
41 SetXAxis(min_value, max_value, label, left_margin, right_margin);
42}
43
44void Plot::SetYAxis(float min_value,
45 float max_value,
46 std::string label,
47 float bottom_margin,
48 float top_margin) {
49 RTC_DCHECK_LE(min_value, max_value);
50 yaxis_min_ = min_value - bottom_margin * (max_value - min_value);
51 yaxis_max_ = max_value + top_margin * (max_value - min_value);
52 yaxis_label_ = label;
53}
54
55void Plot::SetSuggestedYAxis(float min_value,
56 float max_value,
57 std::string label,
58 float bottom_margin,
59 float top_margin) {
60 for (const auto& series : series_list_) {
61 for (const auto& point : series.points) {
62 min_value = std::min(min_value, point.y);
63 max_value = std::max(max_value, point.y);
64 }
65 }
66 SetYAxis(min_value, max_value, label, bottom_margin, top_margin);
67}
68
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020069void Plot::SetTitle(const std::string& title) {
tereliusdc35dcd2016-08-01 12:03:27 -070070 title_ = title;
71}
72
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020073void Plot::SetId(const std::string& id) {
74 id_ = id;
75}
76
philipel35ba9bd2017-04-19 05:58:51 -070077void Plot::AppendTimeSeries(TimeSeries&& time_series) {
78 series_list_.emplace_back(std::move(time_series));
terelius23c595a2017-03-15 01:59:12 -070079}
80
philipel23c7f252017-07-14 06:30:03 -070081void Plot::AppendIntervalSeries(IntervalSeries&& interval_series) {
82 interval_list_.emplace_back(std::move(interval_series));
83}
84
terelius2c8e8a32017-06-02 01:29:48 -070085void Plot::AppendTimeSeriesIfNotEmpty(TimeSeries&& time_series) {
86 if (time_series.points.size() > 0) {
87 series_list_.emplace_back(std::move(time_series));
88 }
89}
90
tereliusdc35dcd2016-08-01 12:03:27 -070091} // namespace webrtc