Android Open Source - AndroidGraph Graph Relate To Screen






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_Base;
//w  ww  .ja  v  a 2 s.  c  o m
import android.content.Context;
import android.util.AttributeSet;

/**
 * Abstract class inherited by GraphView for converting a given x, y coordinate to graph dimensions.
 * Created by Mike on 25/07/2014.
 */
public abstract class GraphRelateToScreen extends GraphDrawBackground {

    public final static int ORIGIN_LOWER = 0;
    public final static int ORIGIN_HIGHER = 1;

    protected Point maxDisplayedValue;
    protected Point minDisplayedValue;

    GraphRelateToScreen(Context context)
    {
        super(context);
        maxDisplayedValue = new Point();
        minDisplayedValue = new Point();
    }

    public GraphRelateToScreen(Context context, AttributeSet attr)
    {
        super(context, attr);
    }

    /**
     * Given graph coord, output screen coord.
     *
     * @param point
     * @return
     */
    public Point convToScreenCoords(Point point, int origin) {
        if (graphHeight.y <= 0)
            return point; //to do.
        switch (origin) {
            case (ORIGIN_LOWER):
                point.x = graphWidth.x + point.x;
                point.y = graphHeight.y - point.y;
                break;
            case (ORIGIN_HIGHER):
                point.x = graphWidth.x + point.x;
                point.y = point.y + margin.y;
                break;
            default:
                break;
        }
        return point;
    }

    public Point convToScreenCoords(float x, float y, int origin) {
        Point point = new Point(x, y);
        return convToScreenCoords(point, origin);
    }

    public void setMaxDisplayedValue(Point point)
    {
        maxDisplayedValue = point;
    }

    public void setMaxDisplayedValue(int x, int y)
    {
       setMaxDisplayedValue( new Point(x, y) );
    }

    public void setMinDisplayedValue(Point point)
    {
        minDisplayedValue = point;
    }

    public void setMinDisplayedValue(int x, int y)
    {
        setMinDisplayedValue( new Point(x, y) );
    }
}




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