XYSplineRenderer.java :  » Graphic-Library » mjograph » mjo » core » plot » Java Open Source

Java Open Source » Graphic Library » mjograph 
mjograph » mjo » core » plot » XYSplineRenderer.java
package mjo.core.plot;

import mjo.components.smooth.*;
import mjo.core.data.*;

import java.awt.*;
import java.awt.geom.*;

import org.jfree.ui.*;
import org.jfree.data.xy.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.renderer.xy.*;
import org.jfree.ui.RectangleEdge;


/***/
public class XYSplineRenderer extends XYLineAndShapeRenderer{
    //
    public XYSplineRenderer(){
  super();
    }

    //
    protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea){
  //
  if(item != dataset.getItemCount(series) - 1)
      return;

  //java(weight)bothersome

  MjoXYSeries s = (MjoXYSeries)((MjoDataset)dataset).getSeries(series);
  int weight = s.getWeight(), up = s.getUp();
  

  int n, i, j, count = dataset.getItemCount(series);
  double x1, y1, haba;
  RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
  RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

  //
  boolean logX = (domainAxis instanceof LogarithmicAxis), logY = (rangeAxis instanceof LogarithmicAxis);

  //
  double [] x = new double[count], y = new double[count];
  for(i = 0; i < count; i++){
      x[i] = dataset.getXValue(series, i);
      y[i] = dataset.getYValue(series, i);
      if(logX)    x[i] = ZoomLogarithmicAxis.log10(x[i]);
      if(logY)    y[i] = ZoomLogarithmicAxis.log10(y[i]);
  }

  //
  double [][] sc = SmoothAlgorithm.cp_wspline(count, x, y, weight);
  
  //
  GeneralPath path = new GeneralPath();

  //-----------------------
  if(logX)      x1 = Math.pow(10, x[0]);
  else      x1 = x[0];
  if(logY)      y1 = Math.pow(10, SmoothAlgorithm.eval_spline(sc, 0, 0));
  else      y1 = SmoothAlgorithm.eval_spline(sc, 0, 0);
  
  path.moveTo((float)domainAxis.valueToJava2D(x1, dataArea, xAxisLocation), (float)rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));//moveTo
  haba = x[1] - x[0];
  for(j = 1; j < up; j++){
      if(logX)      x1 = Math.pow(10, x[0] + haba / up * j);
      else      x1 = x[0] + haba / up * j;
      if(logY)      y1 = Math.pow(10, SmoothAlgorithm.eval_spline(sc, 0, haba / up * j));
      else      y1 =  SmoothAlgorithm.eval_spline(sc, 0, haba / up * j);

      path.lineTo((float)domainAxis.valueToJava2D(x1, dataArea, xAxisLocation), (float)rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));
  }
  
  //-----------------------
  for(n = 1; n < count - 1; n++){
      haba = x[n+1] - x[n];
      for(j = 0; j < up; j++){
    if(logX)    x1 = Math.pow(10, x[n] + haba / up * j);
    else      x1 = x[n] + haba / up * j;
    if(logY)    y1 = Math.pow(10, SmoothAlgorithm.eval_spline(sc, n, haba / up * j));
    else      y1 =  SmoothAlgorithm.eval_spline(sc, n, haba / up * j);
    
    path.lineTo((float)domainAxis.valueToJava2D(x1, dataArea, xAxisLocation), (float)rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));

    //NumberAxis
    //path.lineTo((float)((NumberAxis)domainAxis).valueToJava2D(x1, dataArea, xAxisLocation), (float)((NumberAxis)rangeAxis).valueToJava2D(y1, dataArea, yAxisLocation));
    
      }
  }

  //-----------------------
  if(logX)      x1 = Math.pow(10, x[count-1]);
  else      x1 = x[count-1];
  if(logY)      y1 = Math.pow(10, SmoothAlgorithm.eval_spline(sc, count-1, 0));
  else      y1 = SmoothAlgorithm.eval_spline(sc, count-1, 0);
  path.lineTo((float)domainAxis.valueToJava2D(x1, dataArea, xAxisLocation), (float)rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));
  

  
  //
  drawFirstPassShape(g2, pass, series, item, path);
  
    }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.