More fixes related to MarkerView drawing
This commit is contained in:
parent
8a37bbda38
commit
5ff8f9609b
14 changed files with 102 additions and 31 deletions
|
@ -68,7 +68,7 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
|
|||
mChart.setMaxVisibleValueCount(200);
|
||||
mChart.setPinchZoom(true);
|
||||
|
||||
mSeekBarX.setProgress(1);
|
||||
mSeekBarX.setProgress(10);
|
||||
mSeekBarY.setProgress(50);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
|
|
|
@ -17,9 +17,9 @@ import com.github.mikephil.charting.components.Legend.LegendPosition;
|
|||
import com.github.mikephil.charting.components.MarkerView;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
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.data.RadarEntry;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
|
@ -210,20 +210,20 @@ public class RadarChartActivitry extends DemoBase {
|
|||
float min = 20;
|
||||
int cnt = 5;
|
||||
|
||||
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
|
||||
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
|
||||
ArrayList<RadarEntry> yVals1 = new ArrayList<RadarEntry>();
|
||||
ArrayList<RadarEntry> yVals2 = new ArrayList<RadarEntry>();
|
||||
|
||||
// IMPORTANT: In a PieChart, no values (Entry) should have the same
|
||||
// xIndex (even if from different DataSets), since no values can be
|
||||
// drawn above each other.
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
float val = (float) (Math.random() * mult) + min;
|
||||
yVals1.add(new Entry(i, val));
|
||||
yVals1.add(new RadarEntry(val));
|
||||
}
|
||||
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
float val = (float) (Math.random() * mult) + min;
|
||||
yVals2.add(new Entry(i, val));
|
||||
yVals2.add(new RadarEntry(val));
|
||||
}
|
||||
|
||||
RadarDataSet set1 = new RadarDataSet(yVals1, "Last Week");
|
||||
|
|
|
@ -183,7 +183,7 @@ public class PieChart extends PieRadarChartBase<PieData> {
|
|||
|
||||
float rotationAngle = getRotationAngle();
|
||||
|
||||
int entryIndex = getData().getDataSet().getEntryIndex(highlight.getX(), DataSet.Rounding.CLOSEST);
|
||||
int entryIndex = (int) highlight.getX();
|
||||
|
||||
// offset needed to center the drawn text in the slice
|
||||
float offset = mDrawAngles[entryIndex] / 2;
|
||||
|
|
|
@ -201,12 +201,21 @@ public class RadarChart extends PieRadarChartBase<RadarData> {
|
|||
|
||||
float sliceangle = getSliceAngle();
|
||||
|
||||
for (int i = 0; i < mData.getMaxEntryCountSet().getEntryCount(); i++) {
|
||||
if (sliceangle * (i + 1) - sliceangle / 2f > a)
|
||||
return i;
|
||||
int max = mData.getMaxEntryCountSet().getEntryCount();
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < max; i++) {
|
||||
|
||||
float referenceAngle = sliceangle * (i + 1) - sliceangle / 2f;
|
||||
|
||||
if (referenceAngle > a) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,6 +45,18 @@ public class PieEntry extends Entry {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setX(float x) {
|
||||
super.setX(x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public float getX() {
|
||||
return super.getX();
|
||||
}
|
||||
|
||||
public PieEntry copy() {
|
||||
PieEntry e = new PieEntry(getY(), label, getData());
|
||||
return e;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
package com.github.mikephil.charting.data;
|
||||
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -49,4 +50,9 @@ public class RadarData extends ChartData<IRadarDataSet> {
|
|||
public List<String> getLabels() {
|
||||
return mLabels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry getEntryForHighlight(Highlight highlight) {
|
||||
return getDataSetByIndex(highlight.getDataSetIndex()).getEntryForIndex((int) highlight.getX());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.github.mikephil.charting.utils.ColorTemplate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataSet {
|
||||
public class RadarDataSet extends LineRadarDataSet<RadarEntry> implements IRadarDataSet {
|
||||
|
||||
/// flag indicating whether highlight circle should be drawn or not
|
||||
protected boolean mDrawHighlightCircleEnabled = false;
|
||||
|
@ -25,7 +25,7 @@ public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataS
|
|||
protected float mHighlightCircleOuterRadius = 4.0f;
|
||||
protected float mHighlightCircleStrokeWidth = 2.0f;
|
||||
|
||||
public RadarDataSet(List<Entry> yVals, String label) {
|
||||
public RadarDataSet(List<RadarEntry> yVals, String label) {
|
||||
super(yVals, label);
|
||||
}
|
||||
|
||||
|
@ -114,9 +114,9 @@ public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataS
|
|||
}
|
||||
|
||||
@Override
|
||||
public DataSet<Entry> copy() {
|
||||
public DataSet<RadarEntry> copy() {
|
||||
|
||||
List<Entry> yVals = new ArrayList<Entry>();
|
||||
List<RadarEntry> yVals = new ArrayList<RadarEntry>();
|
||||
|
||||
for (int i = 0; i < mValues.size(); i++) {
|
||||
yVals.add(mValues.get(i).copy());
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.github.mikephil.charting.data;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
/**
|
||||
* Created by philipp on 13/06/16.
|
||||
*/
|
||||
@SuppressLint("ParcelCreator")
|
||||
public class RadarEntry extends Entry {
|
||||
|
||||
public RadarEntry(float value) {
|
||||
super(0f, value);
|
||||
}
|
||||
|
||||
public RadarEntry(float value, Object data) {
|
||||
super(0f, value, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the same as getY(). Returns the value of the RadarEntry.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float getValue() {
|
||||
return getY();
|
||||
}
|
||||
|
||||
public RadarEntry copy() {
|
||||
RadarEntry e = new RadarEntry(getY(), getData());
|
||||
return e;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setX(float x) {
|
||||
super.setX(x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public float getX() {
|
||||
return super.getX();
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import io.realm.RealmResults;
|
|||
/**
|
||||
* Created by Philipp Jahoda on 08/11/15.
|
||||
*/
|
||||
public abstract class RealmLineRadarDataSet<T extends RealmObject> extends RealmLineScatterCandleRadarDataSet<T, Entry> implements ILineRadarDataSet<Entry> {
|
||||
public abstract class RealmLineRadarDataSet<T extends RealmObject, S extends Entry> extends RealmLineScatterCandleRadarDataSet<T, S> implements ILineRadarDataSet<S> {
|
||||
|
||||
/** the color that is used for filling the line surface */
|
||||
private int mFillColor = Color.rgb(140, 234, 255);
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.DashPathEffect;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.LineDataSet;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
|
||||
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
|
||||
|
@ -21,7 +22,7 @@ import io.realm.RealmResults;
|
|||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T> implements ILineDataSet {
|
||||
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T, Entry> implements ILineDataSet {
|
||||
|
||||
/** Drawing mode for this line dataset **/
|
||||
private LineDataSet.Mode mMode = LineDataSet.Mode.LINEAR;
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.github.mikephil.charting.data.realm.implementation;
|
|||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
@ -12,7 +14,7 @@ import io.realm.RealmResults;
|
|||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmRadarDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T> implements IRadarDataSet {
|
||||
public class RealmRadarDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T, RadarEntry> implements IRadarDataSet {
|
||||
|
||||
/// flag indicating whether highlight circle should be drawn or not
|
||||
protected boolean mDrawHighlightCircleEnabled = false;
|
||||
|
|
|
@ -69,12 +69,8 @@ public class RadarHighlighter extends PieRadarHighlighter<RadarChart> {
|
|||
|
||||
float y = (entry.getY() - mChart.getYChartMin());
|
||||
|
||||
if (Float.isNaN(y))
|
||||
continue;
|
||||
|
||||
PointF p = Utils.getPosition(
|
||||
mChart.getCenterOffsets(),
|
||||
y * factor * phaseY,
|
||||
mChart.getCenterOffsets(), y * factor * phaseY,
|
||||
sliceangle * index * phaseX + mChart.getRotationAngle());
|
||||
|
||||
vals.add(new Highlight(index, entry.getY(), p.x, p.y, i, dataSet.getAxisDependency()));
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.github.mikephil.charting.interfaces.datasets;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 03/11/15.
|
||||
*/
|
||||
public interface IRadarDataSet extends ILineRadarDataSet<Entry> {
|
||||
public interface IRadarDataSet extends ILineRadarDataSet<RadarEntry> {
|
||||
|
||||
/// flag indicating whether highlight circle should be drawn or not
|
||||
boolean isDrawHighlightCircleEnabled();
|
||||
|
|
|
@ -10,8 +10,8 @@ import android.graphics.drawable.Drawable;
|
|||
|
||||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.RadarData;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
@ -97,7 +97,7 @@ public class RadarChartRenderer extends LineRadarRenderer {
|
|||
|
||||
mRenderPaint.setColor(dataSet.getColor(j));
|
||||
|
||||
Entry e = dataSet.getEntryForIndex(j);
|
||||
RadarEntry e = dataSet.getEntryForIndex(j);
|
||||
|
||||
PointF p = Utils.getPosition(
|
||||
center,
|
||||
|
@ -169,7 +169,7 @@ public class RadarChartRenderer extends LineRadarRenderer {
|
|||
|
||||
for (int j = 0; j < dataSet.getEntryCount(); j++) {
|
||||
|
||||
Entry entry = dataSet.getEntryForIndex(j);
|
||||
RadarEntry entry = dataSet.getEntryForIndex(j);
|
||||
|
||||
PointF p = Utils.getPosition(
|
||||
center,
|
||||
|
@ -257,13 +257,14 @@ public class RadarChartRenderer extends LineRadarRenderer {
|
|||
if (set == null || !set.isHighlightEnabled())
|
||||
continue;
|
||||
|
||||
Entry e = set.getEntryForXPos(high.getX());
|
||||
RadarEntry e = set.getEntryForIndex((int) high.getX());
|
||||
|
||||
if (!isInBoundsX(e, set))
|
||||
continue;
|
||||
|
||||
PointF p = Utils.getPosition(center,
|
||||
(e.getY() - mChart.getYChartMin()) * factor * mAnimator.getPhaseY(),
|
||||
float y = (e.getY() - mChart.getYChartMin());
|
||||
|
||||
PointF p = Utils.getPosition(center, y * factor * mAnimator.getPhaseY(),
|
||||
sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle());
|
||||
|
||||
high.setDraw(p.x, p.y);
|
||||
|
|
Loading…
Add table
Reference in a new issue