| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/tools/event_log_visualizer/plot_python.h" | 11 #include "webrtc/tools/event_log_visualizer/plot_python.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 | 14 |
| 15 #include <memory> |
| 16 |
| 15 namespace webrtc { | 17 namespace webrtc { |
| 16 namespace plotting { | 18 namespace plotting { |
| 17 | 19 |
| 18 PythonPlot::PythonPlot() {} | 20 PythonPlot::PythonPlot() {} |
| 19 | 21 |
| 20 PythonPlot::~PythonPlot() {} | 22 PythonPlot::~PythonPlot() {} |
| 21 | 23 |
| 22 void PythonPlot::draw() { | 24 void PythonPlot::Draw() { |
| 23 // Write python commands to stdout. Intended program usage is | 25 // Write python commands to stdout. Intended program usage is |
| 24 // ./event_log_visualizer event_log160330.dump | python | 26 // ./event_log_visualizer event_log160330.dump | python |
| 25 | 27 |
| 26 if (!series.empty()) { | 28 if (!series_list_.empty()) { |
| 27 printf("color_count = %zu\n", series.size()); | 29 printf("color_count = %zu\n", series_list_.size()); |
| 28 printf( | 30 printf( |
| 29 "hls_colors = [(i*1.0/color_count, 0.25+i*0.5/color_count, 0.8) for i " | 31 "hls_colors = [(i*1.0/color_count, 0.25+i*0.5/color_count, 0.8) for i " |
| 30 "in range(color_count)]\n"); | 32 "in range(color_count)]\n"); |
| 31 printf("rgb_colors = [colorsys.hls_to_rgb(*hls) for hls in hls_colors]\n"); | 33 printf("rgb_colors = [colorsys.hls_to_rgb(*hls) for hls in hls_colors]\n"); |
| 32 | 34 |
| 33 for (size_t i = 0; i < series.size(); i++) { | 35 for (size_t i = 0; i < series_list_.size(); i++) { |
| 34 // List x coordinates | 36 // List x coordinates |
| 35 printf("x%zu = [", i); | 37 printf("x%zu = [", i); |
| 36 if (series[i].points.size() > 0) | 38 if (series_list_[i].points.size() > 0) |
| 37 printf("%G", series[i].points[0].x); | 39 printf("%G", series_list_[i].points[0].x); |
| 38 for (size_t j = 1; j < series[i].points.size(); j++) | 40 for (size_t j = 1; j < series_list_[i].points.size(); j++) |
| 39 printf(", %G", series[i].points[j].x); | 41 printf(", %G", series_list_[i].points[j].x); |
| 40 printf("]\n"); | 42 printf("]\n"); |
| 41 | 43 |
| 42 // List y coordinates | 44 // List y coordinates |
| 43 printf("y%zu = [", i); | 45 printf("y%zu = [", i); |
| 44 if (series[i].points.size() > 0) | 46 if (series_list_[i].points.size() > 0) |
| 45 printf("%G", series[i].points[0].y); | 47 printf("%G", series_list_[i].points[0].y); |
| 46 for (size_t j = 1; j < series[i].points.size(); j++) | 48 for (size_t j = 1; j < series_list_[i].points.size(); j++) |
| 47 printf(", %G", series[i].points[j].y); | 49 printf(", %G", series_list_[i].points[j].y); |
| 48 printf("]\n"); | 50 printf("]\n"); |
| 49 | 51 |
| 50 if (series[i].style == BAR_GRAPH) { | 52 if (series_list_[i].style == BAR_GRAPH) { |
| 51 // There is a plt.bar function that draws bar plots, | 53 // There is a plt.bar function that draws bar plots, |
| 52 // but it is *way* too slow to be useful. | 54 // but it is *way* too slow to be useful. |
| 53 printf( | 55 printf( |
| 54 "plt.vlines(x%zu, map(lambda t: min(t,0), y%zu), map(lambda t: " | 56 "plt.vlines(x%zu, map(lambda t: min(t,0), y%zu), map(lambda t: " |
| 55 "max(t,0), y%zu), color=rgb_colors[%zu], " | 57 "max(t,0), y%zu), color=rgb_colors[%zu], " |
| 56 "label=\'%s\')\n", | 58 "label=\'%s\')\n", |
| 57 i, i, i, i, series[i].label.c_str()); | 59 i, i, i, i, series_list_[i].label.c_str()); |
| 58 } else if (series[i].style == LINE_GRAPH) { | 60 } else if (series_list_[i].style == LINE_GRAPH) { |
| 59 printf("plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\')\n", i, | 61 printf("plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\')\n", i, |
| 60 i, i, series[i].label.c_str()); | 62 i, i, series_list_[i].label.c_str()); |
| 61 } else { | 63 } else { |
| 62 printf("raise Exception(\"Unknown graph type\")\n"); | 64 printf("raise Exception(\"Unknown graph type\")\n"); |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 printf("plt.xlim(%f, %f)\n", xaxis_min, xaxis_max); | 69 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_); |
| 68 printf("plt.ylim(%f, %f)\n", yaxis_min, yaxis_max); | 70 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_); |
| 69 printf("plt.xlabel(\'%s\')\n", xaxis_label.c_str()); | 71 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); |
| 70 printf("plt.ylabel(\'%s\')\n", yaxis_label.c_str()); | 72 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); |
| 71 printf("plt.title(\'%s\')\n", title.c_str()); | 73 printf("plt.title(\'%s\')\n", title_.c_str()); |
| 72 if (!series.empty()) { | 74 if (!series_list_.empty()) { |
| 73 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); | 75 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 | 78 |
| 77 PythonPlotCollection::PythonPlotCollection() {} | 79 PythonPlotCollection::PythonPlotCollection() {} |
| 78 | 80 |
| 79 PythonPlotCollection::~PythonPlotCollection() {} | 81 PythonPlotCollection::~PythonPlotCollection() {} |
| 80 | 82 |
| 81 void PythonPlotCollection::draw() { | 83 void PythonPlotCollection::Draw() { |
| 82 printf("import matplotlib.pyplot as plt\n"); | 84 printf("import matplotlib.pyplot as plt\n"); |
| 83 printf("import colorsys\n"); | 85 printf("import colorsys\n"); |
| 84 for (size_t i = 0; i < plots.size(); i++) { | 86 for (size_t i = 0; i < plots_.size(); i++) { |
| 85 printf("plt.figure(%zu)\n", i); | 87 printf("plt.figure(%zu)\n", i); |
| 86 plots[i]->draw(); | 88 plots_[i]->Draw(); |
| 87 } | 89 } |
| 88 printf("plt.show()\n"); | 90 printf("plt.show()\n"); |
| 89 } | 91 } |
| 90 | 92 |
| 91 Plot* PythonPlotCollection::append_new_plot() { | 93 Plot* PythonPlotCollection::AppendNewPlot() { |
| 92 Plot* plot = new PythonPlot(); | 94 Plot* plot = new PythonPlot(); |
| 93 plots.push_back(std::unique_ptr<Plot>(plot)); | 95 plots_.push_back(std::unique_ptr<Plot>(plot)); |
| 94 return plot; | 96 return plot; |
| 95 } | 97 } |
| 96 | 98 |
| 97 } // namespace plotting | 99 } // namespace plotting |
| 98 } // namespace webrtc | 100 } // namespace webrtc |
| OLD | NEW |