Reinvented Markers - interface based, enhanced default behaviour
Two default implementations exist now: MarkerView, MarkerImage The default behaviour constraints the marker to the view's bounds.
This commit is contained in:
parent
f63002e196
commit
51f0e53a7f
36 changed files with 393 additions and 1488 deletions
|
@ -47,22 +47,12 @@
|
|||
<activity android:name="RadarChartActivitry"></activity>
|
||||
<activity android:name="LineChartActivityColored"></activity>
|
||||
<activity android:name="DynamicalAddingActivity"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityLine"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityHorizontalBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityScatter"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityCandle"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBubble"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityPie"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityRadar"></activity>
|
||||
<activity android:name=".realm.RealmMainActivity"></activity>
|
||||
<activity android:name="RealtimeLineChartActivity"></activity>
|
||||
<activity android:name="CombinedChartActivity"></activity>
|
||||
<activity android:name="PerformanceLineChart"></activity>
|
||||
<activity android:name="BarChartActivitySinus"></activity>
|
||||
<activity android:name="ScrollViewActivity"></activity>
|
||||
<activity android:name="StackedBarActivityNegative"></activity>
|
||||
<activity android:name=".realm.RealmWikiExample"></activity>
|
||||
<activity android:name=".BarChartPositiveNegative"></activity>
|
||||
<activity android:name=".FilledLineActivity"></activity>
|
||||
<activity android:name=".HalfPieChartActivity"></activity>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'realm-android'
|
||||
//apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
|
|
|
@ -119,7 +119,9 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
|
|||
// l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
|
||||
// "def", "ghj", "ikl", "mno" });
|
||||
|
||||
mChart.setMarkerView(new XYMarkerView(this, xAxisFormatter));
|
||||
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
|
||||
setData(12, 50);
|
||||
|
||||
|
|
|
@ -70,9 +70,8 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
|
|||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
|
||||
mSeekBarX.setProgress(10);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
|
|
@ -87,11 +87,11 @@ public class DynamicalAddingActivity extends DemoBase implements OnChartValueSel
|
|||
|
||||
if (set != null) {
|
||||
|
||||
Entry e = set.getEntryForXPos(set.getEntryCount() - 1);
|
||||
Entry e = set.getEntryForXValue(set.getEntryCount() - 1);
|
||||
|
||||
data.removeEntry(e, 0);
|
||||
// or remove by index
|
||||
// mData.removeEntryByXPos(xIndex, dataSetIndex);
|
||||
// mData.removeEntryByXValue(xIndex, dataSetIndex);
|
||||
data.notifyDataChanged();
|
||||
mChart.notifyDataSetChanged();
|
||||
mChart.invalidate();
|
||||
|
|
|
@ -79,9 +79,8 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
|
|||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
|
||||
XAxis xl = mChart.getXAxis();
|
||||
xl.setAvoidFirstLastClipping(true);
|
||||
|
|
|
@ -92,9 +92,8 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
|
|||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
|
||||
// x-axis limit line
|
||||
LimitLine llXAxis = new LimitLine(10f, "Index 10");
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.github.mikephil.charting.charts.RadarChart;
|
|||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.Legend.LegendPosition;
|
||||
import com.github.mikephil.charting.components.MarkerImage;
|
||||
import com.github.mikephil.charting.components.MarkerView;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
|
@ -58,9 +59,8 @@ public class RadarChartActivitry extends DemoBase {
|
|||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
|
||||
setData();
|
||||
|
||||
|
|
|
@ -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.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
|
@ -40,17 +41,12 @@ public class MyMarkerView extends MarkerView {
|
|||
|
||||
tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
|
||||
}
|
||||
|
||||
super.refreshContent(e, highlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXOffset(float xpos) {
|
||||
// this will center the marker-view horizontally
|
||||
return -(getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYOffset(float ypos) {
|
||||
// this will cause the marker-view to be above the selected value
|
||||
return -getHeight();
|
||||
public MPPointF getOffset() {
|
||||
return new MPPointF(-(getWidth() / 2), -getHeight());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.MPPointF;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
|
@ -38,17 +39,12 @@ public class RadarMarkerView extends MarkerView {
|
|||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
float value = e.getY();
|
||||
tvContent.setText(mFormattedStringCache.getFormattedValue(value) + " %");
|
||||
|
||||
super.refreshContent(e, highlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXOffset(float xpos) {
|
||||
// this will center the marker-view horizontally
|
||||
return -(getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYOffset(float ypos) {
|
||||
// this will cause the marker-view to be above the selected value
|
||||
return -getHeight()-10;
|
||||
public MPPointF getOffset() {
|
||||
return new MPPointF(-(getWidth() / 2), -getHeight() - 10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,180 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* Demo class that encapsulates data stored in realm.io database.
|
||||
* This class represents data suitable for all chart-types.
|
||||
*/
|
||||
public class RealmDemoData extends RealmObject {
|
||||
|
||||
private float yValue;
|
||||
private float xValue;
|
||||
|
||||
private float open, close, high, low;
|
||||
|
||||
private float bubbleSize;
|
||||
|
||||
private RealmList<RealmFloat> stackValues;
|
||||
|
||||
private String someStringField;
|
||||
|
||||
/**
|
||||
* label for pie entries
|
||||
*/
|
||||
private String label;
|
||||
|
||||
// ofc there could me more fields here...
|
||||
|
||||
public RealmDemoData() {
|
||||
|
||||
}
|
||||
|
||||
public RealmDemoData(float yValue) {
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
public RealmDemoData(float xValue, float yValue) {
|
||||
this.xValue = xValue;
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for stacked bars.
|
||||
*
|
||||
* @param xValue
|
||||
* @param stackValues
|
||||
*/
|
||||
public RealmDemoData(float xValue, float[] stackValues) {
|
||||
this.xValue = xValue;
|
||||
this.stackValues = new RealmList<RealmFloat>();
|
||||
|
||||
for (float val : stackValues) {
|
||||
this.stackValues.add(new RealmFloat(val));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for candles.
|
||||
*
|
||||
* @param xValue
|
||||
* @param high
|
||||
* @param low
|
||||
* @param open
|
||||
* @param close
|
||||
*/
|
||||
public RealmDemoData(float xValue, float high, float low, float open, float close) {
|
||||
this.yValue = (high + low) / 2f;
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
this.open = open;
|
||||
this.close = close;
|
||||
this.xValue = xValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for bubbles.
|
||||
*
|
||||
* @param xValue
|
||||
* @param yValue
|
||||
* @param bubbleSize
|
||||
*/
|
||||
public RealmDemoData(float xValue, float yValue, float bubbleSize) {
|
||||
this.xValue = xValue;
|
||||
this.yValue = yValue;
|
||||
this.bubbleSize = bubbleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for pie chart.
|
||||
*
|
||||
* @param yValue
|
||||
* @param label
|
||||
*/
|
||||
public RealmDemoData(float yValue, String label) {
|
||||
this.yValue = yValue;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public float getyValue() {
|
||||
return yValue;
|
||||
}
|
||||
|
||||
public void setyValue(float yValue) {
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
public float getxValue() {
|
||||
return xValue;
|
||||
}
|
||||
|
||||
public void setxValue(float xValue) {
|
||||
this.xValue = xValue;
|
||||
}
|
||||
|
||||
public RealmList<RealmFloat> getStackValues() {
|
||||
return stackValues;
|
||||
}
|
||||
|
||||
public void setStackValues(RealmList<RealmFloat> stackValues) {
|
||||
this.stackValues = stackValues;
|
||||
}
|
||||
|
||||
public float getOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void setOpen(float open) {
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
public float getClose() {
|
||||
return close;
|
||||
}
|
||||
|
||||
public void setClose(float close) {
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public float getHigh() {
|
||||
return high;
|
||||
}
|
||||
|
||||
public void setHigh(float high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public float getLow() {
|
||||
return low;
|
||||
}
|
||||
|
||||
public void setLow(float low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public float getBubbleSize() {
|
||||
return bubbleSize;
|
||||
}
|
||||
|
||||
public void setBubbleSize(float bubbleSize) {
|
||||
this.bubbleSize = bubbleSize;
|
||||
}
|
||||
|
||||
public String getSomeStringField() {
|
||||
return someStringField;
|
||||
}
|
||||
|
||||
public void setSomeStringField(String someStringField) {
|
||||
this.someStringField = someStringField;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 09/11/15.
|
||||
*/
|
||||
public class RealmFloat extends RealmObject {
|
||||
|
||||
private float floatValue;
|
||||
|
||||
public RealmFloat() {
|
||||
|
||||
}
|
||||
|
||||
public RealmFloat(float floatValue) {
|
||||
this.floatValue = floatValue;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
return floatValue;
|
||||
}
|
||||
|
||||
public void setFloatValue(float value) {
|
||||
this.floatValue = value;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import com.github.mikephil.charting.components.MarkerView;
|
|||
import com.github.mikephil.charting.data.BarEntry;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
|
@ -46,17 +47,12 @@ public class StackedBarsMarkerView extends MarkerView {
|
|||
|
||||
tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
|
||||
}
|
||||
|
||||
super.refreshContent(e, highlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXOffset(float xpos) {
|
||||
// this will center the marker-view horizontally
|
||||
return -(getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYOffset(float ypos) {
|
||||
// this will cause the marker-view to be above the selected value
|
||||
return -getHeight();
|
||||
public MPPointF getOffset() {
|
||||
return new MPPointF(-(getWidth() / 2), -getHeight());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.github.mikephil.charting.data.CandleEntry;
|
|||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
|
@ -40,17 +41,12 @@ public class XYMarkerView extends MarkerView {
|
|||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
|
||||
tvContent.setText("x: " + xAxisValueFormatter.getFormattedValue(e.getX(), null) + ", y: " + format.format(e.getY()));
|
||||
|
||||
super.refreshContent(e, highlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXOffset(float xpos) {
|
||||
// this will center the marker-view horizontally
|
||||
return -(getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYOffset(float ypos) {
|
||||
// this will cause the marker-view to be above the selected value
|
||||
return -getHeight();
|
||||
public MPPointF getOffset() {
|
||||
return new MPPointF(-(getWidth() / 2), -getHeight());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ public class BarChartFrag extends SimpleFragment implements OnChartGestureListen
|
|||
mChart.setOnChartGestureListener(this);
|
||||
|
||||
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
|
||||
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setDrawBarShadow(false);
|
||||
|
|
|
@ -34,8 +34,8 @@ public class ScatterChartFrag extends SimpleFragment {
|
|||
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
|
||||
|
||||
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
|
||||
|
||||
mChart.setMarkerView(mv);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv);
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
mChart.setData(generateScatterData(6, 10000, 200));
|
||||
|
|
|
@ -46,7 +46,6 @@ import com.xxmassdeveloper.mpchartexample.ScrollViewActivity;
|
|||
import com.xxmassdeveloper.mpchartexample.StackedBarActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.StackedBarActivityNegative;
|
||||
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
|
||||
import com.xxmassdeveloper.mpchartexample.realm.RealmMainActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -131,10 +130,6 @@ public class MainActivity extends Activity implements OnItemClickListener {
|
|||
"BarChart positive / negative",
|
||||
"This demonstrates how to create a BarChart with positive and negative values in different colors."));
|
||||
|
||||
ContentItem realm = new ContentItem(
|
||||
"Realm.io Database",
|
||||
"This demonstrates how to use this library with Realm.io mobile database.");
|
||||
objects.add(realm);
|
||||
|
||||
ContentItem time = new ContentItem(
|
||||
"Time Chart",
|
||||
|
@ -274,10 +269,6 @@ public class MainActivity extends Activity implements OnItemClickListener {
|
|||
i = new Intent(this, BarChartPositiveNegative.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 28:
|
||||
i = new Intent(this, RealmMainActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 29:
|
||||
i = new Intent(this, LineChartTime.class);
|
||||
startActivity(i);
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.formatter.PercentFormatter;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmConfiguration;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 05/11/15.
|
||||
*/
|
||||
public abstract class RealmBaseActivity extends DemoBase {
|
||||
|
||||
protected Realm mRealm;
|
||||
|
||||
protected Typeface mTf;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTitle("Realm.io Examples");
|
||||
}
|
||||
|
||||
protected void setup(Chart<?> chart) {
|
||||
|
||||
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
|
||||
|
||||
// no description text
|
||||
chart.setDescription("");
|
||||
chart.setNoDataTextDescription("You need to provide data for the chart.");
|
||||
|
||||
// enable touch gestures
|
||||
chart.setTouchEnabled(true);
|
||||
|
||||
if (chart instanceof BarLineChartBase) {
|
||||
|
||||
BarLineChartBase mChart = (BarLineChartBase) chart;
|
||||
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
// enable scaling and dragging
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setScaleEnabled(true);
|
||||
|
||||
// if disabled, scaling can be done on x- and y-axis separately
|
||||
mChart.setPinchZoom(false);
|
||||
|
||||
YAxis leftAxis = mChart.getAxisLeft();
|
||||
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
|
||||
leftAxis.setTypeface(mTf);
|
||||
leftAxis.setTextSize(8f);
|
||||
leftAxis.setTextColor(Color.DKGRAY);
|
||||
leftAxis.setValueFormatter(new PercentFormatter());
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setTypeface(mTf);
|
||||
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||
xAxis.setTextSize(8f);
|
||||
xAxis.setTextColor(Color.DKGRAY);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void styleData(ChartData data) {
|
||||
data.setValueTypeface(mTf);
|
||||
data.setValueTextSize(8f);
|
||||
data.setValueTextColor(Color.DKGRAY);
|
||||
data.setValueFormatter(new PercentFormatter());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
|
||||
RealmConfiguration realmConfig = new RealmConfiguration.Builder(getApplicationContext()).build();
|
||||
Realm.setDefaultConfiguration(realmConfig);
|
||||
|
||||
mRealm = Realm.getDefaultInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mRealm.close();
|
||||
}
|
||||
|
||||
protected void writeToDB(int objectCount) {
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
float value = 40f + (float) (Math.random() * 60f);
|
||||
|
||||
RealmDemoData d = new RealmDemoData(i, value);
|
||||
mRealm.copyToRealm(d);
|
||||
}
|
||||
|
||||
mRealm.commitTransaction();
|
||||
}
|
||||
|
||||
protected void writeToDBStack(int objectCount) {
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
float val1 = 34f + (float) (Math.random() * 12.0f);
|
||||
float val2 = 34f + (float) (Math.random() * 12.0f);
|
||||
float[] stack = new float[]{val1, val2, 100 - val1 - val2};
|
||||
|
||||
RealmDemoData d = new RealmDemoData(i, stack);
|
||||
mRealm.copyToRealm(d);
|
||||
}
|
||||
|
||||
mRealm.commitTransaction();
|
||||
}
|
||||
|
||||
protected void writeToDBCandle(int objectCount) {
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
float mult = 50;
|
||||
float val = (float) (Math.random() * 40) + mult;
|
||||
|
||||
float high = (float) (Math.random() * 9) + 8f;
|
||||
float low = (float) (Math.random() * 9) + 8f;
|
||||
|
||||
float open = (float) (Math.random() * 6) + 1f;
|
||||
float close = (float) (Math.random() * 6) + 1f;
|
||||
|
||||
boolean even = i % 2 == 0;
|
||||
|
||||
RealmDemoData d = new RealmDemoData(i, val + high, val - low, even ? val + open : val - open,
|
||||
even ? val - close : val + close);
|
||||
|
||||
mRealm.copyToRealm(d);
|
||||
}
|
||||
|
||||
mRealm.commitTransaction();
|
||||
}
|
||||
|
||||
protected void writeToDBBubble(int objectCount) {
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
float value = 30f + (float) (Math.random() * 100.0);
|
||||
float size = 15f + (float) (Math.random() * 20.0);
|
||||
|
||||
RealmDemoData d = new RealmDemoData(i, value, size);
|
||||
mRealm.copyToRealm(d);
|
||||
}
|
||||
|
||||
mRealm.commitTransaction();
|
||||
}
|
||||
|
||||
protected void writeToDBPie() {
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
float value1 = 15f + (float) (Math.random() * 8f);
|
||||
float value2 = 15f + (float) (Math.random() * 8f);
|
||||
float value3 = 15f + (float) (Math.random() * 8f);
|
||||
float value4 = 15f + (float) (Math.random() * 8f);
|
||||
float value5 = 100f - value1 - value2 - value3 - value4;
|
||||
|
||||
float[] values = new float[] { value1, value2, value3, value4, value5 };
|
||||
String[] labels = new String[]{ "iOS", "Android", "WP 10", "BlackBerry", "Other"};
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
RealmDemoData d = new RealmDemoData(values[i], labels[i]);
|
||||
mRealm.copyToRealm(d);
|
||||
}
|
||||
|
||||
mRealm.commitTransaction();
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.BarChart;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityBar extends RealmBaseActivity {
|
||||
|
||||
private BarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_barchart_noseekbar);
|
||||
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(20);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "yValue"); // stacked entries
|
||||
set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
|
||||
set.setLabel("Realm BarDataSet");
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
BarData data = new BarData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.setFitBars(true);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.BubbleChart;
|
||||
import com.github.mikephil.charting.data.BubbleData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityBubble extends RealmBaseActivity {
|
||||
|
||||
private BubbleChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_bubblechart_noseekbar);
|
||||
|
||||
mChart = (BubbleChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.setPinchZoom(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBBubble(10);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmBubbleDataSet<RealmDemoData> set = new RealmBubbleDataSet<RealmDemoData>(result, "xValue", "yValue", "bubbleSize");
|
||||
set.setLabel("Realm BubbleDataSet");
|
||||
set.setColors(ColorTemplate.COLORFUL_COLORS, 110);
|
||||
|
||||
ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
BubbleData data = new BubbleData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.CandleStickChart;
|
||||
import com.github.mikephil.charting.data.CandleData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityCandle extends RealmBaseActivity {
|
||||
|
||||
private CandleStickChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_candlechart_noseekbar);
|
||||
|
||||
mChart = (CandleStickChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBCandle(50);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "xValue", "high", "low", "open", "close");
|
||||
set.setLabel("Realm CandleDataSet");
|
||||
set.setShadowColor(Color.DKGRAY);
|
||||
set.setShadowWidth(0.7f);
|
||||
set.setDecreasingColor(Color.RED);
|
||||
set.setDecreasingPaintStyle(Paint.Style.FILL);
|
||||
set.setIncreasingColor(Color.rgb(122, 242, 84));
|
||||
set.setIncreasingPaintStyle(Paint.Style.STROKE);
|
||||
set.setNeutralColor(Color.BLUE);
|
||||
|
||||
ArrayList<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
CandleData data = new CandleData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityHorizontalBar extends RealmBaseActivity {
|
||||
|
||||
private HorizontalBarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_horizontalbarchart_noseekbar);
|
||||
|
||||
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMinValue(0f);
|
||||
mChart.setDrawValueAboveBar(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBStack(50);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "stackValues", "floatValue"); // stacked entries
|
||||
set.setColors(new int[]{ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E")});
|
||||
set.setLabel("Mobile OS distribution");
|
||||
set.setStackLabels(new String[]{"iOS", "Android", "Other"});
|
||||
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
BarData data = new BarData(dataSets);
|
||||
styleData(data);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityLine extends RealmBaseActivity {
|
||||
|
||||
private LineChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_linechart_noseekbar);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMaxValue(150f);
|
||||
mChart.getAxisLeft().setAxisMinValue(0f);
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(40);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setDrawCubic(false);
|
||||
set.setLabel("Realm LineDataSet");
|
||||
set.setDrawCircleHole(false);
|
||||
set.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setLineWidth(1.8f);
|
||||
set.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
LineData data = new LineData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityPie extends RealmBaseActivity {
|
||||
|
||||
private PieChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_piechart_noseekbar);
|
||||
|
||||
mChart = (PieChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.setCenterText(generateCenterSpannableText());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBPie();
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label"); // stacked entries
|
||||
set.setColors(ColorTemplate.VORDIPLOM_COLORS);
|
||||
set.setLabel("Example market share");
|
||||
set.setSliceSpace(2);
|
||||
|
||||
// create a data object with the dataset list
|
||||
PieData data = new PieData(set);
|
||||
styleData(data);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
data.setValueTextSize(12f);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400);
|
||||
}
|
||||
|
||||
private SpannableString generateCenterSpannableText() {
|
||||
|
||||
SpannableString s = new SpannableString("Realm.io\nmobile database");
|
||||
s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
|
||||
s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
|
||||
s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
|
||||
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
|
||||
s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
|
||||
return s;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
import com.github.mikephil.charting.data.RadarData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityRadar extends RealmBaseActivity {
|
||||
|
||||
private RadarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_radarchart_noseekbar);
|
||||
|
||||
mChart = (RadarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getYAxis().setEnabled(false);
|
||||
mChart.getXAxis().setEnabled(false);
|
||||
mChart.setWebAlpha(180);
|
||||
mChart.setWebColorInner(Color.DKGRAY);
|
||||
mChart.setWebColor(Color.GRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(7);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
|
||||
RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "yValue"); // stacked entries
|
||||
set.setLabel("Realm RadarDataSet");
|
||||
set.setDrawFilled(true);
|
||||
set.setColor(ColorTemplate.rgb("#009688"));
|
||||
set.setFillColor(ColorTemplate.rgb("#009688"));
|
||||
set.setFillAlpha(130);
|
||||
set.setLineWidth(2f);
|
||||
|
||||
ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
RadarData data = new RadarData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400);
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityScatter extends RealmBaseActivity {
|
||||
|
||||
private ScatterChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_scatterchart_noseekbar);
|
||||
|
||||
mChart = (ScatterChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
mChart.setPinchZoom(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(45);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setLabel("Realm ScatterDataSet");
|
||||
set.setScatterShapeSize(9f);
|
||||
set.setColor(ColorTemplate.rgb("#CDDC39"));
|
||||
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
|
||||
|
||||
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
ScatterData data = new ScatterData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.ContentItem;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.MyAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmConfiguration;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/12/15.
|
||||
*/
|
||||
public class RealmMainActivity extends DemoBase implements AdapterView.OnItemClickListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
setTitle("Realm.io Examples");
|
||||
|
||||
ArrayList<ContentItem> objects = new ArrayList<ContentItem>();
|
||||
|
||||
objects.add(new ContentItem("Line Chart", "Creating a LineChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Bar Chart",
|
||||
"Creating a BarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Horizontal Bar Chart",
|
||||
"Creating a HorizontalBarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Scatter Chart",
|
||||
"Creating a ScatterChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Candle Stick Chart", "Creating a CandleStickChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Bubble Chart", "Creating a BubbleChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Pie Chart", "Creating a PieChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Radar Chart", "Creating a RadarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Realm Wiki", "This is the code related to the wiki entry about realm.io on the MPAndroidChart github page."));
|
||||
|
||||
MyAdapter adapter = new MyAdapter(this, objects);
|
||||
|
||||
ListView lv = (ListView) findViewById(R.id.listView1);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
lv.setOnItemClickListener(this);
|
||||
|
||||
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
|
||||
RealmConfiguration realmConfig = new RealmConfiguration.Builder(getApplicationContext()).build();
|
||||
Realm.setDefaultConfiguration(realmConfig);
|
||||
|
||||
Realm realm = Realm.getDefaultInstance();
|
||||
realm.beginTransaction();
|
||||
realm.deleteAll();
|
||||
realm.commitTransaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
|
||||
|
||||
Intent i;
|
||||
|
||||
switch (pos) {
|
||||
case 0:
|
||||
i = new Intent(this, RealmDatabaseActivityLine.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 1:
|
||||
i = new Intent(this, RealmDatabaseActivityBar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 2:
|
||||
i = new Intent(this, RealmDatabaseActivityHorizontalBar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 3:
|
||||
i = new Intent(this, RealmDatabaseActivityScatter.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 4:
|
||||
i = new Intent(this, RealmDatabaseActivityCandle.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 5:
|
||||
i = new Intent(this, RealmDatabaseActivityBubble.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 6:
|
||||
i = new Intent(this, RealmDatabaseActivityPie.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 7:
|
||||
i = new Intent(this, RealmDatabaseActivityRadar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 8:
|
||||
i = new Intent(this, RealmWikiExample.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
|
||||
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.realm, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://realm.io"));
|
||||
startActivity(i);
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.BarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 18/12/15.
|
||||
*/
|
||||
public class RealmWikiExample extends RealmBaseActivity {
|
||||
|
||||
private LineChart lineChart;
|
||||
private BarChart barChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_realm_wiki);
|
||||
|
||||
lineChart = (LineChart) findViewById(R.id.lineChart);
|
||||
barChart = (BarChart) findViewById(R.id.barChart);
|
||||
setup(lineChart);
|
||||
setup(barChart);
|
||||
|
||||
lineChart.setExtraBottomOffset(5f);
|
||||
barChart.setExtraBottomOffset(5f);
|
||||
|
||||
lineChart.getAxisLeft().setDrawGridLines(false);
|
||||
lineChart.getXAxis().setDrawGridLines(false);
|
||||
lineChart.getXAxis().setLabelCount(5);
|
||||
lineChart.getXAxis().setGranularity(1f);
|
||||
barChart.getAxisLeft().setDrawGridLines(false);
|
||||
barChart.getXAxis().setDrawGridLines(false);
|
||||
barChart.getXAxis().setLabelCount(5);
|
||||
barChart.getXAxis().setGranularity(1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
Score score1 = new Score(100f, 0f, "Peter");
|
||||
mRealm.copyToRealm(score1);
|
||||
Score score2 = new Score(110f, 1f, "Lisa");
|
||||
mRealm.copyToRealm(score2);
|
||||
Score score3 = new Score(130f, 2f, "Dennis");
|
||||
mRealm.copyToRealm(score3);
|
||||
Score score4 = new Score(70f, 3f, "Luke");
|
||||
mRealm.copyToRealm(score4);
|
||||
Score score5 = new Score(80f, 4f, "Sarah");
|
||||
mRealm.copyToRealm(score5);
|
||||
|
||||
mRealm.commitTransaction();
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
// LINE-CHART
|
||||
final RealmResults<Score> results = mRealm.where(Score.class).findAll();
|
||||
|
||||
|
||||
AxisValueFormatter formatter = new AxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return results.get((int) value).getPlayerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
lineChart.getXAxis().setValueFormatter(formatter);
|
||||
barChart.getXAxis().setValueFormatter(formatter);
|
||||
|
||||
RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
lineDataSet.setDrawCubic(false);
|
||||
lineDataSet.setLabel("Result Scores");
|
||||
lineDataSet.setDrawCircleHole(false);
|
||||
lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setLineWidth(1.8f);
|
||||
lineDataSet.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(lineDataSet);
|
||||
|
||||
LineData lineData = new LineData(dataSets);
|
||||
styleData(lineData);
|
||||
|
||||
// set data
|
||||
lineChart.setData(lineData);
|
||||
lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
|
||||
|
||||
// BAR-CHART
|
||||
RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
barDataSet.setColors(new int[]{ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
|
||||
barDataSet.setLabel("Realm BarDataSet");
|
||||
|
||||
ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
|
||||
barDataSets.add(barDataSet);
|
||||
|
||||
BarData barData = new BarData(barDataSets);
|
||||
styleData(barData);
|
||||
|
||||
barChart.setData(barData);
|
||||
barChart.setFitBars(true);
|
||||
barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* our data object
|
||||
*/
|
||||
public class Score extends RealmObject {
|
||||
|
||||
private float totalScore;
|
||||
|
||||
private float scoreNr;
|
||||
|
||||
private String playerName;
|
||||
|
||||
public Score() {
|
||||
}
|
||||
|
||||
public Score(float totalScore, float scoreNr, String playerName) {
|
||||
this.scoreNr = scoreNr;
|
||||
this.playerName = playerName;
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
// all getters and setters...
|
||||
|
||||
public float getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
public void setTotalScore(float totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
public float getScoreNr() {
|
||||
return scoreNr;
|
||||
}
|
||||
|
||||
public void setScoreNr(float scoreNr) {
|
||||
this.scoreNr = scoreNr;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
}
|
|
@ -27,8 +27,8 @@ import android.view.ViewParent;
|
|||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.animation.EasingFunction;
|
||||
import com.github.mikephil.charting.components.IMarker;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.MarkerView;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
|
@ -710,12 +710,12 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
/**
|
||||
* if set to true, the marker view is drawn when a value is clicked
|
||||
*/
|
||||
protected boolean mDrawMarkerViews = true;
|
||||
protected boolean mDrawMarkers = true;
|
||||
|
||||
/**
|
||||
* the view that represents the marker
|
||||
*/
|
||||
protected MarkerView mMarkerView;
|
||||
protected IMarker mMarker;
|
||||
|
||||
/**
|
||||
* draws all MarkerViews on the highlighted positions
|
||||
|
@ -723,7 +723,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
protected void drawMarkers(Canvas canvas) {
|
||||
|
||||
// if there is no marker view or drawing marker is disabled
|
||||
if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight())
|
||||
if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < mIndicesToHighlight.length; i++) {
|
||||
|
@ -746,19 +746,10 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
continue;
|
||||
|
||||
// callbacks to update the content
|
||||
mMarkerView.refreshContent(e, highlight);
|
||||
mMarker.refreshContent(e, highlight);
|
||||
|
||||
mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||
mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
|
||||
mMarkerView.getMeasuredHeight());
|
||||
|
||||
if (pos[1] - mMarkerView.getHeight() <= 0) {
|
||||
float y = mMarkerView.getHeight() - pos[1];
|
||||
mMarkerView.draw(canvas, pos[0], pos[1] + y);
|
||||
} else {
|
||||
mMarkerView.draw(canvas, pos[0], pos[1]);
|
||||
}
|
||||
// draw the marker
|
||||
mMarker.draw(canvas, pos[0], pos[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1272,21 +1263,31 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
}
|
||||
|
||||
/**
|
||||
* sets the view that is displayed when a value is clicked on the chart
|
||||
* sets the marker that is displayed when a value is clicked on the chart
|
||||
*
|
||||
* @param v
|
||||
* @param marker
|
||||
*/
|
||||
public void setMarkerView(MarkerView v) {
|
||||
mMarkerView = v;
|
||||
public void setMarker(IMarker marker) {
|
||||
mMarker = marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the view that is set as a marker view for the chart
|
||||
* returns the marker that is set as a marker view for the chart
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public MarkerView getMarkerView() {
|
||||
return mMarkerView;
|
||||
public IMarker getMarker() {
|
||||
return mMarker;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMarkerView(IMarker v) {
|
||||
setMarker(v);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IMarker getMarkerView() {
|
||||
return getMarker();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1407,25 +1408,35 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if drawing the marker-view is enabled when tapping on values
|
||||
* (use the setMarkerView(View v) method to specify a marker view)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDrawMarkerViewEnabled() {
|
||||
return mDrawMarkerViews;
|
||||
@Deprecated
|
||||
public boolean isDrawMarkerViewsEnabled() {
|
||||
return isDrawMarkersEnabled();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDrawMarkerViews(boolean enabled) {
|
||||
setDrawMarkers(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this to true to draw a user specified marker-view when tapping on
|
||||
* chart values (use the setMarkerView(MarkerView mv) method to specify a
|
||||
* marker view). Default: true
|
||||
* returns true if drawing the marker is enabled when tapping on values
|
||||
* (use the setMarker(IMarker marker) method to specify a marker)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDrawMarkersEnabled() {
|
||||
return mDrawMarkers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this to true to draw a user specified marker when tapping on
|
||||
* chart values (use the setMarker(IMarker marker) method to specify a
|
||||
* marker). Default: true
|
||||
*
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawMarkerViews(boolean enabled) {
|
||||
mDrawMarkerViews = enabled;
|
||||
public void setDrawMarkers(boolean enabled) {
|
||||
mDrawMarkers = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.github.mikephil.charting.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.FSize;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
|
||||
public interface IMarker {
|
||||
|
||||
/**
|
||||
* @return The desired offset you wish the IMarker to have on the x-axis.
|
||||
* By returning x: -(width / 2) you will center the IMarker horizontally.
|
||||
* By returning y: -(height / 2) you will center the IMarker vertically.
|
||||
*/
|
||||
MPPointF getOffset();
|
||||
|
||||
/**
|
||||
* @return The offset for drawing at the specific `point`
|
||||
* If you have no adjustments to make, return getOffset().
|
||||
*
|
||||
* @param posX This is the X position at which the marker wants to be drawn.
|
||||
* You can adjust the offset conditionally based on this argument.
|
||||
* @param posY This is the X position at which the marker wants to be drawn.
|
||||
* You can adjust the offset conditionally based on this argument.
|
||||
*/
|
||||
MPPointF getOffsetForDrawingAtPos(float posX, float posY);
|
||||
|
||||
/**
|
||||
* This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn.
|
||||
*
|
||||
* @param e The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or
|
||||
* CandleEntry, simply cast it at runtime.
|
||||
* @param highlight the highlight object contains information about the highlighted value such as it's dataset-index, the
|
||||
* selected range or stack-index (only stacked bar entries).
|
||||
*/
|
||||
void refreshContent(Entry e, Highlight highlight);
|
||||
|
||||
/**
|
||||
* Draws the IMarker on the given position on the screen with the given Canvas object.
|
||||
*
|
||||
* @param canvas
|
||||
* @param posX
|
||||
* @param posY
|
||||
*/
|
||||
void draw(Canvas canvas, float posX, float posY);
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
package com.github.mikephil.charting.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.FSize;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your
|
||||
* markers.
|
||||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class MarkerImage implements IMarker {
|
||||
|
||||
private Context mContext;
|
||||
private Drawable mDrawable;
|
||||
|
||||
private MPPointF mOffset = new MPPointF();
|
||||
private MPPointF mOffset2 = new MPPointF();
|
||||
private WeakReference<Chart> mWeakChart;
|
||||
|
||||
private FSize mSize = new FSize();
|
||||
private Rect mDrawableBoundsCache = new Rect();
|
||||
|
||||
/**
|
||||
* Constructor. Sets up the MarkerView with a custom layout resource.
|
||||
*
|
||||
* @param context
|
||||
* @param drawableResourceId the drawable resource to render
|
||||
*/
|
||||
public MarkerImage(Context context, int drawableResourceId) {
|
||||
mContext = context;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
{
|
||||
mDrawable = mContext.getResources().getDrawable(drawableResourceId, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
mDrawable = mContext.getResources().getDrawable(drawableResourceId);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOffset(MPPointF offset) {
|
||||
mOffset = offset;
|
||||
|
||||
if (mOffset == null) {
|
||||
mOffset = new MPPointF();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOffset(float offsetX, float offsetY) {
|
||||
mOffset.x = offsetX;
|
||||
mOffset.y = offsetY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPPointF getOffset() {
|
||||
return mOffset;
|
||||
}
|
||||
|
||||
public void setSize(FSize size) {
|
||||
mSize = size;
|
||||
|
||||
if (mSize == null) {
|
||||
mSize = new FSize();
|
||||
}
|
||||
}
|
||||
|
||||
public FSize getSize() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
public void setChartView(Chart chart) {
|
||||
mWeakChart = new WeakReference<>(chart);
|
||||
}
|
||||
|
||||
public Chart getChartView() {
|
||||
return mWeakChart == null ? null : mWeakChart.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPPointF getOffsetForDrawingAtPos(float posX, float posY) {
|
||||
|
||||
MPPointF offset = getOffset();
|
||||
mOffset2.x = offset.x;
|
||||
mOffset2.y = offset.y;
|
||||
|
||||
Chart chart = getChartView();
|
||||
|
||||
float width = mSize.width;
|
||||
float height = mSize.height;
|
||||
|
||||
if (width == 0.f && mDrawable != null) {
|
||||
width = mDrawable.getIntrinsicWidth();
|
||||
}
|
||||
if (height == 0.f && mDrawable != null) {
|
||||
height = mDrawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
if (posX + mOffset2.x < 0) {
|
||||
mOffset2.x = - posX;
|
||||
} else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
|
||||
mOffset2.x = chart.getWidth() - posX - width;
|
||||
}
|
||||
|
||||
if (posY + mOffset2.y < 0) {
|
||||
mOffset2.y = - posY;
|
||||
} else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
|
||||
mOffset2.y = chart.getHeight() - posY - height;
|
||||
}
|
||||
|
||||
return mOffset2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas, float posX, float posY) {
|
||||
|
||||
if (mDrawable == null) return;
|
||||
|
||||
MPPointF offset = getOffsetForDrawingAtPos(posX, posY);
|
||||
|
||||
float width = mSize.width;
|
||||
float height = mSize.height;
|
||||
|
||||
if (width == 0.f && mDrawable != null) {
|
||||
width = mDrawable.getIntrinsicWidth();
|
||||
}
|
||||
if (height == 0.f && mDrawable != null) {
|
||||
height = mDrawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
mDrawable.copyBounds(mDrawableBoundsCache);
|
||||
mDrawable.setBounds(
|
||||
mDrawableBoundsCache.left,
|
||||
mDrawableBoundsCache.top,
|
||||
mDrawableBoundsCache.left + (int)width,
|
||||
mDrawableBoundsCache.top + (int)height);
|
||||
|
||||
int saveId = canvas.save();
|
||||
// translate to the correct position and draw
|
||||
canvas.translate(posX + offset.x, posY + offset.y);
|
||||
mDrawable.draw(canvas);
|
||||
canvas.restoreToCount(saveId);
|
||||
|
||||
mDrawable.setBounds(mDrawableBoundsCache);
|
||||
}
|
||||
}
|
|
@ -6,8 +6,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.FSize;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your
|
||||
|
@ -15,7 +20,11 @@ import com.github.mikephil.charting.highlight.Highlight;
|
|||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public abstract class MarkerView extends RelativeLayout {
|
||||
public class MarkerView extends RelativeLayout implements IMarker {
|
||||
|
||||
private MPPointF mOffset = new MPPointF();
|
||||
private MPPointF mOffset2 = new MPPointF();
|
||||
private WeakReference<Chart> mWeakChart;
|
||||
|
||||
/**
|
||||
* Constructor. Sets up the MarkerView with a custom layout resource.
|
||||
|
@ -44,50 +53,77 @@ public abstract class MarkerView extends RelativeLayout {
|
|||
inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the MarkerView on the given position on the screen with the given Canvas object.
|
||||
*
|
||||
* @param canvas
|
||||
* @param posx
|
||||
* @param posy
|
||||
*/
|
||||
public void draw(Canvas canvas, float posx, float posy) {
|
||||
public void setOffset(MPPointF offset) {
|
||||
mOffset = offset;
|
||||
|
||||
// take offsets into consideration
|
||||
posx += getXOffset(posx);
|
||||
posy += getYOffset(posy);
|
||||
|
||||
// translate to the correct position and draw
|
||||
canvas.translate(posx, posy);
|
||||
draw(canvas);
|
||||
canvas.translate(-posx, -posy);
|
||||
if (mOffset == null) {
|
||||
mOffset = new MPPointF();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method enables a specified custom MarkerView to update it's content everytime the MarkerView is redrawn.
|
||||
*
|
||||
* @param e The Entry the MarkerView belongs to. This can also be any subclass of Entry, like BarEntry or
|
||||
* CandleEntry, simply cast it at runtime.
|
||||
* @param highlight the highlight object contains information about the highlighted value such as it's dataset-index, the
|
||||
* selected range or stack-index (only stacked bar entries).
|
||||
*/
|
||||
public abstract void refreshContent(Entry e, Highlight highlight);
|
||||
public void setOffset(float offsetX, float offsetY) {
|
||||
mOffset.x = offsetX;
|
||||
mOffset.y = offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to return the desired offset you wish the MarkerView to have on the x-axis. By returning -(getWidth() /
|
||||
* 2) you will center the MarkerView horizontally.
|
||||
*
|
||||
* @param xpos the position on the x-axis in pixels where the marker is drawn
|
||||
* @return
|
||||
*/
|
||||
public abstract int getXOffset(float xpos);
|
||||
@Override
|
||||
public MPPointF getOffset() {
|
||||
return mOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to return the desired position offset you wish the MarkerView to have on the y-axis. By returning
|
||||
* -getHeight() you will cause the MarkerView to be above the selected value.
|
||||
*
|
||||
* @param ypos the position on the y-axis in pixels where the marker is drawn
|
||||
* @return
|
||||
*/
|
||||
public abstract int getYOffset(float ypos);
|
||||
public void setChartView(Chart chart) {
|
||||
mWeakChart = new WeakReference<>(chart);
|
||||
}
|
||||
|
||||
public Chart getChartView() {
|
||||
return mWeakChart == null ? null : mWeakChart.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPPointF getOffsetForDrawingAtPos(float posX, float posY) {
|
||||
|
||||
MPPointF offset = getOffset();
|
||||
mOffset2.x = offset.x;
|
||||
mOffset2.y = offset.y;
|
||||
|
||||
Chart chart = getChartView();
|
||||
|
||||
float width = getWidth();
|
||||
float height = getHeight();
|
||||
|
||||
if (posX + mOffset2.x < 0) {
|
||||
mOffset2.x = - posX;
|
||||
} else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
|
||||
mOffset2.x = chart.getWidth() - posX - width;
|
||||
}
|
||||
|
||||
if (posY + mOffset2.y < 0) {
|
||||
mOffset2.y = - posY;
|
||||
} else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
|
||||
mOffset2.y = chart.getHeight() - posY - height;
|
||||
}
|
||||
|
||||
return mOffset2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
|
||||
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||
layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas, float posX, float posY) {
|
||||
|
||||
MPPointF offset = getOffsetForDrawingAtPos(posX, posY);
|
||||
|
||||
int saveId = canvas.save();
|
||||
// translate to the correct position and draw
|
||||
canvas.translate(posX + offset.x, posY + offset.y);
|
||||
draw(canvas);
|
||||
canvas.restoreToCount(saveId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,10 @@ public final class FSize extends ObjectPool.Poolable{
|
|||
pool.recycle(instances);
|
||||
}
|
||||
|
||||
private FSize(final float width, final float height) {
|
||||
public FSize() {
|
||||
}
|
||||
|
||||
public FSize(final float width, final float height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
|
|
@ -20,12 +20,15 @@ public class MPPointF extends ObjectPool.Poolable {
|
|||
pool.setReplenishPercentage(0.5f);
|
||||
}
|
||||
|
||||
private MPPointF(float x, float y){
|
||||
public MPPointF() {
|
||||
}
|
||||
|
||||
public MPPointF(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public static MPPointF getInstance(float x, float y){
|
||||
public static MPPointF getInstance(float x, float y) {
|
||||
MPPointF result = pool.get();
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
|
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "io.realm:realm-gradle-plugin:1.1.0"
|
||||
//classpath "io.realm:realm-gradle-plugin:1.1.0"
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue