terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_tools/event_log_visualizer/plot_protobuf.h" |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | #include <iostream> |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 15 | #include <memory> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include <vector> |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 19 | |
| 20 | ProtobufPlot::ProtobufPlot() {} |
| 21 | |
| 22 | ProtobufPlot::~ProtobufPlot() {} |
| 23 | |
| 24 | void ProtobufPlot::Draw() {} |
| 25 | |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 26 | void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) { |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 27 | for (size_t i = 0; i < series_list_.size(); i++) { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 28 | webrtc::analytics::DataSet* data_set = chart->add_data_sets(); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 29 | for (const auto& point : series_list_[i].points) { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 30 | data_set->add_x_values(point.x); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 31 | } |
| 32 | for (const auto& point : series_list_[i].points) { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 33 | data_set->add_y_values(point.y); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 36 | if (series_list_[i].line_style == LineStyle::kBar) { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 37 | data_set->set_style(webrtc::analytics::ChartStyle::BAR_CHART); |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 38 | } else if (series_list_[i].line_style == LineStyle::kLine) { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 39 | data_set->set_style(webrtc::analytics::ChartStyle::LINE_CHART); |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 40 | } else if (series_list_[i].line_style == LineStyle::kStep) { |
terelius | 77f0580 | 2017-02-01 06:34:53 -0800 | [diff] [blame] | 41 | data_set->set_style(webrtc::analytics::ChartStyle::LINE_STEP_CHART); |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 42 | } else if (series_list_[i].line_style == LineStyle::kNone) { |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 43 | data_set->set_style(webrtc::analytics::ChartStyle::SCATTER_CHART); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 44 | } else { |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 45 | data_set->set_style(webrtc::analytics::ChartStyle::UNDEFINED); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 48 | if (series_list_[i].point_style == PointStyle::kHighlight) |
| 49 | data_set->set_highlight_points(true); |
| 50 | |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 51 | data_set->set_label(series_list_[i].label); |
| 52 | } |
| 53 | |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 54 | 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_); |
Bjorn Terelius | 1aa9ee9 | 2019-06-11 17:39:38 +0200 | [diff] [blame] | 61 | chart->set_id(id_); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | ProtobufPlotCollection::ProtobufPlotCollection() {} |
| 65 | |
| 66 | ProtobufPlotCollection::~ProtobufPlotCollection() {} |
| 67 | |
Bjorn Terelius | ef73f59 | 2018-09-10 20:11:49 +0200 | [diff] [blame] | 68 | void ProtobufPlotCollection::Draw() { |
| 69 | webrtc::analytics::ChartCollection collection; |
| 70 | ExportProtobuf(&collection); |
| 71 | std::cout << collection.SerializeAsString(); |
| 72 | } |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 73 | |
| 74 | void ProtobufPlotCollection::ExportProtobuf( |
skvlad | f581eb7 | 2016-09-07 11:15:37 -0700 | [diff] [blame] | 75 | webrtc::analytics::ChartCollection* collection) { |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 76 | for (const auto& plot : plots_) { |
| 77 | // TODO(terelius): Ensure that there is no way to insert plots other than |
| 78 | // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast |
| 79 | // here. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 80 | webrtc::analytics::Chart* protobuf_representation = |
| 81 | collection->add_charts(); |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 82 | static_cast<ProtobufPlot*>(plot.get()) |
| 83 | ->ExportProtobuf(protobuf_representation); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | Plot* ProtobufPlotCollection::AppendNewPlot() { |
| 88 | Plot* plot = new ProtobufPlot(); |
| 89 | plots_.push_back(std::unique_ptr<Plot>(plot)); |
| 90 | return plot; |
| 91 | } |
| 92 | |
terelius | b246a29 | 2016-08-23 18:15:25 -0700 | [diff] [blame] | 93 | } // namespace webrtc |