Skip to content

Commit

Permalink
"Maps Played" Image Bug Fixes
Browse files Browse the repository at this point in the history
Fixes a couple of bugs with the "maps played" image, and adds the "other" legend item if the total displayed is less than 100%.
  • Loading branch information
tyger07 committed Apr 11, 2021
1 parent 57fd46c commit 6cf8918
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion common/maps/maps-played.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@
$previous_end = 0;
$num_rows = @mysqli_num_rows($result);
$color_steps = round(200 / $num_rows, 0);
$running_total = 0;
imagefilledarc($base, 300, 150, 200, 200, 0, 360, $lighttransparent, IMG_ARC_PIE);
while($row = mysqli_fetch_assoc($result))
{
$key = $row['MapName'];
$number = $row['number'];
$running_total += $number;
$total_rounds = $row['total'];
$fraction = round(($number / $total_rounds * 100), 0);
$degrees = 360 * ($number / $total_rounds);
$wedge_color = imagecolorallocate($base, $loop_count * $color_steps / 2, $loop_count * $color_steps + 40, $loop_count * $color_steps + 40);
if($degrees < 1)
{
$degrees = 1;
}
$wedge_color = imagecolorallocate($base, 0, abs(-220 + ($loop_count * $color_steps + 20)), abs(-220 + ($loop_count * $color_steps + 20)));
// convert map to friendly name
// first find if this map name is even in the map array
if(in_array($key,$map_array))
Expand Down Expand Up @@ -121,6 +127,31 @@
$legend_y_position += 10;
$loop_count++;
$previous_end += $degrees;
if($previous_end > 360)
{
$previous_end = 359;
}
}
if($running_total < $total_rounds)
{
$fraction = round((100 - ($running_total / $total_rounds * 100)), 0);
imagefilledrectangle($base, 457, $legend_y_position + 1, 462, $legend_y_position + 6, $lighttransparent);
imagestring($base, 1, 467, $legend_y_position, "Other", $faded);
if($num_rows > 1)
{
if(strlen((string)$fraction) < 2)
{
imagestring($base, 1, 439, $legend_y_position, " " . $fraction . "%", $faded);
}
else
{
imagestring($base, 1, 439, $legend_y_position, $fraction . "%", $faded);
}
}
else
{
imagestring($base, 1, 433, $legend_y_position, $fraction . "%", $faded);
}
}
imagestring($base, 2, 250, 15, 'Maps Played Most', $faded);
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
$xmlData = @file_get_contents('https://github.com/tyger07/BF4-Server-Stats/releases.atom');
$xml=@simplexml_load_string($xmlData);
$releaseVersion = $xml->entry[0]->id;
if((!empty($releaseVersion)) && (stripos($releaseVersion, '4-5-21') === false))
if((!empty($releaseVersion)) && (stripos($releaseVersion, '4-10-21') === false))
{
echo '
<div class="subsection">
Expand Down

0 comments on commit 6cf8918

Please sign in to comment.