Android Open Source - how-many-squirrels-android Graph Properties






From Project

Back to project page how-many-squirrels-android.

License

The source code is released under:

GNU General Public License

If you think the Android project how-many-squirrels-android 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

package com.howmuchof.squirrels.common.graphview;
// w w w.j a  v a 2s . c o m
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

/*
  * How many squirrels: tool for young naturalist
  *
  * This application is created within the internship
  * in the Education Department of Tomsksoft, http://tomsksoft.com
  * Idea and leading: Sergei Borisov
  *
  * This software is licensed under a GPL v3
  * http://www.gnu.org/licenses/gpl.txt
  *
  * Created by Viacheslav Voronov on 5/1/2014
  */

public class GraphProperties {

    public static int HOR_VALUES_DEFAULT_FORMAT = 0;
    public static int HOR_VALUES_DATE_FORMAT = 1;

    int xFormat = 0;
    Canvas canvas;

    int height;
    int width;

    int minVertValue;
    int maxVertValue;

    int maxHorzValue;
    int minHorzValue;

    Paint gridPaint;
    Paint horzLabelsPaint;
    Paint vertLabelsPaint;
    Paint barPaint;
    Paint bar3DPaint;

    int topBottomIndent;
    int graphIndent;
    int columnWidth;
    int marginLeft;
    int marginColumnLeft;

    public GraphProperties(){
        gridPaint = new Paint();
        gridPaint.setColor(Color.parseColor("#C9C9C9"));
        gridPaint.setStrokeWidth(2);

        barPaint = new Paint();
        barPaint.setColor(Color.BLUE);

        bar3DPaint = new Paint();
        bar3DPaint.setColor(Color.parseColor("#53DED5"));
        bar3DPaint.setStrokeWidth(5);

        topBottomIndent = 90;
        graphIndent = 15;
        columnWidth = 160;
        marginLeft = 10;
        marginColumnLeft = 40;

        horzLabelsPaint = new Paint();
        horzLabelsPaint.setTextSize(35);
        horzLabelsPaint.setTextAlign(Paint.Align.CENTER);

    }

    public Paint getHorzLabelPaint(){
        return horzLabelsPaint;
    }

    public Paint getVertLabelsPaint(){
        return vertLabelsPaint;
    }

    public Paint getGridPaint(){
        return gridPaint;
    }

    public Paint getBarPaint(){
        return barPaint;
    }

    public Paint getBar3DPaint(){
        return bar3DPaint;
    }

    public int getMinVertValue(){
        return minVertValue;
    }

    public int getMaxVertValue(){
        return maxVertValue;
    }

    public void setMinVertValue (int value){
        minVertValue = value;
    }

    public void setMaxVertValue (int value){
        maxVertValue = value;
    }

    public void setXFormat(int format){
        if ((format == HOR_VALUES_DATE_FORMAT)||(format == HOR_VALUES_DEFAULT_FORMAT)){
            xFormat = format;
        }
    }

    public int getXFormat(){
        return xFormat;
    }

    public void setCanvas(Canvas canvas){
        this.canvas = canvas;
        height = canvas.getHeight();
        width = canvas.getWidth();
    }

    public int getTopBottomIndent(){
        return topBottomIndent;
    }

    public void setTopBottomIndent(int value){
        topBottomIndent = value;
    }

    public int getGraphIndent(){
        return graphIndent;
    }

    public void setGraphIndent(int value){
        graphIndent = value;
    }

    public int getColumnWidth(){
        return columnWidth;
    }

    public int getMarginLeft(){
        return marginLeft;
    }

    public int getMarginColumnLeft(){
        return marginColumnLeft;
    }

    public void setColumnWidth(int value){
        columnWidth = value;
    }

    public void setMarginLeft(int value){
        marginLeft = value;
    }

    public void setMarginColumnLeft(int value){
        marginColumnLeft = value;
    }

    public int getHeight(){
        return height;
    }

    public int getWidth(){
        return width;
    }

    public GraphLine getGraphBarCoordinates(double yValue, int curGraph){
        int topY = height - (int)((height - topBottomIndent*2)*((yValue - minVertValue+1)/(maxVertValue - minVertValue + 2))+topBottomIndent);
        int topX = curGraph * (columnWidth + graphIndent) + marginColumnLeft + marginLeft;
        int botY = height - topBottomIndent;
        int botX = topX + columnWidth;

        GraphLine graphLine = new GraphLine();
        graphLine.setGraphBarValues(topX, topY, botX, botY);
        return graphLine;
    }

    public int getGridYPos(float value){
        return height - (int)((height - topBottomIndent*2)*((value - minVertValue+1)/(maxVertValue - minVertValue + 2))+topBottomIndent);
    }

    public int getGraphWidth(int graphAmount){
        return graphAmount * (graphIndent + columnWidth) + marginColumnLeft + marginLeft;
    }
}




Java Source Code List

com.howmuchof.squirrels.android.AddDataActivity.java
com.howmuchof.squirrels.android.DBHelper.java
com.howmuchof.squirrels.android.GraphViewFragment.java
com.howmuchof.squirrels.android.ListViewFragment.java
com.howmuchof.squirrels.android.MainActivity.java
com.howmuchof.squirrels.android.MainFragmentActivity.java
com.howmuchof.squirrels.android.ModifyDataActivity.java
com.howmuchof.squirrels.android.SettingsActivity.java
com.howmuchof.squirrels.android.Squirrel.java
com.howmuchof.squirrels.common.graphview.GraphLine.java
com.howmuchof.squirrels.common.graphview.GraphManager.java
com.howmuchof.squirrels.common.graphview.GraphProperties.java