Fixes related to combinedchart #1853
This commit is contained in:
parent
63eb7dfd91
commit
84160773ed
7 changed files with 139 additions and 62 deletions
|
@ -9,5 +9,8 @@
|
|||
android:id="@+id/actionToggleBarValues"
|
||||
android:title="Toggle bar Values">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionRemoveDataSet"
|
||||
android:title="Remove random set">
|
||||
</item>
|
||||
</menu>
|
|
@ -125,7 +125,7 @@ public class CombinedChartActivity extends DemoBase {
|
|||
set.setValueTextColor(Color.rgb(240, 238, 70));
|
||||
|
||||
set.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||
|
||||
this.set1 = set;
|
||||
d.addDataSet(set);
|
||||
|
||||
return d;
|
||||
|
@ -209,6 +209,9 @@ public class CombinedChartActivity extends DemoBase {
|
|||
return d;
|
||||
}
|
||||
|
||||
private LineDataSet set1;
|
||||
private BubbleDataSet set2;
|
||||
|
||||
protected BubbleData generateBubbleData() {
|
||||
|
||||
BubbleData bd = new BubbleData();
|
||||
|
@ -227,6 +230,7 @@ public class CombinedChartActivity extends DemoBase {
|
|||
set.setValueTextColor(Color.WHITE);
|
||||
set.setHighlightCircleWidth(1.5f);
|
||||
set.setDrawValues(true);
|
||||
this.set2 = set;
|
||||
bd.addDataSet(set);
|
||||
|
||||
return bd;
|
||||
|
@ -259,6 +263,15 @@ public class CombinedChartActivity extends DemoBase {
|
|||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
case R.id.actionRemoveDataSet: {
|
||||
|
||||
int rnd = (int) getRandom(mChart.getData().getDataSetCount(), 0);
|
||||
mChart.getData().removeDataSet(mChart.getData().getDataSetByIndex(rnd));
|
||||
mChart.getData().notifyDataChanged();
|
||||
mChart.notifyDataSetChanged();
|
||||
mChart.invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -572,14 +572,14 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
}
|
||||
|
||||
/**
|
||||
* Highlights the value at the given x-index in the given DataSet. Provide
|
||||
* -1 as the x-index or dataSetIndex to undo all highlighting.
|
||||
* Highlights the value at the given x-position in the given DataSet. Provide
|
||||
* -1 as the dataSetIndex to undo all highlighting. This will trigger a callback to the OnChartValueSelectedListener.
|
||||
*
|
||||
* @param xIndex
|
||||
* @param x
|
||||
* @param dataSetIndex
|
||||
*/
|
||||
public void highlightValue(int xIndex, int dataSetIndex) {
|
||||
highlightValue(xIndex, dataSetIndex, true);
|
||||
public void highlightValue(float x, int dataSetIndex) {
|
||||
highlightValue(x, dataSetIndex, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -656,14 +656,6 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Calls highlightValue(high, true)
|
||||
*/
|
||||
@Deprecated
|
||||
public void highlightTouch(Highlight high) {
|
||||
highlightValue(high, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Highlight object (contains x-index and DataSet index) of the
|
||||
* selected value at the given touch point inside the Line-, Scatter-, or
|
||||
|
|
|
@ -11,13 +11,7 @@ import com.github.mikephil.charting.data.CombinedData;
|
|||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.highlight.CombinedHighlighter;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.CombinedDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
|
||||
import com.github.mikephil.charting.renderer.CombinedChartRenderer;
|
||||
|
||||
/**
|
||||
|
@ -28,11 +22,6 @@ import com.github.mikephil.charting.renderer.CombinedChartRenderer;
|
|||
*/
|
||||
public class CombinedChart extends BarLineChartBase<CombinedData> implements CombinedDataProvider {
|
||||
|
||||
// /**
|
||||
// * flag that enables or disables the highlighting arrow
|
||||
// */
|
||||
// private boolean mDrawHighlightArrow = false;
|
||||
|
||||
/**
|
||||
* if set to true, all values are drawn above their bars, instead of below
|
||||
* their top
|
||||
|
@ -77,9 +66,6 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
|
||||
// Old default behaviour
|
||||
setHighlightFullBarEnabled(true);
|
||||
|
||||
// mRenderer = new CombinedChartRenderer(this, mAnimator,
|
||||
// mViewPortHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,15 +128,6 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
return mDrawValueAboveBar;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * set this to true to draw the highlightning arrow
|
||||
// *
|
||||
// * @param enabled
|
||||
// */
|
||||
// public void setDrawHighlightArrow(boolean enabled) {
|
||||
// mDrawHighlightArrow = enabled;
|
||||
// }
|
||||
|
||||
/**
|
||||
* If set to true, all values are drawn above their bars, instead of below
|
||||
* their top.
|
||||
|
|
|
@ -139,7 +139,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
mRightAxisMin = Float.MAX_VALUE;
|
||||
|
||||
// left axis
|
||||
T firstLeft = getFirstLeft();
|
||||
T firstLeft = getFirstLeft(mDataSets);
|
||||
|
||||
if (firstLeft != null) {
|
||||
|
||||
|
@ -158,7 +158,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
}
|
||||
|
||||
// right axis
|
||||
T firstRight = getFirstRight();
|
||||
T firstRight = getFirstRight(mDataSets);
|
||||
|
||||
if (firstRight != null) {
|
||||
|
||||
|
@ -613,8 +613,8 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public T getFirstLeft() {
|
||||
for (T dataSet : mDataSets) {
|
||||
protected T getFirstLeft(List<T> sets) {
|
||||
for (T dataSet : sets) {
|
||||
if (dataSet.getAxisDependency() == AxisDependency.LEFT)
|
||||
return dataSet;
|
||||
}
|
||||
|
@ -627,8 +627,8 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public T getFirstRight() {
|
||||
for (T dataSet : mDataSets) {
|
||||
public T getFirstRight(List<T> sets) {
|
||||
for (T dataSet : sets) {
|
||||
if (dataSet.getAxisDependency() == AxisDependency.RIGHT)
|
||||
return dataSet;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
package com.github.mikephil.charting.data;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
|
@ -11,7 +14,7 @@ import java.util.List;
|
|||
/**
|
||||
* Data object that allows the combination of Line-, Bar-, Scatter-, Bubble- and
|
||||
* CandleData. Used in the CombinedChart class.
|
||||
*
|
||||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleDataSet<? extends Entry>> {
|
||||
|
@ -28,34 +31,81 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
|
|||
|
||||
public void setData(LineData data) {
|
||||
mLineData = data;
|
||||
mDataSets.addAll(data.getDataSets());
|
||||
init();
|
||||
}
|
||||
|
||||
public void setData(BarData data) {
|
||||
mBarData = data;
|
||||
mDataSets.addAll(data.getDataSets());
|
||||
init();
|
||||
}
|
||||
|
||||
public void setData(ScatterData data) {
|
||||
mScatterData = data;
|
||||
mDataSets.addAll(data.getDataSets());
|
||||
init();
|
||||
}
|
||||
|
||||
public void setData(CandleData data) {
|
||||
mCandleData = data;
|
||||
mDataSets.addAll(data.getDataSets());
|
||||
init();
|
||||
}
|
||||
|
||||
public void setData(BubbleData data) {
|
||||
mBubbleData = data;
|
||||
mDataSets.addAll(data.getDataSets());
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcMinMax() {
|
||||
|
||||
mDataSets = new ArrayList<>();
|
||||
|
||||
mYMax = -Float.MAX_VALUE;
|
||||
mYMin = Float.MAX_VALUE;
|
||||
mXMax = -Float.MAX_VALUE;
|
||||
mXMin = Float.MAX_VALUE;
|
||||
|
||||
mLeftAxisMax = -Float.MAX_VALUE;
|
||||
mLeftAxisMin = Float.MAX_VALUE;
|
||||
mRightAxisMax = -Float.MAX_VALUE;
|
||||
mRightAxisMin = Float.MAX_VALUE;
|
||||
|
||||
List<BarLineScatterCandleBubbleData> allData = getAllData();
|
||||
|
||||
for (ChartData data : allData) {
|
||||
|
||||
data.calcMinMax();
|
||||
|
||||
List<IBarLineScatterCandleBubbleDataSet<? extends Entry>> sets = data.getDataSets();
|
||||
mDataSets.addAll(sets);
|
||||
|
||||
if (data.getYMax() > mYMax)
|
||||
mYMax = data.getYMax();
|
||||
|
||||
if (data.getYMin() < mYMin)
|
||||
mYMin = data.getYMin();
|
||||
|
||||
if (data.getXMax() > mXMax)
|
||||
mXMax = data.getXMax();
|
||||
|
||||
if (data.getXMin() < mXMin)
|
||||
mXMin = data.getXMin();
|
||||
|
||||
if (data.mLeftAxisMax > mLeftAxisMax)
|
||||
mLeftAxisMax = data.mLeftAxisMax;
|
||||
|
||||
if (data.mLeftAxisMin < mLeftAxisMin)
|
||||
mLeftAxisMin = data.mLeftAxisMin;
|
||||
|
||||
if (data.mRightAxisMax > mRightAxisMax)
|
||||
mRightAxisMax = data.mRightAxisMax;
|
||||
|
||||
if (data.mRightAxisMin < mRightAxisMin)
|
||||
mRightAxisMin = data.mRightAxisMin;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BubbleData getBubbleData() {
|
||||
return mBubbleData;
|
||||
}
|
||||
|
@ -78,26 +128,27 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
|
|||
|
||||
/**
|
||||
* Returns all data objects in row: line-bar-scatter-candle-bubble if not null.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<ChartData> getAllData() {
|
||||
public List<BarLineScatterCandleBubbleData> getAllData() {
|
||||
|
||||
List<ChartData> data = new ArrayList<ChartData>();
|
||||
if(mLineData != null)
|
||||
List<BarLineScatterCandleBubbleData> data = new ArrayList<BarLineScatterCandleBubbleData>();
|
||||
if (mLineData != null)
|
||||
data.add(mLineData);
|
||||
if(mBarData != null)
|
||||
if (mBarData != null)
|
||||
data.add(mBarData);
|
||||
if(mScatterData != null)
|
||||
if (mScatterData != null)
|
||||
data.add(mScatterData);
|
||||
if(mCandleData != null)
|
||||
if (mCandleData != null)
|
||||
data.add(mCandleData);
|
||||
if(mBubbleData != null)
|
||||
if (mBubbleData != null)
|
||||
data.add(mBubbleData);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public ChartData getDataByIndex(int index) {
|
||||
public BarLineScatterCandleBubbleData getDataByIndex(int index) {
|
||||
return getAllData().get(index);
|
||||
}
|
||||
|
||||
|
@ -126,7 +177,7 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
|
|||
@Override
|
||||
public Entry getEntryForHighlight(Highlight highlight) {
|
||||
|
||||
List<ChartData> dataObjects = getAllData();
|
||||
List<BarLineScatterCandleBubbleData> dataObjects = getAllData();
|
||||
|
||||
if (highlight.getDataIndex() >= dataObjects.size())
|
||||
return null;
|
||||
|
@ -142,9 +193,9 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
|
|||
List<?> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
|
||||
.getEntriesForXPos(highlight.getX());
|
||||
for (Object entry : entries)
|
||||
if (((Entry)entry).getY() == highlight.getY() ||
|
||||
if (((Entry) entry).getY() == highlight.getY() ||
|
||||
Float.isNaN(highlight.getY()))
|
||||
return (Entry)entry;
|
||||
return (Entry) entry;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -153,4 +204,44 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
|
|||
public int getDataIndex(ChartData data) {
|
||||
return getAllData().indexOf(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDataSet(IBarLineScatterCandleBubbleDataSet<? extends Entry> d) {
|
||||
|
||||
List<BarLineScatterCandleBubbleData> datas = getAllData();
|
||||
|
||||
boolean success = false;
|
||||
|
||||
for (ChartData data : datas) {
|
||||
|
||||
success = data.removeDataSet(d);
|
||||
|
||||
if (success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean removeDataSet(int index) {
|
||||
Log.e("MPAndroidChart", "removeDataSet(int index) not supported for CombinedData");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean removeEntry(Entry e, int dataSetIndex) {
|
||||
Log.e("MPAndroidChart", "removeEntry(...) not supported for CombinedData");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean removeEntry(float xPos, int dataSetIndex) {
|
||||
Log.e("MPAndroidChart", "removeEntry(...) not supported for CombinedData");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.github.mikephil.charting.highlight;
|
||||
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.data.DataSet;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
|
||||
|
@ -32,7 +33,7 @@ public class CombinedHighlighter extends ChartHighlighter<CombinedDataProvider>
|
|||
|
||||
List<Highlight> vals = new ArrayList<Highlight>();
|
||||
|
||||
List<ChartData> dataObjects = mChart.getCombinedData().getAllData();
|
||||
List<BarLineScatterCandleBubbleData> dataObjects = mChart.getCombinedData().getAllData();
|
||||
|
||||
for (int i = 0; i < dataObjects.size(); i++) {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue