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