Skip to content

Commit c956931

Browse files
committed
Rendered avg-time data in 3 categories (avgTime, totalTime, #of trips) inside a scroll-box. Tweaked some styling.
1 parent 9c9eca6 commit c956931

2 files changed

Lines changed: 94 additions & 11 deletions

File tree

app/charts/route-trace.jsx

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/jsx-one-expression-per-line */
22
import React, { useContext } from 'react';
3-
import { Bar } from 'react-chartjs-2';
3+
// import { Bar } from 'react-chartjs-2';
44
import CommunicationsContext from '../context/OverviewContext';
55

66
const RouteLocations = (props) => {
@@ -20,7 +20,7 @@ const RouteLocations = (props) => {
2020
if (new Date(a.timeSent) < new Date(b.timeSent)) return -1;
2121
return 0;
2222
});
23-
console.log('commData (AFTER sorting):', communicationsData);
23+
// console.log('commData (AFTER sorting):', communicationsData);
2424

2525
// Iterate over sorted array to build up resObj.
2626
for (let i = 0; i < communicationsData.length; i += 1) {
@@ -67,9 +67,8 @@ const RouteLocations = (props) => {
6767
// Filter the array so that only subarrays w/ len > 1 are kept.
6868
// (len == 1 means there's only one point in the route. There's no meaningful data to be gained from those.)
6969
const tracePoints = Object.values(resObj).filter(subArray => subArray.length > 1);
70-
const position = communicationsData[0].correlatingid ? 0 : tracePoints.length - 1;
71-
console.log('tracePoints arr:', tracePoints);
72-
console.log('position for tracePoints:', position);
70+
// console.log('tracePoints arr:', tracePoints);
71+
7372

7473
// Construct an obj that stores data necessary for calculating avg speed of requests btw 2 pts.
7574
const avgDataObj = {};
@@ -100,14 +99,16 @@ const RouteLocations = (props) => {
10099
}
101100
}
102101
/** End of nested loops */
103-
104102
console.log('avgDataObj:', avgDataObj);
105-
106103
/****************************************/
104+
107105
// Array of <divs> to be rendered. Each <div> contains route name and time difference.
108106
const resArray = [];
109107

110-
// iterate over Trace Points, creating a <div> for every data obj.
108+
const position = communicationsData[0].correlatingid ? 0 : tracePoints.length - 1;
109+
console.log('position for tracePoints:', position);
110+
111+
// iterate over ONE elem in tracePoints, creating a <div> for every data obj.
111112
for (let i = 0; i < tracePoints[position].length; i += 1) {
112113
if (i !== tracePoints[position].length - 1) {
113114
// Calc time difference (when not at the end of array):
@@ -137,14 +138,68 @@ const RouteLocations = (props) => {
137138
);
138139
}
139140
}
141+
// console.log('resArray: ', resArray);
142+
143+
/**** Making a list of avg speed-related data. ********/
144+
// const avgData = [];
145+
// Object.entries(avgDataObj).forEach((el, i) => {
146+
// avgData.push(
147+
// <span className="avgDataDetails" key={`${i}+${el[0]}`}>
148+
// {el[0]}: {el[1]}
149+
// </span>
150+
// )
151+
// })
152+
// console.log('avgData (array):', avgData);
140153

141-
console.log('resArray: ', resArray);
154+
/**** Making CATEGORIZED lists of avg speed-related data. ********/
155+
const avgTime = [], totalTime = [], count = [];
156+
let i = 0; // For unique keys for each <span> //
142157

158+
for (const key in avgDataObj) {
159+
i += 1;
160+
161+
if (key.endsWith('AvgTime')) {
162+
avgTime.push(
163+
<span className="avgDataDetails" key={i}>
164+
{key.slice(0, -7)}: {avgDataObj[key]} ms
165+
</span>
166+
)
167+
}
168+
if (key.endsWith('TotalTime')) {
169+
totalTime.push(
170+
<span className="avgDataDetails" key={i}>
171+
{key.slice(0, -9)}: {avgDataObj[key]} ms
172+
</span>
173+
)
174+
}
175+
if (key.endsWith('Count')) {
176+
count.push(
177+
<span className="avgDataDetails" key={i}>
178+
{key.slice(0, -5)}: {avgDataObj[key]}
179+
</span>
180+
)
181+
}
182+
}
183+
// console.log('avgTime:', avgTime);
184+
// console.log('totalTime:', totalTime);
185+
// console.log('count:', count);
186+
/****************/
143187

144-
// return div with Trace Points data
145188
return (
146-
<div>
189+
<div id="routeDataArea">
190+
{/* Data on the lastest route */}
147191
{resArray}
192+
193+
{/* Rendering avg-speed related data */}
194+
<div id="avgData">
195+
{/* {avgData} */}
196+
<span className="avgData-titles">Average time between points:</span>
197+
{avgTime}
198+
<span className="avgData-titles">Total time between points:</span>
199+
{totalTime}
200+
<span className="avgData-titles">Number of trips between points:</span>
201+
{count}
202+
</div>
148203
</div>
149204
);
150205
};

app/index.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,32 @@ select {
423423
margin-right: 10px;
424424
}
425425

426+
/*** 3.0 changes ****/
427+
#routeDataArea {
428+
display: flex;
429+
flex-direction: column;
430+
align-items: center;
431+
}
432+
#avgData {
433+
display: flex;
434+
flex-direction: column;
435+
height: 25em;
436+
width: 30em;
437+
overflow: scroll;
438+
overflow-x: hidden;
439+
}
440+
.avgData-titles {
441+
font-size: 1.5em;
442+
}
443+
.avgDataDetails {
444+
color: rgb(97, 97, 97);
445+
width: 29em;
446+
}
447+
.avgDataDetails:hover {
448+
color: white;
449+
text-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
450+
}
451+
/*********************/
426452

427453
.RouteCircle {
428454
font-family: Arial, Helvetica, sans-serif;
@@ -443,6 +469,7 @@ select {
443469
background: linear-gradient(315deg, rgb(237, 225, 62) 57%, rgb(253, 229, 45) 100%);
444470
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
445471
}
472+
446473
/*** 3.0 changes: applying same styles to time diff text ****/
447474
#routeText, #routeTimeDiff {
448475
color: rgb(97, 97, 97);
@@ -455,6 +482,7 @@ select {
455482
text-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
456483
}
457484
/**********************************/
485+
458486
form {
459487
width: 100%;
460488
font-size: 2vh;

0 commit comments

Comments
 (0)