bufferImage.dispose();
}
bufferImage = new Image( canvas.getDisplay(), bounds );
GC image = new GC( bufferImage );
int max_x = 0;
int max_y = 0;
int max_z = 0;
for (int i=0;i<values.length;i++){
int[] entry = (int[])values[i];
if ( entry[0] > max_x ){
max_x = entry[0];
}
if ( entry[1] > max_y ){
max_y = entry[1];
}
if ( entry[2] > max_z ){
max_z = entry[2];
}
}
int usable_width = bounds.width - PAD_LEFT - PAD_RIGHT;
int usable_height = bounds.height - PAD_TOP - PAD_BOTTOM;
try {
image.setAntialias( SWT.ON );
} catch (Exception e) {
// Ignore ERROR_NO_GRAPHICS_LIBRARY error or any others
}
double x_ratio = ((float)usable_width-((usable_height/2)/ANGLE_TAN)) / max_x;
double y_ratio = ((float)usable_height/2) / max_y;
double z_ratio = ((float)usable_height/2) / max_z;
// grid
int x_axis_left_x = PAD_LEFT;
int x_axis_left_y = usable_height + PAD_TOP;
int x_axis_right_x = PAD_LEFT + usable_width;
int x_axis_right_y = usable_height + PAD_TOP;
int y_axis_left_x = PAD_LEFT;
int y_axis_left_y = usable_height + PAD_TOP;
int y_axis_right_x = PAD_LEFT + (int)((usable_height/2) / ANGLE_TAN );
int y_axis_right_y = usable_height / 2;
int z_axis_bottom_x = PAD_LEFT;
int z_axis_bottom_y = usable_height + PAD_TOP;
int z_axis_top_x = PAD_LEFT;
int z_axis_top_y = PAD_TOP + usable_height / 2;
Rectangle old_clip = image.getClipping();
image.setClipping( new Rectangle( PAD_LEFT, PAD_RIGHT, usable_width, usable_height ));
image.setForeground( Colors.light_grey );
int x_lines = 10;
for (int i=1;i<x_lines;i++){
int x1 = x_axis_left_x + (( y_axis_right_x - y_axis_left_x )*i/x_lines);
int y1 = x_axis_left_y - (( y_axis_left_y - y_axis_right_y )*i/x_lines);
int x2 = x_axis_right_x;
int y2 = y1;
image.drawLine( x1, y1, x2, y2 );
}
int y_lines = 10;
for (int i=1;i<y_lines;i++){
int x1 = y_axis_left_x + (( x_axis_right_x - x_axis_left_x )*i/x_lines);
int y1 = y_axis_left_y;
int x2 = y_axis_right_x + (( x_axis_right_x - x_axis_left_x )*i/x_lines);
int y2 = y_axis_right_y;
image.drawLine( x1, y1, x2, y2 );
}
image.setClipping( old_clip );
int z_lines = 10;
for (int i=1;i<z_lines;i++){
int z = z_axis_bottom_y + ( z_axis_top_y - z_axis_bottom_y )*i/z_lines;
image.drawLine( z_axis_bottom_x, z, z_axis_bottom_x-4, z );
}
// now values
for (int i=0;i<values.length;i++){
int[] entry = (int[])values[i];
int draw_x = (int)( x_ratio * entry[0] );
int draw_y = (int)( y_ratio * entry[1] );
int draw_z = (int)( z_ratio * entry[2] );
draw_x += draw_y / ANGLE_TAN;
image.setForeground( colours[(int)(((float)entry[2]/max_z)*(colours.length-1))]);
image.drawLine(
PAD_LEFT + draw_x,
PAD_TOP + usable_height - draw_y,
PAD_LEFT + draw_x,
PAD_TOP + usable_height - ( draw_y + draw_z ));
}
image.setForeground( Colors.black );
image.drawRectangle( bounds.x, bounds.y, bounds.width-1, bounds.height-1 );
int font_height = image.getFontMetrics().getHeight();
int char_width = image.getFontMetrics().getAverageCharWidth();
// x axis
image.drawLine( x_axis_left_x, x_axis_left_y, x_axis_right_x, x_axis_right_y );
image.drawLine( usable_width, x_axis_right_y - 4, x_axis_right_x, x_axis_right_y );
image.drawLine( usable_width, x_axis_right_y + 4, x_axis_right_x, x_axis_right_y );
String x_text = labels[0] + " - " + formatters[0].format( max_x );
image.drawText(
x_text,
x_axis_right_x - 20 - x_text.length()*char_width,
x_axis_right_y - font_height - 2,
SWT.DRAW_TRANSPARENT );
// z axis
String z_text = labels[2] + " - " + formatters[2].format( max_z );
image.drawText( z_text, z_axis_top_x + 4, z_axis_top_y + 10, SWT.DRAW_TRANSPARENT );
image.drawLine( z_axis_bottom_x, z_axis_bottom_y, z_axis_top_x, z_axis_top_y );
image.drawLine( z_axis_top_x-4, z_axis_top_y + 10, z_axis_top_x, z_axis_top_y );
image.drawLine( z_axis_top_x+4, z_axis_top_y + 10, z_axis_top_x, z_axis_top_y );
// y axis
image.drawLine( y_axis_left_x, y_axis_left_y, y_axis_right_x, y_axis_right_y );
image.drawLine( y_axis_right_x-6, y_axis_right_y, y_axis_right_x, y_axis_right_y );
image.drawLine( y_axis_right_x, y_axis_right_y + 6, y_axis_right_x, y_axis_right_y );
String y_text = labels[1] + " - " + formatters[1].format( max_y );
image.drawText(
y_text,
y_axis_right_x - (y_text.length() * char_width),
y_axis_right_y - font_height - 2,
SWT.DRAW_TRANSPARENT );
image.drawText( title, ( bounds.width - title.length()*char_width )/2, 1, SWT.DRAW_TRANSPARENT );
image.dispose();
}finally{
this_mon.exit();
}