1 package JSci.swing; 2 3 import java.awt.*; 4 import JSci.awt.*; 5 11 public class JLineGraph extends JGraph2D { 12 15 public JLineGraph(Graph2DModel gm) { 16 super(gm); 17 } 18 22 protected void drawData(Graphics g) { 23 Point p1, p2; 25 int i; 26 model.firstSeries(); 27 if(model.seriesLength() > 0) { 28 g.setColor(seriesColor[0]); 29 drawSeries(g); 30 } 31 for(int n=1;model.nextSeries();n++) { 32 if(model.seriesLength() > 0) { 33 g.setColor(seriesColor[n]); 34 drawSeries(g); 35 } 36 } 37 super.drawData(g); 38 } 39 private void drawSeries(Graphics g) { 40 Point p1 = null; 41 for(int i=0; i<model.seriesLength(); i++) { 42 final float y = model.getYCoord(i); 43 if(Float.isNaN(y)) { 44 p1 = null; 45 } else if(p1 == null) { 46 p1 = dataToScreen(model.getXCoord(i), y); 47 } else { 48 Point p2 = dataToScreen(model.getXCoord(i), y); 49 g.drawLine(p1.x, p1.y, p2.x, p2.y); 50 p1 = p2; 51 } 52 } 53 } 54 } 55 56 | Popular Tags |