com.github.mikephil.charting.utils.SelectionDetail Java Examples
The following examples show how to use
com.github.mikephil.charting.utils.SelectionDetail.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarHighlighter.java From NetKnight with Apache License 2.0 | 6 votes |
@Override protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) { dataSetIndex = Math.max(dataSetIndex, 0); BarData barData = mChart.getBarData(); IDataSet dataSet = barData.getDataSetCount() > dataSetIndex ? barData.getDataSetByIndex(dataSetIndex) : null; if (dataSet == null) return null; final float yValue = dataSet.getYValForXIndex(xIndex); if (yValue == Double.NaN) return null; return new SelectionDetail( yValue, dataSetIndex, dataSet); }
Example #2
Source File: ChartHighlighter.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Returns a Highlight object corresponding to the given x- and y- touch positions in pixels. * * @param x * @param y * @return */ public Highlight getHighlight(float x, float y) { int xIndex = getXIndex(x); SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, -1); if (selectionDetail == null) return null; return new Highlight(xIndex, selectionDetail.value, selectionDetail.dataIndex, selectionDetail.dataSetIndex); }
Example #3
Source File: CombinedHighlighter.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ @Override protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; CombinedData data = (CombinedData) mChart.getData(); // get all chartdata objects List<ChartData> dataObjects = data.getAllData(); for (int i = 0; i < dataObjects.size(); i++) { for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) { IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVals[] = dataSet.getYValsForXIndex(xIndex); for (float yVal : yVals) { pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet)); } } } } return vals; }
Example #4
Source File: BarHighlighter.java From NetKnight with Apache License 2.0 | 5 votes |
/** * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected. * * @param selectionDetail the selection detail to work with looking for stacked values * @param set * @param xIndex * @param yValue * @return */ protected Highlight getStackedHighlight( SelectionDetail selectionDetail, IBarDataSet set, int xIndex, double yValue) { BarEntry entry = set.getEntryForXIndex(xIndex); if (entry == null) return null; if (entry.getVals() == null) { return new Highlight(xIndex, entry.getVal(), selectionDetail.dataIndex, selectionDetail.dataSetIndex); } Range[] ranges = getRanges(entry); if (ranges.length > 0) { int stackIndex = getClosestStackIndex(ranges, (float)yValue); return new Highlight( xIndex, entry.getPositiveSum() - entry.getNegativeSum(), selectionDetail.dataIndex, selectionDetail.dataSetIndex, stackIndex, ranges[stackIndex] ); } return null; }
Example #5
Source File: PieRadarChartBase.java From NetKnight with Apache License 2.0 | 4 votes |
/** * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail * objects give information about the value at the selected index and the * DataSet it belongs to. INFORMATION: This method does calculations at * runtime. Do not over-use in performance critical situations. * * @return */ public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); for (int i = 0; i < mData.getDataSetCount(); i++) { IDataSet<?> dataSet = mData.getDataSetByIndex(i); // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (Float.isNaN(yVal)) continue; vals.add(new SelectionDetail(yVal, i, dataSet)); } return vals; }
Example #6
Source File: HorizontalBarHighlighter.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); final int xIndex = getXIndex(x); final float baseNoSpace = getBase(x); final int setCount = barData.getDataSetCount(); int dataSetIndex = ((int)baseNoSpace) % setCount; if (dataSetIndex < 0) { dataSetIndex = 0; } else if (dataSetIndex >= setCount) { dataSetIndex = setCount - 1; } SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex); if (selectionDetail == null) return null; IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set.isStacked()) { float[] pts = new float[2]; pts[0] = y; // take any transformer to determine the x-axis value mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts); return getStackedHighlight(selectionDetail, set, xIndex, pts[0]); } return new Highlight( xIndex, selectionDetail.value, selectionDetail.dataIndex, selectionDetail.dataSetIndex, -1); }
Example #7
Source File: ChartHighlighter.java From NetKnight with Apache License 2.0 | 4 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @param dataSetIndex dataSet index to look at. -1 if unspecified. * @return */ protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); if (mChart.getData() == null) return vals; float[] pts = new float[2]; for (int i = 0, dataSetCount = mChart.getData().getDataSetCount(); i < dataSetCount; i++) { if (dataSetIndex > -1 && dataSetIndex != i) continue; IDataSet dataSet = mChart.getData().getDataSetByIndex(i); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float[] yVals = dataSet.getYValsForXIndex(xIndex); for (float yVal : yVals) { if (Float.isNaN(yVal)) continue; pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], yVal, i, dataSet)); } } } return vals; }
Example #8
Source File: BarHighlighter.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); final int xIndex = getXIndex(x); final float baseNoSpace = getBase(x); final int setCount = barData.getDataSetCount(); int dataSetIndex = ((int)baseNoSpace) % setCount; if (dataSetIndex < 0) { dataSetIndex = 0; } else if (dataSetIndex >= setCount) { dataSetIndex = setCount - 1; } SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex); if (selectionDetail == null) return null; IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set.isStacked()) { float[] pts = new float[2]; pts[1] = y; // take any transformer to determine the x-axis value mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts); return getStackedHighlight(selectionDetail, set, xIndex, pts[1]); } return new Highlight( xIndex, selectionDetail.value, selectionDetail.dataIndex, selectionDetail.dataSetIndex, -1); }
Example #9
Source File: PieRadarChartTouchListener.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public boolean onSingleTapUp(MotionEvent e) { mLastGesture = ChartGesture.SINGLE_TAP; OnChartGestureListener l = mChart.getOnChartGestureListener(); if (l != null) { l.onChartSingleTapped(e); } if(!mChart.isHighlightPerTapEnabled()) { return false; } float distance = mChart.distanceToCenter(e.getX(), e.getY()); // check if a slice was touched if (distance > mChart.getRadius()) { // if no slice was touched, highlight nothing if (mLastHighlighted == null) mChart.highlightValues(null); // no listener callback else mChart.highlightTouch(null); // listener callback mLastHighlighted = null; } else { float angle = mChart.getAngleForPoint(e.getX(), e.getY()); if (mChart instanceof PieChart) { angle /= mChart.getAnimator().getPhaseY(); } int index = mChart.getIndexForAngle(angle); // check if the index could be found if (index < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { List<SelectionDetail> valsAtIndex = mChart.getSelectionDetailsAtIndex(index); int dataSetIndex = 0; // get the dataset that is closest to the selection (PieChart // only // has one DataSet) if (mChart instanceof RadarChart) { dataSetIndex = Utils.getClosestDataSetIndexByValue( valsAtIndex, distance / ((RadarChart) mChart).getFactor(), null); } if (dataSetIndex < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { Highlight h = new Highlight(index, dataSetIndex); performHighlight(h, e); } } } return true; }
Example #10
Source File: PieRadarChartBase.java From iMoney with Apache License 2.0 | 4 votes |
/** * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail * objects give information about the value at the selected index and the * DataSet it belongs to. INFORMATION: This method does calculations at * runtime. Do not over-use in performance critical situations. * * @return */ public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); for (int i = 0; i < mData.getDataSetCount(); i++) { DataSet<?> dataSet = mData.getDataSetByIndex(i); // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; vals.add(new SelectionDetail(yVal, i, dataSet)); } return vals; }
Example #11
Source File: PieRadarChartTouchListener.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public boolean onSingleTapUp(MotionEvent e) { mLastGesture = ChartGesture.SINGLE_TAP; OnChartGestureListener l = mChart.getOnChartGestureListener(); if (l != null) { l.onChartSingleTapped(e); } if(!mChart.isHighlightPerTapEnabled()) { return false; } float distance = mChart.distanceToCenter(e.getX(), e.getY()); // check if a slice was touched if (distance > mChart.getRadius()) { // if no slice was touched, highlight nothing if (mLastHighlighted == null) mChart.highlightValues(null); // no listener callback else mChart.highlightTouch(null); // listener callback mLastHighlighted = null; } else { float angle = mChart.getAngleForPoint(e.getX(), e.getY()); if (mChart instanceof PieChart) { angle /= mChart.getAnimator().getPhaseY(); } int index = mChart.getIndexForAngle(angle); // check if the index could be found if (index < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { List<SelectionDetail> valsAtIndex = mChart.getSelectionDetailsAtIndex(index); int dataSetIndex = 0; // get the dataset that is closest to the selection (PieChart // only // has one DataSet) if (mChart instanceof RadarChart) { dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, distance / ((RadarChart) mChart).getFactor(), null); } if (dataSetIndex < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { Highlight h = new Highlight(index, dataSetIndex); performHighlight(h, e); } } } return true; }
Example #12
Source File: PieRadarChartBase.java From Stayfit with Apache License 2.0 | 4 votes |
/** * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail * objects give information about the value at the selected index and the * DataSet it belongs to. INFORMATION: This method does calculations at * runtime. Do not over-use in performance critical situations. * * @return */ public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); for (int i = 0; i < mData.getDataSetCount(); i++) { IDataSet<?> dataSet = mData.getDataSetByIndex(i); // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; vals.add(new SelectionDetail(yVal, i, dataSet)); } return vals; }
Example #13
Source File: PieRadarChartTouchListener.java From iMoney with Apache License 2.0 | 4 votes |
@Override public boolean onSingleTapUp(MotionEvent e) { OnChartGestureListener l = mChart.getOnChartGestureListener(); if (l != null) { l.onChartSingleTapped(e); } float distance = mChart.distanceToCenter(e.getX(), e.getY()); // check if a slice was touched if (distance > mChart.getRadius()) { // if no slice was touched, highlight nothing mChart.highlightValues(null); mLastHighlighted = null; } else { float angle = mChart.getAngleForPoint(e.getX(), e.getY()); if (mChart instanceof PieChart) { angle /= mChart.getAnimator().getPhaseY(); } int index = mChart.getIndexForAngle(angle); // check if the index could be found if (index < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { List<SelectionDetail> valsAtIndex = mChart.getSelectionDetailsAtIndex(index); int dataSetIndex = 0; // get the dataset that is closest to the selection (PieChart // only // has one DataSet) if (mChart instanceof RadarChart) { dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, distance / ((RadarChart) mChart).getFactor(), null); } if (dataSetIndex < 0) { mChart.highlightValues(null); mLastHighlighted = null; } else { Highlight h = new Highlight(index, dataSetIndex); if (h.equalTo(mLastHighlighted)) { mChart.highlightTouch(null); mLastHighlighted = null; } else { mChart.highlightTouch(h); mLastHighlighted = h; } } } } return true; }
Example #14
Source File: ChartHighlighter.java From Stayfit with Apache License 2.0 | 3 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; for (int i = 0; i < mChart.getData().getDataSetCount(); i++) { IDataSet dataSet = mChart.getData().getDataSetByIndex(i); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], i, dataSet)); } } return vals; }
Example #15
Source File: ChartHighlighter.java From Stayfit with Apache License 2.0 | 3 votes |
/** * Returns the corresponding dataset-index for a given xIndex and xy-touch position in pixels. * * @param xIndex * @param x * @param y * @return */ protected int getDataSetIndex(int xIndex, float x, float y) { List<SelectionDetail> valsAtIndex = getSelectionDetailsAtIndex(xIndex); float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT); float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT); YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT; int dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, y, axis); return dataSetIndex; }
Example #16
Source File: CombinedHighlighter.java From Stayfit with Apache License 2.0 | 3 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ @Override protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { CombinedData data = (CombinedData) mChart.getData(); // get all chartdata objects List<ChartData> dataObjects = data.getAllData(); List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; for (int i = 0; i < dataObjects.size(); i++) { for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) { IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], j, dataSet)); } } } return vals; }
Example #17
Source File: ChartHighlighter.java From iMoney with Apache License 2.0 | 3 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; for (int i = 0; i < mChart.getData().getDataSetCount(); i++) { DataSet<?> dataSet = mChart.getData().getDataSetByIndex(i); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], i, dataSet)); } } return vals; }
Example #18
Source File: ChartHighlighter.java From iMoney with Apache License 2.0 | 3 votes |
/** * Returns the corresponding dataset-index for a given xIndex and xy-touch position in pixels. * * @param xIndex * @param x * @param y * @return */ protected int getDataSetIndex(int xIndex, float x, float y) { List<SelectionDetail> valsAtIndex = getSelectionDetailsAtIndex(xIndex); float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT); float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT); YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT; int dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, y, axis); return dataSetIndex; }
Example #19
Source File: ChartHighlighter.java From NetKnight with Apache License 2.0 | 3 votes |
/** * Returns the corresponding SelectionDetail for a given xIndex and y-touch position in pixels. * * @param xIndex * @param y * @param dataSetIndex * @return */ protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) { List<SelectionDetail> valsAtIndex = getSelectionDetailsAtIndex(xIndex, dataSetIndex); float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT); float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT); YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT; SelectionDetail detail = Utils.getClosestSelectionDetailByPixelY(valsAtIndex, y, axis); return detail; }
Example #20
Source File: CombinedHighlighter.java From iMoney with Apache License 2.0 | 3 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ @Override protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) { CombinedData data = (CombinedData) mChart.getData(); // get all chartdata objects List<ChartData> dataObjects = data.getAllData(); List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; for (int i = 0; i < dataObjects.size(); i++) { for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) { DataSet<?> dataSet = dataObjects.get(i).getDataSetByIndex(j); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVal = dataSet.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], j, dataSet)); } } } return vals; }