function print_percentage_bar($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) { if ($percent > "100") { $size_percent = "100"; } else { $size_percent = $percent; } $percentage_bar['border'] = "#" . $left_background; $percentage_bar['bg'] = "#" . $right_background; $percentage_bar['width'] = $width; $percentage_bar['text'] = $right_text; $percentage_bar['bars'][0] = array('percent' => $size_percent, 'colour' => '#' . $left_background, 'text' => $left_text); $output = percentage_bar($percentage_bar); return $output; }
<?php $swap_used = $device_state['ucd_mem']['swap_total'] - $device_state['ucd_mem']['swap_avail']; $swap_perc = round($swap_used / $device_state['ucd_mem']['swap_total'] * 100); $swap_free_perc = 100 - $swap_perc; $background = get_percentage_colours('40'); $percentage_bar = array(); $percentage_bar['border'] = "#356AA0"; $percentage_bar['bg'] = "#f0f0f0"; $percentage_bar['width'] = "100%"; $percentage_bar['text'] = $swap_free_perc . "%"; $percentage_bar['text_c'] = "#356AA0"; $percentage_bar['bars'][0] = array('percent' => $swap_perc, 'colour' => '#356AA0', 'text' => $swap_perc . '%'); echo ' <tr>'; echo ' <td class="entity">Swap</td>'; echo ' <td>'; echo percentage_bar($percentage_bar); echo ' </td>'; echo ' </tr>'; ?> <tr class="small"> <td colspan=2> <div class="row" style="margin-left: 5px;"> <div class="col-md-4"><i style="font-size: 7px; line-height: 7px; background-color: #356AA0; border: 1px #aaa solid;"> </i> <strong>已用:</strong> <?php echo formatStorage($swap_used * 1024) . ' (' . $swap_perc . '%)'; ?> </div> <div class="col-md-4"><i style="font-size: 7px; line-height: 7px; background-color: #ddd; border: 1px #aaa solid;"> </i> <strong>空闲:</strong> <?php echo formatStorage($device_state['ucd_mem']['swap_avail'] * 1024) . ' (' . $swap_free_perc . '%)';