use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class ScatterChart method drawData.
@Override
protected void drawData() {
ArrayList<ScatterDataSet> dataSets = mData.getDataSets();
for (int i = 0; i < mData.getDataSetCount(); i++) {
ScatterDataSet dataSet = dataSets.get(i);
ArrayList<Entry> entries = dataSet.getYVals();
float shapeHalf = dataSet.getScatterShapeSize() / 2f;
float[] valuePoints = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
ScatterShape shape = dataSet.getScatterShape();
for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) {
if (isOffContentRight(valuePoints[j]))
break;
// make sure the lines don't do shitty things outside bounds
if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1]))
continue;
// Set the color for the currently drawn value. If the index is
// out of bounds, reuse colors.
mRenderPaint.setColor(dataSet.getColor(j));
if (shape == ScatterShape.SQUARE) {
mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint);
} else if (shape == ScatterShape.CIRCLE) {
mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint);
} else if (shape == ScatterShape.CROSS) {
mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint);
mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint);
} else if (shape == ScatterShape.TRIANGLE) {
// create a triangle path
Path tri = new Path();
tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf);
tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf);
tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf);
tri.close();
mDrawCanvas.drawPath(tri, mRenderPaint);
} else if (shape == ScatterShape.CUSTOM) {
Path customShape = dataSet.getCustomScatterShape();
if (customShape == null)
return;
// transform the provided custom path
mTrans.pathValueToPixel(customShape);
mDrawCanvas.drawPath(customShape, mRenderPaint);
}
}
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class LineChart method drawAdditional.
/**
* draws the circle value indicators
*/
@Override
protected void drawAdditional() {
mRenderPaint.setStyle(Paint.Style.FILL);
ArrayList<LineDataSet> dataSets = mData.getDataSets();
for (int i = 0; i < mData.getDataSetCount(); i++) {
LineDataSet dataSet = dataSets.get(i);
// if drawing circles is enabled for this dataset
if (dataSet.isDrawCirclesEnabled()) {
ArrayList<Entry> entries = dataSet.getYVals();
float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
for (int j = 0; j < positions.length * mPhaseX; j += 2) {
// Set the color for the currently drawn value. If the index
// is
// out of bounds, reuse colors.
mRenderPaint.setColor(dataSet.getCircleColor(j / 2));
if (isOffContentRight(positions[j]))
break;
// bounds
if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
continue;
mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize(), mRenderPaint);
mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize() / 2f, mCirclePaintInner);
}
}
// else do nothing
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class LineChart method drawValues.
@Override
protected void drawValues() {
// if values are drawn
if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) {
ArrayList<LineDataSet> dataSets = mData.getDataSets();
for (int i = 0; i < mData.getDataSetCount(); i++) {
LineDataSet dataSet = dataSets.get(i);
// make sure the values do not interfear with the circles
int valOffset = (int) (dataSet.getCircleSize() * 1.75f);
if (!dataSet.isDrawCirclesEnabled())
valOffset = valOffset / 2;
ArrayList<Entry> entries = dataSet.getYVals();
float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
for (int j = 0; j < positions.length * mPhaseX; j += 2) {
if (isOffContentRight(positions[j]))
break;
if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
continue;
float val = entries.get(j / 2).getVal();
if (mDrawUnitInChart) {
mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - valOffset, mValuePaint);
} else {
mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - valOffset, mValuePaint);
}
}
}
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class PieChart method drawData.
@Override
protected void drawData() {
float angle = mRotationAngle;
ArrayList<PieDataSet> dataSets = mData.getDataSets();
int cnt = 0;
for (int i = 0; i < mData.getDataSetCount(); i++) {
PieDataSet dataSet = dataSets.get(i);
ArrayList<Entry> entries = dataSet.getYVals();
for (int j = 0; j < entries.size(); j++) {
float newangle = mDrawAngles[cnt];
float sliceSpace = dataSet.getSliceSpace();
Entry e = entries.get(j);
// draw only if the value is greater than zero
if ((Math.abs(e.getVal()) > 0.000001)) {
if (!needsHighlight(e.getXIndex(), i)) {
mRenderPaint.setColor(dataSet.getColor(j));
mDrawCanvas.drawArc(mCircleBox, angle + sliceSpace / 2f, newangle * mPhaseY - sliceSpace / 2f, true, mRenderPaint);
}
// if(sliceSpace > 0f) {
//
// PointF outer = getPosition(c, radius, angle);
// PointF inner = getPosition(c, radius * mHoleRadiusPercent
// / 100f, angle);
// }
}
angle += newangle * mPhaseX;
cnt++;
}
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class PieChart method drawValues.
@Override
protected void drawValues() {
// if neither xvals nor yvals are drawn, return
if (!mDrawXVals && !mDrawYValues)
return;
PointF center = getCenterCircleBox();
// get whole the radius
float r = getRadius();
float off = r / 2f;
if (mDrawHole) {
off = (r - (r / 100f * mHoleRadiusPercent)) / 2f;
}
// offset to keep things inside the chart
r -= off;
ArrayList<PieDataSet> dataSets = mData.getDataSets();
int cnt = 0;
for (int i = 0; i < mData.getDataSetCount(); i++) {
PieDataSet dataSet = dataSets.get(i);
ArrayList<Entry> entries = dataSet.getYVals();
for (int j = 0; j < entries.size() * mPhaseX; j++) {
// offset needed to center the drawn text in the slice
float offset = mDrawAngles[cnt] / 2;
// calculate the text position
float x = (float) (r * Math.cos(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset) * mPhaseY)) + center.x);
float y = (float) (r * Math.sin(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset) * mPhaseY)) + center.y);
String val = "";
float value = entries.get(j).getVal();
if (mUsePercentValues)
val = mValueFormatter.getFormattedValue(Math.abs(getPercentOfTotal(value))) + " %";
else
val = mValueFormatter.getFormattedValue(value);
if (mDrawUnitInChart)
val = val + mUnit;
// draw everything, depending on settings
if (mDrawXVals && mDrawYValues) {
// use ascent and descent to calculate the new line
// position,
// 1.6f is the line spacing
float lineHeight = (mValuePaint.ascent() + mValuePaint.descent()) * 1.6f;
y -= lineHeight / 2;
mDrawCanvas.drawText(val, x, y, mValuePaint);
if (j < mData.getXValCount())
mDrawCanvas.drawText(mData.getXVals().get(j), x, y + lineHeight, mValuePaint);
} else if (mDrawXVals && !mDrawYValues) {
if (j < mData.getXValCount())
mDrawCanvas.drawText(mData.getXVals().get(j), x, y, mValuePaint);
} else if (!mDrawXVals && mDrawYValues) {
mDrawCanvas.drawText(val, x, y, mValuePaint);
}
cnt++;
}
}
}
Aggregations