| 1 25 package org.jrobin.graph; 26 27 import java.io.*; 28 import java.awt.Font ; 29 import java.awt.Color ; 30 import java.awt.BasicStroke ; 31 import java.util.*; 32 import java.text.SimpleDateFormat ; 33 import java.text.DateFormat ; 34 35 import org.jrobin.core.RrdException; 36 import org.jrobin.core.XmlWriter; 37 38 58 public class RrdGraphDef extends RrdExportDef implements Serializable 59 { 60 private Title title = null; private String valueAxisLabel = null; private TimeAxisLabel timeAxisLabel = null; 67 private boolean lazyGeneration = false; private boolean gridX = true; private boolean gridY = true; private boolean minorGridX = true; private boolean minorGridY = true; private boolean majorGridX = true; private boolean majorGridY = true; private boolean frontGrid = true; private boolean antiAliasing = true; private boolean showLegend = true; private boolean drawSignature = true; 79 private Color backColor = new Color ( 245, 245, 245 ); private Color canvasColor = Color.WHITE; private Color borderColor = Color.LIGHT_GRAY; private Color normalFontColor = Color.BLACK; private Color titleFontColor = Color.BLACK; private Color majorGridColor = new Color (130,30,30); private Color minorGridColor = new Color (140,140,140); private Color axisColor = new Color (130,30,30); private Color arrowColor = Color.RED; private Color frameColor = Color.LIGHT_GRAY; 90 private Font titleFont = null; private Font normalFont = null; 93 private File background = null; private File overlay = null; 96 private int chart_lpadding = Grapher.CHART_LPADDING; 98 private int firstDayOfWeek = TimeAxisUnit.MONDAY; 100 private double baseValue = ValueFormatter.DEFAULT_BASE; private int scaleIndex = ValueFormatter.NO_SCALE; 103 private BasicStroke borderStroke = null; private TimeAxisUnit tAxis = null; private ValueAxisUnit vAxis = null; private GridRange gridRange = null; 108 private int commentLines = 0; private int commentLineShift = 0; 112 private ArrayList plotDefs = new ArrayList( 10 ); private ArrayList comments = new ArrayList( 10 ); 115 116 122 public RrdGraphDef() { 123 } 124 125 132 public RrdGraphDef( long startTime, long endTime ) throws RrdException 133 { 134 setTimePeriod( startTime, endTime ); 135 } 136 137 144 public RrdGraphDef( Date start, Date end) throws RrdException 145 { 146 setTimePeriod( start, end ); 147 } 148 149 156 public RrdGraphDef( GregorianCalendar start, GregorianCalendar end ) throws RrdException 157 { 158 setTimePeriod( start, end ); 159 } 160 161 162 173 public void setLazy( boolean lazyGeneration ) 174 { 175 this.lazyGeneration = lazyGeneration; 176 } 177 178 182 public void setTitle( String title ) throws RrdException 183 { 184 this.title = new Title( title ); 185 } 186 187 191 public void setVerticalLabel( String label) 192 { 193 this.valueAxisLabel = label; 194 } 195 196 211 public void setTimeAxisLabel( String label ) throws RrdException 212 { 213 if ( label != null ) 214 { 215 timeAxisLabel = new TimeAxisLabel( label ); 216 commentLines += timeAxisLabel.getLineCount(); 217 commentLineShift = (timeAxisLabel.isCompleteLine() ? 0 : 1); 218 219 comments.add( 0, timeAxisLabel ); 220 } 221 } 222 223 227 public void setBackColor( Color backColor ) 228 { 229 this.backColor = backColor; 230 } 231 232 236 public void setCanvasColor( Color canvasColor ) 237 { 238 this.canvasColor = canvasColor; 239 } 240 241 248 public void setImageBorder( Color c, int w ) 249 { 250 this.borderStroke = new BasicStroke ( w ); 251 if ( c != null ) 252 this.borderColor = c; 253 } 254 255 260 public void setTitleFontColor( Color c ) 261 { 262 this.titleFontColor = c; 263 } 264 265 270 public void setDefaultFontColor( Color c ) 271 { 272 this.normalFontColor = c; 273 } 274 275 280 public void setTitleFont( Font f ) 281 { 282 this.titleFont = f; 283 } 284 285 290 public void setDefaultFont( Font f ) 291 { 292 this.normalFont = f; 293 } 294 295 300 public void setMajorGridColor( Color c ) 301 { 302 this.majorGridColor = c; 303 } 304 305 309 public void setMinorGridColor( Color c ) 310 { 311 this.minorGridColor = c; 312 } 313 314 318 public void setFrameColor( Color c ) 319 { 320 this.frameColor = c; 321 } 322 323 327 public void setAxisColor( Color c ) 328 { 329 this.axisColor = c; 330 } 331 332 336 public void setArrowColor( Color c ) 337 { 338 this.arrowColor = c; 339 } 340 341 345 public void setMinorGridX( boolean visible ) 346 { 347 this.minorGridX = visible; 348 } 349 350 354 public void setMinorGridY( boolean visible ) 355 { 356 this.minorGridY = visible; 357 } 358 359 363 public void setMajorGridX( boolean visible ) 364 { 365 this.majorGridX = visible; 366 } 367 368 372 public void setMajorGridY( boolean visible ) 373 { 374 this.majorGridY = visible; 375 } 376 377 381 public void setGridX( boolean visible ) 382 { 383 this.gridX = visible; 384 } 385 386 390 public void setGridY( boolean visible ) 391 { 392 this.gridY = visible; 393 } 394 395 400 public void setFrontGrid( boolean frontGrid ) 401 { 402 this.frontGrid = frontGrid; 403 } 404 405 411 public void setShowLegend( boolean showLegend ) 412 { 413 this.showLegend = showLegend; 414 } 415 416 423 public void setShowSignature( boolean showSignature ) 424 { 425 this.drawSignature = showSignature; 426 } 427 428 433 public void setAntiAliasing( boolean aa ) 434 { 435 this.antiAliasing = aa; 436 } 437 438 442 public void setChartLeftPadding( int lp ) 443 { 444 this.chart_lpadding = lp; 445 } 446 447 458 public void setBackground( String fileName ) 459 { 460 File bgFile = new File( fileName ); 461 if ( bgFile.exists() ) 462 this.background = bgFile; 463 } 464 465 477 public void setOverlay( String fileName ) 478 { 479 File ovFile = new File( fileName ); 480 if ( ovFile.exists() ) 481 this.overlay = ovFile; 482 } 483 484 491 public void setBaseValue( double base ) 492 { 493 this.baseValue = base; 494 } 495 496 507 public void setUnitsExponent( int e ) 508 { 509 this.scaleIndex = (6 - e / 3); } 511 512 int getUnitsExponent() { 513 return (6 - scaleIndex) * 3; 514 } 515 516 524 525 public void setGridRange( double lower, double upper, boolean rigid ) 526 { 527 gridRange = new GridRange( lower, upper, rigid ); 528 } 529 530 535 public void setLowerLimit( double lower ) 536 { 537 gridRange = new GridRange( lower, Double.NaN, false ); 538 } 539 540 547 public void setValueAxis( double gridStep, double labelStep ) 548 { 549 vAxis = new ValueAxisUnit( gridStep, labelStep ); 550 } 551 552 568 public void setTimeAxis( int minGridTimeUnit, 569 int minGridUnitSteps, 570 int majGridTimeUnit, 571 int majGridUnitSteps, 572 String dateFormat, 573 boolean centerLabels ) 574 { 575 this.tAxis = new TimeAxisUnit( minGridTimeUnit, 576 minGridUnitSteps, 577 majGridTimeUnit, 578 majGridUnitSteps, 579 new SimpleDateFormat ( dateFormat ), 580 centerLabels , 581 firstDayOfWeek 582 ); 583 } 584 585 590 public void setFirstDayOfWeek( int day ) 591 { 592 firstDayOfWeek = day; 593 } 594 595 606 public void line( String sourceName, Color color, String legend ) throws RrdException 607 { 608 plotDefs.add( new Line(sourceName, color) ); 609 addLegend( legend, color ); 610 } 611 612 623 public void line( String sourceName, Color color, String legend, int lineWidth ) throws RrdException 624 { 625 plotDefs.add( new Line(sourceName, color, lineWidth) ); 626 addLegend( legend, color ); 627 } 628 629 642 public void line( GregorianCalendar t1, double v1, GregorianCalendar t2, double v2, Color color, String legend, int lineWidth ) throws RrdException 643 { 644 plotDefs.add( new CustomLine( t1.getTimeInMillis() / 1000, v1, t2.getTimeInMillis() / 1000, v2, color, lineWidth ) ); 645 addLegend( legend, color ); 646 } 647 648 659 public void area( String sourceName, Color color, String legend ) throws RrdException 660 { 661 plotDefs.add( new Area(sourceName, color) ); 662 addLegend( legend, color ); 663 } 664 665 679 public void area( GregorianCalendar t1, double v1, GregorianCalendar t2, double v2, Color color, String legend ) throws RrdException 680 { 681 plotDefs.add( new CustomArea( t1.getTimeInMillis() / 1000, v1, t2.getTimeInMillis() / 1000, v2, color ) ); 682 addLegend( legend, color ); 683 } 684 685 695 public void stack( String sourceName, Color color, String legend ) throws RrdException 696 { 697 plotDefs.add( new Stack(sourceName, color) ); 698 addLegend( legend, color ); 699 } 700 701 709 public void hrule(double value, Color color, String legend) throws RrdException { 710 plotDefs.add( new CustomLine( Long.MIN_VALUE, value, Long.MAX_VALUE, value, color ) ); 711 addLegend( legend, color ); 712 } 713 714 723 public void hrule(double value, Color color, String legend, int lineWidth) throws RrdException { 724 plotDefs.add( new CustomLine( Long.MIN_VALUE, value, Long.MAX_VALUE, value, color, lineWidth ) ); 725 addLegend( legend, color ); 726 } 727 728 735 public void vrule( GregorianCalendar timestamp, Color color, String legend ) throws RrdException { 736 long timeSecs = timestamp.getTimeInMillis() / 1000; 737 plotDefs.add( new CustomLine( timeSecs, Double.MIN_VALUE, timeSecs, Double.MAX_VALUE, color ) ); 738 addLegend( legend, color ); 739 } 740 741 750 public void vrule( GregorianCalendar timestamp, Color color, String legend, int lineWidth ) throws RrdException { 751 long timeSecs = timestamp.getTimeInMillis() / 1000; 752 plotDefs.add( new CustomLine( timeSecs, Double.MIN_VALUE, timeSecs, Double.MAX_VALUE, color, lineWidth ) ); 753 addLegend( legend, color ); 754 } 755 756 768 public void comment(String text) throws RrdException { 769 addComment( new Comment(text) ); 770 } 771 772 782 public void time( String text, String pattern ) throws RrdException { 783 addComment( new TimeText( text, pattern ) ); 784 } 785 786 795 public void time( String text, DateFormat format ) throws RrdException { 796 addComment( new TimeText( text, format ) ); 797 } 798 799 810 public void time( String text, String pattern, long timestamp ) throws RrdException { 811 addComment( new TimeText( text, pattern, timestamp ) ); 812 } 813 814 824 public void time( String text, DateFormat format, long timestamp ) throws RrdException { 825 addComment( new TimeText( text, format, timestamp ) ); 826 } 827 828 839 public void time( String text, String pattern, Date date ) throws RrdException { 840 addComment( new TimeText( text, pattern, date ) ); 841 } 842 843 853 public void time( String text, DateFormat format, Date date ) throws RrdException { 854 addComment( new TimeText( text, format, date ) ); 855 } 856 857 |