Android Open Source - AndroidGraph Line






From Project

Back to project page AndroidGraph.

License

The source code is released under:

MIT License

If you think the Android project AndroidGraph 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.nimble.android_graph.Graph;
/*from  w w  w.  j a  v a2  s . co m*/
import android.graphics.Color;

import java.util.ArrayList;

import com.nimble.android_graph.Graph_Base.Range2d;
import com.nimble.android_graph.Graph_Base.Point;

/**
 * Created by Michael Leith on 18/07/2014.
 */
public class Line {

    ArrayList<Point> points;
    int colour = Color.BLACK;
    int shadow = Color.DKGRAY;
    private boolean useShadow;
    int startPoint = 0, endPoint = 0;
    boolean incrementStartPoint = true;

    Range2d widthLimit = new Range2d();
    Range2d heightLimit = new Range2d();
    Range2d margin = new Range2d();

    float distBetweenPoints = 0.5f;

    public Line() 
    {
        points = new ArrayList<Point>();
        useShadow = false;
    }

    public void addPoint(float x, float y)
    {
        addPoint( new Point(x, y) );
    }

    public void addPoint(Point point)
    {
        if(widthLimit.length <= 0 || heightLimit.length <= 0)
            return;

        if(points == null)
            points = new ArrayList<Point>();
        points.add(point);

        if( outOfBounds(point.x - points.get(startPoint).graphSpaceX )) // Check dimensions have been measured :) FIX
            incrementStartPoint();
        endPoint++;
    }

    /**
     * Add directly beside previous point.
     * @param y
     */
    public void linearAdd(float y) {
        if (!points.isEmpty())
        {
            float x = points.get(points.size() - 1).graphSpaceX + distBetweenPoints;
            addPoint(x, y);
        }
        else
            addPoint(0, y);
    }

    public float getNextX()
    {
        if(!points.isEmpty())
            return points.get(points.size() - 1).graphSpaceX + distBetweenPoints;
        return 0;
    }


    private boolean outOfBounds(float x) //only x-axis for now.
    {
        return (x > (widthLimit.length + 20f));
    }

    public void updateWidthLimit(Range2d width, Range2d height, Range2d margin)
    {
        widthLimit = width;
        heightLimit = height;
        this.margin = margin;
    }

    private void incrementStartPoint()
    {
        if(incrementStartPoint)
            startPoint++;
    }

    public void modifyStartPoint(int startPointOffset)
    {
        int start = startPoint + startPointOffset;

        if(start < 0 || start >= points.size()) //don't draw line.
            return;
        startPoint += startPointOffset;
        endPoint += startPointOffset > points.size() ? points.size() : startPointOffset ;
    }

    public void setIncrementStartPoint(boolean state)
    {
        incrementStartPoint = state;
    }

    public void setColour(int newColour)
    {
        colour = newColour;
    }

    public void setShadow(int newShadow)
    {
        shadow = newShadow;
        useShadow = true;
    }

    public void setUseShadow(boolean status)
    {
        useShadow = status;
    }

    public boolean isUseShadow()
    {
        return useShadow;
    }

}




Java Source Code List

Nimble.com.androidgraph.ApplicationTest.java
com.nimble.android_graph.Activities.FragmentList.java
com.nimble.android_graph.Activities.GraphActivity.java
com.nimble.android_graph.Activities.GraphFragment.java
com.nimble.android_graph.Activities.GroupsFragment.java
com.nimble.android_graph.Graph.CurveGraph.java
com.nimble.android_graph.Graph.LineGraph.java
com.nimble.android_graph.Graph.Line.java
com.nimble.android_graph.Graph.ScatterGraph.java
com.nimble.android_graph.Graph.SineWave.java
com.nimble.android_graph.Graph_Base.Coord2d.java
com.nimble.android_graph.Graph_Base.GraphDataSettings.java
com.nimble.android_graph.Graph_Base.GraphDrawBackground.java
com.nimble.android_graph.Graph_Base.GraphRelateToScreen.java
com.nimble.android_graph.Graph_Base.GraphThreading.java
com.nimble.android_graph.Graph_Base.GraphTouchEvent.java
com.nimble.android_graph.Graph_Base.GraphViewDimensions.java
com.nimble.android_graph.Graph_Base.GraphView.java
com.nimble.android_graph.Graph_Base.Point.java
com.nimble.android_graph.Graph_Base.Range2d.java
com.nimble.android_graph.Graph.sine_scatter.java
com.nimble.android_graph.generics.Methods.java
com.nimble.android_graph.generics.ViewManipulators.java
com.nimble.android_graph.generics.testingSuite.java