blob: a02451a7c4800defe09ef8001db1ef5b16002e48 [file] [log] [blame]
Stephan Pleines85b295c2024-02-04 17:50:26 -08001#include "aos/analysis/in_process_plotter.h"
James Kuszmaul48671362020-12-24 13:54:16 -08002#include "aos/init.h"
James Kuszmaul48671362020-12-24 13:54:16 -08003
4// To run this example, do:
5// bazel run -c opt //frc971/analysis:in_process_plotter_demo
6// And then open localhost:8080, select "C++ Plotter" from the drop-down, and
7// then select "TITLE!" or "Trig Functions" from the second drop-down to see
8// each plot.
9int main(int argc, char *argv[]) {
10 aos::InitGoogle(&argc, &argv);
11 frc971::analysis::Plotter plotter;
12 plotter.Title("TITLE!");
13 plotter.AddFigure("Fig Foo");
14 plotter.ShareXAxis(true);
15 plotter.AddLine({1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, "y = x");
16 plotter.AddLine({5, 4, 3, 2, 1}, {1, 2, 3, 4, 5}, "y = -x");
17 plotter.YLabel("Y Axis");
18 plotter.AddFigure("Fig Bar");
19 plotter.ShareXAxis(true);
20 plotter.AddLine({1, 2, 3}, {3, 4, 5}, "y = x + 2");
21 plotter.XLabel("X Axis (Linked to both above plots)");
22 plotter.Publish();
23
24 plotter.Title("Trig Functions");
25
26 plotter.AddFigure("Sin & Cos");
27 std::vector<double> x;
28 std::vector<double> sinx;
29 std::vector<double> cosx;
30 constexpr int kNumPoints = 100000;
31 for (int ii = 0; ii < kNumPoints; ++ii) {
32 x.push_back(ii * 2 * M_PI / kNumPoints);
33 sinx.push_back(std::sin(x.back()));
34 cosx.push_back(std::cos(x.back()));
35 }
36 plotter.AddLine(x, sinx, "sin(x)");
37 plotter.AddLine(x, cosx, "cos(x)");
38 plotter.Publish();
39
40 plotter.Spin();
41}