blob: 3b2842d8775bda0f5dcc9dc67f68ec86b902f935 [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
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <iostream>
tereliusb246a292016-08-23 18:15:25 -070016#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <vector>
tereliusb246a292016-08-23 18:15:25 -070018
19namespace webrtc {
tereliusb246a292016-08-23 18:15:25 -070020
21ProtobufPlot::ProtobufPlot() {}
22
23ProtobufPlot::~ProtobufPlot() {}
24
25void ProtobufPlot::Draw() {}
26
skvladf581eb72016-09-07 11:15:37 -070027void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) {
tereliusb246a292016-08-23 18:15:25 -070028 for (size_t i = 0; i < series_list_.size(); i++) {
skvladf581eb72016-09-07 11:15:37 -070029 webrtc::analytics::DataSet* data_set = chart->add_data_sets();
tereliusb246a292016-08-23 18:15:25 -070030 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070031 data_set->add_x_values(point.x);
tereliusb246a292016-08-23 18:15:25 -070032 }
33 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070034 data_set->add_y_values(point.y);
tereliusb246a292016-08-23 18:15:25 -070035 }
36
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010037 if (series_list_[i].line_style == LineStyle::kBar) {
skvladf581eb72016-09-07 11:15:37 -070038 data_set->set_style(webrtc::analytics::ChartStyle::BAR_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010039 } else if (series_list_[i].line_style == LineStyle::kLine) {
skvladf581eb72016-09-07 11:15:37 -070040 data_set->set_style(webrtc::analytics::ChartStyle::LINE_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010041 } else if (series_list_[i].line_style == LineStyle::kStep) {
terelius77f05802017-02-01 06:34:53 -080042 data_set->set_style(webrtc::analytics::ChartStyle::LINE_STEP_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010043 } else if (series_list_[i].line_style == LineStyle::kNone) {
philipele127e7a2017-03-29 16:28:53 +020044 data_set->set_style(webrtc::analytics::ChartStyle::SCATTER_CHART);
tereliusb246a292016-08-23 18:15:25 -070045 } else {
skvladf581eb72016-09-07 11:15:37 -070046 data_set->set_style(webrtc::analytics::ChartStyle::UNDEFINED);
tereliusb246a292016-08-23 18:15:25 -070047 }
48
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010049 if (series_list_[i].point_style == PointStyle::kHighlight)
50 data_set->set_highlight_points(true);
51
tereliusb246a292016-08-23 18:15:25 -070052 data_set->set_label(series_list_[i].label);
53 }
54
skvladf581eb72016-09-07 11:15:37 -070055 chart->set_xaxis_min(xaxis_min_);
56 chart->set_xaxis_max(xaxis_max_);
57 chart->set_yaxis_min(yaxis_min_);
58 chart->set_yaxis_max(yaxis_max_);
59 chart->set_xaxis_label(xaxis_label_);
60 chart->set_yaxis_label(yaxis_label_);
61 chart->set_title(title_);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020062 chart->set_id(id_);
tereliusb246a292016-08-23 18:15:25 -070063}
64
65ProtobufPlotCollection::ProtobufPlotCollection() {}
66
67ProtobufPlotCollection::~ProtobufPlotCollection() {}
68
Bjorn Tereliusef73f592018-09-10 20:11:49 +020069void ProtobufPlotCollection::Draw() {
70 webrtc::analytics::ChartCollection collection;
71 ExportProtobuf(&collection);
72 std::cout << collection.SerializeAsString();
73}
tereliusb246a292016-08-23 18:15:25 -070074
75void ProtobufPlotCollection::ExportProtobuf(
skvladf581eb72016-09-07 11:15:37 -070076 webrtc::analytics::ChartCollection* collection) {
tereliusb246a292016-08-23 18:15:25 -070077 for (const auto& plot : plots_) {
78 // TODO(terelius): Ensure that there is no way to insert plots other than
79 // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast
80 // here.
Yves Gerey665174f2018-06-19 15:03:05 +020081 webrtc::analytics::Chart* protobuf_representation =
82 collection->add_charts();
tereliusb246a292016-08-23 18:15:25 -070083 static_cast<ProtobufPlot*>(plot.get())
84 ->ExportProtobuf(protobuf_representation);
85 }
86}
87
88Plot* ProtobufPlotCollection::AppendNewPlot() {
89 Plot* plot = new ProtobufPlot();
90 plots_.push_back(std::unique_ptr<Plot>(plot));
91 return plot;
92}
93
tereliusb246a292016-08-23 18:15:25 -070094} // namespace webrtc