1 7 package org.ejtools.graph.renderer; 8 9 import java.awt.Graphics ; 10 import java.awt.Insets ; 11 12 import org.ejtools.graph.GraphRenderer; 13 14 19 public class DefaultGraphRenderer extends AbstractGraphRenderer 20 { 21 22 public DefaultGraphRenderer() 23 { 24 super(); 25 } 26 27 28 31 protected void paintComponent(Graphics graphics) 32 { 33 double minX = element.getXRange().getMin(); 34 double maxX = element.getXRange().getMax(); 35 double minY = element.getYRange().getMin(); 36 double maxY = element.getYRange().getMax(); 37 38 Insets insets = this.getInsets(); 39 int x = insets.left; 40 int y = insets.top; 41 double width = (double) this.getWidth() - 1 - insets.left - insets.right; 42 double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; 43 44 double scaleX = width / (maxX - minX); 45 double scaleY = -height / (maxY - minY); 46 double offsetX = x - scaleX * minX; 47 double offsetY = y - scaleY * maxY; 48 49 if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) 50 { 51 scaleX = 1.0d; 52 offsetX = -minX; 53 } 54 if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) 55 { 56 scaleX = 1.0d; 57 offsetX = width - maxX; 58 } 59 60 this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY); 61 } 62 } 63 | Popular Tags |