int max_metric = 0;
for (int i=0;i<zones.length;i++){
SpeedManagerPingZone zone = zones[i];
int metric = zone.getMetric();
if ( metric > 0 ){
max_metric = Math.max( max_metric, metric );
max_x = Math.max( max_x, zone.getUploadEndBytesPerSec());
max_y = Math.max( max_y, zone.getDownloadEndBytesPerSec());
}
}
if ( max_x > 0 && max_y > 0 ){
double x_ratio = (double)usable_width/max_x;
double y_ratio = (double)usable_height/max_y;
List texts = new ArrayList();
for (int i=0;i<zones.length;i++){
SpeedManagerPingZone zone = zones[i];
int metric = zone.getMetric();
int x1 = zone.getUploadStartBytesPerSec();
int y1 = zone.getDownloadStartBytesPerSec();
int x2 = zone.getUploadEndBytesPerSec();
int y2 = zone.getDownloadEndBytesPerSec();
if ( metric > 0 ){
int colour_index = (int)((float)metric*colours.length/max_metric);
if ( colour_index >= colours.length ){
colour_index = colours.length-1;
}
gc.setBackground( colours[colour_index] );
int x = PAD_LEFT + (int)(x1*x_ratio);
int y = PAD_TOP + (int)(y1*y_ratio);
int width = (int)Math.ceil((x2-x1+1)*x_ratio);
int height = (int)Math.ceil((y2-y1+1)*y_ratio );
int y_draw = usable_height + PAD_TOP + PAD_TOP - y - height;
gc.fillRectangle( x, y_draw, width, height );
int text_metric = zone.getMetric();
String text = String.valueOf( metric );
int text_width = text.length()*char_width + 4;