blob: 309214b2a97267968c7c5aac3738c213c692a822 [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>
14#include <iostream>
tereliusb246a292016-08-23 18:15:25 -070015#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010016#include <vector>
tereliusb246a292016-08-23 18:15:25 -070017
18namespace webrtc {
tereliusb246a292016-08-23 18:15:25 -070019
20ProtobufPlot::ProtobufPlot() {}
21
22ProtobufPlot::~ProtobufPlot() {}
23
24void ProtobufPlot::Draw() {}
25
skvladf581eb72016-09-07 11:15:37 -070026void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) {
tereliusb246a292016-08-23 18:15:25 -070027 for (size_t i = 0; i < series_list_.size(); i++) {
skvladf581eb72016-09-07 11:15:37 -070028 webrtc::analytics::DataSet* data_set = chart->add_data_sets();
tereliusb246a292016-08-23 18:15:25 -070029 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070030 data_set->add_x_values(point.x);
tereliusb246a292016-08-23 18:15:25 -070031 }
32 for (const auto& point : series_list_[i].points) {
skvladf581eb72016-09-07 11:15:37 -070033 data_set->add_y_values(point.y);
tereliusb246a292016-08-23 18:15:25 -070034 }
35
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010036 if (series_list_[i].line_style == LineStyle::kBar) {
skvladf581eb72016-09-07 11:15:37 -070037 data_set->set_style(webrtc::analytics::ChartStyle::BAR_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010038 } else if (series_list_[i].line_style == LineStyle::kLine) {
skvladf581eb72016-09-07 11:15:37 -070039 data_set->set_style(webrtc::analytics::ChartStyle::LINE_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010040 } else if (series_list_[i].line_style == LineStyle::kStep) {
terelius77f05802017-02-01 06:34:53 -080041 data_set->set_style(webrtc::analytics::ChartStyle::LINE_STEP_CHART);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010042 } else if (series_list_[i].line_style == LineStyle::kNone) {
philipele127e7a2017-03-29 16:28:53 +020043 data_set->set_style(webrtc::analytics::ChartStyle::SCATTER_CHART);
tereliusb246a292016-08-23 18:15:25 -070044 } else {
skvladf581eb72016-09-07 11:15:37 -070045 data_set->set_style(webrtc::analytics::ChartStyle::UNDEFINED);
tereliusb246a292016-08-23 18:15:25 -070046 }
47
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +010048 if (series_list_[i].point_style == PointStyle::kHighlight)
49 data_set->set_highlight_points(true);
50
tereliusb246a292016-08-23 18:15:25 -070051 data_set->set_label(series_list_[i].label);
52 }
53
skvladf581eb72016-09-07 11:15:37 -070054 chart->set_xaxis_min(xaxis_min_);
55 chart->set_xaxis_max(xaxis_max_);
56 chart->set_yaxis_min(yaxis_min_);
57 chart->set_yaxis_max(yaxis_max_);
58 chart->set_xaxis_label(xaxis_label_);
59 chart->set_yaxis_label(yaxis_label_);
60 chart->set_title(title_);
tereliusb246a292016-08-23 18:15:25 -070061}
62
63ProtobufPlotCollection::ProtobufPlotCollection() {}
64
65ProtobufPlotCollection::~ProtobufPlotCollection() {}
66
Bjorn Tereliusef73f592018-09-10 20:11:49 +020067void ProtobufPlotCollection::Draw() {
68 webrtc::analytics::ChartCollection collection;
69 ExportProtobuf(&collection);
70 std::cout << collection.SerializeAsString();
71}
tereliusb246a292016-08-23 18:15:25 -070072
73void ProtobufPlotCollection::ExportProtobuf(
skvladf581eb72016-09-07 11:15:37 -070074 webrtc::analytics::ChartCollection* collection) {
tereliusb246a292016-08-23 18:15:25 -070075 for (const auto& plot : plots_) {
76 // TODO(terelius): Ensure that there is no way to insert plots other than
77 // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast
78 // here.
Yves Gerey665174f2018-06-19 15:03:05 +020079 webrtc::analytics::Chart* protobuf_representation =
80 collection->add_charts();
tereliusb246a292016-08-23 18:15:25 -070081 static_cast<ProtobufPlot*>(plot.get())
82 ->ExportProtobuf(protobuf_representation);
83 }
84}
85
86Plot* ProtobufPlotCollection::AppendNewPlot() {
87 Plot* plot = new ProtobufPlot();
88 plots_.push_back(std::unique_ptr<Plot>(plot));
89 return plot;
90}
91
tereliusb246a292016-08-23 18:15:25 -070092} // namespace webrtc