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 | |
| 11 | #include "webrtc/tools/event_log_visualizer/plot_protobuf.h" |
| 12 | |
| 13 | #include <memory> |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace plotting { |
| 17 | |
| 18 | ProtobufPlot::ProtobufPlot() {} |
| 19 | |
| 20 | ProtobufPlot::~ProtobufPlot() {} |
| 21 | |
| 22 | void ProtobufPlot::Draw() {} |
| 23 | |
| 24 | void ProtobufPlot::ExportProtobuf(protobuf_plot::Plot* plot) { |
| 25 | for (size_t i = 0; i < series_list_.size(); i++) { |
| 26 | protobuf_plot::DataSet* data_set = plot->add_data_sets(); |
| 27 | for (const auto& point : series_list_[i].points) { |
| 28 | data_set->add_xvalues(point.x); |
| 29 | } |
| 30 | for (const auto& point : series_list_[i].points) { |
| 31 | data_set->add_yvalues(point.y); |
| 32 | } |
| 33 | |
| 34 | if (series_list_[i].style == BAR_GRAPH) { |
| 35 | data_set->set_style(protobuf_plot::BAR_GRAPH); |
| 36 | } else if (series_list_[i].style == LINE_GRAPH) { |
| 37 | data_set->set_style(protobuf_plot::LINE_GRAPH); |
| 38 | } else if (series_list_[i].style == LINE_DOT_GRAPH) { |
| 39 | data_set->set_style(protobuf_plot::LINE_DOT_GRAPH); |
| 40 | } else { |
| 41 | data_set->set_style(protobuf_plot::UNDEFINED); |
| 42 | } |
| 43 | |
| 44 | data_set->set_label(series_list_[i].label); |
| 45 | } |
| 46 | |
| 47 | plot->set_xaxis_min(xaxis_min_); |
| 48 | plot->set_xaxis_max(xaxis_max_); |
| 49 | plot->set_yaxis_min(yaxis_min_); |
| 50 | plot->set_yaxis_max(yaxis_max_); |
| 51 | plot->set_xaxis_label(xaxis_label_); |
| 52 | plot->set_yaxis_label(yaxis_label_); |
| 53 | plot->set_title(title_); |
| 54 | } |
| 55 | |
| 56 | ProtobufPlotCollection::ProtobufPlotCollection() {} |
| 57 | |
| 58 | ProtobufPlotCollection::~ProtobufPlotCollection() {} |
| 59 | |
| 60 | void ProtobufPlotCollection::Draw() {} |
| 61 | |
| 62 | void ProtobufPlotCollection::ExportProtobuf( |
| 63 | protobuf_plot::PlotCollection* collection) { |
| 64 | for (const auto& plot : plots_) { |
| 65 | // TODO(terelius): Ensure that there is no way to insert plots other than |
| 66 | // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast |
| 67 | // here. |
| 68 | protobuf_plot::Plot* protobuf_representation = collection->add_plots(); |
| 69 | static_cast<ProtobufPlot*>(plot.get()) |
| 70 | ->ExportProtobuf(protobuf_representation); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | Plot* ProtobufPlotCollection::AppendNewPlot() { |
| 75 | Plot* plot = new ProtobufPlot(); |
| 76 | plots_.push_back(std::unique_ptr<Plot>(plot)); |
| 77 | return plot; |
| 78 | } |
| 79 | |
| 80 | } // namespace plotting |
| 81 | } // namespace webrtc |