Don't look so shocked. Software is not dead. It evolves. Especially useful software.
Some problems I fixed...
- added visuals for bus types and capacity
- simplified data flow
- color scheme
Let's get to work! We will first streamline the data flow.
The first thing we'll want to do is remove the JavaScript. This upgrade removes all JavaScript in lieu of UI simplicity. To that end, this entire section needs to go.<script>
function showArrivalFor($bus)
{
var hide = document.getElementsByClassName("arrival");
for (var i = 0; i < hide.length; i++)
{
hide[i].style.display = "none";
}
var show = document.getElementById("arrival_" + $bus);
show.style.display = "block";
}
</script>
function showArrivalFor($bus)
{
var hide = document.getElementsByClassName("arrival");
for (var i = 0; i < hide.length; i++)
{
hide[i].style.display = "none";
}
var show = document.getElementById("arrival_" + $bus);
show.style.display = "block";
}
</script>
Remove this entire div. We want everything to be visible when the data is fetched. No more strategically hiding some of it. This means there are less steps for the user to go through, reducing interface friction.
<div id="bus" style="display:<?php echo (count($buses) == 0 ? "none" : "block");?>">
<h1>🚏 BUS SERVICES</h1>
<?php
foreach($buses as $bus)
{
?>
<button onclick="showArrivalFor('<?php echo $bus->ServiceNo; ?>');">
<?php
echo $bus->ServiceNo;
?>
</button>
<?php
}
?>
</div>
<br />
<h1>🚏 BUS SERVICES</h1>
<?php
foreach($buses as $bus)
{
?>
<button onclick="showArrivalFor('<?php echo $bus->ServiceNo; ?>');">
<?php
echo $bus->ServiceNo;
?>
</button>
<?php
}
?>
</div>
<br />
Remove this too. We won't need it any more.
#bus button
{
background-color: rgb(50, 0, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 3px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 5em;
font-size: 20px;
font-weight: bold;
}
{
background-color: rgb(50, 0, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 3px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 5em;
font-size: 20px;
font-weight: bold;
}
In this section, the div should still be styled using the arrival CSS class, but the style that hides it, should be removed, as well as the id attribute.
<?php
foreach($buses as $bus)
{
?>
<div class="arrival">
<h1> BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>
<?php
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
?>
</div>
<?php
}
?>
foreach($buses as $bus)
{
?>
<div class="arrival">
<h1> BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>
<?php
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
?>
</div>
<?php
}
?>
So far so good....
Next, the Color Scheme
Now here's a bit of styling. I enlarged the front to almost double what it was previously, changed the background color to orange, and gave container a white translucent border.body
{
background-color: rgb(200, 150, 0);
font-family: sans-serif;
font-size: 25px;
}
#container
{
border-radius: 20px;
border: 3px solid rgba(255, 255, 255, 0.5);
padding: 2em;
}
{
background-color: rgb(200, 150, 0);
font-family: sans-serif;
font-size: 25px;
}
#container
{
border-radius: 20px;
border: 3px solid rgba(255, 255, 255, 0.5);
padding: 2em;
}
I also removed some of these properties. They're no longer necessary.
#container div
{
/* border-radius: 20px; */
/* border: 3px solid rgba(100, 0, 0, 0.2); */
padding: 0.5em;
color: rgb(0, 0, 0);
}
{
/* border-radius: 20px; */
/* border: 3px solid rgba(100, 0, 0, 0.2); */
padding: 0.5em;
color: rgb(0, 0, 0);
}
That wasn't too hard!
More changes. A couple things are happening here. I remove borders from the rendering of the textbox and button for a clean flat look. I also change the button and hover color.
#stop input
{
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0);
padding: 5px;
width: 10em;
height: 1em;
}
#stop button
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0);
padding: 5px;
width: 10em;
}
#stop button:hover
{
background-color: rgb(150, 50, 0);
}
{
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0);
padding: 5px;
width: 10em;
height: 1em;
}
#stop button
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0);
padding: 5px;
width: 10em;
}
#stop button:hover
{
background-color: rgb(150, 50, 0);
}
While we're at it, let's declutter by removing these icons.
<!--<h1>🚏 BUS STOP <?php echo $busStop;?></h1>-->
<h1>BUS STOP <?php echo $busStop;?></h1>
<h1>BUS STOP <?php echo $busStop;?></h1>
<!--<h1>🚌 BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>-->
<h1>BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>
<h1>BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>
Looks cleaner now, doesn't it?
In fact, let's clean this up even more.
<!--<h1>BUS <?php echo $bus->ServiceNo; ?> ARRIVAL TIMINGS</h1>-->
<h1><?php echo $bus->ServiceNo; ?></h1>
<h1><?php echo $bus->ServiceNo; ?></h1>
In the CSS, we provision styling for all h1 tags in arrival. The important thing is that it's floated left. The rest is just aesthetics. I'm going for white text on a yellow background, with rounded corners.
#stop button:hover
{
background-color: rgb(150, 50, 0);
}
.arrival h1
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 4em;
height: 40px;
font-size: 30px;
font-weight: bold;
float: left;
text-align: center;
}
</style>
{
background-color: rgb(150, 50, 0);
}
.arrival h1
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 4em;
height: 40px;
font-size: 30px;
font-weight: bold;
float: left;
text-align: center;
}
</style>
So now that long-ass title has been reduced to a number.
Now provision some styling for h2 tags. We want them to be a more rounded white block, and appear to the right of the bus number. Thus, floating left is a must.
.arrival h1
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 4em;
height: 40px;
font-size: 30px;
font-weight: bold;
float: left;
text-align: center;
}
.arrival h2
{
background-color: rgb(255, 255, 255);
border-radius: 15px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 7em;
height: 40px;
font-size: 25px;
font-weight: bold;
float: left;
text-align: center;
margin-left: 0.5em;
}
</style>
{
background-color: rgb(255, 200, 0);
color: rgb(255, 255, 255);
border-radius: 5px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 4em;
height: 40px;
font-size: 30px;
font-weight: bold;
float: left;
text-align: center;
}
.arrival h2
{
background-color: rgb(255, 255, 255);
border-radius: 15px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 7em;
height: 40px;
font-size: 25px;
font-weight: bold;
float: left;
text-align: center;
margin-left: 0.5em;
}
</style>
But oops, this is a mess.
Add this line here to make sure floats are cleared.
<?php
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
?>
</div>
<br style="clear: both" />
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
?>
</div>
<br style="clear: both" />
All better now.
Presenting additional data
The final part is here. I want to show bus type and capacity, which is data already present in the API response. I simply did not make use of it the last time. Time to address that oversight!First, let's relocate the logic to a function, so that the heavy lifting gets concentrated in one place. We'll create busArrivalDisplay() shortly, and retain formatArrivalTime().
<?php
/*
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
*/
if ($bus->NextBus)
{
echo busArrivalDisplay($bus->NextBus);
}
if ($bus->NextBus2)
{
echo busArrivalDisplay($bus->NextBus2);
}
if ($bus->NextBus3)
{
echo busArrivalDisplay($bus->NextBus);
}
?>
/*
if ($bus->NextBus)
{
echo "<h2>" . formatArrivalTime($bus->NextBus->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus2)
{
echo "<h2>" . formatArrivalTime($bus->NextBus2->EstimatedArrival) . "</h2>";
}
if ($bus->NextBus3)
{
echo "<h2>" . formatArrivalTime($bus->NextBus3->EstimatedArrival) . "</h2>";
}
*/
if ($bus->NextBus)
{
echo busArrivalDisplay($bus->NextBus);
}
if ($bus->NextBus2)
{
echo busArrivalDisplay($bus->NextBus2);
}
if ($bus->NextBus3)
{
echo busArrivalDisplay($bus->NextBus);
}
?>
In here, we modify formatArrivalTime() slightly to replace "T". It may or may not come up, but why take the chance, eh? Then create busArrivalDisplay(), with obj as a parameter. obj will contain all the information you need. The classes here are based on the Load property in the returned response.
function formatArrivalTime($strTime)
{
$newStr = str_replace("+08:00", "", $strTime);
$newStr = str_replace("T", " ", $newStr);
return date("h:i A", strtotime($newStr));
}
function busArrivalDisplay($obj)
{
$html = "<h2 class='capacity_" . $obj->Load . "'>";
$html .= formatArrivalTime($obj->EstimatedArrival);
$html .= "</h2>";
return $html;
}
{
$newStr = str_replace("+08:00", "", $strTime);
$newStr = str_replace("T", " ", $newStr);
return date("h:i A", strtotime($newStr));
}
function busArrivalDisplay($obj)
{
$html = "<h2 class='capacity_" . $obj->Load . "'>";
$html .= formatArrivalTime($obj->EstimatedArrival);
$html .= "</h2>";
return $html;
}
We will make use of the various possible values of capacity. In the CSS, we define different colors for capacity. "SEA" means that there are seats, so the color is green. "SDA" means that there's standing space, so we use yellow. "LSD" means that there's limited standing space. The bus is almost full. So use deep red for this.
.arrival h2
{
background-color: rgb(255, 255, 255);
border-radius: 15px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 7em;
height: 40px;
font-size: 25px;
font-weight: bold;
float: left;
text-align: center;
margin-left: 0.5em;
}
.capacity_SEA
{
color: rgb(0, 200, 0);
}
.capacity_SDA
{
color: rgb(200, 200, 0);
}
.capacity_LSD
{
color: rgb(200, 0, 0);
}
</style>
{
background-color: rgb(255, 255, 255);
border-radius: 15px;
border: 0px solid rgba(0, 0, 0, 0.5);
padding: 5px;
width: 7em;
height: 40px;
font-size: 25px;
font-weight: bold;
float: left;
text-align: center;
margin-left: 0.5em;
}
.capacity_SEA
{
color: rgb(0, 200, 0);
}
.capacity_SDA
{
color: rgb(200, 200, 0);
}
.capacity_LSD
{
color: rgb(200, 0, 0);
}
</style>
So now we have differently-colored times.
Now for bus types. Basically, I only care about the difference between single and double decker buses. Therefore, all other bus types will just use the same image as the single decker bus.
I used some stock images for this. I actually have only two images. The others are all duplicates with different names.
(img)
| icon_.png icon_BD.png icon SD.png |
| icon_DD.png |
Then we add this line. This adds a transparent PNG, according to the bus type, to the information.
function busArrivalDisplay($obj)
{
$html = "<h2 class='capacity_" . $obj->Load . "'>";
$html .= "<img height='30' src='icon_" . $obj->Type . ".png' /> ";
$html .= formatArrivalTime($obj->EstimatedArrival);
$html .= "</h2>";
return $html;
}
{
$html = "<h2 class='capacity_" . $obj->Load . "'>";
$html .= "<img height='30' src='icon_" . $obj->Type . ".png' /> ";
$html .= formatArrivalTime($obj->EstimatedArrival);
$html .= "</h2>";
return $html;
}
Beautiful!
Enjoy this version!
I really think it's more user-friendly, especially on mobile. Before this, I tested it on desktop, but it doesn't really make sense to do that because, well, if you're trying to look up bus arrival data outdoors, why would you be using a laptop? Yeah I know, I dropped the ball. It's on me. Hopefully this makes up for it!Stay bus-y,
T___T
T___T








No comments:
Post a Comment