Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cb6dabb
Eliminate allocs - ObjectPool and Tests (#1892)
tonypatino-monoclesociety Jun 28, 2016
d299546
Eliminate allocs - FSize pooling (#1892)
tonypatino-monoclesociety Jun 28, 2016
fcf26aa
Eliminate allocs - PointD pooling (#1892)
tonypatino-monoclesociety Jun 28, 2016
0f2e213
Eliminate allocs - Legend arrays (#1892)
tonypatino-monoclesociety Jun 28, 2016
f86c163
Eliminate allocs - MPPointF replace PointF (#1892)
tonypatino-monoclesociety Jun 28, 2016
d946f3e
Eliminate allocs - float array buffers (#1892)
tonypatino-monoclesociety Jun 28, 2016
56cfd2b
Eliminate allocs - Matrix and Path buffers (#1892)
tonypatino-monoclesociety Jun 29, 2016
c59b46a
Eliminate allocs - Cache drawn circles as bitmaps (#1892)
tonypatino-monoclesociety Jun 29, 2016
bd45d73
Eliminate allocs - Array Access (#1892)
tonypatino-monoclesociety Jun 29, 2016
0b72b55
Eliminate allocs - Cache formatted Strings (#1892)
tonypatino-monoclesociety Jun 29, 2016
d372fd3
Eliminate allocs - Rect and RectF buffers (#1892)
tonypatino-monoclesociety Jun 30, 2016
a04ad28
Eliminate allocs - Cache XBounds in Renderer (#1892)
tonypatino-monoclesociety Jun 30, 2016
424ee02
Eliminate allocs - String Caches now have Prim subtypes (#1892)
tonypatino-monoclesociety Jun 30, 2016
7fd18d2
Eliminate allocs - Buffer Paint.FontMetrics (#1892)
tonypatino-monoclesociety Jun 30, 2016
69f17b2
Eliminate allocs - Buffer ArrayLists (#1892)
tonypatino-monoclesociety Jun 30, 2016
afdbd2c
Eliminate allocs - Tests for StringCache (#1892)
tonypatino-monoclesociety Jun 30, 2016
b037f55
Eliminate allocs - XAxisRender array (#1892)
tonypatino-monoclesociety Jun 30, 2016
5a18d0e
Eliminate allocs - Adjust pool replenishing (#1892)
tonypatino-monoclesociety Jun 30, 2016
38fbefe
Eliminate allocs - Move and Zoom Job Pools (#1892)
tonypatino-monoclesociety Jun 30, 2016
37f2498
Eliminate allocs - MFPoint recycle (#1892)
tonypatino-monoclesociety Jun 30, 2016
66094db
Eliminate allocs - Copy arrays without new[] (#1892)
tonypatino-monoclesociety Jun 30, 2016
523c7e5
Render bug fix - circle bitmap sizes (#1892)
tonypatino-monoclesociety Jul 1, 2016
d5df3ad
Crash fix - Create small clip paths (#1895)
tonypatino-monoclesociety Jul 1, 2016
8775860
Revert "Crash fix - Create small clip paths (#1895)"
tonypatino-monoclesociety Jul 1, 2016
b5da8dc
Crash fix - Create small clip paths (#1895)
tonypatino-monoclesociety Jul 1, 2016
40c5c87
Perf + Bug (#1892) (#1895)
tonypatino-monoclesociety Jul 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MPChartExample/res/layout/activity_linechart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:layout_margin="8dp"
android:layout_toLeftOf="@+id/tvYMax"
android:layout_marginRight="5dp"
android:max="200"
android:max="150"
android:paddingBottom="12dp" />

<SeekBar
Expand All @@ -30,7 +30,7 @@
android:layout_marginBottom="35dp"
android:layout_toLeftOf="@+id/tvXMax"
android:layout_marginRight="5dp"
android:max="500"
android:max="1500"
android:paddingBottom="12dp" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.annotation.SuppressLint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -33,6 +34,7 @@
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
Expand Down Expand Up @@ -256,22 +258,26 @@ private void setData(int count, float range) {
}
}

protected RectF mOnValueSelectedRectF = new RectF();
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {

if (e == null)
return;

RectF bounds = mChart.getBarBounds((BarEntry) e);
PointF position = mChart.getPosition(e, AxisDependency.LEFT);
RectF bounds = mOnValueSelectedRectF;
mChart.getBarBounds((BarEntry) e, bounds);
MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);

Log.i("bounds", bounds.toString());
Log.i("position", position.toString());

Log.i("x-index",
"low: " + mChart.getLowestVisibleX() + ", high: "
+ mChart.getHighestVisibleX());

MPPointF.recycleInstance(position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.AxisValueFormatter;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;

Expand Down Expand Up @@ -164,15 +165,15 @@ public Data(float xValue, float yValue, String xAxisValue) {

private class ValueFormatter implements com.github.mikephil.charting.formatter.ValueFormatter {

private DecimalFormat mFormat;
private FormattedStringCache.PrimIntFloat mFormattedStringCache;

public ValueFormatter() {
mFormat = new DecimalFormat("######.0");
mFormattedStringCache = new FormattedStringCache.PrimIntFloat(new DecimalFormat("######.0"));
}

@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value);
return mFormattedStringCache.getFormattedValue(value, dataSetIndex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.annotation.SuppressLint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -27,6 +28,7 @@
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;

import java.util.ArrayList;
Expand Down Expand Up @@ -245,19 +247,24 @@ private void setData(int count, float range) {
}
}

protected RectF mOnValueSelectedRectF = new RectF();
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {

if (e == null)
return;

RectF bounds = mChart.getBarBounds((BarEntry) e);
PointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
RectF bounds = mOnValueSelectedRectF;
mChart.getBarBounds((BarEntry) e, bounds);

MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency());

Log.i("bounds", bounds.toString());
Log.i("position", position.toString());

MPPointF.recycleInstance(position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {

Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

LimitLine ll1 = new LimitLine(130f, "Upper Limit");
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
Expand All @@ -129,7 +129,7 @@ protected void onCreate(Bundle savedInstanceState) {
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.addLimitLine(ll1);
leftAxis.addLimitLine(ll2);
leftAxis.setAxisMaxValue(220f);
leftAxis.setAxisMaxValue(200f);
leftAxis.setAxisMinValue(-50f);
//leftAxis.setYOffset(20f);
leftAxis.enableGridDashedLine(10f, 10f, 0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.AxisValueFormatter;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
Expand Down Expand Up @@ -91,11 +92,12 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setGranularity(60000L); // one minute in millis
xAxis.setValueFormatter(new AxisValueFormatter() {

private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm");
private FormattedStringCache.Generic<Long, Date> mFormattedStringCache = new FormattedStringCache.Generic<>(new SimpleDateFormat("dd MMM HH:mm"));

@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(new Date((long) value));
Long v = (long) value;
return mFormattedStringCache.getFormattedValue(new Date(v), v);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,22 @@ private void feedMultiple() {
if (thread != null)
thread.interrupt();

final Runnable runnable = new Runnable() {

@Override
public void run() {
addEntry();
}
};

thread = new Thread(new Runnable() {

@Override
public void run() {
for (int i = 0; i < 1000; i++) {

runOnUiThread(new Runnable() {

@Override
public void run() {
addEntry();
}
});
// Don't generate garbage runnables inside the loop.
runOnUiThread(runnable);

try {
Thread.sleep(25);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.formatter.AxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
Expand Down Expand Up @@ -79,11 +80,11 @@ protected void onCreate(Bundle savedInstanceState) {
xAxis.setGranularity(10f);
xAxis.setValueFormatter(new AxisValueFormatter() {

private DecimalFormat format = new DecimalFormat("###");
private FormattedStringCache.PrimFloat format = new FormattedStringCache.PrimFloat(new DecimalFormat("###"));

@Override
public String getFormattedValue(float value, AxisBase axis) {
return format.format(value) + "-" + format.format(value + 10);
return format.getFormattedValue(value) + "-" + format.getFormattedValue(value+10);
}

@Override
Expand Down Expand Up @@ -222,22 +223,25 @@ public void onNothingSelected() {

private class CustomFormatter implements ValueFormatter, AxisValueFormatter {

private DecimalFormat mFormat;
private FormattedStringCache.Generic<Integer, Float> mFormatValue;
private FormattedStringCache.PrimFloat mFormatAxis;

public CustomFormatter() {
mFormat = new DecimalFormat("###");
mFormatValue = new FormattedStringCache.Generic<>(new DecimalFormat("###"));
mFormatAxis = new FormattedStringCache.PrimFloat(new DecimalFormat("###"));
}

// data
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(Math.abs(value)) + "m";
return mFormatValue.getFormattedValue(value, dataSetIndex) + "m";
}

// YAxis
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(Math.abs(value)) + "m";
Float v = Math.abs(value);
return mFormatAxis.getFormattedValue(v) + "m";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.AxisValueFormatter;
import com.github.mikephil.charting.formatter.FormattedStringCache;

import java.text.DecimalFormat;

public class MyAxisValueFormatter implements AxisValueFormatter {

private DecimalFormat mFormat;
private FormattedStringCache.PrimFloat mFormattedStringCache;

public MyAxisValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0");
mFormattedStringCache = new FormattedStringCache.PrimFloat(new DecimalFormat("###,###,###,##0.0"));
}

@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(value) + " $";
return mFormattedStringCache.getFormattedValue(value) + " $";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.AxisValueFormatter;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.utils.ViewPortHandler;

import java.text.DecimalFormat;
Expand All @@ -11,13 +12,13 @@
*/
public class MyCustomXAxisValueFormatter implements AxisValueFormatter {

private DecimalFormat mFormat;
private FormattedStringCache.PrimFloat mFormattedStringCache;
private ViewPortHandler mViewPortHandler;

public MyCustomXAxisValueFormatter(ViewPortHandler viewPortHandler) {
mViewPortHandler = viewPortHandler;
// maybe do something here or provide parameters in constructor
mFormat = new DecimalFormat("###,###,###,##0.0");
mFormattedStringCache = new FormattedStringCache.PrimFloat(new DecimalFormat("###,###,###,##0.0"));
}

@Override
Expand All @@ -26,14 +27,15 @@ public String getFormattedValue(float value, AxisBase axis) {
//Log.i("TRANS", "x: " + viewPortHandler.getTransX() + ", y: " + viewPortHandler.getTransY());

// e.g. adjust the x-axis values depending on scale / zoom level
if (mViewPortHandler.getScaleX() > 5)
final float xScale = mViewPortHandler.getScaleX();
if (xScale > 5)
return "4";
else if (mViewPortHandler.getScaleX() > 3)
else if (xScale > 3)
return "3";
else if (mViewPortHandler.getScaleX() > 1)
else if (xScale > 1)
return "2";
else
return mFormat.format(value);
return mFormattedStringCache.getFormattedValue(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.xxmassdeveloper.mpchartexample.custom;

import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;

import java.text.DecimalFormat;

public class MyValueFormatter implements ValueFormatter {

private DecimalFormat mFormat;
private FormattedStringCache.Generic<Integer, Float> mFormattedStringCache;

public MyValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0");
mFormattedStringCache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,###,##0.0"));
}

@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value) + " $";
return mFormattedStringCache.getFormattedValue(value, dataSetIndex) + " $";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.Utils;
import com.xxmassdeveloper.mpchartexample.R;
Expand All @@ -22,7 +23,7 @@
public class RadarMarkerView extends MarkerView {

private TextView tvContent;
private DecimalFormat format = new DecimalFormat("##0");
private FormattedStringCache.PrimFloat mFormattedStringCache = new FormattedStringCache.PrimFloat(new DecimalFormat("##0"));

public RadarMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
Expand All @@ -35,7 +36,8 @@ public RadarMarkerView(Context context, int layoutResource) {
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
tvContent.setText(format.format(e.getY()) + " %");
float value = e.getY();
tvContent.setText(mFormattedStringCache.getFormattedValue(value) + " %");
}

@Override
Expand Down
Loading