Merge branch 'master' of https://github.com/PhilJay/MPAndroidChart
This commit is contained in:
commit
d4e2e697e6
26 changed files with 126 additions and 52 deletions
|
@ -107,7 +107,10 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
|
|||
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setForm(LegendForm.SQUARE);
|
||||
l.setFormSize(9f);
|
||||
l.setTextSize(11f);
|
||||
|
|
|
@ -77,7 +77,10 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
|
|||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART_INSIDE);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(true);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setYOffset(0f);
|
||||
l.setYEntrySpace(0f);
|
||||
|
|
|
@ -93,7 +93,10 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
|
|||
mSeekBarX.setProgress(150); // set data
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setForm(LegendForm.SQUARE);
|
||||
l.setFormSize(9f);
|
||||
l.setTextSize(11f);
|
||||
|
|
|
@ -72,7 +72,10 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
|
|||
mSeekBarY.setProgress(50);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
l.setTypeface(mTfLight);
|
||||
|
||||
YAxis yl = mChart.getAxisLeft();
|
||||
|
|
|
@ -62,7 +62,10 @@ public class CombinedChartActivity extends DemoBase {
|
|||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setWordWrapEnabled(true);
|
||||
l.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
|
||||
YAxis rightAxis = mChart.getAxisRight();
|
||||
rightAxis.setDrawGridLines(false);
|
||||
|
|
|
@ -71,7 +71,10 @@ public class HalfPieChartActivity extends DemoBase {
|
|||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.ABOVE_CHART_CENTER);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setXEntrySpace(7f);
|
||||
l.setYEntrySpace(0f);
|
||||
l.setYOffset(0f);
|
||||
|
|
|
@ -107,7 +107,10 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
|
|||
mSeekBarX.setOnSeekBarChangeListener(this);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setFormSize(8f);
|
||||
l.setXEntrySpace(4f);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,6 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
|
|||
Legend l = mChart.getLegend();
|
||||
|
||||
// modify the legend ...
|
||||
// l.setPosition(LegendPosition.LEFT_OF_CHART);
|
||||
l.setForm(LegendForm.LINE);
|
||||
|
||||
// dont forget to refresh the drawing
|
||||
|
|
|
@ -156,7 +156,6 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
|
|||
Legend l = mChart.getLegend();
|
||||
|
||||
// modify the legend ...
|
||||
// l.setPosition(LegendPosition.LEFT_OF_CHART);
|
||||
l.setForm(LegendForm.LINE);
|
||||
|
||||
// // dont forget to refresh the drawing
|
||||
|
|
|
@ -89,12 +89,14 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
|
|||
Legend l = mChart.getLegend();
|
||||
|
||||
// modify the legend ...
|
||||
// l.setPosition(LegendPosition.LEFT_OF_CHART);
|
||||
l.setForm(LegendForm.LINE);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setTextSize(11f);
|
||||
l.setTextColor(Color.WHITE);
|
||||
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
// l.setYOffset(11f);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
|
|
|
@ -75,7 +75,10 @@ public class MultiLineChartActivity extends DemoBase implements OnSeekBarChangeL
|
|||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -96,7 +96,10 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
|
|||
mSeekBarY.setOnSeekBarChangeListener(this);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
l.setXEntrySpace(7f);
|
||||
l.setYEntrySpace(0f);
|
||||
l.setYOffset(0f);
|
||||
|
|
|
@ -102,7 +102,10 @@ public class PiePolylineChartActivity extends DemoBase implements OnSeekBarChang
|
|||
// mChart.spin(2000, 0, 360);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
l.setEnabled(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,10 @@ public class RadarChartActivitry extends DemoBase {
|
|||
yAxis.setDrawLabels(false);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.ABOVE_CHART_CENTER);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setXEntrySpace(7f);
|
||||
l.setYEntrySpace(5f);
|
||||
|
|
|
@ -66,7 +66,6 @@ public class RealtimeLineChartActivity extends DemoBase implements
|
|||
Legend l = mChart.getLegend();
|
||||
|
||||
// modify the legend ...
|
||||
// l.setPosition(LegendPosition.LEFT_OF_CHART);
|
||||
l.setForm(LegendForm.LINE);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setTextColor(Color.WHITE);
|
||||
|
|
|
@ -70,7 +70,10 @@ public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeLis
|
|||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
l.setTypeface(mTfLight);
|
||||
l.setXOffset(5f);
|
||||
|
||||
|
|
|
@ -88,7 +88,10 @@ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListe
|
|||
mSeekBarY.setProgress(100);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setFormSize(8f);
|
||||
l.setFormToTextSpace(4f);
|
||||
l.setXEntrySpace(6f);
|
||||
|
|
|
@ -93,7 +93,10 @@ public class StackedBarActivityNegative extends DemoBase implements
|
|||
});
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
||||
l.setDrawInside(false);
|
||||
l.setFormSize(8f);
|
||||
l.setFormToTextSpace(4f);
|
||||
l.setXEntrySpace(6f);
|
||||
|
|
|
@ -43,7 +43,10 @@ public class PieChartFrag extends SimpleFragment {
|
|||
mChart.setTransparentCircleRadius(50f);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
|
||||
mChart.setData(generatePieData());
|
||||
|
||||
|
|
|
@ -73,7 +73,10 @@ public class PieChartItem extends ChartItem {
|
|||
holder.chart.setData((PieData) mChartData);
|
||||
|
||||
Legend l = holder.chart.getLegend();
|
||||
l.setPosition(LegendPosition.RIGHT_OF_CHART);
|
||||
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
||||
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
|
||||
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
||||
l.setDrawInside(false);
|
||||
l.setYEntrySpace(0f);
|
||||
l.setYOffset(0f);
|
||||
|
||||
|
|
|
@ -430,16 +430,18 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
mDescPaint.setColor(mDescription.getTextColor());
|
||||
mDescPaint.setTextAlign(mDescription.getTextAlign());
|
||||
|
||||
float x, y;
|
||||
|
||||
// if no position specified, draw on default position
|
||||
if (position == null) {
|
||||
|
||||
float x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset();
|
||||
float y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset();
|
||||
|
||||
c.drawText(mDescription.getText(), x, y, mDescPaint);
|
||||
x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset();
|
||||
y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset();
|
||||
} else {
|
||||
c.drawText(mDescription.getText(), position.x, position.y, mDescPaint);
|
||||
x = position.x;
|
||||
y = position.y;
|
||||
}
|
||||
|
||||
c.drawText(mDescription.getText(), x, y, mDescPaint);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,10 @@ import java.util.List;
|
|||
public class Legend extends ComponentBase {
|
||||
|
||||
/**
|
||||
* This property is deprecated - Use `position`, `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`,
|
||||
* This property is deprecated - Use `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`,
|
||||
* `direction`.
|
||||
*/
|
||||
@Deprecated
|
||||
public enum LegendPosition {
|
||||
RIGHT_OF_CHART, RIGHT_OF_CHART_CENTER, RIGHT_OF_CHART_INSIDE,
|
||||
LEFT_OF_CHART, LEFT_OF_CHART_CENTER, LEFT_OF_CHART_INSIDE,
|
||||
|
@ -423,10 +424,10 @@ public class Legend extends ComponentBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* returns the position of the legend relative to the chart
|
||||
*
|
||||
* @return
|
||||
* This property is deprecated - Use `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`,
|
||||
* `direction`.
|
||||
*/
|
||||
@Deprecated
|
||||
public LegendPosition getPosition() {
|
||||
|
||||
if (mOrientation == LegendOrientation.VERTICAL
|
||||
|
@ -463,10 +464,10 @@ public class Legend extends ComponentBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* sets the position of the legend relative to the whole chart
|
||||
*
|
||||
* @param newValue
|
||||
* This property is deprecated - Use `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`,
|
||||
* `direction`.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPosition(LegendPosition newValue) {
|
||||
|
||||
switch (newValue) {
|
||||
|
|
|
@ -298,13 +298,28 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
|
|||
while (low < high) {
|
||||
int m = (low + high) / 2;
|
||||
|
||||
float d1 = Math.abs(mValues.get(m).getX() - xValue);
|
||||
float d2 = Math.abs(mValues.get(m + 1).getX() - xValue);
|
||||
final float d1 = mValues.get(m).getX() - xValue,
|
||||
d2 = mValues.get(m + 1).getX() - xValue,
|
||||
ad1 = Math.abs(d1), ad2 = Math.abs(d2);
|
||||
|
||||
if (d2 <= d1) {
|
||||
if (ad2 < ad1) {
|
||||
// [m + 1] is closer to xValue
|
||||
// Search in an higher place
|
||||
low = m + 1;
|
||||
} else {
|
||||
} else if (ad1 < ad2) {
|
||||
// [m] is closer to xValue
|
||||
// Search in a lower place
|
||||
high = m;
|
||||
} else {
|
||||
// We have multiple sequential x-value with same distance
|
||||
|
||||
if (d1 >= 0.0) {
|
||||
// Search in a lower place
|
||||
high = m;
|
||||
} else if (d1 < 0.0) {
|
||||
// Search in an higher place
|
||||
low = m + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,9 @@ public abstract class AxisRenderer extends Renderer {
|
|||
mAxis.mCenteredEntries = new float[n];
|
||||
}
|
||||
|
||||
float offset = (mAxis.mEntries[1] - mAxis.mEntries[0]) / 2f;
|
||||
float offset = 0.f;
|
||||
if (mAxis.mEntries.length > 1)
|
||||
offset = (mAxis.mEntries[1] - mAxis.mEntries[0]) / 2f;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
mAxis.mCenteredEntries[i] = mAxis.mEntries[i] + offset;
|
||||
|
|
|
@ -199,22 +199,33 @@ public class LineChartRenderer extends LineRadarRenderer {
|
|||
float curDx = 0f;
|
||||
float curDy = 0f;
|
||||
|
||||
Entry prevPrev = dataSet.getEntryForIndex(mXBounds.min);
|
||||
Entry prev = prevPrev;
|
||||
Entry cur = prev;
|
||||
Entry next = dataSet.getEntryForIndex(mXBounds.min + 1);
|
||||
// Take an extra point from the left, and an extra from the right.
|
||||
// That's because we need 4 points for a cubic bezier (cubic=4), otherwise we get lines moving and doing weird stuff on the edges of the chart.
|
||||
// So in the starting `prev` and `cur`, go -2, -1
|
||||
// And in the `lastIndex`, add +1
|
||||
|
||||
if (cur == null || next == null) return;
|
||||
final int firstIndex = mXBounds.min + 1;
|
||||
final int lastIndex = mXBounds.min + mXBounds.range;
|
||||
|
||||
Entry prevPrev;
|
||||
Entry prev = dataSet.getEntryForIndex(Math.max(firstIndex - 2, 0));
|
||||
Entry cur = dataSet.getEntryForIndex(Math.max(firstIndex - 1, 0));
|
||||
Entry next = cur;
|
||||
int nextIndex = -1;
|
||||
|
||||
if (cur == null) return;
|
||||
|
||||
// let the spline start
|
||||
cubicPath.moveTo(cur.getX(), cur.getY() * phaseY);
|
||||
|
||||
for (int j = mXBounds.min + 1; j <= mXBounds.range + mXBounds.min; j++) {
|
||||
|
||||
prevPrev = dataSet.getEntryForIndex(j == 1 ? 0 : j - 2);
|
||||
prev = dataSet.getEntryForIndex(j - 1);
|
||||
cur = dataSet.getEntryForIndex(j);
|
||||
next = mXBounds.max > j + 1 ? dataSet.getEntryForIndex(j + 1) : cur;
|
||||
prevPrev = prev;
|
||||
prev = cur;
|
||||
cur = nextIndex == j ? next : dataSet.getEntryForIndex(j);
|
||||
|
||||
nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j;
|
||||
next = dataSet.getEntryForIndex(nextIndex);
|
||||
|
||||
prevDx = (cur.getX() - prevPrev.getX()) * intensity;
|
||||
prevDy = (cur.getY() - prevPrev.getY()) * intensity;
|
||||
|
@ -350,8 +361,6 @@ public class LineChartRenderer extends LineRadarRenderer {
|
|||
// make sure the lines don't do shitty things outside
|
||||
// bounds
|
||||
if (!mViewPortHandler.isInBoundsLeft(mLineBuffer[2])
|
||||
|| (!mViewPortHandler.isInBoundsTop(mLineBuffer[1]) && !mViewPortHandler
|
||||
.isInBoundsBottom(mLineBuffer[3]))
|
||||
|| (!mViewPortHandler.isInBoundsTop(mLineBuffer[1]) && !mViewPortHandler
|
||||
.isInBoundsBottom(mLineBuffer[3])))
|
||||
continue;
|
||||
|
|
|
@ -207,8 +207,6 @@ public class YAxisRendererHorizontalBarChart extends YAxisRenderer {
|
|||
c.drawPath(zeroLinePath, mZeroLinePaint);
|
||||
|
||||
c.restoreToCount(clipRestoreCount);
|
||||
|
||||
c.restoreToCount(clipRestoreCount);
|
||||
}
|
||||
|
||||
protected Path mRenderLimitLinesPathBuffer = new Path();
|
||||
|
|
Loading…
Add table
Reference in a new issue