Remove Realm related classes from project
This commit is contained in:
parent
da6ded7bce
commit
a233e38978
28 changed files with 42 additions and 2287 deletions
|
@ -5,7 +5,7 @@
|
|||
android:versionName="3.0.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:minSdkVersion="16"
|
||||
android:targetSdkVersion="23" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion '23.0.2'
|
||||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 52
|
||||
versionName '3.0.0'
|
||||
|
@ -54,8 +55,8 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile project(':MPChartLib') // remove this if you only imported the example project
|
||||
compile project(':MPChartLib-Realm')
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'io.realm:realm-android:0.87.5' // dependency for realm-database API (http://realm.io)
|
||||
//compile 'io.realm:realm-android:0.87.5' // dependency for realm-database API (http://realm.io)
|
||||
//compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
|
||||
}
|
||||
|
|
|
@ -83,15 +83,11 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
RealmConfiguration config = new RealmConfiguration.Builder(this)
|
||||
.name("myrealm.realm")
|
||||
.build();
|
||||
// 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.deleteRealm(config);
|
||||
|
||||
Realm.setDefaultConfiguration(config);
|
||||
|
||||
mRealm = Realm.getInstance(config);
|
||||
mRealm = Realm.getDefaultInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,7 +100,7 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.clear(RealmDemoData.class);
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
|
@ -121,7 +117,7 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.clear(RealmDemoData.class);
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
|
@ -140,7 +136,7 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.clear(RealmDemoData.class);
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
|
@ -168,7 +164,7 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.clear(RealmDemoData.class);
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
for (int i = 0; i < objectCount; i++) {
|
||||
|
||||
|
@ -186,7 +182,7 @@ public abstract class RealmBaseActivity extends DemoBase {
|
|||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
mRealm.clear(RealmDemoData.class);
|
||||
mRealm.delete(RealmDemoData.class);
|
||||
|
||||
float value1 = 15f + (float) (Math.random() * 8f);
|
||||
float value2 = 15f + (float) (Math.random() * 8f);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RealmDatabaseActivityBar extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
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
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmDatabaseActivityBubble extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmBubbleDataSet<RealmDemoData> set = new RealmBubbleDataSet<RealmDemoData>(result, "xValue", "yValue", "bubbleSize");
|
||||
set.setLabel("Realm BubbleDataSet");
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmDatabaseActivityCandle extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "xValue", "high", "low", "open", "close");
|
||||
set.setLabel("Realm CandleDataSet");
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmDatabaseActivityHorizontalBar extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
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
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RealmDatabaseActivityLine extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setDrawCubic(false);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmDatabaseActivityPie extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
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
|
||||
|
|
|
@ -53,10 +53,10 @@ public class RealmDatabaseActivityRadar extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
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, "xValue", "yValue"); // stacked entries
|
||||
RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "yValue"); // stacked entries
|
||||
set.setLabel("Realm RadarDataSet");
|
||||
set.setDrawFilled(true);
|
||||
set.setColor(ColorTemplate.rgb("#009688"));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmDatabaseActivityScatter extends RealmBaseActivity {
|
|||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setLabel("Realm ScatterDataSet");
|
||||
|
|
|
@ -17,6 +17,9 @@ 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.
|
||||
*/
|
||||
|
@ -52,6 +55,15 @@ public class RealmMainActivity extends DemoBase implements AdapterView.OnItemCli
|
|||
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
|
||||
|
|
|
@ -81,7 +81,7 @@ public class RealmWikiExample extends RealmBaseActivity {
|
|||
private void setData() {
|
||||
|
||||
// LINE-CHART
|
||||
final RealmResults<Score> results = mRealm.allObjects(Score.class);
|
||||
final RealmResults<Score> results = mRealm.where(Score.class).findAll();
|
||||
|
||||
|
||||
AxisValueFormatter formatter = new AxisValueFormatter() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
//apply plugin: 'com.github.dcendents.android-maven'
|
||||
//apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
|
@ -8,7 +8,7 @@ android {
|
|||
buildToolsVersion '23.0.2'
|
||||
// resourcePrefix 'mpcht'
|
||||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 3
|
||||
versionName '3.0.0'
|
||||
|
@ -36,7 +36,7 @@ repositories {
|
|||
dependencies {
|
||||
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
//compile 'com.android.support:support-v4:19.+'
|
||||
provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API
|
||||
//provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.mockito:mockito-core:1.9.5"
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.base;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 08/11/15.
|
||||
*/
|
||||
public abstract class RealmBarLineScatterCandleBubbleDataSet<T extends RealmObject, S extends Entry> extends RealmBaseDataSet<T, S> implements IBarLineScatterCandleBubbleDataSet<S> {
|
||||
|
||||
/** default highlight color */
|
||||
protected int mHighLightColor = Color.rgb(255, 187, 115);
|
||||
|
||||
public RealmBarLineScatterCandleBubbleDataSet(RealmResults<T> results, String yValuesField) {
|
||||
super(results, yValuesField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes the realm RealmResults, sorts & stores them.
|
||||
*
|
||||
* @param results
|
||||
* @param xValuesField
|
||||
* @param yValuesField
|
||||
*/
|
||||
public RealmBarLineScatterCandleBubbleDataSet(RealmResults<T> results, String xValuesField, String yValuesField) {
|
||||
super(results, xValuesField, yValuesField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color that is used for drawing the highlight indicators. Dont
|
||||
* forget to resolve the color using getResources().getColor(...) or
|
||||
* Color.rgb(...).
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setHighLightColor(int color) {
|
||||
mHighLightColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighLightColor() {
|
||||
return mHighLightColor;
|
||||
}
|
||||
}
|
|
@ -1,379 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.base;
|
||||
|
||||
import com.github.mikephil.charting.data.BaseDataSet;
|
||||
import com.github.mikephil.charting.data.DataSet;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
import io.realm.Sort;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 06/11/15.
|
||||
*/
|
||||
public abstract class RealmBaseDataSet<T extends RealmObject, S extends Entry> extends BaseDataSet<S> {
|
||||
|
||||
/**
|
||||
* a list of queried realm objects
|
||||
*/
|
||||
protected RealmResults<T> results;
|
||||
|
||||
/**
|
||||
* a cached list of all data read from the database
|
||||
*/
|
||||
protected List<S> mValues;
|
||||
|
||||
/**
|
||||
* maximum y-value in the value array
|
||||
*/
|
||||
protected float mYMax = -Float.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* minimum y-value in the value array
|
||||
*/
|
||||
protected float mYMin = Float.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* maximum x-value in the value array
|
||||
*/
|
||||
protected float mXMax = -Float.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* minimum x-value in the value array
|
||||
*/
|
||||
protected float mXMin = Float.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* fieldname of the column that contains the y-values of this dataset
|
||||
*/
|
||||
protected String mYValuesField;
|
||||
|
||||
/**
|
||||
* fieldname of the column that contains the x-values of this dataset
|
||||
*/
|
||||
protected String mXValuesField;
|
||||
|
||||
public RealmBaseDataSet(RealmResults<T> results, String yValuesField) {
|
||||
this.results = results;
|
||||
this.mYValuesField = yValuesField;
|
||||
this.mValues = new ArrayList<S>();
|
||||
|
||||
if (mXValuesField != null)
|
||||
this.results.sort(mXValuesField, Sort.ASCENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes the realm RealmResults, sorts & stores them.
|
||||
*
|
||||
* @param results
|
||||
* @param xValuesField
|
||||
* @param yValuesField
|
||||
*/
|
||||
public RealmBaseDataSet(RealmResults<T> results, String xValuesField, String yValuesField) {
|
||||
this.results = results;
|
||||
this.mYValuesField = yValuesField;
|
||||
this.mXValuesField = xValuesField;
|
||||
this.mValues = new ArrayList<S>();
|
||||
|
||||
if (mXValuesField != null)
|
||||
this.results.sort(mXValuesField, Sort.ASCENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds the DataSet based on the given RealmResults.
|
||||
*/
|
||||
public void build(RealmResults<T> results) {
|
||||
|
||||
int xIndex = 0;
|
||||
for (T object : results) {
|
||||
mValues.add(buildEntryFromResultObject(object, xIndex++));
|
||||
}
|
||||
}
|
||||
|
||||
public S buildEntryFromResultObject(T realmObject, float x) {
|
||||
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
|
||||
|
||||
return (S) new Entry(mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), dynamicObject.getFloat(mYValuesField));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYMin() {
|
||||
//return results.min(mYValuesField).floatValue();
|
||||
return mYMin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYMax() {
|
||||
//return results.max(mYValuesField).floatValue();
|
||||
return mYMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXMin() {
|
||||
return mXMin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXMax() {
|
||||
return mXMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntryCount() {
|
||||
return mValues.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcMinMax() {
|
||||
|
||||
if (mValues == null || mValues.isEmpty())
|
||||
return;
|
||||
|
||||
mYMax = -Float.MAX_VALUE;
|
||||
mYMin = Float.MAX_VALUE;
|
||||
mXMax = -Float.MAX_VALUE;
|
||||
mXMin = Float.MAX_VALUE;
|
||||
|
||||
for (S e : mValues) {
|
||||
calcMinMax(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the min and max x and y value of this DataSet based on the given Entry.
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
protected void calcMinMax(S e) {
|
||||
|
||||
if (e.getY() < mYMin)
|
||||
mYMin = e.getY();
|
||||
|
||||
if (e.getY() > mYMax)
|
||||
mYMax = e.getY();
|
||||
|
||||
if (e.getX() < mXMin)
|
||||
mXMin = e.getX();
|
||||
|
||||
if (e.getX() > mXMax)
|
||||
mXMax = e.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public S getEntryForXPos(float xPos) {
|
||||
//DynamicRealmObject o = new DynamicRealmObject(results.where().equalTo(mXValuesField, xIndex).findFirst());
|
||||
//return new Entry(o.getFloat(mYValuesField), o.getInt(mXValuesField));
|
||||
return getEntryForXPos(xPos, DataSet.Rounding.CLOSEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public S getEntryForXPos(float xPos, DataSet.Rounding rounding) {
|
||||
int index = getEntryIndex(xPos, rounding);
|
||||
if (index > -1)
|
||||
return mValues.get(index);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<S> getEntriesForXPos(float xVal) {
|
||||
|
||||
List<S> entries = new ArrayList<>();
|
||||
|
||||
// {
|
||||
// T object = results.get(xVal);
|
||||
// if (object != null)
|
||||
// entries.add(buildEntryFromResultObject(object, xVal));
|
||||
// } else
|
||||
|
||||
if (mXValuesField != null) {
|
||||
RealmResults<T> foundObjects = results.where().equalTo(mXValuesField, xVal).findAll();
|
||||
|
||||
for (T e : foundObjects)
|
||||
entries.add(buildEntryFromResultObject(e, xVal));
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public S getEntryForIndex(int index) {
|
||||
//DynamicRealmObject o = new DynamicRealmObject(results.get(index));
|
||||
//return new Entry(o.getFloat(mYValuesField), o.getInt(mXValuesField));
|
||||
return mValues.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntryIndex(float xPos, DataSet.Rounding rounding) {
|
||||
|
||||
int low = 0;
|
||||
int high = mValues.size() - 1;
|
||||
int closest = -1;
|
||||
|
||||
while (low <= high) {
|
||||
int m = (high + low) / 2;
|
||||
|
||||
if (xPos == mValues.get(m).getX()) {
|
||||
while (m > 0 && mValues.get(m - 1).getX() == xPos)
|
||||
m--;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
if (xPos > mValues.get(m).getX())
|
||||
low = m + 1;
|
||||
else
|
||||
high = m - 1;
|
||||
|
||||
closest = m;
|
||||
}
|
||||
|
||||
if (closest != -1) {
|
||||
float closestXPos = mValues.get(closest).getX();
|
||||
if (rounding == DataSet.Rounding.UP) {
|
||||
if (closestXPos < xPos && closest < mValues.size() - 1) {
|
||||
++closest;
|
||||
}
|
||||
} else if (rounding == DataSet.Rounding.DOWN) {
|
||||
if (closestXPos > xPos && closest > 0) {
|
||||
--closest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntryIndex(S e) {
|
||||
return mValues.indexOf(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addEntry(S e) {
|
||||
|
||||
if (e == null)
|
||||
return false;
|
||||
|
||||
float val = e.getY();
|
||||
|
||||
if (mValues == null) {
|
||||
mValues = new ArrayList<S>();
|
||||
}
|
||||
|
||||
calcMinMax(e);
|
||||
|
||||
// add the entry
|
||||
mValues.add(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeEntry(S e) {
|
||||
|
||||
if (e == null)
|
||||
return false;
|
||||
|
||||
if (mValues == null)
|
||||
return false;
|
||||
|
||||
// remove the entry
|
||||
boolean removed = mValues.remove(e);
|
||||
|
||||
if (removed) {
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntryOrdered(S e) {
|
||||
|
||||
if (e == null)
|
||||
return;
|
||||
|
||||
float val = e.getY();
|
||||
|
||||
if (mValues == null) {
|
||||
mValues = new ArrayList<S>();
|
||||
}
|
||||
|
||||
if (mValues.size() == 0) {
|
||||
mYMax = val;
|
||||
mYMin = val;
|
||||
} else {
|
||||
if (mYMax < val)
|
||||
mYMax = val;
|
||||
if (mYMin > val)
|
||||
mYMin = val;
|
||||
}
|
||||
|
||||
if (mValues.size() > 0 && mValues.get(mValues.size() - 1).getX() > e.getX()) {
|
||||
int closestIndex = getEntryIndex(e.getX(), DataSet.Rounding.UP);
|
||||
mValues.add(closestIndex, e);
|
||||
return;
|
||||
}
|
||||
|
||||
mValues.add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the List of values that has been extracted from the RealmResults
|
||||
* using the provided fieldnames.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<S> getValues() {
|
||||
return mValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
mValues.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public RealmResults<T> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fieldname that represents the "y-values" in the realm-data.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getYValuesField() {
|
||||
return mYValuesField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field name that is used for getting the y-values out of the RealmResultSet.
|
||||
*
|
||||
* @param yValuesField
|
||||
*/
|
||||
public void setYValuesField(String yValuesField) {
|
||||
this.mYValuesField = yValuesField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fieldname that represents the "x-values" in the realm-data.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getXValuesField() {
|
||||
return mXValuesField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field name that is used for getting the x-values out of the RealmResultSet.
|
||||
*
|
||||
* @param xValuesField
|
||||
*/
|
||||
public void setXValuesField(String xValuesField) {
|
||||
this.mXValuesField = xValuesField;
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.base;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 08/11/15.
|
||||
*/
|
||||
public abstract class RealmLineRadarDataSet<T extends RealmObject, S extends Entry> extends RealmLineScatterCandleRadarDataSet<T, S> implements ILineRadarDataSet<S> {
|
||||
|
||||
/** the color that is used for filling the line surface */
|
||||
private int mFillColor = Color.rgb(140, 234, 255);
|
||||
|
||||
/** the drawable to be used for filling the line surface*/
|
||||
protected Drawable mFillDrawable;
|
||||
|
||||
/** transparency used for filling line surface */
|
||||
private int mFillAlpha = 85;
|
||||
|
||||
/** the width of the drawn data lines */
|
||||
private float mLineWidth = 2.5f;
|
||||
|
||||
/** if true, the data will also be drawn filled */
|
||||
private boolean mDrawFilled = false;
|
||||
|
||||
|
||||
public RealmLineRadarDataSet(RealmResults<T> results, String yValuesField) {
|
||||
super(results, yValuesField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes the realm RealmResults, sorts & stores them.
|
||||
*
|
||||
* @param results
|
||||
* @param yValuesField
|
||||
* @param xIndexField
|
||||
*/
|
||||
public RealmLineRadarDataSet(RealmResults<T> results, String yValuesField, String xIndexField) {
|
||||
super(results, yValuesField, xIndexField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFillColor() {
|
||||
return mFillColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the color that is used for filling the line surface
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setFillColor(int color) {
|
||||
mFillColor = color;
|
||||
mFillDrawable = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getFillDrawable() {
|
||||
return mFillDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the drawable to be used to fill the area below the line.
|
||||
*
|
||||
* @param drawable
|
||||
*/
|
||||
public void setFillDrawable(Drawable drawable) {
|
||||
this.mFillDrawable = drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFillAlpha() {
|
||||
return mFillAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the alpha value (transparency) that is used for filling the line
|
||||
* surface (0-255), default: 85
|
||||
*
|
||||
* @param alpha
|
||||
*/
|
||||
public void setFillAlpha(int alpha) {
|
||||
mFillAlpha = alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
|
||||
* thinner line == better performance, thicker line == worse performance
|
||||
*
|
||||
* @param width
|
||||
*/
|
||||
public void setLineWidth(float width) {
|
||||
|
||||
if (width < 0.2f)
|
||||
width = 0.2f;
|
||||
if (width > 10.0f)
|
||||
width = 10.0f;
|
||||
mLineWidth = Utils.convertDpToPixel(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLineWidth() {
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawFilled(boolean filled) {
|
||||
mDrawFilled = filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawFilledEnabled() {
|
||||
return mDrawFilled;
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.base;
|
||||
|
||||
import android.graphics.DashPathEffect;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 08/11/15.
|
||||
*/
|
||||
public abstract class RealmLineScatterCandleRadarDataSet<T extends RealmObject, S extends Entry> extends RealmBarLineScatterCandleBubbleDataSet<T, S> implements ILineScatterCandleRadarDataSet<S> {
|
||||
|
||||
protected boolean mDrawVerticalHighlightIndicator = true;
|
||||
protected boolean mDrawHorizontalHighlightIndicator = true;
|
||||
|
||||
/** the width of the highlight indicator lines */
|
||||
protected float mHighlightLineWidth = 0.5f;
|
||||
|
||||
/** the path effect for dashed highlight-lines */
|
||||
protected DashPathEffect mHighlightDashPathEffect = null;
|
||||
|
||||
public RealmLineScatterCandleRadarDataSet(RealmResults<T> results, String yValuesField) {
|
||||
super(results, yValuesField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes the realm RealmResults, sorts & stores them.
|
||||
*
|
||||
* @param results
|
||||
* @param xValueField
|
||||
* @param yValuesField
|
||||
*/
|
||||
public RealmLineScatterCandleRadarDataSet(RealmResults<T> results, String xValueField, String yValuesField) {
|
||||
super(results, xValueField, yValuesField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawHorizontalHighlightIndicator(boolean enabled) {
|
||||
this.mDrawHorizontalHighlightIndicator = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawVerticalHighlightIndicator(boolean enabled) {
|
||||
this.mDrawVerticalHighlightIndicator = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables / disables both vertical and horizontal highlight-indicators.
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawHighlightIndicators(boolean enabled) {
|
||||
setDrawVerticalHighlightIndicator(enabled);
|
||||
setDrawHorizontalHighlightIndicator(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVerticalHighlightIndicatorEnabled() {
|
||||
return mDrawVerticalHighlightIndicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHorizontalHighlightIndicatorEnabled() {
|
||||
return mDrawHorizontalHighlightIndicator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the highlight line in dp.
|
||||
* @param width
|
||||
*/
|
||||
public void setHighlightLineWidth(float width) {
|
||||
mHighlightLineWidth = Utils.convertDpToPixel(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHighlightLineWidth() {
|
||||
return mHighlightLineWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -"
|
||||
*
|
||||
* @param lineLength the length of the line pieces
|
||||
* @param spaceLength the length of space inbetween the line-pieces
|
||||
* @param phase offset, in degrees (normally, use 0)
|
||||
*/
|
||||
public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) {
|
||||
mHighlightDashPathEffect = new DashPathEffect(new float[] {
|
||||
lineLength, spaceLength
|
||||
}, phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the highlight-line to be drawn in dashed mode.
|
||||
*/
|
||||
public void disableDashedHighlightLine() {
|
||||
mHighlightDashPathEffect = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the dashed-line effect is enabled for highlight lines, false if not.
|
||||
* Default: disabled
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDashedHighlightLineEnabled() {
|
||||
return mHighlightDashPathEffect == null ? false : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashPathEffect getDashPathEffectHighlight() {
|
||||
return mHighlightDashPathEffect;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.base;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 19/12/15.
|
||||
*/
|
||||
public final class RealmUtils {
|
||||
|
||||
// /**
|
||||
// * Transforms the given Realm-ResultSet into a String array by using the provided xValuesField.
|
||||
// *
|
||||
// * @param result
|
||||
// * @param xPositionField
|
||||
// * @param xLabelField
|
||||
// * @return
|
||||
// */
|
||||
// public static List<XAxisValue> toXVals(RealmResults<? extends RealmObject> result, String xPositionField, String xLabelField) {
|
||||
//
|
||||
// List<XAxisValue> xVals = new ArrayList<XAxisValue>();
|
||||
//
|
||||
// for (RealmObject object : result) {
|
||||
//
|
||||
// DynamicRealmObject dynamicObject = new DynamicRealmObject(object);
|
||||
//
|
||||
// XAxisValue val = new XAxisValue(dynamicObject.getDouble(xPositionField), dynamicObject.getString(xLabelField));
|
||||
// xVals.add(val);
|
||||
// }
|
||||
//
|
||||
// return xVals;
|
||||
// }
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.github.mikephil.charting.data.BarEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmFieldType;
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmBarDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BarEntry>
|
||||
implements IBarDataSet {
|
||||
|
||||
private String mStackValueFieldName;
|
||||
|
||||
/**
|
||||
* the maximum number of bars that are stacked upon each other, this value
|
||||
* is calculated from the Entries that are added to the DataSet
|
||||
*/
|
||||
private int mStackSize = 1;
|
||||
|
||||
/**
|
||||
* the color used for drawing the bar shadows
|
||||
*/
|
||||
private int mBarShadowColor = Color.rgb(215, 215, 215);
|
||||
|
||||
private float mBarBorderWidth = 0.0f;
|
||||
|
||||
private int mBarBorderColor = Color.BLACK;
|
||||
|
||||
/**
|
||||
* the alpha value used to draw the highlight indicator bar
|
||||
*/
|
||||
private int mHighLightAlpha = 120;
|
||||
|
||||
/**
|
||||
* array of labels used to describe the different values of the stacked bars
|
||||
*/
|
||||
private String[] mStackLabels = new String[]{
|
||||
"Stack"
|
||||
};
|
||||
|
||||
public RealmBarDataSet(RealmResults<T> results, String xValuesField, String yValuesField) {
|
||||
super(results, xValuesField, yValuesField);
|
||||
mHighLightColor = Color.rgb(0, 0, 0);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for supporting stacked values.
|
||||
*
|
||||
* @param results
|
||||
* @param xValuesField
|
||||
* @param yValuesField
|
||||
* @param stackValueFieldName
|
||||
*/
|
||||
public RealmBarDataSet(RealmResults<T> results, String xValuesField, String yValuesField, String
|
||||
stackValueFieldName) {
|
||||
super(results, xValuesField, yValuesField);
|
||||
this.mStackValueFieldName = stackValueFieldName;
|
||||
mHighLightColor = Color.rgb(0, 0, 0);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(RealmResults<T> results) {
|
||||
|
||||
super.build(results);
|
||||
|
||||
calcStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BarEntry buildEntryFromResultObject(T realmObject, float x) {
|
||||
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
|
||||
|
||||
if (dynamicObject.getFieldType(mYValuesField) == RealmFieldType.LIST) {
|
||||
|
||||
RealmList<DynamicRealmObject> list = dynamicObject.getList(mYValuesField);
|
||||
float[] values = new float[list.size()];
|
||||
|
||||
int i = 0;
|
||||
for (DynamicRealmObject o : list) {
|
||||
values[i] = o.getFloat(mStackValueFieldName);
|
||||
i++;
|
||||
}
|
||||
|
||||
return new BarEntry(
|
||||
mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), values);
|
||||
} else {
|
||||
float value = dynamicObject.getFloat(mYValuesField);
|
||||
return new BarEntry(mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcMinMax() {
|
||||
|
||||
if (mValues == null || mValues.isEmpty())
|
||||
return;
|
||||
|
||||
mYMax = -Float.MAX_VALUE;
|
||||
mYMin = Float.MAX_VALUE;
|
||||
mXMax = -Float.MAX_VALUE;
|
||||
mXMin = Float.MAX_VALUE;
|
||||
|
||||
for (BarEntry e : mValues) {
|
||||
|
||||
if (e != null && !Float.isNaN(e.getY())) {
|
||||
|
||||
if (e.getYVals() == null) {
|
||||
|
||||
if (e.getY() < mYMin)
|
||||
mYMin = e.getY();
|
||||
|
||||
if (e.getY() > mYMax)
|
||||
mYMax = e.getY();
|
||||
} else {
|
||||
|
||||
if (-e.getNegativeSum() < mYMin)
|
||||
mYMin = -e.getNegativeSum();
|
||||
|
||||
if (e.getPositiveSum() > mYMax)
|
||||
mYMax = e.getPositiveSum();
|
||||
}
|
||||
|
||||
if (e.getX() < mXMin)
|
||||
mXMin = e.getX();
|
||||
|
||||
if (e.getX() > mXMax)
|
||||
mXMax = e.getX();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calcStackSize() {
|
||||
|
||||
for (int i = 0; i < mValues.size(); i++) {
|
||||
|
||||
float[] vals = mValues.get(i).getYVals();
|
||||
|
||||
if (vals != null && vals.length > mStackSize)
|
||||
mStackSize = vals.length;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackSize() {
|
||||
return mStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStacked() {
|
||||
return mStackSize > 1 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color used for drawing the bar-shadows. The bar shadows is a
|
||||
* surface behind the bar that indicates the maximum value. Don't for get to
|
||||
* use getResources().getColor(...) to set this. Or Color.rgb(...).
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setBarShadowColor(int color) {
|
||||
mBarShadowColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarShadowColor() {
|
||||
return mBarShadowColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width used for drawing borders around the bars.
|
||||
* If borderWidth == 0, no border will be drawn.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void setBarBorderWidth(float width) {
|
||||
mBarBorderWidth = width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width used for drawing borders around the bars.
|
||||
* If borderWidth == 0, no border will be drawn.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public float getBarBorderWidth() {
|
||||
return mBarBorderWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color drawing borders around the bars.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void setBarBorderColor(int color) {
|
||||
mBarBorderColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color drawing borders around the bars.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getBarBorderColor() {
|
||||
return mBarBorderColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alpha value (transparency) that is used for drawing the highlight
|
||||
* indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
|
||||
*
|
||||
* @param alpha
|
||||
*/
|
||||
public void setHighLightAlpha(int alpha) {
|
||||
mHighLightAlpha = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighLightAlpha() {
|
||||
return mHighLightAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets labels for different values of bar-stacks, in case there are one.
|
||||
*
|
||||
* @param labels
|
||||
*/
|
||||
public void setStackLabels(String[] labels) {
|
||||
mStackLabels = labels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStackLabels() {
|
||||
return mStackLabels;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import com.github.mikephil.charting.data.BubbleEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmBubbleDataSet<T extends RealmObject> extends RealmBarLineScatterCandleBubbleDataSet<T, BubbleEntry> implements IBubbleDataSet {
|
||||
|
||||
private String mSizeField;
|
||||
|
||||
protected float mMaxSize;
|
||||
protected boolean mNormalizeSize = true;
|
||||
|
||||
private float mHighlightCircleWidth = 2.5f;
|
||||
|
||||
/**
|
||||
* Constructor for creating a CandleDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
* @param sizeField the name of the field in your data object that represents the bubble size
|
||||
*/
|
||||
public RealmBubbleDataSet(RealmResults<T> result, String yValuesField, String sizeField) {
|
||||
super(result, yValuesField);
|
||||
this.mSizeField = sizeField;
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating a CandleDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
* @param xIndexField the name of the field in your data object that represents the x-index
|
||||
* @param sizeField the name of the field in your data object that represents the bubble size
|
||||
*/
|
||||
public RealmBubbleDataSet(RealmResults<T> result, String yValuesField, String xIndexField, String sizeField) {
|
||||
super(result, yValuesField, xIndexField);
|
||||
this.mSizeField = sizeField;
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BubbleEntry buildEntryFromResultObject(T realmObject, float x) {
|
||||
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
|
||||
|
||||
return new BubbleEntry(
|
||||
mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField),
|
||||
dynamicObject.getFloat(mYValuesField),
|
||||
dynamicObject.getFloat(mSizeField));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcMinMax() {
|
||||
|
||||
if (mValues == null || mValues.isEmpty())
|
||||
return;
|
||||
|
||||
mYMax = -Float.MAX_VALUE;
|
||||
mYMin = Float.MAX_VALUE;
|
||||
mXMax = -Float.MAX_VALUE;
|
||||
mXMin = Float.MAX_VALUE;
|
||||
|
||||
for (BubbleEntry e : mValues) {
|
||||
|
||||
calcMinMax(e);
|
||||
|
||||
final float size = e.getSize();
|
||||
|
||||
if (size > mMaxSize) {
|
||||
mMaxSize = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxSize() {
|
||||
return mMaxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalizeSizeEnabled() {
|
||||
return mNormalizeSize;
|
||||
}
|
||||
|
||||
public void setNormalizeSizeEnabled(boolean normalizeSize) {
|
||||
mNormalizeSize = normalizeSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHighlightCircleWidth(float width) {
|
||||
mHighlightCircleWidth = Utils.convertDpToPixel(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHighlightCircleWidth() {
|
||||
return mHighlightCircleWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database fieldname for the bubble size.
|
||||
*
|
||||
* @param sizeField
|
||||
*/
|
||||
public void setSizeField(String sizeField) {
|
||||
this.mSizeField = sizeField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database fieldname that stores bubble size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getSizeField() {
|
||||
return mSizeField;
|
||||
}
|
||||
}
|
|
@ -1,316 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.data.CandleEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmCandleDataSet<T extends RealmObject> extends RealmLineScatterCandleRadarDataSet<T, CandleEntry>
|
||||
implements ICandleDataSet {
|
||||
|
||||
private String mHighField;
|
||||
private String mLowField;
|
||||
private String mOpenField;
|
||||
private String mCloseField;
|
||||
|
||||
/**
|
||||
* the width of the shadow of the candle
|
||||
*/
|
||||
private float mShadowWidth = 3f;
|
||||
|
||||
/**
|
||||
* should the candle bars show?
|
||||
* when false, only "ticks" will show
|
||||
* <p/>
|
||||
* - default: true
|
||||
*/
|
||||
private boolean mShowCandleBar = true;
|
||||
|
||||
/**
|
||||
* the space between the candle entries, default 0.1f (10%)
|
||||
*/
|
||||
private float mBarSpace = 0.1f;
|
||||
|
||||
/**
|
||||
* use candle color for the shadow
|
||||
*/
|
||||
private boolean mShadowColorSameAsCandle = false;
|
||||
|
||||
/**
|
||||
* paint style when open < close
|
||||
* increasing candlesticks are traditionally hollow
|
||||
*/
|
||||
protected Paint.Style mIncreasingPaintStyle = Paint.Style.STROKE;
|
||||
|
||||
/**
|
||||
* paint style when open > close
|
||||
* descreasing candlesticks are traditionally filled
|
||||
*/
|
||||
protected Paint.Style mDecreasingPaintStyle = Paint.Style.FILL;
|
||||
|
||||
/**
|
||||
* color for open == close
|
||||
*/
|
||||
protected int mNeutralColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
/**
|
||||
* color for open < close
|
||||
*/
|
||||
protected int mIncreasingColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
/**
|
||||
* color for open > close
|
||||
*/
|
||||
protected int mDecreasingColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
/**
|
||||
* shadow line color, set -1 for backward compatibility and uses default
|
||||
* color
|
||||
*/
|
||||
protected int mShadowColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
/**
|
||||
* Constructor for creating a LineDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param highField the name of the field in your data object that represents the "high" value
|
||||
* @param lowField the name of the field in your data object that represents the "low" value
|
||||
* @param openField the name of the field in your data object that represents the "open" value
|
||||
* @param closeField the name of the field in your data object that represents the "close" value
|
||||
*/
|
||||
public RealmCandleDataSet(RealmResults<T> result, String highField, String lowField, String openField, String
|
||||
closeField) {
|
||||
super(result, null);
|
||||
this.mHighField = highField;
|
||||
this.mLowField = lowField;
|
||||
this.mOpenField = openField;
|
||||
this.mCloseField = closeField;
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating a LineDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param xValueField the name of the field in your data object that represents the "x" value
|
||||
* @param highField the name of the field in your data object that represents the "high" value
|
||||
* @param lowField the name of the field in your data object that represents the "low" value
|
||||
* @param openField the name of the field in your data object that represents the "open" value
|
||||
* @param closeField the name of the field in your data object that represents the "close" value
|
||||
*/
|
||||
public RealmCandleDataSet(RealmResults<T> result, String xValueField, String highField, String lowField, String openField, String
|
||||
closeField) {
|
||||
super(result, xValueField, null);
|
||||
this.mHighField = highField;
|
||||
this.mLowField = lowField;
|
||||
this.mOpenField = openField;
|
||||
this.mCloseField = closeField;
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandleEntry buildEntryFromResultObject(T realmObject, float x) {
|
||||
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
|
||||
|
||||
return new CandleEntry(
|
||||
mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField),
|
||||
dynamicObject.getFloat(mHighField),
|
||||
dynamicObject.getFloat(mLowField),
|
||||
dynamicObject.getFloat(mOpenField),
|
||||
dynamicObject.getFloat(mCloseField));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcMinMax() {
|
||||
|
||||
if (mValues == null || mValues.isEmpty())
|
||||
return;
|
||||
|
||||
mYMax = -Float.MAX_VALUE;
|
||||
mYMin = Float.MAX_VALUE;
|
||||
mXMax = -Float.MAX_VALUE;
|
||||
mXMin = Float.MAX_VALUE;
|
||||
|
||||
for (CandleEntry e : mValues) {
|
||||
|
||||
if (e.getLow() < mYMin)
|
||||
mYMin = e.getLow();
|
||||
|
||||
if (e.getHigh() > mYMax)
|
||||
mYMax = e.getHigh();
|
||||
|
||||
if (e.getX() < mXMin)
|
||||
mXMin = e.getX();
|
||||
|
||||
if (e.getX() > mXMax)
|
||||
mXMax = e.getX();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the space that is left out on the left and right side of each
|
||||
* candle, default 0.1f (10%), max 0.45f, min 0f
|
||||
*
|
||||
* @param space
|
||||
*/
|
||||
public void setBarSpace(float space) {
|
||||
|
||||
if (space < 0f)
|
||||
space = 0f;
|
||||
if (space > 0.45f)
|
||||
space = 0.45f;
|
||||
|
||||
mBarSpace = space;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBarSpace() {
|
||||
return mBarSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the candle-shadow-line in pixels. Default 3f.
|
||||
*
|
||||
* @param width
|
||||
*/
|
||||
public void setShadowWidth(float width) {
|
||||
mShadowWidth = Utils.convertDpToPixel(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShadowWidth() {
|
||||
return mShadowWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the candle bars should show?
|
||||
*
|
||||
* @param showCandleBar
|
||||
*/
|
||||
public void setShowCandleBar(boolean showCandleBar) {
|
||||
mShowCandleBar = showCandleBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShowCandleBar() {
|
||||
return mShowCandleBar;
|
||||
}
|
||||
|
||||
|
||||
/** BELOW THIS COLOR HANDLING */
|
||||
|
||||
/**
|
||||
* Sets the one and ONLY color that should be used for this DataSet when
|
||||
* open == close.
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setNeutralColor(int color) {
|
||||
mNeutralColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNeutralColor() {
|
||||
return mNeutralColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the one and ONLY color that should be used for this DataSet when
|
||||
* open < close.
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setIncreasingColor(int color) {
|
||||
mIncreasingColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncreasingColor() {
|
||||
return mIncreasingColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the one and ONLY color that should be used for this DataSet when
|
||||
* open > close.
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setDecreasingColor(int color) {
|
||||
mDecreasingColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecreasingColor() {
|
||||
return mDecreasingColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint.Style getIncreasingPaintStyle() {
|
||||
return mIncreasingPaintStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets paint style when open < close
|
||||
*
|
||||
* @param paintStyle
|
||||
*/
|
||||
public void setIncreasingPaintStyle(Paint.Style paintStyle) {
|
||||
this.mIncreasingPaintStyle = paintStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint.Style getDecreasingPaintStyle() {
|
||||
return mDecreasingPaintStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets paint style when open > close
|
||||
*
|
||||
* @param decreasingPaintStyle
|
||||
*/
|
||||
public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
|
||||
this.mDecreasingPaintStyle = decreasingPaintStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getShadowColor() {
|
||||
return mShadowColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets shadow color for all entries
|
||||
*
|
||||
* @param shadowColor
|
||||
*/
|
||||
public void setShadowColor(int shadowColor) {
|
||||
this.mShadowColor = shadowColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShadowColorSameAsCandle() {
|
||||
return mShadowColorSameAsCandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets shadow color to be the same color as the candle color
|
||||
*
|
||||
* @param shadowColorSameAsCandle
|
||||
*/
|
||||
public void setShadowColorSameAsCandle(boolean shadowColorSameAsCandle) {
|
||||
this.mShadowColorSameAsCandle = shadowColorSameAsCandle;
|
||||
}
|
||||
}
|
|
@ -1,371 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.DashPathEffect;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.LineDataSet;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
|
||||
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
|
||||
import com.github.mikephil.charting.formatter.FillFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T, Entry> implements ILineDataSet {
|
||||
|
||||
/** Drawing mode for this line dataset **/
|
||||
private LineDataSet.Mode mMode = LineDataSet.Mode.LINEAR;
|
||||
|
||||
/**
|
||||
* List representing all colors that are used for the circles
|
||||
*/
|
||||
private List<Integer> mCircleColors = null;
|
||||
|
||||
/**
|
||||
* the color of the inner circles
|
||||
*/
|
||||
private int mCircleColorHole = Color.WHITE;
|
||||
|
||||
/**
|
||||
* the radius of the circle-shaped value indicators
|
||||
*/
|
||||
private float mCircleRadius = 8f;
|
||||
|
||||
/** the hole radius of the circle-shaped value indicators */
|
||||
private float mCircleHoleRadius = 4f;
|
||||
|
||||
/**
|
||||
* sets the intensity of the cubic lines
|
||||
*/
|
||||
private float mCubicIntensity = 0.2f;
|
||||
|
||||
/**
|
||||
* the path effect of this DataSet that makes dashed lines possible
|
||||
*/
|
||||
private DashPathEffect mDashPathEffect = null;
|
||||
|
||||
/**
|
||||
* formatter for customizing the position of the fill-line
|
||||
*/
|
||||
private FillFormatter mFillFormatter = new DefaultFillFormatter();
|
||||
|
||||
/**
|
||||
* if true, drawing circles is enabled
|
||||
*/
|
||||
private boolean mDrawCircles = true;
|
||||
|
||||
private boolean mDrawCircleHole = true;
|
||||
|
||||
/**
|
||||
* Constructor for creating a LineDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
*/
|
||||
public RealmLineDataSet(RealmResults<T> result, String yValuesField) {
|
||||
super(result, yValuesField);
|
||||
mCircleColors = new ArrayList<Integer>();
|
||||
|
||||
// default color
|
||||
mCircleColors.add(Color.rgb(140, 234, 255));
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating a LineDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param xValuesField the name of the field in your data object that represents the x-axis value
|
||||
* @param yValuesField the name of the field in your data object that represents the y-axis value
|
||||
*/
|
||||
public RealmLineDataSet(RealmResults<T> result, String xValuesField, String yValuesField) {
|
||||
super(result, xValuesField, yValuesField);
|
||||
mCircleColors = new ArrayList<Integer>();
|
||||
|
||||
// default color
|
||||
mCircleColors.add(Color.rgb(140, 234, 255));
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the drawing mode for this line dataset
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public LineDataSet.Mode getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the drawing mode for this line dataset
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void setMode(LineDataSet.Mode mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic,
|
||||
* Min = 0.05f = low cubic effect, Default: 0.2f
|
||||
*
|
||||
* @param intensity
|
||||
*/
|
||||
public void setCubicIntensity(float intensity) {
|
||||
|
||||
if (intensity > 1f)
|
||||
intensity = 1f;
|
||||
if (intensity < 0.05f)
|
||||
intensity = 0.05f;
|
||||
|
||||
mCubicIntensity = intensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCubicIntensity() {
|
||||
return mCubicIntensity;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the size (radius) of the circle shpaed value indicators, default
|
||||
* size = 4f
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
public void setCircleSize(float size) {
|
||||
mCircleRadius = Utils.convertDpToPixel(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCircleRadius() {
|
||||
return mCircleRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the hole radius of the drawn circles.
|
||||
* Default radius = 2f
|
||||
*
|
||||
* @param holeRadius
|
||||
*/
|
||||
public void setCircleHoleRadius(float holeRadius) {
|
||||
mCircleHoleRadius = Utils.convertDpToPixel(holeRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCircleHoleRadius() {
|
||||
return mCircleHoleRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the line to be drawn in dashed mode, e.g. like this
|
||||
* "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF.
|
||||
* Keep in mind that hardware acceleration boosts performance.
|
||||
*
|
||||
* @param lineLength the length of the line pieces
|
||||
* @param spaceLength the length of space in between the pieces
|
||||
* @param phase offset, in degrees (normally, use 0)
|
||||
*/
|
||||
public void enableDashedLine(float lineLength, float spaceLength, float phase) {
|
||||
mDashPathEffect = new DashPathEffect(new float[]{
|
||||
lineLength, spaceLength
|
||||
}, phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the line to be drawn in dashed mode.
|
||||
*/
|
||||
public void disableDashedLine() {
|
||||
mDashPathEffect = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDashedLineEnabled() {
|
||||
return mDashPathEffect == null ? false : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashPathEffect getDashPathEffect() {
|
||||
return mDashPathEffect;
|
||||
}
|
||||
|
||||
/**
|
||||
* set this to true to enable the drawing of circle indicators for this
|
||||
* DataSet, default true
|
||||
*
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawCircles(boolean enabled) {
|
||||
this.mDrawCircles = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawCirclesEnabled() {
|
||||
return mDrawCircles;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDrawCubic(boolean enabled) {
|
||||
mMode = enabled ? LineDataSet.Mode.CUBIC_BEZIER : LineDataSet.Mode.LINEAR;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean isDrawCubicEnabled() {
|
||||
return mMode == LineDataSet.Mode.CUBIC_BEZIER;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDrawStepped(boolean enabled) {
|
||||
mMode = enabled ? LineDataSet.Mode.STEPPED : LineDataSet.Mode.LINEAR;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean isDrawSteppedEnabled() {
|
||||
return mMode == LineDataSet.Mode.STEPPED;
|
||||
}
|
||||
|
||||
/** ALL CODE BELOW RELATED TO CIRCLE-COLORS */
|
||||
|
||||
/**
|
||||
* returns all colors specified for the circles
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<Integer> getCircleColors() {
|
||||
return mCircleColors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCircleColor(int index) {
|
||||
return mCircleColors.get(index % mCircleColors.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the colors that should be used for the circles of this DataSet.
|
||||
* Colors are reused as soon as the number of Entries the DataSet represents
|
||||
* is higher than the size of the colors array. Make sure that the colors
|
||||
* are already prepared (by calling getResources().getColor(...)) before
|
||||
* adding them to the DataSet.
|
||||
*
|
||||
* @param colors
|
||||
*/
|
||||
public void setCircleColors(List<Integer> colors) {
|
||||
mCircleColors = colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the colors that should be used for the circles of this DataSet.
|
||||
* Colors are reused as soon as the number of Entries the DataSet represents
|
||||
* is higher than the size of the colors array. Make sure that the colors
|
||||
* are already prepared (by calling getResources().getColor(...)) before
|
||||
* adding them to the DataSet.
|
||||
*
|
||||
* @param colors
|
||||
*/
|
||||
public void setCircleColors(int[] colors) {
|
||||
this.mCircleColors = ColorTemplate.createColors(colors);
|
||||
}
|
||||
|
||||
/**
|
||||
* ets the colors that should be used for the circles of this DataSet.
|
||||
* Colors are reused as soon as the number of Entries the DataSet represents
|
||||
* is higher than the size of the colors array. You can use
|
||||
* "new String[] { R.color.red, R.color.green, ... }" to provide colors for
|
||||
* this method. Internally, the colors are resolved using
|
||||
* getResources().getColor(...)
|
||||
*
|
||||
* @param colors
|
||||
*/
|
||||
public void setCircleColors(int[] colors, Context c) {
|
||||
|
||||
List<Integer> clrs = new ArrayList<Integer>();
|
||||
|
||||
for (int color : colors) {
|
||||
clrs.add(c.getResources().getColor(color));
|
||||
}
|
||||
|
||||
mCircleColors = clrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the one and ONLY color that should be used for this DataSet.
|
||||
* Internally, this recreates the colors array and adds the specified color.
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setCircleColor(int color) {
|
||||
resetCircleColors();
|
||||
mCircleColors.add(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* resets the circle-colors array and creates a new one
|
||||
*/
|
||||
public void resetCircleColors() {
|
||||
mCircleColors = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the inner circle of the line-circles.
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setCircleColorHole(int color) {
|
||||
mCircleColorHole = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCircleHoleColor() {
|
||||
return mCircleColorHole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this to true to allow drawing a hole in each data circle.
|
||||
*
|
||||
* @param enabled
|
||||
*/
|
||||
public void setDrawCircleHole(boolean enabled) {
|
||||
mDrawCircleHole = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawCircleHoleEnabled() {
|
||||
return mDrawCircleHole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a custom FillFormatter to the chart that handles the position of the
|
||||
* filled-line for each DataSet. Set this to null to use the default logic.
|
||||
*
|
||||
* @param formatter
|
||||
*/
|
||||
public void setFillFormatter(FillFormatter formatter) {
|
||||
|
||||
if (formatter == null)
|
||||
mFillFormatter = new DefaultFillFormatter();
|
||||
else
|
||||
mFillFormatter = formatter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FillFormatter getFillFormatter() {
|
||||
return mFillFormatter;
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import com.github.mikephil.charting.data.CandleEntry;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.PieEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmBaseDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmPieDataSet<T extends RealmObject> extends RealmBaseDataSet<T, PieEntry> implements IPieDataSet {
|
||||
|
||||
/**
|
||||
* the space in pixels between the chart-slices, default 0f
|
||||
*/
|
||||
private float mSliceSpace = 0f;
|
||||
|
||||
/**
|
||||
* indicates the selection distance of a pie slice
|
||||
*/
|
||||
private float mShift = 18f;
|
||||
|
||||
private PieDataSet.ValuePosition mXValuePosition = PieDataSet.ValuePosition.INSIDE_SLICE;
|
||||
private PieDataSet.ValuePosition mYValuePosition = PieDataSet.ValuePosition.INSIDE_SLICE;
|
||||
private int mValueLineColor = 0xff000000;
|
||||
private float mValueLineWidth = 1.0f;
|
||||
private float mValueLinePart1OffsetPercentage = 75.f;
|
||||
private float mValueLinePart1Length = 0.3f;
|
||||
private float mValueLinePart2Length = 0.4f;
|
||||
private boolean mValueLineVariableLength = true;
|
||||
|
||||
private String mLabelField;
|
||||
|
||||
/**
|
||||
* Constructor for creating a PieDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
*/
|
||||
public RealmPieDataSet(RealmResults<T> result, String yValuesField) {
|
||||
super(result, yValuesField);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
public RealmPieDataSet(RealmResults<T> result, String yValuesField, String labelField) {
|
||||
super(result, yValuesField);
|
||||
this.mLabelField = labelField;
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PieEntry buildEntryFromResultObject(T realmObject, float x) {
|
||||
DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);
|
||||
|
||||
if(mLabelField == null) {
|
||||
return new PieEntry(dynamicObject.getFloat(mYValuesField));
|
||||
} else {
|
||||
return new PieEntry(dynamicObject.getFloat(mYValuesField), dynamicObject.getString(mLabelField));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the space that is left out between the piechart-slices in dp.
|
||||
* Default: 0 --> no space, maximum 20f
|
||||
*
|
||||
* @param spaceDp
|
||||
*/
|
||||
public void setSliceSpace(float spaceDp) {
|
||||
|
||||
if (spaceDp > 20)
|
||||
spaceDp = 20f;
|
||||
if (spaceDp < 0)
|
||||
spaceDp = 0f;
|
||||
|
||||
mSliceSpace = Utils.convertDpToPixel(spaceDp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSliceSpace() {
|
||||
return mSliceSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the distance the highlighted piechart-slice of this DataSet is
|
||||
* "shifted" away from the center of the chart, default 12f
|
||||
*
|
||||
* @param shift
|
||||
*/
|
||||
public void setSelectionShift(float shift) {
|
||||
mShift = Utils.convertDpToPixel(shift);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSelectionShift() {
|
||||
return mShift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PieDataSet.ValuePosition getXValuePosition()
|
||||
{
|
||||
return mXValuePosition;
|
||||
}
|
||||
|
||||
public void setXValuePosition(PieDataSet.ValuePosition xValuePosition)
|
||||
{
|
||||
this.mXValuePosition = xValuePosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PieDataSet.ValuePosition getYValuePosition()
|
||||
{
|
||||
return mYValuePosition;
|
||||
}
|
||||
|
||||
public void setYValuePosition(PieDataSet.ValuePosition yValuePosition)
|
||||
{
|
||||
this.mYValuePosition = yValuePosition;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, indicates line color */
|
||||
@Override
|
||||
public int getValueLineColor()
|
||||
{
|
||||
return mValueLineColor;
|
||||
}
|
||||
|
||||
public void setValueLineColor(int valueLineColor)
|
||||
{
|
||||
this.mValueLineColor = valueLineColor;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, indicates line width */
|
||||
@Override
|
||||
public float getValueLineWidth()
|
||||
{
|
||||
return mValueLineWidth;
|
||||
}
|
||||
|
||||
public void setValueLineWidth(float valueLineWidth)
|
||||
{
|
||||
this.mValueLineWidth = valueLineWidth;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */
|
||||
@Override
|
||||
public float getValueLinePart1OffsetPercentage()
|
||||
{
|
||||
return mValueLinePart1OffsetPercentage;
|
||||
}
|
||||
|
||||
public void setValueLinePart1OffsetPercentage(float valueLinePart1OffsetPercentage)
|
||||
{
|
||||
this.mValueLinePart1OffsetPercentage = valueLinePart1OffsetPercentage;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, indicates length of first half of the line */
|
||||
@Override
|
||||
public float getValueLinePart1Length()
|
||||
{
|
||||
return mValueLinePart1Length;
|
||||
}
|
||||
|
||||
public void setValueLinePart1Length(float valueLinePart1Length)
|
||||
{
|
||||
this.mValueLinePart1Length = valueLinePart1Length;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, indicates length of second half of the line */
|
||||
@Override
|
||||
public float getValueLinePart2Length()
|
||||
{
|
||||
return mValueLinePart2Length;
|
||||
}
|
||||
|
||||
public void setValueLinePart2Length(float valueLinePart2Length)
|
||||
{
|
||||
this.mValueLinePart2Length = valueLinePart2Length;
|
||||
}
|
||||
|
||||
/** When valuePosition is OutsideSlice, this allows variable line length */
|
||||
@Override
|
||||
public boolean isValueLineVariableLength()
|
||||
{
|
||||
return mValueLineVariableLength;
|
||||
}
|
||||
|
||||
public void setValueLineVariableLength(boolean valueLineVariableLength)
|
||||
{
|
||||
this.mValueLineVariableLength = valueLineVariableLength;
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmRadarDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T, RadarEntry> implements IRadarDataSet {
|
||||
|
||||
/// flag indicating whether highlight circle should be drawn or not
|
||||
protected boolean mDrawHighlightCircleEnabled = false;
|
||||
|
||||
protected int mHighlightCircleFillColor = Color.WHITE;
|
||||
|
||||
/// The stroke color for highlight circle.
|
||||
/// If Utils.COLOR_NONE, the color of the dataset is taken.
|
||||
protected int mHighlightCircleStrokeColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
protected int mHighlightCircleStrokeAlpha = (int)(0.3 * 255);
|
||||
protected float mHighlightCircleInnerRadius = 3.0f;
|
||||
protected float mHighlightCircleOuterRadius = 4.0f;
|
||||
protected float mHighlightCircleStrokeWidth = 2.0f;
|
||||
|
||||
/**
|
||||
* Constructor for creating a RadarDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
*/
|
||||
public RealmRadarDataSet(RealmResults<T> result, String yValuesField) {
|
||||
super(result, yValuesField);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating a RadarDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param xValuesField the name of the field in your data object that represents the x value
|
||||
* @param yValuesField the name of the field in your data object that represents the y value
|
||||
*/
|
||||
public RealmRadarDataSet(RealmResults<T> result, String xValuesField, String yValuesField) {
|
||||
super(result, xValuesField, yValuesField);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/// Returns true if highlight circle should be drawn, false if not
|
||||
@Override
|
||||
public boolean isDrawHighlightCircleEnabled()
|
||||
{
|
||||
return mDrawHighlightCircleEnabled;
|
||||
}
|
||||
|
||||
/// Sets whether highlight circle should be drawn or not
|
||||
@Override
|
||||
public void setDrawHighlightCircleEnabled(boolean enabled)
|
||||
{
|
||||
mDrawHighlightCircleEnabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighlightCircleFillColor()
|
||||
{
|
||||
return mHighlightCircleFillColor;
|
||||
}
|
||||
|
||||
public void setHighlightCircleFillColor(int color)
|
||||
{
|
||||
mHighlightCircleFillColor = color;
|
||||
}
|
||||
|
||||
/// Returns the stroke color for highlight circle.
|
||||
/// If Utils.COLOR_NONE, the color of the dataset is taken.
|
||||
@Override
|
||||
public int getHighlightCircleStrokeColor()
|
||||
{
|
||||
return mHighlightCircleStrokeColor;
|
||||
}
|
||||
|
||||
/// Sets the stroke color for highlight circle.
|
||||
/// Set to Utils.COLOR_NONE in order to use the color of the dataset;
|
||||
public void setHighlightCircleStrokeColor(int color)
|
||||
{
|
||||
mHighlightCircleStrokeColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighlightCircleStrokeAlpha()
|
||||
{
|
||||
return mHighlightCircleStrokeAlpha;
|
||||
}
|
||||
|
||||
public void setHighlightCircleStrokeAlpha(int alpha)
|
||||
{
|
||||
mHighlightCircleStrokeAlpha = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHighlightCircleInnerRadius()
|
||||
{
|
||||
return mHighlightCircleInnerRadius;
|
||||
}
|
||||
|
||||
public void setHighlightCircleInnerRadius(float radius)
|
||||
{
|
||||
mHighlightCircleInnerRadius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHighlightCircleOuterRadius()
|
||||
{
|
||||
return mHighlightCircleOuterRadius;
|
||||
}
|
||||
|
||||
public void setHighlightCircleOuterRadius(float radius)
|
||||
{
|
||||
mHighlightCircleOuterRadius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHighlightCircleStrokeWidth()
|
||||
{
|
||||
return mHighlightCircleStrokeWidth;
|
||||
}
|
||||
|
||||
public void setHighlightCircleStrokeWidth(float strokeWidth)
|
||||
{
|
||||
mHighlightCircleStrokeWidth = strokeWidth;
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package com.github.mikephil.charting.data.realm.implementation;
|
||||
|
||||
import com.github.mikephil.charting.charts.ScatterChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
import com.github.mikephil.charting.renderer.scatter.ShapeRenderer;
|
||||
import com.github.mikephil.charting.renderer.scatter.SquareShapeRenderer;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.github.mikephil.charting.utils.ShapeRendererHandler;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/11/15.
|
||||
*/
|
||||
public class RealmScatterDataSet<T extends RealmObject> extends RealmLineScatterCandleRadarDataSet<T, Entry> implements IScatterDataSet {
|
||||
|
||||
/**
|
||||
* Renderer responsible for rendering this DataSet, default: square
|
||||
*/
|
||||
protected ShapeRenderer mShapeRenderer = new SquareShapeRenderer();
|
||||
|
||||
/**
|
||||
* the size the scattershape will have, in density pixels
|
||||
*/
|
||||
private float mShapeSize = 10f;
|
||||
|
||||
/**
|
||||
* The radius of the hole in the shape (applies to Square, Circle and Triangle)
|
||||
* - default: 0.0
|
||||
*/
|
||||
private float mScatterShapeHoleRadius = 0f;
|
||||
|
||||
/**
|
||||
* Color for the hole in the shape.
|
||||
* Setting to `ColorTemplate.COLOR_NONE` will behave as transparent.
|
||||
* - default: ColorTemplate.COLOR_NONE
|
||||
*/
|
||||
private int mScatterShapeHoleColor = ColorTemplate.COLOR_NONE;
|
||||
|
||||
/**
|
||||
* Constructor for creating a ScatterDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param yValuesField the name of the field in your data object that represents the y-value
|
||||
*/
|
||||
public RealmScatterDataSet(RealmResults<T> result, String yValuesField) {
|
||||
super(result, yValuesField);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating a ScatterDataSet with realm data.
|
||||
*
|
||||
* @param result the queried results from the realm database
|
||||
* @param xValuesField the name of the field in your data object that represents the x value
|
||||
* @param yValuesField the name of the field in your data object that represents the y value
|
||||
*/
|
||||
public RealmScatterDataSet(RealmResults<T> result, String xValuesField, String yValuesField) {
|
||||
super(result, xValuesField, yValuesField);
|
||||
|
||||
build(this.results);
|
||||
calcMinMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size in density pixels the drawn scattershape will have. This
|
||||
* only applies for non custom shapes.
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
public void setScatterShapeSize(float size) {
|
||||
mShapeSize = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScatterShapeSize() {
|
||||
return mShapeSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ScatterShape this DataSet should be drawn with. This will search for an available ShapeRenderer and set this
|
||||
* renderer for the DataSet.
|
||||
*
|
||||
* @param shape
|
||||
*/
|
||||
public void setScatterShape(ScatterChart.ScatterShape shape) {
|
||||
|
||||
ShapeRendererHandler handler = new ShapeRendererHandler();
|
||||
mShapeRenderer = handler.getShapeRenderer(shape);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new ShapeRenderer responsible for drawing this DataSet.
|
||||
* This can also be used to set a custom ShapeRenderer aside from the default ones.
|
||||
*
|
||||
* @param shapeRenderer
|
||||
*/
|
||||
public void setShapeRenderer(ShapeRenderer shapeRenderer) {
|
||||
mShapeRenderer = shapeRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeRenderer getShapeRenderer() {
|
||||
return mShapeRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the radius of the hole in the shape
|
||||
*
|
||||
* @param holeRadius
|
||||
*/
|
||||
public void setScatterShapeHoleRadius(float holeRadius) {
|
||||
mScatterShapeHoleRadius = holeRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScatterShapeHoleRadius() {
|
||||
return mScatterShapeHoleRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color for the hole in the shape
|
||||
*
|
||||
* @param holeColor
|
||||
*/
|
||||
public void setScatterShapeHoleColor(int holeColor) {
|
||||
mScatterShapeHoleColor = holeColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScatterShapeHoleColor() {
|
||||
return mScatterShapeHoleColor;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
//classpath "io.realm:realm-gradle-plugin:1.0.0"
|
||||
classpath "io.realm:realm-gradle-plugin:1.0.1"
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
include 'MPChartLib'
|
||||
//include 'MPAndroidChart-Realm'
|
||||
include 'MPChartExample'
|
||||
include ':MPChartLib-Realm'
|
||||
project(':MPChartLib-Realm').projectDir = new File('../MPAndroidChart-Realm/MPChartLib-Realm')
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue