James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame^] | 1 | // This file provides a basic demonstration of the plotting functionality. |
| 2 | // The plotDemo() function provided here is called by |
| 3 | // //frc971/analysis:plot_index.ts |
| 4 | // To view the demo plot, run |
| 5 | // bazel run -c opt //frc971/analysis:live_web_plotter_demo |
| 6 | // And then navigate to |
| 7 | // http://localhost:8080/?plot=Demo |
| 8 | // The plot=Demo isn't structly necessary, but ensures that this plot is |
| 9 | // selected by default--otherwise, you'll need to select "Demo" from the |
| 10 | // drop-down menu. |
| 11 | // |
| 12 | // This example shows how to: |
| 13 | // (a) Make use of the AosPlotter to plot a shmem message as a time-series. |
| 14 | // (b) Define your own custom plot with whatever data you want. |
| 15 | import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter'; |
| 16 | import {Plot} from 'org_frc971/aos/network/www/plotter'; |
| 17 | import * as proxy from 'org_frc971/aos/network/www/proxy'; |
| 18 | |
| 19 | import Connection = proxy.Connection; |
| 20 | |
| 21 | export function plotDemo(conn: Connection, parentDiv: Element): void { |
| 22 | const width = 900; |
| 23 | const height = 400; |
| 24 | |
| 25 | const benchmarkDiv = document.createElement('div'); |
| 26 | benchmarkDiv.style.top = height.toString(); |
| 27 | benchmarkDiv.style.left = '0'; |
| 28 | benchmarkDiv.style.position = 'absolute'; |
| 29 | parentDiv.appendChild(benchmarkDiv); |
| 30 | |
| 31 | const benchmarkPlot = new Plot(benchmarkDiv, width, height); |
| 32 | |
| 33 | const aosPlotter = new AosPlotter(conn); |
| 34 | |
| 35 | { |
| 36 | // Setup a plot that just shows the PID of each timing report message. |
| 37 | // For the basic live_web_plotter_demo, this will be a boring line showing |
| 38 | // just the PID of the proxy process. On a real system, or against a logfile, |
| 39 | // this would show the PIDs of all active processes. |
| 40 | const timingReport = |
| 41 | aosPlotter.addMessageSource('/aos', 'aos.timing.Report'); |
| 42 | const timingPlot = |
| 43 | aosPlotter.addPlot(parentDiv, [0, 0], [width, height]); |
| 44 | timingPlot.plot.getAxisLabels().setTitle('Timing Report PID'); |
| 45 | timingPlot.plot.getAxisLabels().setYLabel('PID'); |
| 46 | timingPlot.plot.getAxisLabels().setXLabel('Monotonic Send Time (sec)'); |
| 47 | const msgLine = timingPlot.addMessageLine(timingReport, ['pid']); |
| 48 | msgLine.setDrawLine(false); |
| 49 | msgLine.setPointSize(5); |
| 50 | } |
| 51 | |
| 52 | // Set up and draw the benchmarking plot. |
| 53 | benchmarkPlot.getAxisLabels().setTitle( |
| 54 | 'Benchmarking plot (1M points per line)'); |
| 55 | const line1 = benchmarkPlot.getDrawer().addLine(); |
| 56 | // For demonstration purposes, make line1 only have points and line2 only have |
| 57 | // lines. |
| 58 | line1.setDrawLine(false); |
| 59 | line1.setLabel('LINE ONE'); |
| 60 | const line2 = benchmarkPlot.getDrawer().addLine(); |
| 61 | line2.setPointSize(0); |
| 62 | line2.setLabel('LINE TWO'); |
| 63 | const NUM_POINTS = 1000000; |
| 64 | const points1 = []; |
| 65 | const points2 = []; |
| 66 | for (let ii = 0; ii < NUM_POINTS; ++ii) { |
| 67 | points1.push(ii); |
| 68 | points2.push(ii); |
| 69 | points1.push(Math.sin(ii * 10 / NUM_POINTS)); |
| 70 | points2.push(Math.cos(ii * 10 / NUM_POINTS)); |
| 71 | } |
| 72 | line1.setPoints(new Float32Array(points1)); |
| 73 | line2.setPoints(new Float32Array(points2)); |
| 74 | } |