Allow drawables for RadarChart area filling.
This commit is contained in:
parent
981c7b4dc7
commit
cf3a09d3e0
4 changed files with 79 additions and 45 deletions
|
@ -179,11 +179,13 @@ public class RadarChartActivitry extends DemoBase {
|
|||
|
||||
RadarDataSet set1 = new RadarDataSet(yVals1, "Set 1");
|
||||
set1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
|
||||
set1.setFillColor(ColorTemplate.VORDIPLOM_COLORS[0]);
|
||||
set1.setDrawFilled(true);
|
||||
set1.setLineWidth(2f);
|
||||
|
||||
RadarDataSet set2 = new RadarDataSet(yVals2, "Set 2");
|
||||
set2.setColor(ColorTemplate.VORDIPLOM_COLORS[4]);
|
||||
set2.setFillColor(ColorTemplate.VORDIPLOM_COLORS[4]);
|
||||
set2.setDrawFilled(true);
|
||||
set2.setLineWidth(2f);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.github.mikephil.charting.utils.ViewPortHandler;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class LineChartRenderer extends LineScatterCandleRadarRenderer {
|
||||
public class LineChartRenderer extends LineRadarRenderer {
|
||||
|
||||
protected LineDataProvider mChart;
|
||||
|
||||
|
@ -127,22 +127,6 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
mRenderPaint.setPathEffect(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the provided path in filled mode with the provided drawable.
|
||||
*/
|
||||
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
|
||||
c.save();
|
||||
c.clipPath(filledPath);
|
||||
|
||||
drawable.setBounds((int) mViewPortHandler.contentLeft(),
|
||||
(int) mViewPortHandler.contentTop(),
|
||||
(int) mViewPortHandler.contentRight(),
|
||||
(int) mViewPortHandler.contentBottom());
|
||||
drawable.draw(c);
|
||||
|
||||
c.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a cubic line.
|
||||
*
|
||||
|
@ -271,7 +255,7 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
trans.pathValueToPixel(spline);
|
||||
|
||||
final Drawable drawable = dataSet.getFillDrawable();
|
||||
if (dataSet.getFillDrawable() != null) {
|
||||
if (drawable != null) {
|
||||
|
||||
drawFilledPath(c, spline, drawable);
|
||||
} else {
|
||||
|
@ -384,24 +368,6 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the provided path in filled mode with the provided color and alpha.
|
||||
* Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
|
||||
*
|
||||
* @param c
|
||||
* @param filledPath
|
||||
* @param fillColor
|
||||
* @param fillAlpha
|
||||
*/
|
||||
protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
|
||||
c.save();
|
||||
c.clipPath(filledPath);
|
||||
|
||||
int color = (fillAlpha << 24) | (fillColor & 0xffffff);
|
||||
c.drawColor(color);
|
||||
c.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the path that is used for filled drawing.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.github.mikephil.charting.renderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 25/01/16.
|
||||
*/
|
||||
public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
|
||||
|
||||
public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
|
||||
super(animator, viewPortHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the provided path in filled mode with the provided drawable.
|
||||
*
|
||||
* @param c
|
||||
* @param filledPath
|
||||
* @param drawable
|
||||
*/
|
||||
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
|
||||
c.save();
|
||||
c.clipPath(filledPath);
|
||||
|
||||
drawable.setBounds((int) mViewPortHandler.contentLeft(),
|
||||
(int) mViewPortHandler.contentTop(),
|
||||
(int) mViewPortHandler.contentRight(),
|
||||
(int) mViewPortHandler.contentBottom());
|
||||
drawable.draw(c);
|
||||
|
||||
c.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the provided path in filled mode with the provided color and alpha.
|
||||
* Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
|
||||
*
|
||||
* @param c
|
||||
* @param filledPath
|
||||
* @param fillColor
|
||||
* @param fillAlpha
|
||||
*/
|
||||
protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
|
||||
c.save();
|
||||
c.clipPath(filledPath);
|
||||
|
||||
int color = (fillAlpha << 24) | (fillColor & 0xffffff);
|
||||
c.drawColor(color);
|
||||
c.restore();
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import android.graphics.Color;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
|
@ -16,7 +17,7 @@ import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
|||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
public class RadarChartRenderer extends LineScatterCandleRadarRenderer {
|
||||
public class RadarChartRenderer extends LineRadarRenderer {
|
||||
|
||||
protected RadarChart mChart;
|
||||
|
||||
|
@ -96,20 +97,29 @@ public class RadarChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
|
||||
surface.close();
|
||||
|
||||
// draw filled
|
||||
if (dataSet.isDrawFilledEnabled()) {
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
mRenderPaint.setAlpha(dataSet.getFillAlpha());
|
||||
c.drawPath(surface, mRenderPaint);
|
||||
mRenderPaint.setAlpha(255);
|
||||
}
|
||||
|
||||
mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
// draw the line (only if filled is disabled or alpha is below 255)
|
||||
if (!dataSet.isDrawFilledEnabled() || dataSet.getFillAlpha() < 255)
|
||||
c.drawPath(surface, mRenderPaint);
|
||||
|
||||
final Drawable drawable = dataSet.getFillDrawable();
|
||||
if (drawable != null) {
|
||||
|
||||
drawFilledPath(c, surface, drawable);
|
||||
} else {
|
||||
|
||||
drawFilledPath(c, surface, dataSet.getFillColor(), dataSet.getFillAlpha());
|
||||
}
|
||||
//
|
||||
// // draw filled
|
||||
// if (dataSet.isDrawFilledEnabled()) {
|
||||
// mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
// mRenderPaint.setAlpha(dataSet.getFillAlpha());
|
||||
// c.drawPath(surface, mRenderPaint);
|
||||
// mRenderPaint.setAlpha(255);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue