@ -1,4 +1,4 @@
// ChartPlotter.java
// ChartPlotter.java
// ---------------------------
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
@ -33,25 +33,25 @@ import javax.imageio.ImageIO;
public class ChartPlotter extends RasterPlotter {
public static final int DIMENSION_RIGHT = 0 ;
public static final int DIMENSION_TOP = 1 ;
public static final int DIMENSION_LEFT = 2 ;
public static final int DIMENSION_BOTTOM = 3 ;
public static final int DIMENSION_ANOT0 = 4 ;
public static final int DIMENSION_ANOT1 = 5 ;
private int leftborder ;
private int rightborder ;
private int topborder ;
private int bottomborder ;
private int [ ] scales = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private int [ ] pixels = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private int [ ] offsets = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private String [ ] colnames = new String [ ] { "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" } ;
private String [ ] colscale = new String [ ] { null , null , null , null , null , null } ;
private String [ ] tablenames = new String [ ] { "" , "" , "" , "" , "" , "" } ;
private final int leftborder ;
private final int rightborder ;
private final int topborder ;
private final int bottomborder ;
private final int [ ] scales = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private final int [ ] pixels = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private final int [ ] offsets = new int [ ] { 0 , 0 , 0 , 0 , 0 , 0 } ;
private final String [ ] colnames = new String [ ] { "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" , "FFFFFF" } ;
private final String [ ] colscale = new String [ ] { null , null , null , null , null , null } ;
private final String [ ] tablenames = new String [ ] { "" , "" , "" , "" , "" , "" } ;
public ChartPlotter ( final int width , final int height , final String backgroundColor , final String foregroundColor , final String lightColor ,
final int leftborder , final int rightborder , final int topborder , final int bottomborder ,
final String name , final String subline ) {
@ -72,7 +72,7 @@ public class ChartPlotter extends RasterPlotter {
PrintTool . print ( this , width / 2 - subline . length ( ) * 3 , 14 , 0 , subline , - 1 ) ;
}
}
public void declareDimension ( final int dimensionType , final int scale , final int pixelperscale , final int offset , final String colorNaming , final String colorScale , final String name ) {
if ( ( dimensionType = = DIMENSION_LEFT ) | | ( dimensionType = = DIMENSION_RIGHT ) ) {
drawVerticalScale ( ( dimensionType = = DIMENSION_LEFT ) , scale , pixelperscale , offset , colorNaming , colorScale , name ) ;
@ -80,38 +80,38 @@ public class ChartPlotter extends RasterPlotter {
if ( ( dimensionType = = DIMENSION_TOP ) | | ( dimensionType = = DIMENSION_BOTTOM ) ) {
drawHorizontalScale ( ( dimensionType = = DIMENSION_TOP ) , scale , pixelperscale , offset , colorNaming , colorScale , name ) ;
}
scales[ dimensionType ] = scale ;
pixels[ dimensionType ] = pixelperscale ;
offsets[ dimensionType ] = offset ;
colnames[ dimensionType ] = colorNaming ;
colscale[ dimensionType ] = colorScale ;
tablenames[ dimensionType ] = name ;
this . scales[ dimensionType ] = scale ;
this . pixels[ dimensionType ] = pixelperscale ;
this . offsets[ dimensionType ] = offset ;
this . colnames[ dimensionType ] = colorNaming ;
this . colscale[ dimensionType ] = colorScale ;
this . tablenames[ dimensionType ] = name ;
}
public void chartDot ( final int dimension_x , final int dimension_y , final int coord_x , final int coord_y , final int dotsize , String anot , int anotAngle ) {
final int x = ( coord_x - offsets [ dimension_x ] ) * pixels [ dimension_x ] / scales[ dimension_x ] ;
final int y = ( coord_y - offsets [ dimension_y ] ) * pixels [ dimension_y ] / scales[ dimension_y ] ;
if ( dotsize = = 1 ) plot ( leftborder + x , height - bottomborder - y , 100 ) ;
else dot ( leftborder + x , height - bottomborder - y , dotsize , true , 100 ) ;
if ( anot ! = null ) PrintTool . print ( this , leftborder + x + dotsize + 2 + ( ( anotAngle = = 315 ) ? - 9 : 0 ) , height - bottomborder - y + ( ( anotAngle = = 315 ) ? - 3 : 0 ) , anotAngle , anot , ( anotAngle = = 0 ) ? - 1 : ( ( anotAngle = = 315 ) ? 1 : 0 ) ) ;
public void chartDot ( final int dimension_x , final int dimension_y , final int coord_x , final int coord_y , final int dotsize , final String anot , final int anotAngle ) {
final int x = ( coord_x - this . offsets [ dimension_x ] ) * this . pixels [ dimension_x ] / this . scales[ dimension_x ] ;
final int y = ( coord_y - this . offsets [ dimension_y ] ) * this . pixels [ dimension_y ] / this . scales[ dimension_y ] ;
if ( dotsize = = 1 ) plot ( this . leftborder + x , this . height - this . bottomborder - y , 100 ) ;
else dot ( this . leftborder + x , this . height - this . bottomborder - y , dotsize , true , 100 ) ;
if ( anot ! = null ) PrintTool . print ( this , this . leftborder + x + dotsize + 2 + ( ( anotAngle = = 315 ) ? - 9 : 0 ) , this . height - this . bottomborder - y + ( ( anotAngle = = 315 ) ? - 3 : 0 ) , anotAngle , anot , ( anotAngle = = 0 ) ? - 1 : ( ( anotAngle = = 315 ) ? 1 : 0 ) ) ;
}
public void chartLine ( final int dimension_x , final int dimension_y , final int coord_x1 , final int coord_y1 , final int coord_x2 , final int coord_y2 ) {
final int x1 = ( coord_x1 - offsets [ dimension_x ] ) * pixels [ dimension_x ] / scales[ dimension_x ] ;
final int y1 = ( coord_y1 - offsets [ dimension_y ] ) * pixels [ dimension_y ] / scales[ dimension_y ] ;
final int x2 = ( coord_x2 - offsets [ dimension_x ] ) * pixels [ dimension_x ] / scales[ dimension_x ] ;
final int y2 = ( coord_y2 - offsets [ dimension_y ] ) * pixels [ dimension_y ] / scales[ dimension_y ] ;
line ( leftborder + x1 , height - bottomborder - y1 , leftborder + x2 , height - bottomborder - y2 , 100 ) ;
final int x1 = ( coord_x1 - this . offsets [ dimension_x ] ) * this . pixels [ dimension_x ] / this . scales[ dimension_x ] ;
final int y1 = ( coord_y1 - this . offsets [ dimension_y ] ) * this . pixels [ dimension_y ] / this . scales[ dimension_y ] ;
final int x2 = ( coord_x2 - this . offsets [ dimension_x ] ) * this . pixels [ dimension_x ] / this . scales[ dimension_x ] ;
final int y2 = ( coord_y2 - this . offsets [ dimension_y ] ) * this . pixels [ dimension_y ] / this . scales[ dimension_y ] ;
line ( this . leftborder + x1 , this . height - this . bottomborder - y1 , this . leftborder + x2 , this . height - this . bottomborder - y2 , 100 ) ;
}
private void drawHorizontalScale ( final boolean top , final int scale , final int pixelperscale , final int offset , final String colorNaming , final String colorScale , final String name ) {
final int y = ( top ) ? topborder : height - bottomborder;
int x = leftborder;
final int y = ( top ) ? this . topborder : this . height - this . bottomborder;
int x = this . leftborder;
int s = offset ;
while ( x < width - rightborder) {
if ( ( colorScale ! = null ) & & ( x > leftborder ) & & ( x < ( width - rightborder) ) ) {
while ( x < this . width - this . rightborder) {
if ( ( colorScale ! = null ) & & ( x > this . leftborder ) & & ( x < ( this . width - this . rightborder) ) ) {
setColor ( colorScale ) ;
line ( x , topborder , x , height - bottomborder, 100 ) ;
line ( x , this . topborder , x , this . height - this . bottomborder, 100 ) ;
}
setColor ( colorNaming ) ;
line ( x , y - 3 , x , y + 3 , 100 ) ;
@ -120,34 +120,36 @@ public class ChartPlotter extends RasterPlotter {
s + = scale ;
}
setColor ( colorNaming ) ;
PrintTool . print ( this , width - rightborder, ( top ) ? y - 9 : y + 15 , 0 , name , 1 ) ;
line ( leftborder - 4 , y , width - rightborder + 4 , y , 100 ) ;
PrintTool . print ( this , this . width - this . rightborder, ( top ) ? y - 9 : y + 15 , 0 , name , 1 ) ;
line ( this . leftborder - 4 , y , this . width - this . rightborder + 4 , y , 100 ) ;
}
private void drawVerticalScale ( final boolean left , final int scale , final int pixelperscale , final int offset , final String colorNaming , final String colorScale , final String name ) {
final int x = ( left ) ? leftborder : width - rightborder ;
int y = height - bottomborder ;
assert pixelperscale > 0 ;
assert scale > 0 ;
final int x = ( left ) ? this . leftborder : this . width - this . rightborder ;
int y = this . height - this . bottomborder ;
int s = offset ;
String s1 ;
int s1max = 0 ;
while ( y > topborder) {
if ( ( colorScale ! = null ) & & ( y > topborder ) & & ( y < ( height - bottomborder) ) ) {
while ( y > this . topborder) {
if ( ( colorScale ! = null ) & & ( y > this . topborder ) & & ( y < ( this . height - this . bottomborder) ) ) {
setColor ( colorScale ) ;
line ( leftborder , y , width - rightborder, y , 100 ) ;
line ( this . leftborder , y , this . width - this . rightborder, y , 100 ) ;
}
setColor ( colorNaming ) ;
line ( x - 3 , y , x + 3 , y , 100 ) ;
s1 = ( s > = 1000000 & & s % 10000 = = 0 ) ? Integer . toString ( s / 1000000 ) + "M" : ( s > = 1000 & & s % 1000 = = 0 ) ? Integer . toString ( s / 1000 ) + "K" : Integer . toString ( s ) ;
if ( s1 . length ( ) > s1max ) s1max = s1 . length ( ) ;
PrintTool . print ( this , ( left ) ? leftborder - 4 : width - rightborder + 4 , y , 0 , s1 , ( left ) ? 1 : - 1 ) ;
PrintTool . print ( this , ( left ) ? this . leftborder - 4 : this . width - this . rightborder + 4 , y , 0 , s1 , ( left ) ? 1 : - 1 ) ;
y - = pixelperscale ;
s + = scale ;
}
setColor ( colorNaming ) ;
PrintTool . print ( this , ( left ) ? x - s1max * 6 - 6 : x + s1max * 6 + 9 , topborder, 90 , name , 1 ) ;
line ( x , topborder - 4 , x , height - bottomborder + 4 , 100 ) ;
PrintTool . print ( this , ( left ) ? x - s1max * 6 - 6 : x + s1max * 6 + 9 , this . topborder, 90 , name , 1 ) ;
line ( x , this . topborder - 4 , x , this . height - this . bottomborder + 4 , 100 ) ;
}
public static void main ( final String [ ] args ) {
System . setProperty ( "java.awt.headless" , "true" ) ;
final String bg = "FFFFFF" ;
@ -176,7 +178,7 @@ public class ChartPlotter extends RasterPlotter {
ImageIO . write ( ip . getImage ( ) , "png" , fos ) ;
fos . close ( ) ;
} catch ( final IOException e ) { }
}
}