Android Open Source - AnkiStats Y Grid






From Project

Back to project page AnkiStats.

License

The source code is released under:

GNU General Public License

If you think the Android project AnkiStats listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * /* w w w  .  ja v a2s . c  o m*/
 */
package com.wildplot.android.rendering;

import com.wildplot.android.rendering.graphics.wrapper.Color;
import com.wildplot.android.rendering.graphics.wrapper.Graphics;
import com.wildplot.android.rendering.graphics.wrapper.Rectangle;
import com.wildplot.android.rendering.interfaces.Drawable;


/**
 * This class represents grid lines parallel to the y-axis
 * 
 * 
 */
public class YGrid implements Drawable {
  public boolean hasVariableLimits = true;
  
  private boolean isAutoTic = true;
  
  private int pixelDistance = 25;
  /**
   * the color of the grid lines
   */
  private Color color = Color.LIGHT_GRAY;
  
  /**
   * the Sheet the grid lines will be drawn onto
   */
  private PlotSheet plotSheet;
  
  /**
   * start point for relative positioning of grid
   */
  private double ticStart = 0;
  
  /**
   * the space between two grid lines
   */
  private double tic = 1;
  
  /**
   * maximal distance from x axis the grid will be drawn
   */
  private double xLength = 10;
  
  /**
   * maximal distance from y axis the grid will be drawn
   */
  private double yLength = 2;
  
  /**
   * true if the grid should be drawn into the direction left to the axis
   */
  private boolean gridkOnLeft = true;

  /**
   * true if the grid should be drawn into the direction right to the axis
   */
  private boolean gridOnRight = true;
  
  /**
   * true if the grid should be drawn under the x-axis
   */
  private boolean gridOnDownside = true;
  
  /**
   * true if the grid should be drawn above the x-axis
   */
  private boolean gridOnUpside = true;
    private double[] mTickPositions;

    /**
   * Constructor for an Y-Grid object
   * @param plotSheet the sheet the grid will be drawn onto
   * @param ticStart start point for relative positioning of grid
   * @param tic the space between two grid lines
   */
  public YGrid(PlotSheet plotSheet, double ticStart, double tic) {
    super();
    this.plotSheet = plotSheet;
    this.ticStart = ticStart;
    this.tic = tic;
  }

  /**
   * Constructor for an Y-Grid object
   * @param color set color of the grid
   * @param plotSheet the sheet the grid will be drawn onto
   * @param ticStart start point for relative positioning of grid
   * @param tic the space between two grid lines
   */
  public YGrid(Color color, PlotSheet plotSheet, double ticStart, double tic) {
    super();
    this.color = color;
    this.plotSheet = plotSheet;
    this.ticStart = ticStart;
    this.tic = tic;
  }
  
  /**
   * Constructor for an Y-Grid object
   * @param plotSheet the sheet the grid will be drawn onto
   * @param ticStart start point for relative positioning of grid
   */
  public YGrid(PlotSheet plotSheet, double ticStart, int pixelDistance) {
    super();
    this.plotSheet = plotSheet;
    this.ticStart = ticStart;
    this.pixelDistance = pixelDistance;
  }

  /**
   * Constructor for an Y-Grid object
   * @param color set color of the grid
   * @param plotSheet the sheet the grid will be drawn onto
   * @param ticStart start point for relative positioning of grid
   */
  public YGrid(Color color, PlotSheet plotSheet, double ticStart, int pixelDistance) {
    super();
    this.color = color;
    this.plotSheet = plotSheet;
    this.ticStart = ticStart;
    this.pixelDistance = pixelDistance;
  }

  /* (non-Javadoc)
   * @see rendering.Drawable#paint(java.awt.Graphics)
   */
  @Override
  public void paint(Graphics g) {
    Color oldColor = g.getColor();
    Rectangle field = g.getClipBounds();
    g.setColor(color);
    
    if(this.hasVariableLimits) {
      this.xLength = Math.max(Math.abs(plotSheet.getxRange()[0]), Math.abs(plotSheet.getxRange()[1]));
      this.yLength = Math.max(Math.abs(plotSheet.getyRange()[0]), Math.abs(plotSheet.getyRange()[1]));
    }
    if(this.isAutoTic)
      this.tic = plotSheet.ticsCalcX(pixelDistance, field);


        int tics = (int)((this.ticStart - (0-this.xLength))/tic);
    double leftStart = this.ticStart - this.tic*tics; 
    
    if(leftStart < 0 ) {
      if(!this.gridkOnLeft) {
        while(leftStart<0) {
          leftStart+=this.tic;
        }
      }
      
    }


        if(mTickPositions == null)
            drawImplicitLines(g, leftStart);
        else
            drawExplicitLines(g);


    //System.err.println("out of loop");
    g.setColor(oldColor);

  }
    private void drawImplicitLines(Graphics g, double leftStart){
        Rectangle field = g.getClipBounds();
        double currentX = leftStart;

        while(currentX <= this.xLength && !(currentX > 0 && !this.gridOnRight)) {
            drawGridLine(currentX, g, field);
            currentX+=this.tic;
            //System.err.println("another loop");
        }
    }

    private void drawExplicitLines(Graphics g){
        Rectangle field = g.getClipBounds();

        for(int i = 0; i< mTickPositions.length; i++) {
            double currentX = mTickPositions[i];
            drawGridLine(currentX, g, field);
        }
    }
  
  /**
   * Draw a grid line in specified graphics object
   * @param x x-position the vertical line shall be drawn
   * @param g graphic the line shall be drawn onto
   * @param field definition of the graphic boundaries
   */
  private void drawGridLine(double x, Graphics g, Rectangle field) {
    if(this.gridOnUpside) {
      g.drawLine(plotSheet.xToGraphic(x, field), plotSheet.yToGraphic(0, field), plotSheet.xToGraphic(x, field), plotSheet.yToGraphic(yLength, field));
    }
    
    if(this.gridOnDownside) {
      g.drawLine(plotSheet.xToGraphic(x, field), plotSheet.yToGraphic(0, field), plotSheet.xToGraphic(x, field), plotSheet.yToGraphic(-yLength, field));
    }
  }
  
  /**
   * true if the grid should be drawn into the direction left to the axis
   */
  public void setGridkOnLeft(boolean gridkOnLeft) {
    this.gridkOnLeft = gridkOnLeft;
  }
  
  /**
   * true if the grid should be drawn into the direction right to the axis
   */
  public void setGridOnRight(boolean gridOnRight) {
    this.gridOnRight = gridOnRight;
  }
  
  /**
   * true if the grid should be drawn under the x-axis
   */
  public void setGridOnDownside(boolean gridOnDownside) {
    this.gridOnDownside = gridOnDownside;
  }

  /**
   * true if the grid should be drawn above the x-axis
   */
  public void setGridOnUpside(boolean gridOnUpside) {
    this.gridOnUpside = gridOnUpside;
  }
  
  public boolean isOnFrame() {
    return false;
  }

  @Override
  public void abortAndReset() {
    // TODO Auto-generated method stub
    
  }
    @Override
    public boolean isClusterable() {
        return true;
    }

    @Override
    public boolean isCritical() {
        return true;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public void setExplicitTics(double[] tickPositions){
        mTickPositions = tickPositions;
    }
    public void unsetExplicitTics(){
        mTickPositions = null;
    }
}




Java Source Code List

com.wildplot.android.ankistats.AnkiDb.java
com.wildplot.android.ankistats.AnkiStatsActivity.java
com.wildplot.android.ankistats.AnkiStatsApplication.java
com.wildplot.android.ankistats.AnswerButton.java
com.wildplot.android.ankistats.ApplicationTest.java
com.wildplot.android.ankistats.CardsTypes.java
com.wildplot.android.ankistats.CollectionData.java
com.wildplot.android.ankistats.Forecast.java
com.wildplot.android.ankistats.HourlyBreakdown.java
com.wildplot.android.ankistats.Intervals.java
com.wildplot.android.ankistats.ReviewCount.java
com.wildplot.android.ankistats.Utils.java
com.wildplot.android.ankistats.WeeklyBreakdown.java
com.wildplot.android.parsing.Atom.java
com.wildplot.android.parsing.ExpressionFormatException.java
com.wildplot.android.parsing.Expression.java
com.wildplot.android.parsing.Factor.java
com.wildplot.android.parsing.Pow.java
com.wildplot.android.parsing.Term.java
com.wildplot.android.parsing.TopLevelParser.java
com.wildplot.android.parsing.TreeElement.java
com.wildplot.android.parsing.AtomTypes.FunctionXAtom.java
com.wildplot.android.parsing.AtomTypes.FunctionXYAtom.java
com.wildplot.android.parsing.AtomTypes.MathFunctionAtom.java
com.wildplot.android.parsing.AtomTypes.NumberAtom.java
com.wildplot.android.parsing.AtomTypes.VariableAtom.java
com.wildplot.android.parsing.AtomTypes.XVariableAtom.java
com.wildplot.android.parsing.AtomTypes.YVariableAtom.java
com.wildplot.android.rendering.AdvancedPlotSheet.java
com.wildplot.android.rendering.BarGraph.java
com.wildplot.android.rendering.DrawableContainer.java
com.wildplot.android.rendering.FunctionDrawer.java
com.wildplot.android.rendering.FunctionDrawer_y.java
com.wildplot.android.rendering.Integral.java
com.wildplot.android.rendering.LegendDrawable.java
com.wildplot.android.rendering.LinesPoints.java
com.wildplot.android.rendering.Lines.java
com.wildplot.android.rendering.MultiScreenPart.java
com.wildplot.android.rendering.PieChart.java
com.wildplot.android.rendering.PlotSheet.java
com.wildplot.android.rendering.PointDrawer2D.java
com.wildplot.android.rendering.RelativeColorGradient.java
com.wildplot.android.rendering.ReliefDrawer.java
com.wildplot.android.rendering.XAxisBarGraph.java
com.wildplot.android.rendering.XAxisHistoGram.java
com.wildplot.android.rendering.XAxis.java
com.wildplot.android.rendering.XGrid.java
com.wildplot.android.rendering.YAxisBarGraph.java
com.wildplot.android.rendering.YAxisHistoGram.java
com.wildplot.android.rendering.YAxis.java
com.wildplot.android.rendering.YGrid.java
com.wildplot.android.rendering.graphics.wrapper.BasicStroke.java
com.wildplot.android.rendering.graphics.wrapper.BufferedImage.java
com.wildplot.android.rendering.graphics.wrapper.Color.java
com.wildplot.android.rendering.graphics.wrapper.FontMetrics.java
com.wildplot.android.rendering.graphics.wrapper.Graphics2D.java
com.wildplot.android.rendering.graphics.wrapper.Graphics.java
com.wildplot.android.rendering.graphics.wrapper.Rectangle.java
com.wildplot.android.rendering.graphics.wrapper.Stroke.java
com.wildplot.android.rendering.interfaces.Drawable.java
com.wildplot.android.rendering.interfaces.Function2D.java
com.wildplot.android.rendering.interfaces.Function3D.java
com.wildplot.android.rendering.interfaces.Legendable.java
com.wildplot.android.rendering.interfaces.StepFunction2D.java