Removed dead code, fixed centerViewPort(...) issue.
This commit is contained in:
parent
f179354e23
commit
797a553017
5 changed files with 44 additions and 72 deletions
|
@ -52,6 +52,9 @@ public class LineChartFrag extends SimpleFragment {
|
|||
|
||||
mChart.setData(getComplexity());
|
||||
|
||||
// mChart.setScaleMinima(3f, 3f);
|
||||
// mChart.centerViewPort(300, 0);
|
||||
|
||||
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
|
||||
|
||||
mChart.setYLabelTypeface(tf);
|
||||
|
|
|
@ -303,9 +303,9 @@ public abstract class BarLineChartBase extends Chart {
|
|||
|
||||
if (mLegend == null)
|
||||
return;
|
||||
|
||||
|
||||
Log.i(LOG_TAG, "Offsets calculated.");
|
||||
|
||||
|
||||
// setup offsets for legend
|
||||
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
|
||||
|
||||
|
@ -431,29 +431,29 @@ public abstract class BarLineChartBase extends Chart {
|
|||
mMatrixOffset.set(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Calculates the offsets that belong to the legend, this method is only
|
||||
* relevant when drawing into the chart. It can be used to refresh the
|
||||
* legend.
|
||||
*/
|
||||
public void calculateLegendOffsets() {
|
||||
|
||||
// setup offsets for legend
|
||||
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
|
||||
public void calculateLegendOffsets() {
|
||||
|
||||
mLegend.setOffsetRight(mLegend.getMaximumEntryLength(mLegendLabelPaint));
|
||||
mLegendLabelPaint.setTextAlign(Align.LEFT);
|
||||
// setup offsets for legend
|
||||
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
|
||||
|
||||
} else if (mLegend.getPosition() == LegendPosition.BELOW_CHART_LEFT
|
||||
|| mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT) {
|
||||
mLegend.setOffsetRight(mLegend.getMaximumEntryLength(mLegendLabelPaint));
|
||||
mLegendLabelPaint.setTextAlign(Align.LEFT);
|
||||
|
||||
if (mXLabels.getPosition() == XLabelPosition.TOP)
|
||||
mLegend.setOffsetBottom(mLegendLabelPaint.getTextSize() * 3.5f);
|
||||
else {
|
||||
mLegend.setOffsetBottom(mLegendLabelPaint.getTextSize() * 2.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mLegend.getPosition() == LegendPosition.BELOW_CHART_LEFT
|
||||
|| mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT) {
|
||||
|
||||
if (mXLabels.getPosition() == XLabelPosition.TOP)
|
||||
mLegend.setOffsetBottom(mLegendLabelPaint.getTextSize() * 3.5f);
|
||||
else {
|
||||
mLegend.setOffsetBottom(mLegendLabelPaint.getTextSize() * 2.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates the modulus for x-labels and grid
|
||||
|
@ -501,14 +501,14 @@ public abstract class BarLineChartBase extends Chart {
|
|||
|
||||
// additional handling for space (default 10% space), spacing only
|
||||
// applies with non-rounded y-label
|
||||
float space = mDeltaY / 100f * 10f;
|
||||
float space = mDeltaY / 100f * 10f;
|
||||
|
||||
if (mStartAtZero) {
|
||||
mYChartMin = 0;
|
||||
} else {
|
||||
mYChartMin = mYChartMin - space;
|
||||
}
|
||||
|
||||
|
||||
// calc delta
|
||||
mYChartMax = mYChartMax + space;
|
||||
mDeltaY = Math.abs(mYChartMax - mYChartMin);
|
||||
|
@ -979,8 +979,8 @@ public abstract class BarLineChartBase extends Chart {
|
|||
* Centers the viewport around the specified x-index and the specified
|
||||
* y-value in the chart. Centering the viewport outside the bounds of the
|
||||
* chart is not possible. Makes most sense in combination with the
|
||||
* setScaleMinima(...) method. SHOULD BE CALLED AFTER setting data for the
|
||||
* chart.
|
||||
* setScaleMinima(...) method. First set the scale minima, then center the
|
||||
* viewport. SHOULD BE CALLED AFTER setting data for the chart.
|
||||
*
|
||||
* @param xIndex the index on the x-axis to center to
|
||||
* @param yVal the value ont he y-axis to center to
|
||||
|
@ -997,6 +997,9 @@ public abstract class BarLineChartBase extends Chart {
|
|||
float indicesInView = mDeltaX / mScaleX;
|
||||
float valsInView = mDeltaY / mScaleY;
|
||||
|
||||
// Log.i(LOG_TAG, "indices: " + indicesInView + ", vals: " +
|
||||
// valsInView);
|
||||
|
||||
float[] pts = new float[] {
|
||||
xIndex - indicesInView / 2f, yVal + valsInView / 2f
|
||||
};
|
||||
|
@ -1011,7 +1014,7 @@ public abstract class BarLineChartBase extends Chart {
|
|||
|
||||
save.postTranslate(x, y);
|
||||
|
||||
refreshTouchNoInvalidate(save);
|
||||
refreshTouch(save);
|
||||
|
||||
// Log.i(LOG_TAG, "ViewPort centered, xIndex: " + xIndex +
|
||||
// ", yVal: " + yVal
|
||||
|
@ -1649,17 +1652,20 @@ public abstract class BarLineChartBase extends Chart {
|
|||
public float getScaleY() {
|
||||
return mScaleY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* if the chart is fully zoomed out, return true
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isFullyZoomedOut() {
|
||||
|
||||
// Log.i(LOG_TAG, "MinScaleX: " + mMinScaleX + ", ScaleX: " + mScaleX);
|
||||
|
||||
if(mScaleX <= mMinScaleX && mScaleY <= mMinScaleY) return true;
|
||||
else return false;
|
||||
|
||||
// Log.i(LOG_TAG, "MinScaleX: " + mMinScaleX + ", ScaleX: " + mScaleX);
|
||||
|
||||
if (mScaleX <= mMinScaleX && mScaleY <= mMinScaleY)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,10 +27,7 @@ public class ChartData {
|
|||
|
||||
/** holds all the datasets (e.g. different lines) the chart represents */
|
||||
private ArrayList<DataSet> mDataSets;
|
||||
|
||||
/** array that holds all the different labels that are in the DataSet array */
|
||||
private ArrayList<String> mDiffLabels;
|
||||
|
||||
|
||||
/**
|
||||
* constructor for chart data
|
||||
*
|
||||
|
@ -76,7 +73,6 @@ public class ChartData {
|
|||
this.mXVals = xVals;
|
||||
this.mDataSets = dataSets;
|
||||
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
|
||||
|
@ -102,31 +98,10 @@ public class ChartData {
|
|||
* Does all necessary calculations, if the underlying data has changed
|
||||
*/
|
||||
private void doCalculations() {
|
||||
calcTypes();
|
||||
calcMinMax();
|
||||
calcYValueSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates all different labels that occur in the DataSets and stores
|
||||
* them for fast access
|
||||
*/
|
||||
private void calcTypes() {
|
||||
mDiffLabels = new ArrayList<String>();
|
||||
|
||||
// check which dataset to use
|
||||
ArrayList<DataSet> dataSets = mDataSets;
|
||||
|
||||
for (int i = 0; i < dataSets.size(); i++) {
|
||||
|
||||
String label = dataSets.get(i).getLabel();
|
||||
|
||||
if (!alreadyCounted(mDiffLabels, label)) {
|
||||
mDiffLabels.add(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calc minimum and maximum y value over all datasets
|
||||
*/
|
||||
|
@ -161,6 +136,9 @@ public class ChartData {
|
|||
}
|
||||
|
||||
private boolean alreadyCounted(ArrayList<String> countedLabels, String label) {
|
||||
|
||||
if(label == null) return true;
|
||||
|
||||
for (int i = 0; i < countedLabels.size(); i++) {
|
||||
if (countedLabels.get(i).equals(label))
|
||||
return true;
|
||||
|
@ -302,15 +280,6 @@ public class ChartData {
|
|||
return mDataSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns all the different DataSet labels the chartdata represents
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getLabels() {
|
||||
return mDiffLabels;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the total number of x-values this chartdata represents (the size
|
||||
* of the xvals array)
|
||||
|
|
|
@ -30,10 +30,7 @@ public class DrawingContext {
|
|||
// if an old one exist, finish the other one first
|
||||
finishNewDrawingEntry(chartData);
|
||||
}
|
||||
// keep type count correct
|
||||
if (!chartData.getLabels().contains(mLastDrawnDataSetIndex)) {
|
||||
chartData.getLabels().add("DS " + mLastDrawnDataSetIndex);
|
||||
}
|
||||
|
||||
mCurrentDrawingEntries = new ArrayList<Entry>();
|
||||
this.mCurrentDrawingDataSet = new DataSet(mCurrentDrawingEntries, "DS " + mLastDrawnDataSetIndex);
|
||||
chartData.getDataSets().add(mCurrentDrawingDataSet);
|
||||
|
|
|
@ -86,10 +86,7 @@ public abstract class Utils {
|
|||
* @return
|
||||
*/
|
||||
public static int calcTextWidth(Paint paint, String demoText) {
|
||||
|
||||
Rect r = new Rect();
|
||||
paint.getTextBounds(demoText, 0, demoText.length(), r);
|
||||
return r.width();
|
||||
return (int) paint.measureText(demoText);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue