blob: e986a74fdc6509e75456e0e94b1e9aafcb30a115 [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 {
tereliusb246a292016-08-23 18:15:25 -070016
17ProtobufPlot::ProtobufPlot() {}
18
19ProtobufPlot::~ProtobufPlot() {}
20
21void ProtobufPlot::Draw() {}
22
skvladf581eb72016-09-07 11:15:37 -070023void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) {
tereliusb246a292016-08-23 18:15:25 -070024 for (size_t i = 0; i < series_list_.size(); i++) {
skvladf581eb72016-09-07 11:15:37 -070025 webrtc::analytics::DataSet* data_set = chart->add_data_sets();
tereliusb246a292016-08-23 18:15:25 -070026 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070027 data_set->add_x_values(point.x);
tereliusb246a292016-08-23 18:15:25 -070028 }
29 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070030 data_set->add_y_values(point.y);
tereliusb246a292016-08-23 18:15:25 -070031 }
32
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010033 if (series_list_[i].line_style == LineStyle::kBar) {
skvladf581eb72016-09-07 11:15:37 -070034 data_set->set_style(webrtc::analytics::ChartStyle::BAR_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010035 } else if (series_list_[i].line_style == LineStyle::kLine) {
skvladf581eb72016-09-07 11:15:37 -070036 data_set->set_style(webrtc::analytics::ChartStyle::LINE_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010037 } else if (series_list_[i].line_style == LineStyle::kStep) {
terelius77f05802017-02-01 06:34:53 -080038 data_set->set_style(webrtc::analytics::ChartStyle::LINE_STEP_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010039 } else if (series_list_[i].line_style == LineStyle::kNone) {
philipele127e7a2017-03-29 16:28:53 +020040 data_set->set_style(webrtc::analytics::ChartStyle::SCATTER_CHART);
tereliusb246a292016-08-23 18:15:25 -070041 } else {
skvladf581eb72016-09-07 11:15:37 -070042 data_set->set_style(webrtc::analytics::ChartStyle::UNDEFINED);
tereliusb246a292016-08-23 18:15:25 -070043 }
44
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010045 if (series_list_[i].point_style == PointStyle::kHighlight)
46 data_set->set_highlight_points(true);
47
tereliusb246a292016-08-23 18:15:25 -070048 data_set->set_label(series_list_[i].label);
49 }
50
skvladf581eb72016-09-07 11:15:37 -070051 chart->set_xaxis_min(xaxis_min_);
52 chart->set_xaxis_max(xaxis_max_);
53 chart->set_yaxis_min(yaxis_min_);
54 chart->set_yaxis_max(yaxis_max_);
55 chart->set_xaxis_label(xaxis_label_);
56 chart->set_yaxis_label(yaxis_label_);
57 chart->set_title(title_);
tereliusb246a292016-08-23 18:15:25 -070058}
59
60ProtobufPlotCollection::ProtobufPlotCollection() {}
61
62ProtobufPlotCollection::~ProtobufPlotCollection() {}
63
64void ProtobufPlotCollection::Draw() {}
65
66void ProtobufPlotCollection::ExportProtobuf(
skvladf581eb72016-09-07 11:15:37 -070067 webrtc::analytics::ChartCollection* collection) {
tereliusb246a292016-08-23 18:15:25 -070068 for (const auto& plot : plots_) {
69 // TODO(terelius): Ensure that there is no way to insert plots other than
70 // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast
71 // here.
skvladf581eb72016-09-07 11:15:37 -070072 webrtc::analytics::Chart* protobuf_representation
73 = collection->add_charts();
tereliusb246a292016-08-23 18:15:25 -070074 static_cast<ProtobufPlot*>(plot.get())
75 ->ExportProtobuf(protobuf_representation);
76 }
77}
78
79Plot* ProtobufPlotCollection::AppendNewPlot() {
80 Plot* plot = new ProtobufPlot();
81 plots_.push_back(std::unique_ptr<Plot>(plot));
82 return plot;
83}
84
tereliusb246a292016-08-23 18:15:25 -070085} // namespace webrtc