Skip to content

Commit

Permalink
Renamed values -> entries for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 22, 2020
1 parent a8542c3 commit 67f82f1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public DataSet<BarEntry> copy() {
List<BarEntry> yVals = new ArrayList<BarEntry>();
yVals.clear();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

BarDataSet copied = new BarDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public DataSet<BubbleEntry> copy() {

List<BubbleEntry> yVals = new ArrayList<BubbleEntry>();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public DataSet<CandleEntry> copy() {
List<CandleEntry> yVals = new ArrayList<CandleEntry>();
yVals.clear();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

CandleDataSet copied = new CandleDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
/**
* the entries that this DataSet represents / holds together
*/
protected List<T> mValues = null;
protected List<T> mEntries;

/**
* maximum y-value in the value array
Expand Down Expand Up @@ -45,15 +45,15 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
* label that describes the DataSet can be specified. The label can also be
* used to retrieve the DataSet from a ChartData object.
*
* @param values
* @param entries
* @param label
*/
public DataSet(List<T> values, String label) {
public DataSet(List<T> entries, String label) {
super(label);
this.mValues = values;
this.mEntries = entries;

if (mValues == null)
mValues = new ArrayList<T>();
if (mEntries == null)
mEntries = new ArrayList<T>();

calcMinMax();
}
Expand All @@ -66,10 +66,10 @@ public void calcMinMax() {
mXMax = -Float.MAX_VALUE;
mXMin = Float.MAX_VALUE;

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return;

for (T e : mValues) {
for (T e : mEntries) {
calcMinMax(e);
}
}
Expand All @@ -79,7 +79,7 @@ public void calcMinMaxY(float fromX, float toX) {
mYMax = -Float.MAX_VALUE;
mYMin = Float.MAX_VALUE;

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return;

int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN);
Expand All @@ -90,7 +90,7 @@ public void calcMinMaxY(float fromX, float toX) {
for (int i = indexFrom; i <= indexTo; i++) {

// only recalculate y
calcMinMaxY(mValues.get(i));
calcMinMaxY(mEntries.get(i));
}
}

Expand Down Expand Up @@ -129,25 +129,47 @@ protected void calcMinMaxY(T e) {

@Override
public int getEntryCount() {
return mValues.size();
return mEntries.size();
}

/**
* Returns the array of entries that this DataSet represents.
* This method is deprecated.
* Use getEntries() instead.
*
* @return
*/
@Deprecated
public List<T> getValues() {
return mValues;
return mEntries;
}

/**
* Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged()
* Returns the array of entries that this DataSet represents.
*
* @return
*/
public List<T> getEntries() {
return mEntries;
}

/**
* This method is deprecated.
* Use setEntries(...) instead.
*
* @param values
*/
@Deprecated
public void setValues(List<T> values) {
mValues = values;
setEntries(values);
}

/**
* Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged()
*
* @return
*/
public void setEntries(List<T> entries) {
mEntries = entries;
notifyDataSetChanged();
}

Expand All @@ -162,8 +184,8 @@ public void setValues(List<T> values) {
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(toSimpleString());
for (int i = 0; i < mValues.size(); i++) {
buffer.append(mValues.get(i).toString() + " ");
for (int i = 0; i < mEntries.size(); i++) {
buffer.append(mEntries.get(i).toString() + " ");
}
return buffer.toString();
}
Expand All @@ -176,7 +198,7 @@ public String toString() {
*/
public String toSimpleString() {
StringBuffer buffer = new StringBuffer();
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mValues.size() +
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mEntries.size() +
"\n");
return buffer.toString();
}
Expand Down Expand Up @@ -207,23 +229,23 @@ public void addEntryOrdered(T e) {
if (e == null)
return;

if (mValues == null) {
mValues = new ArrayList<T>();
if (mEntries == null) {
mEntries = new ArrayList<T>();
}

calcMinMax(e);

if (mValues.size() > 0 && mValues.get(mValues.size() - 1).getX() > e.getX()) {
if (mEntries.size() > 0 && mEntries.get(mEntries.size() - 1).getX() > e.getX()) {
int closestIndex = getEntryIndex(e.getX(), e.getY(), Rounding.UP);
mValues.add(closestIndex, e);
mEntries.add(closestIndex, e);
} else {
mValues.add(e);
mEntries.add(e);
}
}

@Override
public void clear() {
mValues.clear();
mEntries.clear();
notifyDataSetChanged();
}

Expand All @@ -233,9 +255,9 @@ public boolean addEntry(T e) {
if (e == null)
return false;

List<T> values = getValues();
List<T> values = getEntries();
if (values == null) {
values = new ArrayList<T>();
values = new ArrayList<>();
}

calcMinMax(e);
Expand All @@ -250,11 +272,11 @@ public boolean removeEntry(T e) {
if (e == null)
return false;

if (mValues == null)
if (mEntries == null)
return false;

// remove the entry
boolean removed = mValues.remove(e);
boolean removed = mEntries.remove(e);

if (removed) {
calcMinMax();
Expand All @@ -265,15 +287,15 @@ public boolean removeEntry(T e) {

@Override
public int getEntryIndex(Entry e) {
return mValues.indexOf(e);
return mEntries.indexOf(e);
}

@Override
public T getEntryForXValue(float xValue, float closestToY, Rounding rounding) {

int index = getEntryIndex(xValue, closestToY, rounding);
if (index > -1)
return mValues.get(index);
return mEntries.get(index);
return null;
}

Expand All @@ -284,24 +306,24 @@ public T getEntryForXValue(float xValue, float closestToY) {

@Override
public T getEntryForIndex(int index) {
return mValues.get(index);
return mEntries.get(index);
}

@Override
public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return -1;

int low = 0;
int high = mValues.size() - 1;
int high = mEntries.size() - 1;
int closest = high;

while (low < high) {
int m = (low + high) / 2;

final float d1 = mValues.get(m).getX() - xValue,
d2 = mValues.get(m + 1).getX() - xValue,
final float d1 = mEntries.get(m).getX() - xValue,
d2 = mEntries.get(m + 1).getX() - xValue,
ad1 = Math.abs(d1), ad2 = Math.abs(d2);

if (ad2 < ad1) {
Expand All @@ -328,10 +350,10 @@ public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {
}

if (closest != -1) {
float closestXValue = mValues.get(closest).getX();
float closestXValue = mEntries.get(closest).getX();
if (rounding == Rounding.UP) {
// If rounding up, and found x-value is lower than specified x, and we can go upper...
if (closestXValue < xValue && closest < mValues.size() - 1) {
if (closestXValue < xValue && closest < mEntries.size() - 1) {
++closest;
}
} else if (rounding == Rounding.DOWN) {
Expand All @@ -343,18 +365,18 @@ public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {

// Search by closest to y-value
if (!Float.isNaN(closestToY)) {
while (closest > 0 && mValues.get(closest - 1).getX() == closestXValue)
while (closest > 0 && mEntries.get(closest - 1).getX() == closestXValue)
closest -= 1;

float closestYValue = mValues.get(closest).getY();
float closestYValue = mEntries.get(closest).getY();
int closestYIndex = closest;

while (true) {
closest += 1;
if (closest >= mValues.size())
if (closest >= mEntries.size())
break;

final Entry value = mValues.get(closest);
final Entry value = mEntries.get(closest);

if (value.getX() != closestXValue)
break;
Expand All @@ -378,22 +400,22 @@ public List<T> getEntriesForXValue(float xValue) {
List<T> entries = new ArrayList<T>();

int low = 0;
int high = mValues.size() - 1;
int high = mEntries.size() - 1;

while (low <= high) {
int m = (high + low) / 2;
T entry = mValues.get(m);
T entry = mEntries.get(m);

// if we have a match
if (xValue == entry.getX()) {
while (m > 0 && mValues.get(m - 1).getX() == xValue)
while (m > 0 && mEntries.get(m - 1).getX() == xValue)
m--;

high = mValues.size();
high = mEntries.size();

// loop over all "equal" entries
for (; m < high; m++) {
entry = mValues.get(m);
entry = mEntries.get(m);
if (entry.getX() == xValue) {
entries.add(entry);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public DataSet<Entry> copy() {

List<Entry> yVals = new ArrayList<Entry>();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

LineDataSet copied = new LineDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public DataSet<PieEntry> copy() {

List<PieEntry> yVals = new ArrayList<>();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

PieDataSet copied = new PieDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public DataSet<RadarEntry> copy() {

List<RadarEntry> yVals = new ArrayList<RadarEntry>();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

RadarDataSet copied = new RadarDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public DataSet<Entry> copy() {

List<Entry> yVals = new ArrayList<Entry>();

for (int i = 0; i < mValues.size(); i++) {
yVals.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
yVals.add(mEntries.get(i).copy());
}

ScatterDataSet copied = new ScatterDataSet(yVals, getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
package com.github.mikephil.charting.formatter;

import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collection;

/**
Expand Down

0 comments on commit 67f82f1

Please sign in to comment.