From 06f4af2e791343fc636302c6e38adb450427a040 Mon Sep 17 00:00:00 2001 From: Nidboj132 Date: Tue, 5 Sep 2023 18:23:00 +0200 Subject: added graph and fixed some css Former-commit-id: b0370b8679f2a7b20c2f277c3814401fbc78d54d --- frontend/src/components/pages/summary.js | 115 +++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 5 deletions(-) (limited to 'frontend/src/components/pages/summary.js') diff --git a/frontend/src/components/pages/summary.js b/frontend/src/components/pages/summary.js index 2665d66..276389f 100644 --- a/frontend/src/components/pages/summary.js +++ b/frontend/src/components/pages/summary.js @@ -66,6 +66,7 @@ function HisClick() { const btn = document.querySelectorAll("#section3 #history span button"); btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); btn[hisState].style.backgroundColor = "#202232"; + }} const [selectedRun,setSelectedRun] = React.useState(0) @@ -84,6 +85,96 @@ function selectRun(x,y){ } } +function graph(state) { + // this is such a mess + let graph = data.summary.routes.filter(e=>e.category.id===catState) + let graph_score = [] + data.summary.routes.filter(e=>e.category.id===catState).forEach(e=>graph_score.push(e.history.score_count)) + let graph_dates = [] + data.summary.routes.filter(e=>e.category.id===catState).forEach(e=>graph_dates.push(e.history.date.split("T")[0])) + let graph_max = graph[graph.length-1].history.score_count + let graph_numbers = [] + for (let i=graph_max;i>=0;i--){ + graph_numbers[i]=i + } + + switch (state) { + case 1: //numbers + return graph_numbers + .reverse().map(e=>( + graph_score.includes(e) || e===0 ? + {e}
+ : +
+ )) + case 2: // graph + let i = 1 + let g = 0 + let h = 0 + return graph_numbers.map((e,j)=>( + + { + graph_score.map((e,i)=>( + <> + =h ? "1px dashed white" : "0" }} + > + + {g==h && graph_score.includes(graph_max-j) ? + + : ""} + + =h ? + g-1>=h ? "1px dashed #2b2e46" : "1px solid white" : "0" + : "0"}} + > + + + + =h ? + g-1>=h ? "1px dashed #2b2e46" : "1px solid white" : "0" + : "0"}} + > + + + )) + + } + + + )) + + case 3: // dates + return graph_dates + .reverse().map(e=>( + {e} + )) + default: + break; + + } + +} + const [vid,setVid] = React.useState("") React.useEffect(()=>{ if(data!==null){ @@ -140,7 +231,10 @@ return (
-
+ +
+ {data.summary.routes.filter(e=>e.category.id===catState).length===0 ?
There are no records for this map.
: + <>
Date Record @@ -163,17 +257,28 @@ return ( {r.history.runner_name} ))} -
-
+ + } +
+ +
+ {data.summary.routes.filter(e=>e.category.id===catState).length===0 ?
There are no records for this map.
: +
+
{graph(1)}
+
{graph(2)}
+
{graph(3)}
+
+ } +
-
+ + -
Difficulty -- cgit v1.2.3