blob: baee3dfeee3cd0708bd8e490a791b0560802fa33 [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
11#include "webrtc/tools/event_log_visualizer/plot_base.h"
12
13#include <algorithm>
14
15#include "webrtc/base/checks.h"
16
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
terelius23c595a2017-03-15 01:59:12 -070074TimeSeries* Plot::AddTimeSeries(const char* label, PlotStyle style) {
75 series_list_.emplace_back(label, style);
76 return &series_list_.back();
77}
78
79TimeSeries* Plot::AddTimeSeries(const std::string& label, PlotStyle style) {
80 series_list_.emplace_back(label, style);
81 return &series_list_.back();
82}
83
tereliusdc35dcd2016-08-01 12:03:27 -070084} // namespace plotting
85} // namespace webrtc