blob: 9dc61f79a31936174e6a958b9936aad9c23c0dd6 [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_);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020061 chart->set_id(id_);
tereliusb246a292016-08-23 18:15:25 -070062}
63
64ProtobufPlotCollection::ProtobufPlotCollection() {}
65
66ProtobufPlotCollection::~ProtobufPlotCollection() {}
67
Bjorn Tereliusef73f592018-09-10 20:11:49 +020068void ProtobufPlotCollection::Draw() {
69 webrtc::analytics::ChartCollection collection;
70 ExportProtobuf(&collection);
71 std::cout << collection.SerializeAsString();
72}
tereliusb246a292016-08-23 18:15:25 -070073
74void ProtobufPlotCollection::ExportProtobuf(
skvladf581eb72016-09-07 11:15:37 -070075 webrtc::analytics::ChartCollection* collection) {
tereliusb246a292016-08-23 18:15:25 -070076 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 Gerey665174f2018-06-19 15:03:05 +020080 webrtc::analytics::Chart* protobuf_representation =
81 collection->add_charts();
tereliusb246a292016-08-23 18:15:25 -070082 static_cast<ProtobufPlot*>(plot.get())
83 ->ExportProtobuf(protobuf_representation);
84 }
85}
86
87Plot* ProtobufPlotCollection::AppendNewPlot() {
88 Plot* plot = new ProtobufPlot();
89 plots_.push_back(std::unique_ptr<Plot>(plot));
90 return plot;
91}
92
tereliusb246a292016-08-23 18:15:25 -070093} // namespace webrtc