diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-09-05 18:23:00 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-09-05 18:23:00 +0200 |
| commit | 06f4af2e791343fc636302c6e38adb450427a040 (patch) | |
| tree | bcc7bbcc1303a36a36986dc12431ba07ef279a3c /frontend/src/components/pages/summary.js | |
| parent | docs: update license name in disclaimer (diff) | |
| download | lphub-06f4af2e791343fc636302c6e38adb450427a040.tar.gz lphub-06f4af2e791343fc636302c6e38adb450427a040.tar.bz2 lphub-06f4af2e791343fc636302c6e38adb450427a040.zip | |
added graph and fixed some css
Former-commit-id: b0370b8679f2a7b20c2f277c3814401fbc78d54d
Diffstat (limited to 'frontend/src/components/pages/summary.js')
| -rw-r--r-- | frontend/src/components/pages/summary.js | 115 |
1 files changed, 110 insertions, 5 deletions
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() { | |||
| 66 | const btn = document.querySelectorAll("#section3 #history span button"); | 66 | const btn = document.querySelectorAll("#section3 #history span button"); |
| 67 | btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); | 67 | btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); |
| 68 | btn[hisState].style.backgroundColor = "#202232"; | 68 | btn[hisState].style.backgroundColor = "#202232"; |
| 69 | |||
| 69 | }} | 70 | }} |
| 70 | 71 | ||
| 71 | const [selectedRun,setSelectedRun] = React.useState(0) | 72 | const [selectedRun,setSelectedRun] = React.useState(0) |
| @@ -84,6 +85,96 @@ function selectRun(x,y){ | |||
| 84 | } | 85 | } |
| 85 | } | 86 | } |
| 86 | 87 | ||
| 88 | function graph(state) { | ||
| 89 | // this is such a mess | ||
| 90 | let graph = data.summary.routes.filter(e=>e.category.id===catState) | ||
| 91 | let graph_score = [] | ||
| 92 | data.summary.routes.filter(e=>e.category.id===catState).forEach(e=>graph_score.push(e.history.score_count)) | ||
| 93 | let graph_dates = [] | ||
| 94 | data.summary.routes.filter(e=>e.category.id===catState).forEach(e=>graph_dates.push(e.history.date.split("T")[0])) | ||
| 95 | let graph_max = graph[graph.length-1].history.score_count | ||
| 96 | let graph_numbers = [] | ||
| 97 | for (let i=graph_max;i>=0;i--){ | ||
| 98 | graph_numbers[i]=i | ||
| 99 | } | ||
| 100 | |||
| 101 | switch (state) { | ||
| 102 | case 1: //numbers | ||
| 103 | return graph_numbers | ||
| 104 | .reverse().map(e=>( | ||
| 105 | graph_score.includes(e) || e===0 ? | ||
| 106 | <span>{e}<br/></span> | ||
| 107 | : | ||
| 108 | <span><br/></span> | ||
| 109 | )) | ||
| 110 | case 2: // graph | ||
| 111 | let i = 1 | ||
| 112 | let g = 0 | ||
| 113 | let h = 0 | ||
| 114 | return graph_numbers.map((e,j)=>( | ||
| 115 | <tr id={'graph_row-'+(graph_max-j)} | ||
| 116 | data-graph={ graph_score.includes(graph_max-j) ? g++ : 0} | ||
| 117 | data-graph2={h=0} | ||
| 118 | |||
| 119 | > | ||
| 120 | { | ||
| 121 | graph_score.map((e,i)=>( | ||
| 122 | <> | ||
| 123 | <td className='graph_ver' | ||
| 124 | data-graph={ h++ } | ||
| 125 | style={{outline: | ||
| 126 | g==h-1 ? | ||
| 127 | "1px solid #2b2e46" : g>=h ? "1px dashed white" : "0" }} | ||
| 128 | ></td> | ||
| 129 | |||
| 130 | {g==h && graph_score.includes(graph_max-j) ? | ||
| 131 | <button className='graph-button' | ||
| 132 | onClick={()=>{ | ||
| 133 | selectRun(graph_dates.length-(i-1),catState); | ||
| 134 | }} | ||
| 135 | style={{left: `calc(100% / ${graph_dates.length} * ${h-1})`}} | ||
| 136 | ></button> | ||
| 137 | : ""} | ||
| 138 | |||
| 139 | <td className='graph_hor' id={'graph_table-'+i++} | ||
| 140 | style={{ | ||
| 141 | outline: | ||
| 142 | graph_score.includes(graph_max-j) ? | ||
| 143 | g>=h ? | ||
| 144 | g-1>=h ? "1px dashed #2b2e46" : "1px solid white" : "0" | ||
| 145 | : "0"}} | ||
| 146 | ></td> | ||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | <td className='graph_hor' id={'graph_table-'+i++} | ||
| 151 | style={{outline: | ||
| 152 | graph_score.includes(graph_max-j) ? | ||
| 153 | g>=h ? | ||
| 154 | g-1>=h ? "1px dashed #2b2e46" : "1px solid white" : "0" | ||
| 155 | : "0"}} | ||
| 156 | ></td> | ||
| 157 | |||
| 158 | </> | ||
| 159 | )) | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | </tr> | ||
| 164 | )) | ||
| 165 | |||
| 166 | case 3: // dates | ||
| 167 | return graph_dates | ||
| 168 | .reverse().map(e=>( | ||
| 169 | <span>{e}</span> | ||
| 170 | )) | ||
| 171 | default: | ||
| 172 | break; | ||
| 173 | |||
| 174 | } | ||
| 175 | |||
| 176 | } | ||
| 177 | |||
| 87 | const [vid,setVid] = React.useState("") | 178 | const [vid,setVid] = React.useState("") |
| 88 | React.useEffect(()=>{ | 179 | React.useEffect(()=>{ |
| 89 | if(data!==null){ | 180 | if(data!==null){ |
| @@ -140,7 +231,10 @@ return ( | |||
| 140 | </div> | 231 | </div> |
| 141 | 232 | ||
| 142 | <div id='history'> | 233 | <div id='history'> |
| 143 | <div> | 234 | |
| 235 | <div style={{display: hisState ? "none" : "block"}}> | ||
| 236 | {data.summary.routes.filter(e=>e.category.id===catState).length===0 ? <h5>There are no records for this map.</h5> : | ||
| 237 | <> | ||
| 144 | <div className='record-top'> | 238 | <div className='record-top'> |
| 145 | <span>Date</span> | 239 | <span>Date</span> |
| 146 | <span>Record</span> | 240 | <span>Record</span> |
| @@ -163,17 +257,28 @@ return ( | |||
| 163 | <span>{r.history.runner_name}</span> | 257 | <span>{r.history.runner_name}</span> |
| 164 | </button> | 258 | </button> |
| 165 | ))} | 259 | ))} |
| 166 | |||
| 167 | </div> | 260 | </div> |
| 168 | </div> | 261 | </> |
| 262 | } | ||
| 263 | </div> | ||
| 264 | |||
| 265 | <div style={{display: hisState ? "block" : "none"}}> | ||
| 266 | {data.summary.routes.filter(e=>e.category.id===catState).length===0 ? <h5>There are no records for this map.</h5> : | ||
| 267 | <div id='graph'> | ||
| 268 | <div>{graph(1)}</div> | ||
| 269 | <div>{graph(2)}</div> | ||
| 270 | <div>{graph(3)}</div> | ||
| 271 | </div> | ||
| 272 | } | ||
| 273 | </div> | ||
| 169 | <span> | 274 | <span> |
| 170 | <button onClick={()=>setHisState(0)}>List</button> | 275 | <button onClick={()=>setHisState(0)}>List</button> |
| 171 | <button onClick={()=>setHisState(1)}>Graph</button> | 276 | <button onClick={()=>setHisState(1)}>Graph</button> |
| 172 | </span> | 277 | </span> |
| 173 | </div> | 278 | </div> |
| 279 | |||
| 174 | 280 | ||
| 175 | </section> | 281 | </section> |
| 176 | |||
| 177 | <section id='section4'> | 282 | <section id='section4'> |
| 178 | <div id='difficulty'> | 283 | <div id='difficulty'> |
| 179 | <span>Difficulty</span> | 284 | <span>Difficulty</span> |