From 297c2a225de0529963a7c1d4f1344a6fa0427927 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 7 Aug 2024 12:22:23 -0700 Subject: [PATCH 1/2] Added nth check display limit for monitor details chart --- .../Charts/MonitorDetailsAreaChart/index.jsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 985b5b846..f5671e433 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -47,7 +47,7 @@ const MonitorDetailsAreaChart = ({ checks, filter }) => { }); }; - const filterChecks = (checks, filter) => { + const filterChecks = (checks, filter, numToDisplay) => { const limits = { day: 24 * 60 * 60 * 1000, week: 24 * 60 * 60 * 1000 * 7, @@ -55,20 +55,29 @@ const MonitorDetailsAreaChart = ({ checks, filter }) => { }; const now = new Date().getTime(); - const result = []; + let result = []; for (let i = 0; i < checks.length; i++) { const checkTime = new Date(checks[i].createdAt).getTime(); if (now - checkTime < limits[filter]) { result.push(checks[i]); } } + + // If more than 50 checks, pick every nth check + if (result.length > numToDisplay) { + const n = Math.ceil(result.length / numToDisplay); + result = result.filter((_, idx) => { + return idx % n === 0; + }); + } + return result; }; let normalizedChecks = []; if (checks && checks.length > 0) { - const filteredChecks = filterChecks(checks, filter); - normalizedChecks = NormalizeData(filteredChecks, 33, 100); + const filteredChecks = filterChecks(checks, filter, 75); + normalizedChecks = NormalizeData(filteredChecks, 10, 100); } return ( From d1f0d4f2d31150c4c24f8b6a14fa22cd897c2c5d Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 7 Aug 2024 12:24:06 -0700 Subject: [PATCH 2/2] fixed comment --- Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index f5671e433..39aa8dcbf 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -63,7 +63,7 @@ const MonitorDetailsAreaChart = ({ checks, filter }) => { } } - // If more than 50 checks, pick every nth check + // If more than numToDisplay checks, pick every nth check if (result.length > numToDisplay) { const n = Math.ceil(result.length / numToDisplay); result = result.filter((_, idx) => {