Skip to content

Commit

Permalink
removing / adding series redraws the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoe64 committed Jul 25, 2013
1 parent f669b35 commit d816483
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
target=android-17
android.library=true
72 changes: 41 additions & 31 deletions src/com/jjoe64/graphview/GraphView.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,6 @@ public GraphView(Context context, String title) {
addView(graphViewContentView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1));
}

public GraphViewStyle getGraphViewStyle() {
return graphViewStyle;
}

public void setGraphViewStyle(GraphViewStyle style) {
graphViewStyle = style;
}

public void setTitle(String title) {
this.title = title;
}

private GraphViewData[] _values(int idxSeries) {
GraphViewData[] values = graphSeries.get(idxSeries).values;
if (viewportStart == 0 && viewportSize == 0) {
Expand Down Expand Up @@ -337,6 +325,7 @@ private GraphViewData[] _values(int idxSeries) {
public void addSeries(GraphViewSeries series) {
series.addGraphView(this);
graphSeries.add(series);
redrawAll();
}

protected void drawLegend(Canvas canvas, float height, float width) {
Expand Down Expand Up @@ -436,6 +425,10 @@ synchronized private String[] generateVerlabels(float graphheight) {
return labels;
}

public GraphViewStyle getGraphViewStyle() {
return graphViewStyle;
}

public LegendAlign getLegendAlign() {
return legendAlign;
}
Expand Down Expand Up @@ -550,14 +543,14 @@ protected double getMinY() {
return smallest;
}

public boolean isScrollable() {
return scrollable;
}

public boolean isDisableTouch() {
return disableTouch;
}

public boolean isScrollable() {
return scrollable;
}

public boolean isShowLegend() {
return showLegend;
}
Expand All @@ -572,19 +565,28 @@ public void redrawAll() {
graphViewContentView.invalidate();
}

public void removeSeries(GraphViewSeries series)
{
public void removeAllSeries() {
for (GraphViewSeries s : graphSeries) {
s.removeGraphView(this);
}
while (!graphSeries.isEmpty()) {
graphSeries.remove(0);
}
redrawAll();
}

public void removeSeries(GraphViewSeries series) {
series.removeGraphView(this);
graphSeries.remove(series);
redrawAll();
}

public void removeSeries(int index)
{
if (index < 0 || index >= graphSeries.size())
{
public void removeSeries(int index) {
if (index < 0 || index >= graphSeries.size()) {
throw new IndexOutOfBoundsException("No series at index " + index);
}

graphSeries.remove(index);
removeSeries(graphSeries.get(index));
}

public void scrollToEnd() {
Expand All @@ -594,6 +596,18 @@ public void scrollToEnd() {
redrawAll();
}

/**
* The user can disable any touch gestures, this is useful if you are using a real time graph, but don't want the user to interact
* @param disableTouch
*/
public void setDisableTouch(boolean disableTouch) {
this.disableTouch = disableTouch;
}

public void setGraphViewStyle(GraphViewStyle style) {
graphViewStyle = style;
}

/**
* set's static horizontal labels (from left to right)
* @param horlabels if null, labels were generated automatically
Expand Down Expand Up @@ -678,19 +692,15 @@ public boolean onScale(ScaleGestureDetector detector) {
public void setScrollable(boolean scrollable) {
this.scrollable = scrollable;
}

/**
* The user can disable any touch gestures, this is useful if you are using a real time graph, but don't want the user to interact
* @param disableTouch
*/
public void setDisableTouch(boolean disableTouch) {
this.disableTouch = disableTouch;
}

public void setShowLegend(boolean showLegend) {
this.showLegend = showLegend;
}

public void setTitle(String title) {
this.title = title;
}

/**
* set's static vertical labels (from top to bottom)
* @param verlabels if null, labels were generated automatically
Expand Down
13 changes: 7 additions & 6 deletions src/com/jjoe64/graphview/GraphViewSeries.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.jjoe64.graphview;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.annotation.TargetApi;

import com.jjoe64.graphview.GraphView.GraphViewData;

public class GraphViewSeries {
Expand All @@ -25,12 +22,12 @@ public GraphViewSeriesStyle(int color, int thickness) {
this.color = color;
this.thickness = thickness;
}
public void setValueDependentColor(ValueDependentColor valueDependentColor) {
this.valueDependentColor = valueDependentColor;
}
public ValueDependentColor getValueDependentColor() {
return valueDependentColor;
}
public void setValueDependentColor(ValueDependentColor valueDependentColor) {
this.valueDependentColor = valueDependentColor;
}
}

final String description;
Expand Down Expand Up @@ -81,6 +78,10 @@ public void appendData(GraphViewData value, boolean scrollToEnd) {
}
}

public void removeGraphView(GraphView graphView) {
graphViews.remove(graphView);
}

/**
* clears the current data and set the new.
* redraws the graphview(s)
Expand Down

0 comments on commit d816483

Please sign in to comment.