Search in sources :

Example 11 with ScatterDataSet

use of com.github.mikephil.charting.data.ScatterDataSet in project MPAndroidChart by PhilJay.

the class DataSetTest method testGetEntryForXValueWithDuplicates.

@Test
public void testGetEntryForXValueWithDuplicates() {
    // sorted list of values (by x position)
    List<Entry> values = new ArrayList<Entry>();
    values.add(new Entry(0, 10));
    values.add(new Entry(1, 20));
    values.add(new Entry(2, 30));
    values.add(new Entry(3, 40));
    // duplicate
    values.add(new Entry(3, 50));
    values.add(new Entry(4, 60));
    // duplicate
    values.add(new Entry(4, 70));
    values.add(new Entry(5, 80));
    values.add(new Entry(6, 90));
    values.add(new Entry(7, 100));
    values.add(new Entry(8, 110));
    // duplicate
    values.add(new Entry(8, 120));
    ScatterDataSet set = new ScatterDataSet(values, "");
    Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(0, closest.getX(), 0.01f);
    assertEquals(10, closest.getY(), 0.01f);
    closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(5, closest.getX(), 0.01f);
    assertEquals(80, closest.getY(), 0.01f);
    closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(5, closest.getX(), 0.01f);
    assertEquals(80, closest.getY(), 0.01f);
    closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(5, closest.getX(), 0.01f);
    assertEquals(80, closest.getY(), 0.01f);
    closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(7, closest.getX(), 0.01f);
    assertEquals(100, closest.getY(), 0.01f);
    closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(4, closest.getX(), 0.01f);
    assertEquals(60, closest.getY(), 0.01f);
    List<Entry> entries = set.getEntriesForXValue(4f);
    assertEquals(2, entries.size());
    assertEquals(60, entries.get(0).getY(), 0.01f);
    assertEquals(70, entries.get(1).getY(), 0.01f);
    entries = set.getEntriesForXValue(3.5f);
    assertEquals(0, entries.size());
    entries = set.getEntriesForXValue(2f);
    assertEquals(1, entries.size());
    assertEquals(30, entries.get(0).getY(), 0.01f);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)11 Entry (com.github.mikephil.charting.data.Entry)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)5 ScatterData (com.github.mikephil.charting.data.ScatterData)4 BarEntry (com.github.mikephil.charting.data.BarEntry)2 IScatterDataSet (com.github.mikephil.charting.interfaces.datasets.IScatterDataSet)2 Path (android.graphics.Path)1 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 LineData (com.github.mikephil.charting.data.LineData)1 LineDataSet (com.github.mikephil.charting.data.LineDataSet)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 CustomScatterShapeRenderer (com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer)1