Work on radarchart rendering, cleanup xaxis
This commit is contained in:
parent
4ae9950632
commit
639d335909
12 changed files with 128 additions and 181 deletions
|
@ -10,6 +10,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.Legend.LegendPosition;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
|
@ -17,6 +18,7 @@ import com.github.mikephil.charting.components.YAxis;
|
|||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.RadarData;
|
||||
import com.github.mikephil.charting.data.RadarDataSet;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
@ -64,6 +66,17 @@ public class RadarChartActivitry extends DemoBase {
|
|||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setTypeface(tf);
|
||||
xAxis.setTextSize(9f);
|
||||
xAxis.setValueFormatter(new AxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return mMonths[(int) value % mMonths.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
YAxis yAxis = mChart.getYAxis();
|
||||
yAxis.setTypeface(tf);
|
||||
|
|
|
@ -38,7 +38,6 @@ public class ScrollViewActivity extends DemoBase {
|
|||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setPosition(XAxisPosition.BOTTOM);
|
||||
xAxis.setLabelsToSkip(0);
|
||||
xAxis.setDrawGridLines(false);
|
||||
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
|
|
|
@ -197,7 +197,6 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
|
|||
return;
|
||||
|
||||
long starttime = System.currentTimeMillis();
|
||||
calcModulus();
|
||||
|
||||
// execute all drawing commands
|
||||
drawGridBackground(canvas);
|
||||
|
@ -523,35 +522,6 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
|
|||
prepareValuePxMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates the modulus for xPx-labels and grid
|
||||
*/
|
||||
protected void calcModulus() {
|
||||
|
||||
// if (mXAxis == null || !mXAxis.isEnabled())
|
||||
// return;
|
||||
//
|
||||
// if (!mXAxis.isAxisModulusCustom()) {
|
||||
//
|
||||
// float[] values = new float[9];
|
||||
// mViewPortHandler.getMatrixTouch().getValues(values);
|
||||
//
|
||||
// mXAxis.mAxisLabelModulus = (int) Math
|
||||
// .ceil((mData.getXValCount() * mXAxis.mLabelRotatedWidth)
|
||||
// / (mViewPortHandler.contentWidth() * values[Matrix.MSCALE_X]));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// if (mLogEnabled)
|
||||
// Log.i(LOG_TAG, "X-Axis modulus: " + mXAxis.mAxisLabelModulus +
|
||||
// ", xPx-axis label width: " + mXAxis.mLabelWidth +
|
||||
// ", xPx-axis label rotated width: " + mXAxis.mLabelRotatedWidth +
|
||||
// ", content width: " + mViewPortHandler.contentWidth());
|
||||
//
|
||||
// if (mXAxis.mAxisLabelModulus < 1)
|
||||
// mXAxis.mAxisLabelModulus = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float[] getMarkerPosition(Entry e, Highlight highlight) {
|
||||
|
||||
|
|
|
@ -131,19 +131,6 @@ public class HorizontalBarChart extends BarChart {
|
|||
mXAxis.mAxisMinimum);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void calcModulus() {
|
||||
// float[] values = new float[9];
|
||||
// mViewPortHandler.getMatrixTouch().getValues(values);
|
||||
//
|
||||
// mXAxis.mAxisLabelModulus =
|
||||
// (int) Math.ceil((mData.getXValCount() * mXAxis.mLabelRotatedHeight)
|
||||
// / (mViewPortHandler.contentHeight() * values[Matrix.MSCALE_Y]));
|
||||
//
|
||||
// if (mXAxis.mAxisLabelModulus < 1)
|
||||
// mXAxis.mAxisLabelModulus = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RectF getBarBounds(BarEntry e) {
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ public abstract class PieRadarChartBase<T extends ChartData<? extends IDataSet<?
|
|||
XAxis x = this.getXAxis();
|
||||
|
||||
if (x.isEnabled() && x.isDrawLabelsEnabled()) {
|
||||
minOffset = Math.max(minOffset, x.mLabelRotatedWidth);
|
||||
minOffset = Math.max(minOffset, x.mLabelRotatedWidth * 2f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ public class RadarChart extends PieRadarChartBase<RadarData> {
|
|||
// mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum);
|
||||
|
||||
mYAxis.calculate(mData.getYMin(AxisDependency.LEFT), mData.getYMax(AxisDependency.LEFT));
|
||||
mXAxis.calculate(0, mData.getMaxEntryCountSet().getEntryCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,7 +135,6 @@ public class RadarChart extends PieRadarChartBase<RadarData> {
|
|||
|
||||
mYAxisRenderer.computeAxis(mYAxis.mAxisMinimum, mYAxis.mAxisMaximum, mYAxis.isInverted());
|
||||
mXAxisRenderer.computeAxis(mXAxis.mAxisMinimum, mXAxis.mAxisMaximum, false);
|
||||
//mXAxisRenderer.computeSize(mData.getXValMaximumLength(), mData.getXVals());
|
||||
|
||||
if (mLegend != null && !mLegend.isLegendCustom())
|
||||
mLegendRenderer.computeLegend(mData);
|
||||
|
@ -149,6 +149,12 @@ public class RadarChart extends PieRadarChartBase<RadarData> {
|
|||
if (mData == null)
|
||||
return;
|
||||
|
||||
if (mYAxis.isEnabled())
|
||||
mYAxisRenderer.computeAxis(mYAxis.mAxisMinimum, mYAxis.mAxisMaximum, mYAxis.isInverted());
|
||||
|
||||
if (mXAxis.isEnabled())
|
||||
mXAxisRenderer.computeAxis(mXAxis.mAxisMinimum, mXAxis.mAxisMaximum, false);
|
||||
|
||||
mXAxisRenderer.renderAxisLabels(canvas);
|
||||
|
||||
if (mDrawWeb)
|
||||
|
|
|
@ -41,18 +41,6 @@ public class XAxis extends AxisBase {
|
|||
*/
|
||||
protected float mLabelRotationAngle = 0f;
|
||||
|
||||
/**
|
||||
* the modulus that indicates if a yValue at a specified index in an
|
||||
* array(list) for the xPx-axis-labels is drawn or not. If index % modulus ==
|
||||
* 0 DRAW, else dont draw.
|
||||
*/
|
||||
public int mAxisLabelModulus = 1;
|
||||
|
||||
/**
|
||||
* Is axisLabelModulus a custom yValue or auto calculated? If false, then
|
||||
* it's auto, if true, then custom. default: false (automatic modulus)
|
||||
*/
|
||||
private boolean mIsAxisModulusCustom = false;
|
||||
/**
|
||||
* if set to true, the chart will avoid that the first and last label entry
|
||||
* in the chart "clip" off the edge of the chart
|
||||
|
@ -109,43 +97,6 @@ public class XAxis extends AxisBase {
|
|||
mLabelRotationAngle = angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of labels that should be skipped on the axis before the
|
||||
* next label is drawn. This will disable the feature that automatically
|
||||
* calculates an adequate space between the axis labels and set the number
|
||||
* of labels to be skipped to the fixed number provided by this method. Call
|
||||
* resetLabelsToSkip(...) to re-enable automatic calculation.
|
||||
*
|
||||
* @param count
|
||||
*/
|
||||
public void setLabelsToSkip(int count) {
|
||||
|
||||
if (count < 0)
|
||||
count = 0;
|
||||
|
||||
mIsAxisModulusCustom = true;
|
||||
mAxisLabelModulus = count + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling this will disable a custom number of labels to be skipped (set by
|
||||
* setLabelsToSkip(...)) while drawing the xPx-axis. Instead, the number of
|
||||
* values to skip will again be calculated automatically.
|
||||
*/
|
||||
public void resetLabelsToSkip() {
|
||||
mIsAxisModulusCustom = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a custom axis-modulus has been set that determines the
|
||||
* number of labels to skip when drawing.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAxisModulusCustom() {
|
||||
return mIsAxisModulusCustom;
|
||||
}
|
||||
|
||||
/**
|
||||
* if set to true, the chart will avoid that the first and last label entry
|
||||
* in the chart "clip" off the edge of the chart or the screen
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.github.mikephil.charting.data;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 02/06/16.
|
||||
*/
|
||||
public abstract class BaseEntry {
|
||||
|
||||
/** the y value */
|
||||
private float y = 0f;
|
||||
|
||||
/** optional spot for additional data this Entry represents */
|
||||
private Object mData = null;
|
||||
|
||||
public BaseEntry() {
|
||||
|
||||
}
|
||||
|
||||
public BaseEntry(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public BaseEntry(float y, Object data) {
|
||||
this(y);
|
||||
this.mData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the yPx yValue of this Entry.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the yPx-yValue for the Entry.
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data, additional information that this Entry represents, or
|
||||
* null, if no data has been specified.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets additional data this Entry should represent.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public void setData(Object data) {
|
||||
this.mData = data;
|
||||
}
|
||||
}
|
|
@ -11,17 +11,11 @@ import android.os.Parcelable;
|
|||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class Entry implements Parcelable {
|
||||
public class Entry extends BaseEntry implements Parcelable {
|
||||
|
||||
/** the yPx yValue */
|
||||
private float y = 0f;
|
||||
|
||||
/** the xPx yValue */
|
||||
/** the x value */
|
||||
private float x = 0f;
|
||||
|
||||
/** optional spot for additional data this Entry represents */
|
||||
private Object mData = null;
|
||||
|
||||
public Entry() {
|
||||
|
||||
}
|
||||
|
@ -33,7 +27,7 @@ public class Entry implements Parcelable {
|
|||
* @param y the yPx yValue (the actual yValue of the entry)
|
||||
*/
|
||||
public Entry(float x, float y) {
|
||||
this.y = y;
|
||||
super(y);
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
|
@ -45,8 +39,8 @@ public class Entry implements Parcelable {
|
|||
* @param data Spot for additional data this Entry represents.
|
||||
*/
|
||||
public Entry(float x, float y, Object data) {
|
||||
this(x, y);
|
||||
this.mData = data;
|
||||
super(y, data);
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,50 +61,13 @@ public class Entry implements Parcelable {
|
|||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the yPx yValue of this Entry.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the yPx-yValue for the Entry.
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data, additional information that this Entry represents, or
|
||||
* null, if no data has been specified.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets additional data this Entry should represent.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public void setData(Object data) {
|
||||
this.mData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an exact copy of the entry
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Entry copy() {
|
||||
Entry e = new Entry(x, y, mData);
|
||||
Entry e = new Entry(x, getY(), getData());
|
||||
return e;
|
||||
}
|
||||
|
||||
|
@ -127,13 +84,13 @@ public class Entry implements Parcelable {
|
|||
if (e == null)
|
||||
return false;
|
||||
|
||||
if (e.mData != this.mData)
|
||||
if (e.getData() != this.getData())
|
||||
return false;
|
||||
|
||||
if (Math.abs(e.x - this.x) > 0.000001f)
|
||||
return false;
|
||||
|
||||
if (Math.abs(e.y - this.y) > 0.000001f)
|
||||
if (Math.abs(e.getY() - this.getY()) > 0.000001f)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -155,11 +112,11 @@ public class Entry implements Parcelable {
|
|||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeFloat(this.x);
|
||||
dest.writeFloat(this.y);
|
||||
if (mData != null) {
|
||||
if (mData instanceof Parcelable) {
|
||||
dest.writeFloat(this.getY());
|
||||
if (getData() != null) {
|
||||
if (getData() instanceof Parcelable) {
|
||||
dest.writeInt(1);
|
||||
dest.writeParcelable((Parcelable) this.mData, flags);
|
||||
dest.writeParcelable((Parcelable) this.getData(), flags);
|
||||
} else {
|
||||
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
|
||||
}
|
||||
|
@ -170,9 +127,9 @@ public class Entry implements Parcelable {
|
|||
|
||||
protected Entry(Parcel in) {
|
||||
this.x = in.readFloat();
|
||||
this.y = in.readFloat();
|
||||
this.setY(in.readFloat());
|
||||
if (in.readInt() == 1) {
|
||||
this.mData = in.readParcelable(Object.class.getClassLoader());
|
||||
this.setData(in.readParcelable(Object.class.getClassLoader()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ package com.github.mikephil.charting.data;
|
|||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +14,8 @@ import java.util.List;
|
|||
*/
|
||||
public class RadarData extends ChartData<IRadarDataSet> {
|
||||
|
||||
private List<String> mLabels;
|
||||
|
||||
public RadarData() {
|
||||
super();
|
||||
}
|
||||
|
@ -24,4 +27,26 @@ public class RadarData extends ChartData<IRadarDataSet> {
|
|||
public RadarData(IRadarDataSet... dataSets) {
|
||||
super(dataSets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the labels that should be drawn around the RadarChart at the end of each web line.
|
||||
*
|
||||
* @param labels
|
||||
*/
|
||||
public void setLabels(List<String> labels) {
|
||||
this.mLabels = labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the labels that should be drawn around the RadarChart at the end of each web line.
|
||||
*
|
||||
* @param labels
|
||||
*/
|
||||
public void setLabels(String... labels) {
|
||||
this.mLabels = Arrays.asList(labels);
|
||||
}
|
||||
|
||||
public List<String> getLabels() {
|
||||
return mLabels;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,30 +59,6 @@ public class XAxisRenderer extends AxisRenderer {
|
|||
|
||||
@Override
|
||||
protected void computeAxisValues(float min, float max) {
|
||||
|
||||
// int labelCount = mXAxis.getLabelCount();
|
||||
// float range = Math.abs(max - min);
|
||||
//
|
||||
// float interval = range / (labelCount - 1);
|
||||
//
|
||||
// if (mXAxis.mEntries == null || mXAxis.mEntries.length != labelCount) {
|
||||
// mXAxis.mEntries = new float[labelCount];
|
||||
// mXAxis.mEntryCount = labelCount;
|
||||
// }
|
||||
//
|
||||
// mXAxis.mEntries[0] = min;
|
||||
//
|
||||
// for (int i = 1; i < labelCount; i++) {
|
||||
// mXAxis.mEntries[i] = min + interval * (float) i;
|
||||
// }
|
||||
//
|
||||
// // set decimals
|
||||
// if (interval < 1) {
|
||||
// mXAxis.mDecimals = (int) Math.ceil(-Math.log10(interval));
|
||||
// } else {
|
||||
// mXAxis.mDecimals = 0;
|
||||
// }
|
||||
|
||||
super.computeAxisValues(min, max);
|
||||
|
||||
computeSize();
|
||||
|
|
|
@ -26,7 +26,7 @@ public class XAxisRendererRadarChart extends XAxisRenderer {
|
|||
return;
|
||||
|
||||
final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
|
||||
final PointF drawLabelAnchor = new PointF(0.5f, 0.0f);
|
||||
final PointF drawLabelAnchor = new PointF(0.5f, 0.25f);
|
||||
|
||||
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
|
||||
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
|
||||
|
@ -40,14 +40,14 @@ public class XAxisRendererRadarChart extends XAxisRenderer {
|
|||
|
||||
PointF center = mChart.getCenterOffsets();
|
||||
|
||||
int mod = mXAxis.mAxisLabelModulus;
|
||||
for (int i = 0; i < mXAxis.mEntryCount; i += mod) {
|
||||
String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i], mXAxis);
|
||||
for (int i = 0; i < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) {
|
||||
|
||||
String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis);
|
||||
|
||||
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
|
||||
|
||||
PointF p = Utils.getPosition(center, mChart.getYRange() * factor
|
||||
+ mXAxis.mLabelRotatedWidth / 2f, angle);
|
||||
+ mXAxis.mLabelRotatedWidth, angle);
|
||||
|
||||
drawLabel(c, label, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f,
|
||||
drawLabelAnchor, labelRotationAngleDegrees);
|
||||
|
|
Loading…
Add table
Reference in a new issue