Merge master
This commit is contained in:
commit
af114d180d
20 changed files with 711 additions and 263 deletions
|
@ -12,7 +12,6 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.Legend.LegendPosition;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
|
@ -24,6 +23,7 @@ import com.github.mikephil.charting.highlight.Highlight;
|
|||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -54,6 +54,7 @@ public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeLis
|
|||
|
||||
mChart = (ScatterChart) findViewById(R.id.chart1);
|
||||
mChart.setDescription("");
|
||||
mChart.addShapeRenderer(new CustomScatterShapeRenderer(), CustomScatterShapeRenderer.IDENTIFIER);
|
||||
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
|
@ -179,15 +180,15 @@ public class ScatterChartActivity extends DemoBase implements OnSeekBarChangeLis
|
|||
|
||||
// create a dataset and give it a type
|
||||
ScatterDataSet set1 = new ScatterDataSet(yVals1, "DS 1");
|
||||
set1.setScatterShape(ScatterShape.SQUARE);
|
||||
set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
|
||||
set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
|
||||
ScatterDataSet set2 = new ScatterDataSet(yVals2, "DS 2");
|
||||
set2.setScatterShape(ScatterShape.CIRCLE);
|
||||
set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
|
||||
set2.setScatterShapeHoleColor(ColorTemplate.COLORFUL_COLORS[3]);
|
||||
set2.setScatterShapeHoleRadius(3f);
|
||||
set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);
|
||||
ScatterDataSet set3 = new ScatterDataSet(yVals3, "DS 3");
|
||||
set3.setScatterShape(ScatterShape.CROSS);
|
||||
set3.setScatterShape(CustomScatterShapeRenderer.IDENTIFIER);
|
||||
set3.setColor(ColorTemplate.COLORFUL_COLORS[2]);
|
||||
|
||||
set1.setScatterShapeSize(8f);
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Custom shape renderer that draws a single line.
|
||||
* Created by philipp on 26/06/16.
|
||||
*/
|
||||
public class CustomScatterShapeRenderer implements ShapeRenderer {
|
||||
|
||||
public static final String IDENTIFIER = "single_line";
|
||||
|
||||
@Override
|
||||
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, ScatterBuffer buffer, Paint
|
||||
renderPaint, float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!viewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!viewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !viewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
renderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
renderPaint);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.BarDataSet;
|
||||
import com.github.mikephil.charting.data.BarEntry;
|
||||
|
@ -71,7 +70,7 @@ public abstract class SimpleFragment extends Fragment {
|
|||
|
||||
ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
|
||||
|
||||
ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
|
||||
ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();
|
||||
|
||||
for(int i = 0; i < dataSets; i++) {
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.github.mikephil.charting.data.ScatterData;
|
|||
import com.github.mikephil.charting.highlight.CombinedHighlighter;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.CombinedDataProvider;
|
||||
import com.github.mikephil.charting.renderer.CombinedChartRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
|
||||
/**
|
||||
* This chart class allows the combination of lines, bars, scatter and candle
|
||||
|
@ -22,6 +23,8 @@ import com.github.mikephil.charting.renderer.CombinedChartRenderer;
|
|||
*/
|
||||
public class CombinedChart extends BarLineChartBase<CombinedData> implements CombinedDataProvider {
|
||||
|
||||
private ScatterChart.ShapeRendererHandler mShapeRendererHandler;
|
||||
|
||||
/**
|
||||
* if set to true, all values are drawn above their bars, instead of below
|
||||
* their top
|
||||
|
@ -68,6 +71,8 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
protected void init() {
|
||||
super.init();
|
||||
|
||||
mShapeRendererHandler = new ScatterChart.ShapeRendererHandler();
|
||||
|
||||
setHighlighter(new CombinedHighlighter(this, this));
|
||||
|
||||
// Old default behaviour
|
||||
|
@ -124,6 +129,16 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
return mData.getBubbleData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShapeRenderer(ShapeRenderer shapeRenderer, String shapeIdentifier) {
|
||||
mShapeRendererHandler.addShapeRenderer(shapeRenderer, shapeIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeRenderer getShapeRenderer(String shapeIdentifier) {
|
||||
return mShapeRendererHandler.getShapeRenderer(shapeIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawBarShadowEnabled() {
|
||||
return mDrawBarShadow;
|
||||
|
|
|
@ -7,6 +7,16 @@ import android.util.AttributeSet;
|
|||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
|
||||
import com.github.mikephil.charting.renderer.ScatterChartRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.ChevronDownShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.ChevronUpShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.CircleShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.CrossShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.SquareShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.TriangleShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.XShapeRenderer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* The ScatterChart. Draws dots, triangles, squares and custom shapes into the
|
||||
|
@ -17,12 +27,8 @@ import com.github.mikephil.charting.renderer.ScatterChartRenderer;
|
|||
*/
|
||||
public class ScatterChart extends BarLineChartBase<ScatterData> implements ScatterDataProvider {
|
||||
|
||||
/**
|
||||
* enum that defines the shape that is drawn where the values are
|
||||
*/
|
||||
public enum ScatterShape {
|
||||
SQUARE, CIRCLE, TRIANGLE, CROSS, X,
|
||||
}
|
||||
protected ShapeRendererHandler mShapeRendererHandler;
|
||||
|
||||
|
||||
public ScatterChart(Context context) {
|
||||
super(context);
|
||||
|
@ -36,25 +42,96 @@ public class ScatterChart extends BarLineChartBase<ScatterData> implements Scatt
|
|||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
mShapeRendererHandler = new ShapeRendererHandler();
|
||||
|
||||
mRenderer = new ScatterChartRenderer(this, mAnimator, mViewPortHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all possible predefined ScatterShapes.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ScatterShape[] getAllPossibleShapes() {
|
||||
return new ScatterShape[]{
|
||||
ScatterShape.SQUARE, ScatterShape.CIRCLE, ScatterShape.TRIANGLE, ScatterShape.CROSS
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScatterData getScatterData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShapeRenderer(ShapeRenderer shapeRenderer, String shapeIdentifier) {
|
||||
mShapeRendererHandler.addShapeRenderer(shapeRenderer, shapeIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeRenderer getShapeRenderer(String shapeIdentifier) {
|
||||
return mShapeRendererHandler.getShapeRenderer(shapeIdentifier);
|
||||
}
|
||||
|
||||
public enum ScatterShape {
|
||||
SQUARE("SQUARE"), CIRCLE("CIRCLE"), TRIANGLE("TRIANGLE"), CROSS("CROSS"), X("X"), CHEVRON_UP("CHEVRON_UP"),
|
||||
CHEVRON_DOWN("CHEVRON_DOWN");
|
||||
|
||||
private final String shapeIdentifier;
|
||||
|
||||
ScatterShape(final String shapeIdentifier) {
|
||||
this.shapeIdentifier = shapeIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return shapeIdentifier;
|
||||
}
|
||||
|
||||
public static ScatterShape[] getAllDefaultShapes() {
|
||||
return new ScatterShape[]{SQUARE, CIRCLE, TRIANGLE, CROSS, X, CHEVRON_UP, CHEVRON_DOWN};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler class for all different ShapeRenderers.
|
||||
*/
|
||||
protected static class ShapeRendererHandler {
|
||||
|
||||
/**
|
||||
* Dictionary of ShapeRenderer which are responsible for drawing custom shapes.
|
||||
* Can add to it your custom shapes.
|
||||
* CustomShapeRenderer Implements ShapeRenderer{}
|
||||
*/
|
||||
protected HashMap<String, ShapeRenderer> shapeRendererList;
|
||||
|
||||
public ShapeRendererHandler() {
|
||||
initShapeRenderers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new ShapeRenderer and the shapeIdentifier it is responsible for drawing.
|
||||
* This shapeIdentifier should correspond to a DataSet with the same identifier.
|
||||
*
|
||||
* @param shapeRenderer
|
||||
* @param shapeIdentifier
|
||||
*/
|
||||
public void addShapeRenderer(ShapeRenderer shapeRenderer, String shapeIdentifier) {
|
||||
shapeRendererList.put(shapeIdentifier, shapeRenderer);
|
||||
}
|
||||
|
||||
public ShapeRenderer getShapeRenderer(String shapeIdentifier) {
|
||||
return shapeRendererList.get(shapeIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init default ShapeRenderers.
|
||||
*/
|
||||
protected void initShapeRenderers() {
|
||||
shapeRendererList = new HashMap<>();
|
||||
|
||||
shapeRendererList.put(ScatterShape.SQUARE.toString(), new SquareShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.CIRCLE.toString(), new CircleShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.TRIANGLE.toString(), new TriangleShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.CROSS.toString(), new CrossShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.X.toString(), new XShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.CHEVRON_UP.toString(), new ChevronUpShapeRenderer());
|
||||
shapeRendererList.put(ScatterShape.CHEVRON_DOWN.toString(), new ChevronDownShapeRenderer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public abstract class ComponentBase {
|
|||
*/
|
||||
protected int mTextColor = Color.BLACK;
|
||||
|
||||
|
||||
public ComponentBase() {
|
||||
|
||||
}
|
||||
|
@ -130,6 +131,7 @@ public abstract class ComponentBase {
|
|||
return mTextSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the text color to use for the labels. Make sure to use
|
||||
* getResources().getColor(...) when using a color from the resources.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
package com.github.mikephil.charting.data;
|
||||
|
||||
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> impleme
|
|||
* the type of shape that is set to be drawn where the values are at,
|
||||
* default ScatterShape.SQUARE
|
||||
*/
|
||||
private ScatterShape mScatterShape = ScatterShape.SQUARE;
|
||||
private String mScatterShape = ScatterChart.ScatterShape.SQUARE.toString();
|
||||
|
||||
/**
|
||||
* The radius of the hole in the shape (applies to Square, Circle and Triangle)
|
||||
|
@ -82,17 +82,29 @@ public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> impleme
|
|||
return mShapeSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the shape that is drawn on the position where the values are at.
|
||||
* Sets the shapeIdentifier that this DataSet should be drawn with.
|
||||
* Make sure the ScatterChart has a renderer capable of rendering the provided identifier.
|
||||
*
|
||||
* @param shape
|
||||
*/
|
||||
public void setScatterShape(ScatterShape shape) {
|
||||
mScatterShape = shape;
|
||||
public void setScatterShape(ScatterChart.ScatterShape shape) {
|
||||
mScatterShape = shape.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shapeIdentifier that this DataSet should be drawn with.
|
||||
* Make sure the ScatterChart has a renderer capable of rendering the provided identifier.
|
||||
*
|
||||
* @param shapeIdentifier
|
||||
*/
|
||||
public void setScatterShape(String shapeIdentifier) {
|
||||
mScatterShape = shapeIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScatterShape getScatterShape() {
|
||||
public String getScatterShape() {
|
||||
return mScatterShape;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ import com.github.mikephil.charting.data.Entry;
|
|||
import com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
|
@ -25,7 +23,7 @@ public class RealmScatterDataSet<T extends RealmObject> extends RealmLineScatter
|
|||
* the type of shape that is set to be drawn where the values are at,
|
||||
* default ScatterShape.SQUARE
|
||||
*/
|
||||
private ScatterChart.ScatterShape mScatterShape = ScatterChart.ScatterShape.SQUARE;
|
||||
private String mScatterShape = ScatterChart.ScatterShape.SQUARE.toString();
|
||||
|
||||
/**
|
||||
* The radius of the hole in the shape (applies to Square, Circle and Triangle)
|
||||
|
@ -82,6 +80,17 @@ public class RealmScatterDataSet<T extends RealmObject> extends RealmLineScatter
|
|||
return mShapeSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the shape that is drawn on the position where the values are at.
|
||||
*
|
||||
* @param shape
|
||||
*/
|
||||
public void setScatterShape(ScatterChart.ScatterShape shape) {
|
||||
mScatterShape = shape.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the shape that is drawn on the position where the values are at. If
|
||||
* "CUSTOM" is chosen, you need to call setCustomScatterShape(...) and
|
||||
|
@ -89,12 +98,12 @@ public class RealmScatterDataSet<T extends RealmObject> extends RealmLineScatter
|
|||
*
|
||||
* @param shape
|
||||
*/
|
||||
public void setScatterShape(ScatterChart.ScatterShape shape) {
|
||||
public void setScatterShape(String shape) {
|
||||
mScatterShape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScatterChart.ScatterShape getScatterShape() {
|
||||
public String getScatterShape() {
|
||||
return mScatterShape;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
package com.github.mikephil.charting.interfaces.dataprovider;
|
||||
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
|
||||
public interface ScatterDataProvider extends BarLineScatterCandleBubbleDataProvider {
|
||||
|
||||
ScatterData getScatterData();
|
||||
|
||||
/**
|
||||
* Adds a new ShapeRenderer and the shapeIdentifier it is responsible for drawing.
|
||||
* This shapeIdentifier should correspond to a DataSet with the same identifier.
|
||||
*
|
||||
* @param shapeRenderer
|
||||
* @param shapeIdentifier
|
||||
*/
|
||||
void addShapeRenderer(ShapeRenderer shapeRenderer, String shapeIdentifier);
|
||||
|
||||
/**
|
||||
* Returns the corresponding ShapeRenderer for the given identifier.
|
||||
*
|
||||
* @param shapeIdentifier
|
||||
* @return
|
||||
*/
|
||||
ShapeRenderer getShapeRenderer(String shapeIdentifier);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.mikephil.charting.interfaces.datasets;
|
||||
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,7 @@ public interface IScatterDataSet extends ILineScatterCandleRadarDataSet<Entry> {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
ScatterChart.ScatterShape getScatterShape();
|
||||
String getScatterShape();
|
||||
|
||||
/**
|
||||
* Returns radius of the hole in the shape
|
||||
|
|
|
@ -2,18 +2,15 @@
|
|||
package com.github.mikephil.charting.renderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Path;
|
||||
|
||||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
import com.github.mikephil.charting.utils.PointD;
|
||||
import com.github.mikephil.charting.utils.Transformer;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
@ -66,14 +63,6 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
float phaseY = mAnimator.getPhaseY();
|
||||
|
||||
final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
|
||||
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
|
||||
final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
|
||||
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
|
||||
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
|
||||
|
||||
ScatterShape shape = dataSet.getScatterShape();
|
||||
|
||||
ScatterBuffer buffer = mScatterBuffers[mChart.getScatterData().getIndexOfDataSet(
|
||||
dataSet)];
|
||||
|
@ -82,222 +71,14 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
|
|||
|
||||
trans.pointValuesToPixel(buffer.buffer);
|
||||
|
||||
switch (shape) {
|
||||
case SQUARE:
|
||||
String shape = dataSet.getScatterShape();
|
||||
ShapeRenderer renderer = mChart.getShapeRenderer(shape);
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
if (shapeHoleSize > 0.0) {
|
||||
mRenderPaint.setStyle(Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(shapeStrokeSize);
|
||||
|
||||
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
|
||||
buffer.buffer[i + 1] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
|
||||
buffer.buffer[i] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
buffer.buffer[i + 1] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
mRenderPaint);
|
||||
|
||||
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
mRenderPaint.setStyle(Style.FILL);
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf,
|
||||
buffer.buffer[i + 1] - shapeHoleSizeHalf,
|
||||
buffer.buffer[i] + shapeHoleSizeHalf,
|
||||
buffer.buffer[i + 1] + shapeHoleSizeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
} else {
|
||||
mRenderPaint.setStyle(Style.FILL);
|
||||
|
||||
c.drawRect(buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CIRCLE:
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
if (shapeHoleSize > 0.0) {
|
||||
mRenderPaint.setStyle(Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(shapeStrokeSize);
|
||||
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
mRenderPaint);
|
||||
|
||||
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
mRenderPaint.setStyle(Style.FILL);
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHoleSizeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
} else {
|
||||
mRenderPaint.setStyle(Style.FILL);
|
||||
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TRIANGLE:
|
||||
|
||||
mRenderPaint.setStyle(Style.FILL);
|
||||
|
||||
// create a triangle path
|
||||
Path tri = new Path();
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
tri.moveTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf, buffer.buffer[i + 1] + shapeHalf);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf, buffer.buffer[i + 1] + shapeHalf);
|
||||
|
||||
if (shapeHoleSize > 0.0) {
|
||||
tri.lineTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
|
||||
|
||||
tri.moveTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
}
|
||||
|
||||
tri.close();
|
||||
|
||||
c.drawPath(tri, mRenderPaint);
|
||||
tri.reset();
|
||||
|
||||
if (shapeHoleSize > 0.0 &&
|
||||
shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
|
||||
tri.moveTo(buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.close();
|
||||
|
||||
c.drawPath(tri, mRenderPaint);
|
||||
tri.reset();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CROSS:
|
||||
|
||||
mRenderPaint.setStyle(Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1],
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
break;
|
||||
|
||||
case X:
|
||||
|
||||
mRenderPaint.setStyle(Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
c.drawLine(
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
if (renderer != null) {
|
||||
renderer.renderShape(c, dataSet, mViewPortHandler, buffer, mRenderPaint, shapeSize);
|
||||
} else {
|
||||
throw new RuntimeException("No ShapeRenderer found for provided identifier. Please make sure to add a ShapeRenderer" +
|
||||
" capable of rendering the provided shape.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,6 +329,7 @@ public class XAxisRenderer extends AxisRenderer {
|
|||
mLimitLinePaint.setStrokeWidth(0.5f);
|
||||
mLimitLinePaint.setTextSize(limitLine.getTextSize());
|
||||
|
||||
|
||||
float xOffset = limitLine.getLineWidth() + limitLine.getXOffset();
|
||||
|
||||
final LimitLine.LimitLabelPosition labelPosition = limitLine.getLabelPosition();
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class ChevronDownShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] + (2 * shapeHalf),
|
||||
buffer.buffer[i] + (2 * shapeHalf),
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] + (2 * shapeHalf),
|
||||
buffer.buffer[i] - (2 * shapeHalf),
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class ChevronUpShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - (2 * shapeHalf),
|
||||
buffer.buffer[i] + (2 * shapeHalf),
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - (2 * shapeHalf),
|
||||
buffer.buffer[i] - (2 * shapeHalf),
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class CircleShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
|
||||
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
|
||||
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
|
||||
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
|
||||
|
||||
final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
if (shapeSize > 0.0) {
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(shapeStrokeSize);
|
||||
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
mRenderPaint);
|
||||
|
||||
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHoleSizeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
} else {
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
c.drawCircle(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1],
|
||||
shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class CrossShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1],
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1],
|
||||
mRenderPaint);
|
||||
c.drawLine(
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i],
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:07
|
||||
*/
|
||||
public interface ShapeRenderer {
|
||||
|
||||
/**
|
||||
* Renders the provided ScatterDataSet with a shape.
|
||||
*
|
||||
* @param c
|
||||
* @param dataSet
|
||||
* @param viewPortHandler
|
||||
* @param buffer
|
||||
* @param renderPaint
|
||||
* @param shapeSize
|
||||
*/
|
||||
void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, ScatterBuffer buffer, Paint
|
||||
renderPaint, final float shapeSize);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class SquareShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
|
||||
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
|
||||
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
|
||||
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
|
||||
|
||||
final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
if (shapeSize > 0.0) {
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(shapeStrokeSize);
|
||||
|
||||
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
|
||||
buffer.buffer[i + 1] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
|
||||
buffer.buffer[i] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
buffer.buffer[i + 1] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
|
||||
mRenderPaint);
|
||||
|
||||
if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf,
|
||||
buffer.buffer[i + 1] - shapeHoleSizeHalf,
|
||||
buffer.buffer[i] + shapeHoleSizeHalf,
|
||||
buffer.buffer[i + 1] + shapeHoleSizeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
} else {
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
c.drawRect(buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class TriangleShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
|
||||
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
|
||||
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
|
||||
|
||||
final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
// create a triangle path
|
||||
Path tri = new Path();
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
tri.moveTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf, buffer.buffer[i + 1] + shapeHalf);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf, buffer.buffer[i + 1] + shapeHalf);
|
||||
|
||||
if (shapeSize > 0.0) {
|
||||
tri.lineTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
|
||||
|
||||
tri.moveTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
}
|
||||
|
||||
tri.close();
|
||||
|
||||
c.drawPath(tri, mRenderPaint);
|
||||
tri.reset();
|
||||
|
||||
if (shapeSize > 0.0 &&
|
||||
shapeHoleColor != ColorTemplate.COLOR_NONE) {
|
||||
|
||||
mRenderPaint.setColor(shapeHoleColor);
|
||||
|
||||
tri.moveTo(buffer.buffer[i],
|
||||
buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
|
||||
buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
|
||||
tri.close();
|
||||
|
||||
c.drawPath(tri, mRenderPaint);
|
||||
tri.reset();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.github.mikephil.charting.renderer.scatter;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.buffer.ScatterBuffer;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* Created by wajdic on 15/06/2016.
|
||||
* Created at Time 09:08
|
||||
*/
|
||||
public class XShapeRenderer implements ShapeRenderer {
|
||||
|
||||
|
||||
@Override
|
||||
public void renderShape(
|
||||
Canvas c, IScatterDataSet dataSet,
|
||||
ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
|
||||
|
||||
final float shapeHalf = shapeSize / 2f;
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
|
||||
|
||||
for (int i = 0; i < buffer.size(); i += 2) {
|
||||
|
||||
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
|
||||
break;
|
||||
|
||||
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
|
||||
|| !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
|
||||
continue;
|
||||
|
||||
mRenderPaint.setColor(dataSet.getColor(i / 2));
|
||||
|
||||
c.drawLine(
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
c.drawLine(
|
||||
buffer.buffer[i] + shapeHalf,
|
||||
buffer.buffer[i + 1] - shapeHalf,
|
||||
buffer.buffer[i] - shapeHalf,
|
||||
buffer.buffer[i + 1] + shapeHalf,
|
||||
mRenderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue