@@ -84,9 +84,29 @@ class="rounded-full px-3 py-2 text-white focus:outline-none"
84
84
v-if =" connected && app.statisticsEnabled"
85
85
class =" w-full my-6 px-6"
86
86
>
87
- <div class =" font-semibold uppercase text-gray-700" >
88
- Live statistics
89
- </div >
87
+ <div class =" flex justify-between items-center" >
88
+ <span class =" font-semibold uppercase text-gray-700" >
89
+ Live statistics
90
+ </span >
91
+
92
+ <div class =" space-x-3 flex items-center" >
93
+ <div >
94
+ <input
95
+ type =" checkbox"
96
+ v-model =" autoRefresh"
97
+ class =" mr-2"
98
+ />
99
+ Refresh automatically
100
+ </div >
101
+
102
+ <button
103
+ @click =" loadChart"
104
+ class =" rounded-full bg-blue-500 hover:bg-blue-600 focus:outline-none text-white px-3 py-1"
105
+ >
106
+ Refresh
107
+ </button >
108
+ </div >
109
+ </div >
90
110
91
111
<div
92
112
id =" statisticsChart"
@@ -222,6 +242,9 @@ class="rounded-full px-3 py-1 inline-block text-sm"
222
242
connected: false ,
223
243
connecting: false ,
224
244
sendingEvent: false ,
245
+ autoRefresh: true ,
246
+ refreshInterval: {{ $refreshInterval } } ,
247
+ refreshTicker: null ,
225
248
chart: null ,
226
249
pusher: null ,
227
250
app: null ,
@@ -236,6 +259,19 @@ class="rounded-full px-3 py-1 inline-block text-sm"
236
259
mounted () {
237
260
this .app = this .apps [0 ] || null ;
238
261
},
262
+ destroyed () {
263
+ if (this .refreshTicker ) {
264
+ this .clearRefreshInterval ();
265
+ }
266
+ },
267
+ watch: {
268
+ connected (newVal ) {
269
+ newVal ? this .startRefreshInterval () : this .clearRefreshInterval ();
270
+ },
271
+ autoRefresh (newVal ) {
272
+ newVal ? this .startRefreshInterval () : this .clearRefreshInterval ();
273
+ },
274
+ },
239
275
methods: {
240
276
connect () {
241
277
this .connecting = true ;
@@ -274,12 +310,14 @@ class="rounded-full px-3 py-1 inline-block text-sm"
274
310
this .connected = false ;
275
311
this .connecting = false ;
276
312
this .logs = [];
313
+ this .chart = null ;
277
314
});
278
315
279
316
this .pusher .connection .bind (' error' , event => {
280
317
if (event .error .data .code === 4100 ) {
281
318
this .connected = false ;
282
319
this .logs = [];
320
+ this .chart = null ;
283
321
284
322
throw new Error (" Over capacity" );
285
323
}
@@ -288,12 +326,12 @@ class="rounded-full px-3 py-1 inline-block text-sm"
288
326
});
289
327
290
328
this .subscribeToAllChannels ();
291
- this .subscribeToStatistics ();
292
329
},
293
330
294
331
disconnect () {
295
332
this .pusher .disconnect ();
296
333
this .connecting = false ;
334
+ this .chart = null ;
297
335
},
298
336
299
337
loadChart () {
@@ -333,7 +371,10 @@ class="rounded-full px-3 py-1 inline-block text-sm"
333
371
autosize: true ,
334
372
};
335
373
336
- this .chart = Plotly .newPlot (' statisticsChart' , chartData, layout);
374
+ this .chart = this .chart
375
+ ? Plotly .react (' statisticsChart' , chartData, layout)
376
+ : Plotly .newPlot (' statisticsChart' , chartData, layout);
377
+
337
378
});
338
379
},
339
380
@@ -348,18 +389,6 @@ class="rounded-full px-3 py-1 inline-block text-sm"
348
389
});
349
390
},
350
391
351
- subscribeToStatistics () {
352
- this .pusher .subscribe (' {{ $logPrefix } } statistics' )
353
- .bind (' statistics-updated' , (data ) => {
354
- var update = {
355
- x: [[data .time ], [data .time ], [data .time ]],
356
- y: [[data .peak_connection_count ], [data .websocket_message_count ], [data .api_message_count ]],
357
- };
358
-
359
- Plotly .extendTraces (' statisticsChart' , update, [0 , 1 , 2 ]);
360
- });
361
- },
362
-
363
392
sendEvent () {
364
393
if (! this .sendingEvent ) {
365
394
this .sendingEvent = true ;
@@ -415,6 +444,17 @@ class="rounded-full px-3 py-1 inline-block text-sm"
415
444
416
445
return ' bg-gray-700 text-white' ;
417
446
},
447
+
448
+ startRefreshInterval () {
449
+ this .refreshTicker = setInterval (function () {
450
+ this .loadChart ();
451
+ }.bind (this ), this .refreshInterval * 1000 );
452
+ },
453
+
454
+ stopRefreshInterval () {
455
+ clearInterval (this .refreshTicker );
456
+ this .refreshTicker = null ;
457
+ },
418
458
},
419
459
});
420
460
</script >
0 commit comments