use of com.github.mikephil.charting.data.BarDataSet in project carat by amplab.
the class BarChart method getBarBounds.
/**
* Returns the bounding box of the specified Entry in the specified DataSet.
* Returns null if the Entry could not be found in the charts data.
*
* @param e
* @param dataSetIndex
* @return
*/
public RectF getBarBounds(BarEntry e) {
BarDataSet set = mData.getDataSetForEntry(e);
if (set == null)
return null;
float barspace = set.getBarSpace();
float y = e.getVal();
float x = e.getXIndex();
float spaceHalf = barspace / 2f;
float left = x + spaceHalf;
float right = x + 1f - spaceHalf;
float top = y >= 0 ? y : 0;
float bottom = y <= 0 ? y : 0;
RectF bounds = new RectF(left, top, right, bottom);
mTrans.rectValueToPixel(bounds);
return bounds;
}
use of com.github.mikephil.charting.data.BarDataSet in project carat by amplab.
the class BarChart method drawHighlights.
@Override
protected void drawHighlights() {
int setCount = mData.getDataSetCount();
for (int i = 0; i < mIndicesToHightlight.length; i++) {
Highlight h = mIndicesToHightlight[i];
int index = h.getXIndex();
int dataSetIndex = h.getDataSetIndex();
BarDataSet set = (BarDataSet) mData.getDataSetByIndex(dataSetIndex);
if (set == null)
continue;
mHighlightPaint.setColor(set.getHighLightColor());
mHighlightPaint.setAlpha(set.getHighLightAlpha());
// check outofbounds
if (index < mData.getYValCount() && index >= 0 && index < (mDeltaX * mPhaseX) / mData.getDataSetCount()) {
Entry e = getEntryByDataSetIndex(index, dataSetIndex);
if (e == null)
continue;
// calculate the correct x-position
float x = index * setCount + dataSetIndex + mData.getGroupSpace() / 2f + mData.getGroupSpace() * index;
float y = e.getVal();
prepareBar(x, y, set.getBarSpace());
mDrawCanvas.drawRect(mBarRect, mHighlightPaint);
if (mDrawHighlightArrow) {
mHighlightPaint.setAlpha(255);
// distance between highlight arrow and bar
float offsetY = mDeltaY * 0.07f;
Path arrow = new Path();
arrow.moveTo(x + 0.5f, y + offsetY * 0.3f);
arrow.lineTo(x + 0.2f, y + offsetY);
arrow.lineTo(x + 0.8f, y + offsetY);
mTrans.pathValueToPixel(arrow);
mDrawCanvas.drawPath(arrow, mHighlightPaint);
}
}
}
}
use of com.github.mikephil.charting.data.BarDataSet in project carat by amplab.
the class BarLineChartBase method getPosition.
/**
* Returns the position (in pixels) the provided Entry has inside the chart
* view or null, if the provided Entry is null.
*
* @param e
* @return
*/
public PointF getPosition(Entry e) {
if (e == null)
return null;
float[] vals = new float[] { e.getXIndex(), e.getVal() };
if (this instanceof BarChart) {
BarDataSet set = (BarDataSet) mData.getDataSetForEntry(e);
if (set != null)
vals[0] += set.getBarSpace() / 2f;
}
mTrans.pointValuesToPixel(vals);
return new PointF(vals[0], vals[1]);
}
use of com.github.mikephil.charting.data.BarDataSet in project carat by amplab.
the class Chart method prepareLegend.
/**
* Generates an automatically prepared legend depending on the DataSets in
* the chart and their colors.
*/
public void prepareLegend() {
ArrayList<String> labels = new ArrayList<String>();
ArrayList<Integer> colors = new ArrayList<Integer>();
// loop for building up the colors and labels used in the legend
for (int i = 0; i < mData.getDataSetCount(); i++) {
DataSet<? extends Entry> dataSet = mData.getDataSetByIndex(i);
ArrayList<Integer> clrs = dataSet.getColors();
int entryCount = dataSet.getEntryCount();
// if we have a barchart with stacked bars
if (dataSet instanceof BarDataSet && ((BarDataSet) dataSet).getStackSize() > 1) {
BarDataSet bds = (BarDataSet) dataSet;
String[] sLabels = bds.getStackLabels();
for (int j = 0; j < clrs.size() && j < entryCount && j < bds.getStackSize(); j++) {
labels.add(sLabels[j % sLabels.length]);
colors.add(clrs.get(j));
}
// add the legend description label
colors.add(-2);
labels.add(bds.getLabel());
} else if (dataSet instanceof PieDataSet) {
ArrayList<String> xVals = mData.getXVals();
PieDataSet pds = (PieDataSet) dataSet;
for (int j = 0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) {
labels.add(xVals.get(j));
colors.add(clrs.get(j));
}
// add the legend description label
colors.add(-2);
labels.add(pds.getLabel());
} else {
for (int j = 0; j < clrs.size() && j < entryCount; j++) {
// if multiple colors are set for a DataSet, group them
if (j < clrs.size() - 1 && j < entryCount - 1) {
labels.add(null);
} else {
// add label to the last entry
String label = mData.getDataSetByIndex(i).getLabel();
labels.add(label);
}
colors.add(clrs.get(j));
}
}
}
Legend l = new Legend(colors, labels);
if (mLegend != null) {
// apply the old legend settings to a potential new legend
l.apply(mLegend);
}
mLegend = l;
}
use of com.github.mikephil.charting.data.BarDataSet in project anitrend-app by AniTrend.
the class MediaStatsFragment method showScoreDistribution.
private void showScoreDistribution() {
if (model.getStats() != null && model.getStats().getScoreDistribution() != null) {
configureScoreDistribution(model.getStats().getScoreDistribution());
BarDataSet barDataSet = new BarDataSet(getPresenter().getMediaScoreDistribution(model.getStats().getScoreDistribution()), getString(R.string.title_score_distribution));
barDataSet.setColor(CompatUtil.getColorFromAttr(getContext(), R.attr.colorAccent), 253);
barDataSet.setValueTextColor(CompatUtil.getColorFromAttr(getContext(), R.attr.titleColor));
BarData barData = new BarData(barDataSet);
barData.setBarWidth(0.9f);
binding.seriesScoreDist.setData(barData);
binding.seriesScoreDist.setFitBars(true);
binding.seriesScoreDist.invalidate();
}
}
Aggregations