blob: e5e0a8b0941f19479b355661f95abcfb3ea2a37d [file] [log] [blame]
tereliusb246a292016-08-23 18:15:25 -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_protobuf.h"
tereliusb246a292016-08-23 18:15:25 -070012
13#include <memory>
14
15namespace webrtc {
16namespace plotting {
17
18ProtobufPlot::ProtobufPlot() {}
19
20ProtobufPlot::~ProtobufPlot() {}
21
22void ProtobufPlot::Draw() {}
23
skvladf581eb72016-09-07 11:15:37 -070024void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) {
tereliusb246a292016-08-23 18:15:25 -070025 for (size_t i = 0; i < series_list_.size(); i++) {
skvladf581eb72016-09-07 11:15:37 -070026 webrtc::analytics::DataSet* data_set = chart->add_data_sets();
tereliusb246a292016-08-23 18:15:25 -070027 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070028 data_set->add_x_values(point.x);
tereliusb246a292016-08-23 18:15:25 -070029 }
30 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070031 data_set->add_y_values(point.y);
tereliusb246a292016-08-23 18:15:25 -070032 }
33
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010034 if (series_list_[i].line_style == LineStyle::kBar) {
skvladf581eb72016-09-07 11:15:37 -070035 data_set->set_style(webrtc::analytics::ChartStyle::BAR_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010036 } else if (series_list_[i].line_style == LineStyle::kLine) {
skvladf581eb72016-09-07 11:15:37 -070037 data_set->set_style(webrtc::analytics::ChartStyle::LINE_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010038 } else if (series_list_[i].line_style == LineStyle::kStep) {
terelius77f05802017-02-01 06:34:53 -080039 data_set->set_style(webrtc::analytics::ChartStyle::LINE_STEP_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010040 } else if (series_list_[i].line_style == LineStyle::kNone) {
philipele127e7a2017-03-29 16:28:53 +020041 data_set->set_style(webrtc::analytics::ChartStyle::SCATTER_CHART);
tereliusb246a292016-08-23 18:15:25 -070042 } else {
skvladf581eb72016-09-07 11:15:37 -070043 data_set->set_style(webrtc::analytics::ChartStyle::UNDEFINED);
tereliusb246a292016-08-23 18:15:25 -070044 }
45
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010046 if (series_list_[i].point_style == PointStyle::kHighlight)
47 data_set->set_highlight_points(true);
48
tereliusb246a292016-08-23 18:15:25 -070049 data_set->set_label(series_list_[i].label);
50 }
51
skvladf581eb72016-09-07 11:15:37 -070052 chart->set_xaxis_min(xaxis_min_);
53 chart->set_xaxis_max(xaxis_max_);
54 chart->set_yaxis_min(yaxis_min_);
55 chart->set_yaxis_max(yaxis_max_);
56 chart->set_xaxis_label(xaxis_label_);
57 chart->set_yaxis_label(yaxis_label_);
58 chart->set_title(title_);
tereliusb246a292016-08-23 18:15:25 -070059}
60
61ProtobufPlotCollection::ProtobufPlotCollection() {}
62
63ProtobufPlotCollection::~ProtobufPlotCollection() {}
64
65void ProtobufPlotCollection::Draw() {}
66
67void ProtobufPlotCollection::ExportProtobuf(
skvladf581eb72016-09-07 11:15:37 -070068 webrtc::analytics::ChartCollection* collection) {
tereliusb246a292016-08-23 18:15:25 -070069 for (const auto& plot : plots_) {
70 // TODO(terelius): Ensure that there is no way to insert plots other than
71 // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast
72 // here.
skvladf581eb72016-09-07 11:15:37 -070073 webrtc::analytics::Chart* protobuf_representation
74 = collection->add_charts();
tereliusb246a292016-08-23 18:15:25 -070075 static_cast<ProtobufPlot*>(plot.get())
76 ->ExportProtobuf(protobuf_representation);
77 }
78}
79
80Plot* ProtobufPlotCollection::AppendNewPlot() {
81 Plot* plot = new ProtobufPlot();
82 plots_.push_back(std::unique_ptr<Plot>(plot));
83 return plot;
84}
85
86} // namespace plotting
87} // namespace webrtc