use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class Chart method highlightTouch.
/**
* Highlights the value selected by touch gesture. Unlike
* highlightValues(...), this generates a callback to the
* OnChartValueSelectedListener.
*
* @param highs
*/
public void highlightTouch(Highlight high) {
if (high == null)
mIndicesToHightlight = null;
else {
// set the indices to highlight
mIndicesToHightlight = new Highlight[] { high };
}
// redraw the chart
invalidate();
if (mSelectionListener != null) {
if (!valuesToHighlight())
mSelectionListener.onNothingSelected();
else {
Entry e = getEntryByDataSetIndex(high.getXIndex(), high.getDataSetIndex());
// notify the listener
mSelectionListener.onValueSelected(e, high.getDataSetIndex());
}
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class FileUtils method loadEntriesFromAssets.
/**
* Loads an array of Entries from a textfile from the assets folder.
*
* @param am
* @param path the name of the file in the assets folder (+ path if needed)
* @return
*/
public static ArrayList<Entry> loadEntriesFromAssets(AssetManager am, String path) {
ArrayList<Entry> entries = new ArrayList<Entry>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(am.open(path), "UTF-8"));
String line = reader.readLine();
while (line != null) {
// process line
String[] split = line.split("#");
if (split.length <= 2) {
entries.add(new Entry(Float.parseFloat(split[0]), Integer.parseInt(split[1])));
} else {
float[] vals = new float[split.length - 1];
for (int i = 0; i < vals.length; i++) {
vals[i] = Float.parseFloat(split[i]);
}
entries.add(new BarEntry(vals, Integer.parseInt(split[split.length - 1])));
}
line = reader.readLine();
}
} catch (IOException e) {
Log.e(LOG, e.toString());
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
Log.e(LOG, e.toString());
}
}
}
return entries;
// String label = null;
// ArrayList<Entry> entries = new ArrayList<Entry>();
//
// BufferedReader reader = null;
// try {
// reader = new BufferedReader(
// new InputStreamReader(am.open(path), "UTF-8"));
//
// // do reading, usually loop until end of file reading
// label = reader.readLine();
// String line = reader.readLine();
//
// while (line != null) {
// // process line
// String[] split = line.split("#");
// entries.add(new Entry(Float.parseFloat(split[0]),
// Integer.parseInt(split[1])));
// line = reader.readLine();
// }
// } catch (IOException e) {
// Log.e(LOG, e.toString());
//
// } finally {
//
// if (reader != null) {
// try {
// reader.close();
// } catch (IOException e) {
// Log.e(LOG, e.toString());
// }
// }
// }
//
// DataSet ds = new DataSet(entries, label);
// return ds;
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class FileUtils method loadEntriesFromFile.
/**
* Loads a an Array of Entries from a textfile from the sd-card.
*
* @param path the name of the file on the sd-card (+ path if needed)
* @return
*/
public static ArrayList<Entry> loadEntriesFromFile(String path) {
File sdcard = Environment.getExternalStorageDirectory();
// Get the text file
File file = new File(sdcard, path);
ArrayList<Entry> entries = new ArrayList<Entry>();
try {
@SuppressWarnings("resource") BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
String[] split = line.split("#");
if (split.length <= 2) {
entries.add(new Entry(Float.parseFloat(split[0]), Integer.parseInt(split[1])));
} else {
float[] vals = new float[split.length - 1];
for (int i = 0; i < vals.length; i++) {
vals[i] = Float.parseFloat(split[i]);
}
entries.add(new BarEntry(vals, Integer.parseInt(split[split.length - 1])));
}
}
} catch (IOException e) {
Log.e(LOG, e.toString());
}
return entries;
// File sdcard = Environment.getExternalStorageDirectory();
//
// // Get the text file
// File file = new File(sdcard, path);
//
// ArrayList<Entry> entries = new ArrayList<Entry>();
// String label = "";
//
// try {
// @SuppressWarnings("resource")
// BufferedReader br = new BufferedReader(new FileReader(file));
// String line = br.readLine();
//
// // firstline is the label
// label = line;
//
// while ((line = br.readLine()) != null) {
// String[] split = line.split("#");
// entries.add(new Entry(Float.parseFloat(split[0]),
// Integer.parseInt(split[1])));
// }
// } catch (IOException e) {
// Log.e(LOG, e.toString());
// }
//
// DataSet ds = new DataSet(entries, label);
// return ds;
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class Approximator method reduceWithDouglasPeuker.
/**
* uses the douglas peuker algorithm to reduce the given arraylist of
* entries
*
* @param entries
* @param epsilon
* @return
*/
private ArrayList<Entry> reduceWithDouglasPeuker(ArrayList<Entry> entries, double epsilon) {
// if a shape has 2 or less points it cannot be reduced
if (epsilon <= 0 || entries.size() < 3) {
return entries;
}
// first and last always stay
keep[0] = true;
keep[entries.size() - 1] = true;
// first and last entry are entry point to recursion
algorithmDouglasPeucker(entries, epsilon, 0, entries.size() - 1);
// create a new array with series, only take the kept ones
ArrayList<Entry> reducedEntries = new ArrayList<Entry>();
for (int i = 0; i < entries.size(); i++) {
if (keep[i]) {
Entry curEntry = entries.get(i);
reducedEntries.add(new Entry(curEntry.getVal(), curEntry.getXIndex()));
}
}
return reducedEntries;
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class Transformer method generateTransformedValuesBarChart.
/**
* Transforms an arraylist of Entry into a float array containing the x and
* y values transformed with all matrices for the BARCHART.
*
* @param entries
* @param dataSet the dataset index
* @return
*/
public float[] generateTransformedValuesBarChart(ArrayList<? extends Entry> entries, int dataSet, BarData bd, float phaseY) {
float[] valuePoints = new float[entries.size() * 2];
int setCount = bd.getDataSetCount();
float space = bd.getGroupSpace();
for (int j = 0; j < valuePoints.length; j += 2) {
Entry e = entries.get(j / 2);
// calculate the x-position, depending on datasetcount
float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + 0.5f + space * (j / 2) + space / 2f;
float y = e.getVal();
valuePoints[j] = x;
valuePoints[j + 1] = y * phaseY;
}
pointValuesToPixel(valuePoints);
return valuePoints;
}
Aggregations