Renamed x-pos to x-value where appropriate

This commit is contained in:
Daniel Cohen Gindi 2016-08-08 10:14:58 +03:00
parent 77c10fc9e5
commit f63002e196
20 changed files with 76 additions and 78 deletions

View file

@ -202,7 +202,7 @@ public class BarChart extends BarLineChartBase<BarData> implements BarDataProvid
}
/**
* Highlights the value at the given x-position in the given DataSet. Provide
* Highlights the value at the given x-value in the given DataSet. Provide
* -1 as the dataSetIndex to undo all highlighting.
*
* @param x
@ -230,8 +230,8 @@ public class BarChart extends BarLineChartBase<BarData> implements BarDataProvid
}
/**
* Groups all BarDataSet objects this data object holds together by modifying the x-position of their entries.
* Previously set x-positions of entries will be overwritten. Leaves space between bars and groups as specified
* Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries.
* Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified
* by the parameters.
* Calls notifyDataSetChanged() afterwards.
*

View file

@ -581,7 +581,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
}
/**
* Highlights the value at the given x-position in the given DataSet. Provide
* Highlights the value at the given x-value in the given DataSet. Provide
* -1 as the dataSetIndex to undo all highlighting. This will trigger a callback to the OnChartValueSelectedListener.
*
* @param x
@ -592,7 +592,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
}
/**
* Highlights the value at the given x position in the given DataSet. Provide
* Highlights the value at the given x-value in the given DataSet. Provide
* -1 as the dataSetIndex to undo all highlighting.
*
* @param x

View file

@ -328,7 +328,7 @@ public class PieChart extends PieRadarChartBase<PieData> {
List<IPieDataSet> dataSets = mData.getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
if (dataSets.get(i).getEntryForXPos(xIndex) != null)
if (dataSets.get(i).getEntryForXValue(xIndex) != null)
return i;
}

View file

@ -44,8 +44,8 @@ public class BarData extends BarLineScatterCandleBubbleData<IBarDataSet> {
}
/**
* Groups all BarDataSet objects this data object holds together by modifying the x-position of their entries.
* Previously set x-positions of entries will be overwritten. Leaves space between bars and groups as specified
* Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries.
* Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified
* by the parameters.
* Do not forget to call notifyDataSetChanged() on your BarChart object after calling this method.
*

View file

@ -387,9 +387,9 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}
@Override
public boolean removeEntryByXPos(float xPos) {
public boolean removeEntryByXValue(float xValue) {
T e = getEntryForXPos(xPos);
T e = getEntryForXValue(xValue);
return removeEntry(e);
}

View file

@ -335,7 +335,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
if (highlight.getDataSetIndex() >= mDataSets.size())
return null;
else {
return mDataSets.get(highlight.getDataSetIndex()).getEntryForXPos(highlight.getX());
return mDataSets.get(highlight.getDataSetIndex()).getEntryForXValue(highlight.getX());
}
}
@ -526,17 +526,17 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
* specified index. Returns true if an Entry was removed, false if no Entry
* was found that meets the specified requirements.
*
* @param xPos
* @param xValue
* @param dataSetIndex
* @return
*/
public boolean removeEntry(float xPos, int dataSetIndex) {
public boolean removeEntry(float xValue, int dataSetIndex) {
if (dataSetIndex >= mDataSets.size())
return false;
IDataSet dataSet = mDataSets.get(dataSetIndex);
Entry e = dataSet.getEntryForXPos(xPos);
Entry e = dataSet.getEntryForXValue(xValue);
if (e == null)
return false;
@ -561,7 +561,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
T set = mDataSets.get(i);
for (int j = 0; j < set.getEntryCount(); j++) {
if (e.equalTo(set.getEntryForXPos(e.getX())))
if (e.equalTo(set.getEntryForXValue(e.getX())))
return set;
}
}

View file

@ -3,10 +3,8 @@ 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;
import java.util.ArrayList;
import java.util.List;
@ -194,7 +192,7 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
// if we are not interested in highlighting a specific value.
List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
.getEntriesForXPos(highlight.getX());
.getEntriesForXValue(highlight.getX());
for (Entry entry : entries)
if (entry.getY() == highlight.getY() ||
Float.isNaN(highlight.getY()))
@ -243,7 +241,7 @@ public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatter
@Deprecated
@Override
public boolean removeEntry(float xPos, int dataSetIndex) {
public boolean removeEntry(float xValue, int dataSetIndex) {
Log.e("MPAndroidChart", "removeEntry(...) not supported for CombinedData");
return false;
}

View file

@ -239,17 +239,17 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
}
@Override
public T getEntryForXPos(float xPos, Rounding rounding) {
public T getEntryForXValue(float xValue, Rounding rounding) {
int index = getEntryIndex(xPos, rounding);
int index = getEntryIndex(xValue, rounding);
if (index > -1)
return mValues.get(index);
return null;
}
@Override
public T getEntryForXPos(float xPos) {
return getEntryForXPos(xPos, Rounding.CLOSEST);
public T getEntryForXValue(float xValue) {
return getEntryForXValue(xValue, Rounding.CLOSEST);
}
@Override
@ -258,7 +258,7 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
}
@Override
public int getEntryIndex(float xPos, Rounding rounding) {
public int getEntryIndex(float xValue, Rounding rounding) {
if (mValues == null || mValues.isEmpty())
return -1;
@ -269,8 +269,8 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
while (low < high) {
int m = (low + high) / 2;
float d1 = Math.abs(mValues.get(m).getX() - xPos);
float d2 = Math.abs(mValues.get(m + 1).getX() - xPos);
float d1 = Math.abs(mValues.get(m).getX() - xValue);
float d2 = Math.abs(mValues.get(m + 1).getX() - xValue);
if (d2 <= d1) {
low = m + 1;
@ -280,13 +280,13 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
}
if (high != -1) {
float closestXPos = mValues.get(high).getX();
float closestXValue = mValues.get(high).getX();
if (rounding == Rounding.UP) {
if (closestXPos < xPos && high < mValues.size() - 1) {
if (closestXValue < xValue && high < mValues.size() - 1) {
++high;
}
} else if (rounding == Rounding.DOWN) {
if (closestXPos > xPos && high > 0) {
if (closestXValue > xValue && high > 0) {
--high;
}
}
@ -300,11 +300,11 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
* does calculations at runtime. Do not over-use in performance critical
* situations.
*
* @param xVal
* @param xValue
* @return
*/
@Override
public List<T> getEntriesForXPos(float xVal) {
public List<T> getEntriesForXValue(float xValue) {
List<T> entries = new ArrayList<T>();
@ -315,14 +315,14 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
int m = (high + low) / 2;
T entry = mValues.get(m);
if (xVal == entry.getX()) {
while (m > 0 && mValues.get(m - 1).getX() == xVal)
if (xValue == entry.getX()) {
while (m > 0 && mValues.get(m - 1).getX() == xValue)
m--;
high = mValues.size();
for (; m < high; m++) {
entry = mValues.get(m);
if (entry.getX() == xVal) {
if (entry.getX() == xValue) {
entries.add(entry);
} else {
break;
@ -331,7 +331,7 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
break;
} else {
if (xVal > entry.getX())
if (xValue > entry.getX())
low = m + 1;
else
high = m - 1;

View file

@ -54,7 +54,7 @@ public class BarHighlighter extends ChartHighlighter<BarDataProvider> {
*/
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {
BarEntry entry = set.getEntryForXPos(xVal);
BarEntry entry = set.getEntryForXValue(xVal);
if (entry == null)
return null;

View file

@ -66,7 +66,7 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
*/
protected Highlight getHighlightForX(float xVal, float x, float y) {
List<Highlight> closestValues = getHighlightsAtXPos(xVal, x, y);
List<Highlight> closestValues = getHighlightsAtXValue(xVal, x, y);
if(closestValues.isEmpty()) {
return null;
@ -124,7 +124,7 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
* @param y touch position
* @return
*/
protected List<Highlight> getHighlightsAtXPos(float xVal, float x, float y) {
protected List<Highlight> getHighlightsAtXValue(float xVal, float x, float y) {
mHighlightBuffer.clear();
@ -162,7 +162,7 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
*/
protected Highlight buildHighlight(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {
final Entry e = set.getEntryForXPos(xVal, rounding);
final Entry e = set.getEntryForXValue(xVal, rounding);
if (e == null)
return null;

View file

@ -28,7 +28,7 @@ public class CombinedHighlighter extends ChartHighlighter<CombinedDataProvider>
}
@Override
protected List<Highlight> getHighlightsAtXPos(float xVal, float x, float y) {
protected List<Highlight> getHighlightsAtXValue(float xVal, float x, float y) {
mHighlightBuffer.clear();

View file

@ -45,7 +45,7 @@ public class HorizontalBarHighlighter extends BarHighlighter {
@Override
protected Highlight buildHighlight(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {
final Entry e = set.getEntryForXPos(xVal, rounding);
final Entry e = set.getEntryForXValue(xVal, rounding);
MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());

View file

@ -58,40 +58,40 @@ public interface IDataSet<T extends Entry> {
void calcMinMax();
/**
* Returns the first Entry object found at the given xPos with binary
* search. If the no Entry at the specified xPos is found, this method
* returns the Entry at the xPos according to the rounding.
* Returns the first Entry object found at the given x-value with binary
* search. If the no Entry at the specified x-value is found, this method
* returns the Entry at the x-value according to the rounding.
* INFORMATION: This method does calculations at runtime. Do
* not over-use in performance critical situations.
*
* @param xPos
* @param xValue
* @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
* @return
*/
T getEntryForXPos(float xPos, DataSet.Rounding rounding);
T getEntryForXValue(float xValue, DataSet.Rounding rounding);
/**
* Returns the first Entry object found at the given xPos with binary
* search. If the no Entry at the specified xPos is found, this method
* returns the index at the closest xPos.
* Returns the first Entry object found at the given x-value with binary
* search. If the no Entry at the specified x-value is found, this method
* returns the index at the closest x-value.
* INFORMATION: This method does calculations at runtime. Do
* not over-use in performance critical situations.
*
* @param xPos
* @param xValue
* @return
*/
T getEntryForXPos(float xPos);
T getEntryForXValue(float xValue);
/**
* Returns all Entry objects found at the given xPos with binary
* search. An empty array if no Entry object at that xPos.
* Returns all Entry objects found at the given x-value with binary
* search. An empty array if no Entry object at that x-value.
* INFORMATION: This method does calculations at runtime. Do
* not over-use in performance critical situations.
*
* @param xPos
* @param xValue
* @return
*/
List<T> getEntriesForXPos(float xPos);
List<T> getEntriesForXValue(float xValue);
/**
* Returns the Entry object found at the given index (NOT xIndex) in the values array.
@ -102,17 +102,17 @@ public interface IDataSet<T extends Entry> {
T getEntryForIndex(int index);
/**
* Returns the first Entry index found at the given xPos with binary
* search. If the no Entry at the specified xPos is found, this method
* returns the Entry at the closest xPos.
* Returns the first Entry index found at the given x-value with binary
* search. If the no Entry at the specified x-value is found, this method
* returns the Entry at the closest x-value.
* INFORMATION: This method does calculations at runtime. Do
* not over-use in performance critical situations.
*
* @param xPos
* @param xValue
* @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
* @return
*/
int getEntryIndex(float xPos, DataSet.Rounding rounding);
int getEntryIndex(float xValue, DataSet.Rounding rounding);
/**
* Returns the position of the provided entry in the DataSets Entry array.
@ -183,12 +183,12 @@ public interface IDataSet<T extends Entry> {
boolean removeEntry(T e);
/**
* Removes the Entry object closest to the given xPos from the DataSet.
* Removes the Entry object closest to the given x-value from the DataSet.
* Returns true if an Entry was removed, false if no Entry could be removed.
*
* @param xPos
* @param xValue
*/
boolean removeEntryByXPos(float xPos);
boolean removeEntryByXValue(float xValue);
/**
* Removes the Entry object at the given index in the values array from the DataSet.

View file

@ -341,7 +341,7 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
if (set == null || !set.isHighlightEnabled())
continue;
BarEntry e = set.getEntryForXPos(high.getX());
BarEntry e = set.getEntryForXValue(high.getX());
if (!isInBoundsX(e, set))
continue;

View file

@ -85,8 +85,8 @@ public abstract class BarLineScatterCandleBubbleRenderer extends DataRenderer {
float low = chart.getLowestVisibleX();
float high = chart.getHighestVisibleX();
Entry entryFrom = dataSet.getEntryForXPos(low, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXPos(high, DataSet.Rounding.UP);
Entry entryFrom = dataSet.getEntryForXValue(low, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXValue(high, DataSet.Rounding.UP);
min = dataSet.getEntryIndex(entryFrom);
max = dataSet.getEntryIndex(entryTo);

View file

@ -194,7 +194,7 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
continue;
// In bubble charts - it makes sense to have multiple bubbles on the same X value in the same dataset.
final List<BubbleEntry> entries = set.getEntriesForXPos(high.getX());
final List<BubbleEntry> entries = set.getEntriesForXValue(high.getX());
for (BubbleEntry entry : entries) {

View file

@ -317,7 +317,7 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
if (set == null || !set.isHighlightEnabled())
continue;
CandleEntry e = set.getEntryForXPos(high.getX());
CandleEntry e = set.getEntryForXValue(high.getX());
if (!isInBoundsX(e, set))
continue;

View file

@ -663,7 +663,7 @@ public class LineChartRenderer extends LineRadarRenderer {
if (set == null || !set.isHighlightEnabled())
continue;
Entry e = set.getEntryForXPos(high.getX());
Entry e = set.getEntryForXValue(high.getX());
if (!isInBoundsX(e, set))
continue;

View file

@ -143,7 +143,7 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
if (set == null || !set.isHighlightEnabled())
continue;
Entry e = set.getEntryForXPos(high.getX());
Entry e = set.getEntryForXValue(high.getX());
if (!isInBoundsX(e, set))
continue;

View file

@ -141,7 +141,7 @@ public class DataSetTest {
}
@Test
public void testGetEntryForXPos() {
public void testGetEntryForXValue() {
List<Entry> entries = new ArrayList<Entry>();
entries.add(new Entry(10, 10));
@ -150,31 +150,31 @@ public class DataSetTest {
ScatterDataSet set = new ScatterDataSet(entries, "");
Entry closest = set.getEntryForXPos(17, DataSet.Rounding.CLOSEST);
Entry closest = set.getEntryForXValue(17, DataSet.Rounding.CLOSEST);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXPos(17, DataSet.Rounding.DOWN);
closest = set.getEntryForXValue(17, DataSet.Rounding.DOWN);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXPos(15, DataSet.Rounding.DOWN);
closest = set.getEntryForXValue(15, DataSet.Rounding.DOWN);
assertEquals(15, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXPos(14, DataSet.Rounding.DOWN);
closest = set.getEntryForXValue(14, DataSet.Rounding.DOWN);
assertEquals(10, closest.getX(), 0.01f);
assertEquals(10, closest.getY(), 0.01f);
closest = set.getEntryForXPos(17, DataSet.Rounding.UP);
closest = set.getEntryForXValue(17, DataSet.Rounding.UP);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXPos(21, DataSet.Rounding.UP);
closest = set.getEntryForXValue(21, DataSet.Rounding.UP);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
closest = set.getEntryForXPos(21, DataSet.Rounding.CLOSEST);
closest = set.getEntryForXValue(21, DataSet.Rounding.CLOSEST);
assertEquals(21, closest.getX(), 0.01f);
assertEquals(5, closest.getY(), 0.01f);
}