|
1 | 1 | import StatsManager from "./StatsManager.js"; |
2 | | -import * as plot from "./plot.js"; |
3 | | -import { initNav, paused, show_gc, timerange } from "./nav.js"; |
| 2 | +import PlotManager from "./PlotManager.js"; |
| 3 | +import { initNav, paused, gcEnabled, timerange } from "./nav.js"; |
4 | 4 | import { buildWebsocketURI } from "./utils.js"; |
5 | 5 | import WebSocketClient from "./socket.js"; |
6 | 6 | import "bootstrap/dist/js/bootstrap.min.js"; |
7 | 7 |
|
8 | | -const dataRetentionSeconds = 600; |
9 | | -export var allPlots; |
| 8 | +export let statsMgr; |
| 9 | +export let plotMgr; |
| 10 | + |
| 11 | +export const drawPlots = (force) => { |
| 12 | + if (paused) return; |
| 13 | + const data = statsMgr.slice(timerange); |
| 14 | + plotMgr.update(data, gcEnabled, timerange, force); |
| 15 | +}; |
10 | 16 |
|
11 | | -let statsMgr; |
12 | 17 | export const connect = () => { |
13 | 18 | const uri = buildWebsocketURI(); |
| 19 | + |
14 | 20 | new WebSocketClient( |
15 | 21 | uri, |
16 | 22 | // onConfig |
17 | 23 | (cfg) => { |
18 | | - allPlots = configurePlots(cfg); |
19 | | - statsMgr = new StatsManager(dataRetentionSeconds, cfg); |
20 | | - attachPlots(allPlots); |
21 | | - initNav(allPlots); |
| 24 | + plotMgr = new PlotManager(cfg); |
| 25 | + statsMgr = new StatsManager(600, cfg); |
| 26 | + |
| 27 | + initNav(() => { |
| 28 | + drawPlots(false); |
| 29 | + }); |
22 | 30 | }, |
23 | 31 | // onData |
24 | 32 | (msg) => { |
25 | 33 | statsMgr.pushData(msg); |
26 | | - if (!paused) updatePlots(allPlots, false); |
| 34 | + drawPlots(true); |
27 | 35 | } |
28 | 36 | ); |
29 | 37 | }; |
30 | | - |
31 | | -const configurePlots = (config) => { |
32 | | - const plots = config.series.map((pd) => new plot.Plot(pd)); |
33 | | - return plots; |
34 | | -}; |
35 | | - |
36 | | -const attachPlots = (plots) => { |
37 | | - const plotsDiv = document.getElementById("plots"); |
38 | | - plotsDiv.replaceChildren( |
39 | | - ...plots.map((plot) => { |
40 | | - const div = document.createElement("div"); |
41 | | - div.id = plot.name(); |
42 | | - plot.createElement(div); |
43 | | - return div; |
44 | | - }) |
45 | | - ); |
46 | | -}; |
47 | | - |
48 | | -export const updatePlots = (plots, force = false) => { |
49 | | - const data = statsMgr.slice(timerange); |
50 | | - const shapes = new Map(); |
51 | | - |
52 | | - if (show_gc) { |
53 | | - for (const [name, serie] of data.events) { |
54 | | - shapes.set(name, plot.createVerticalLines(serie)); |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - // Always show the full range on x axis. |
59 | | - const now = data.times[data.times.length - 1]; |
60 | | - let xrange = [now - timerange * 1000, now]; |
61 | | - |
62 | | - plots.forEach((plot) => { |
63 | | - if (!plot.hidden) { |
64 | | - plot.update(xrange, data, shapes, force); |
65 | | - } |
66 | | - }); |
67 | | -}; |
0 commit comments