├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_combine.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── android
│ │ │ └── colin
│ │ │ └── democandlechart
│ │ │ └── StockListBean.java
│ ├── test
│ │ └── java
│ │ │ └── android
│ │ │ └── colin
│ │ │ └── democandlechart
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── android
│ │ └── colin
│ │ └── democandlechart
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── MPChartLib
├── .gitignore
├── ic_launcher-web.png
├── .settings
│ └── gradle
│ │ └── org.springsource.ide.eclipse.gradle.core.prefs
├── src
│ └── com
│ │ └── github
│ │ └── mikephil
│ │ └── charting
│ │ ├── interfaces
│ │ ├── dataprovider
│ │ │ ├── BubbleDataProvider.java
│ │ │ ├── CandleDataProvider.java
│ │ │ ├── ScatterDataProvider.java
│ │ │ ├── LineDataProvider.java
│ │ │ ├── BarDataProvider.java
│ │ │ ├── BarLineScatterCandleBubbleDataProvider.java
│ │ │ └── ChartInterface.java
│ │ └── datasets
│ │ │ ├── IBarLineScatterCandleBubbleDataSet.java
│ │ │ ├── IBubbleDataSet.java
│ │ │ ├── IRadarDataSet.java
│ │ │ ├── IScatterDataSet.java
│ │ │ ├── ILineScatterCandleRadarDataSet.java
│ │ │ ├── ILineRadarDataSet.java
│ │ │ ├── IPieDataSet.java
│ │ │ ├── IBarDataSet.java
│ │ │ ├── ICandleDataSet.java
│ │ │ └── ILineDataSet.java
│ │ ├── formatter
│ │ ├── ColorFormatter.java
│ │ ├── DefaultXAxisValueFormatter.java
│ │ ├── YAxisValueFormatter.java
│ │ ├── FillFormatter.java
│ │ ├── XAxisValueFormatter.java
│ │ ├── DefaultYAxisValueFormatter.java
│ │ ├── PercentFormatter.java
│ │ ├── DefaultFillFormatter.java
│ │ ├── ValueFormatter.java
│ │ ├── DefaultValueFormatter.java
│ │ ├── StackedValueFormatter.java
│ │ └── LargeValueFormatter.java
│ │ ├── exception
│ │ └── DrawingDataSetNotCreatedException.java
│ │ ├── animation
│ │ └── EasingFunction.java
│ │ ├── listener
│ │ ├── OnDrawLineChartTouchListener.java
│ │ ├── OnChartValueSelectedListener.java
│ │ ├── OnDrawListener.java
│ │ ├── OnChartGestureListener.java
│ │ └── ChartTouchListener.java
│ │ ├── utils
│ │ ├── EntryXIndexComparator.java
│ │ ├── PointD.java
│ │ ├── SelectionDetail.java
│ │ ├── FSize.java
│ │ ├── TransformerHorizontalBarChart.java
│ │ └── ColorTemplate.java
│ │ ├── data
│ │ ├── realm
│ │ │ ├── implementation
│ │ │ │ ├── RealmPieData.java
│ │ │ │ ├── RealmBarData.java
│ │ │ │ ├── RealmLineData.java
│ │ │ │ ├── RealmRadarData.java
│ │ │ │ ├── RealmBubbleData.java
│ │ │ │ ├── RealmCandleData.java
│ │ │ │ └── RealmScatterData.java
│ │ │ └── base
│ │ │ │ ├── RealmUtils.java
│ │ │ │ ├── RealmBarLineScatterCandleBubbleDataSet.java
│ │ │ │ └── RealmLineScatterCandleRadarDataSet.java
│ │ ├── BarLineScatterCandleBubbleData.java
│ │ ├── BarLineScatterCandleBubbleDataSet.java
│ │ ├── CandleData.java
│ │ ├── RadarData.java
│ │ ├── LineData.java
│ │ ├── BubbleData.java
│ │ ├── BubbleEntry.java
│ │ ├── ScatterData.java
│ │ ├── PieData.java
│ │ ├── BarData.java
│ │ ├── LineRadarDataSet.java
│ │ ├── CombinedData.java
│ │ ├── CandleEntry.java
│ │ ├── LineScatterCandleRadarDataSet.java
│ │ ├── ScatterDataSet.java
│ │ ├── RadarDataSet.java
│ │ └── BubbleDataSet.java
│ │ ├── jobs
│ │ ├── MoveViewJob.java
│ │ ├── AnimatedMoveViewJob.java
│ │ ├── ViewPortJob.java
│ │ ├── AnimatedViewPortJob.java
│ │ ├── ZoomJob.java
│ │ └── AnimatedZoomJob.java
│ │ ├── buffer
│ │ ├── ScatterBuffer.java
│ │ ├── AbstractBuffer.java
│ │ ├── HorizontalBarBuffer.java
│ │ └── BarBuffer.java
│ │ ├── highlight
│ │ ├── Range.java
│ │ ├── CombinedHighlighter.java
│ │ ├── HorizontalBarHighlighter.java
│ │ ├── ChartHighlighter.java
│ │ └── Highlight.java
│ │ ├── charts
│ │ ├── CandleStickChart.java
│ │ ├── LineChart.java
│ │ ├── ScatterChart.java
│ │ └── BubbleChart.java
│ │ ├── renderer
│ │ ├── Renderer.java
│ │ ├── XAxisRendererRadarChart.java
│ │ ├── LineScatterCandleRadarRenderer.java
│ │ ├── LineRadarRenderer.java
│ │ ├── AxisRenderer.java
│ │ └── XAxisRendererBarChart.java
│ │ ├── components
│ │ └── MarkerView.java
│ │ └── matrix
│ │ └── Vector3.java
├── AndroidManifest.xml
├── project.properties
├── proguard-project.txt
├── build.gradle
└── pom.xml
├── settings.gradle
├── README.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
└── gradlew.bat
/.idea/.name:
--------------------------------------------------------------------------------
1 | DemoCandleChart
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/MPChartLib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':MPChartLib'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KLineChartDemo
2 | K Line Stock Chart which base on MPAndroidChart
3 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/MPChartLib/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/MPChartLib/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DemoCandleChart
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colin-phang/KLineChartDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | /MPChartLib/build
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/MPChartLib/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs:
--------------------------------------------------------------------------------
1 | #org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences
2 | #Mon Jan 18 23:02:46 CET 2016
3 | org.springsource.ide.eclipse.gradle.linkedresources=
4 | org.springsource.ide.eclipse.gradle.rootprojectloc=..
5 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BubbleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.data.BubbleData;
4 |
5 | public interface BubbleDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | BubbleData getBubbleData();
8 | }
9 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/CandleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.data.CandleData;
4 |
5 | public interface CandleDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | CandleData getCandleData();
8 | }
9 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/ScatterDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.data.ScatterData;
4 |
5 | public interface ScatterDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | ScatterData getScatterData();
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/android/colin/democandlechart/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package android.colin.democandlechart;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MPChartLib/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/ColorFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 |
5 | /**
6 | * Interface that can be used to return a customized color instead of setting
7 | * colors via the setColor(...) method of the DataSet.
8 | *
9 | * @author Philipp Jahoda
10 | */
11 | public interface ColorFormatter {
12 |
13 | int getColor(Entry e, int index);
14 | }
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/LineDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.components.YAxis;
4 | import com.github.mikephil.charting.data.LineData;
5 |
6 | public interface LineDataProvider extends BarLineScatterCandleBubbleDataProvider {
7 |
8 | LineData getLineData();
9 |
10 | YAxis getAxis(YAxis.AxisDependency dependency);
11 | }
12 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BarDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.data.BarData;
4 |
5 | public interface BarDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | BarData getBarData();
8 | boolean isDrawBarShadowEnabled();
9 | boolean isDrawValueAboveBarEnabled();
10 | boolean isDrawHighlightArrowEnabled();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_combine.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/android/colin/democandlechart/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package android.colin.democandlechart;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/exception/DrawingDataSetNotCreatedException.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.exception;
2 |
3 | public class DrawingDataSetNotCreatedException extends RuntimeException {
4 |
5 | /**
6 | *
7 | */
8 | private static final long serialVersionUID = 1L;
9 |
10 | public DrawingDataSetNotCreatedException() {
11 | super("Have to create a new drawing set first. Call ChartData's createNewDrawingDataSet() method");
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/animation/EasingFunction.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.animation;
2 |
3 | import android.animation.TimeInterpolator;
4 | import android.annotation.SuppressLint;
5 |
6 | /**
7 | * Interface for creating custom made easing functions. Uses the
8 | * TimeInterpolator interface provided by Android.
9 | */
10 | @SuppressLint("NewApi")
11 | public interface EasingFunction extends TimeInterpolator {
12 |
13 | @Override
14 | float getInterpolation(float input);
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/listener/OnDrawLineChartTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.listener;
2 |
3 | import android.view.GestureDetector.SimpleOnGestureListener;
4 | import android.view.MotionEvent;
5 | import android.view.View;
6 | import android.view.View.OnTouchListener;
7 |
8 | public class OnDrawLineChartTouchListener extends SimpleOnGestureListener implements OnTouchListener {
9 |
10 | @Override
11 | public boolean onTouch(View v, MotionEvent event) {
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 |
5 | /**
6 | * Created by philipp on 21/10/15.
7 | */
8 | public interface IBarLineScatterCandleBubbleDataSet extends IDataSet {
9 |
10 | /**
11 | * Returns the color that is used for drawing the highlight indicators.
12 | *
13 | * @return
14 | */
15 | int getHighLightColor();
16 | }
17 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/EntryXIndexComparator.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.utils;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 |
5 | import java.util.Comparator;
6 |
7 | /**
8 | * Comparator for comparing Entry-objects by their x-index.
9 | * Created by philipp on 17/06/15.
10 | */
11 | public class EntryXIndexComparator implements Comparator {
12 | @Override
13 | public int compare(Entry entry1, Entry entry2) {
14 | return entry1.getXIndex() - entry2.getXIndex();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/PointD.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.utils;
3 |
4 | /**
5 | * Point encapsulating two double values.
6 | *
7 | * @author Philipp Jahoda
8 | */
9 | public class PointD {
10 |
11 | public double x;
12 | public double y;
13 |
14 | public PointD(double x, double y) {
15 | this.x = x;
16 | this.y = y;
17 | }
18 |
19 | /**
20 | * returns a string representation of the object
21 | */
22 | public String toString() {
23 | return "PointD, x: " + x + ", y: " + y;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/MPChartLib/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-23
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/DefaultXAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.utils.ViewPortHandler;
4 |
5 | /**
6 | * Created by Philipp Jahoda on 14/09/15.
7 | * Default formatter class for adjusting x-values before drawing them.
8 | * This simply returns the original value unmodified.
9 | */
10 | public class DefaultXAxisValueFormatter implements XAxisValueFormatter {
11 |
12 | @Override
13 | public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
14 | return original; // just return original, no adjustments
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmPieData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.PieData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
6 |
7 | import io.realm.RealmObject;
8 | import io.realm.RealmResults;
9 |
10 | /**
11 | * Created by Philipp Jahoda on 19/12/15.
12 | */
13 | public class RealmPieData extends PieData {
14 |
15 | public RealmPieData(RealmResults extends RealmObject> result, String xValuesField, IPieDataSet dataSet) {
16 | super(RealmUtils.toXVals(result, xValuesField), dataSet);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BarLineScatterCandleBubbleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import com.github.mikephil.charting.components.YAxis.AxisDependency;
4 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
5 | import com.github.mikephil.charting.utils.Transformer;
6 |
7 | public interface BarLineScatterCandleBubbleDataProvider extends ChartInterface {
8 |
9 | Transformer getTransformer(AxisDependency axis);
10 | int getMaxVisibleCount();
11 | boolean isInverted(AxisDependency axis);
12 |
13 | int getLowestVisibleXIndex();
14 | int getHighestVisibleXIndex();
15 |
16 | BarLineScatterCandleBubbleData getData();
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBarData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.BarData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmBarData extends BarData {
16 |
17 | public RealmBarData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmLineData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.LineData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmLineData extends LineData {
16 |
17 | public RealmLineData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmRadarData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.RadarData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmRadarData extends RadarData{
16 |
17 | public RealmRadarData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBubbleData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.BubbleData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmBubbleData extends BubbleData {
16 |
17 | public RealmBubbleData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmCandleData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.CandleData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmCandleData extends CandleData {
16 |
17 | public RealmCandleData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmScatterData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.implementation;
2 |
3 | import com.github.mikephil.charting.data.ScatterData;
4 | import com.github.mikephil.charting.data.realm.base.RealmUtils;
5 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
6 |
7 | import java.util.List;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/12/15.
14 | */
15 | public class RealmScatterData extends ScatterData {
16 |
17 | public RealmScatterData(RealmResults extends RealmObject> result, String xValuesField, List dataSets) {
18 | super(RealmUtils.toXVals(result, xValuesField), dataSets);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/MoveViewJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.jobs;
3 |
4 | import android.view.View;
5 |
6 | import com.github.mikephil.charting.utils.Transformer;
7 | import com.github.mikephil.charting.utils.ViewPortHandler;
8 |
9 | /**
10 | * Created by Philipp Jahoda on 19/02/16.
11 | */
12 | public class MoveViewJob extends ViewPortJob {
13 |
14 | public MoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v) {
15 | super(viewPortHandler, xValue, yValue, trans, v);
16 | }
17 |
18 | @Override
19 | public void run() {
20 |
21 | pts[0] = xValue;
22 | pts[1] = yValue;
23 |
24 | mTrans.pointValuesToPixel(pts);
25 | mViewPortHandler.centerViewPort(pts, view);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "android.colin.democandlechart"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile project(':MPChartLib')
27 | compile 'com.google.code.gson:gson:2.6.2'
28 | }
29 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/YAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.components.YAxis;
4 |
5 | /**
6 | * Created by Philipp Jahoda on 20/09/15.
7 | * Custom formatter interface that allows formatting of
8 | * YAxis labels before they are being drawn.
9 | */
10 | public interface YAxisValueFormatter {
11 |
12 | /**
13 | * Called when a value from the YAxis is formatted
14 | * before being drawn. For performance reasons, avoid excessive calculations
15 | * and memory allocations inside this method.
16 | *
17 | * @param value the YAxis value to be formatted
18 | * @param yAxis the YAxis object the value belongs to
19 | * @return
20 | */
21 | String getFormattedValue(float value, YAxis yAxis);
22 | }
23 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/SelectionDetail.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.utils;
2 |
3 | import com.github.mikephil.charting.interfaces.datasets.IDataSet;
4 |
5 | /**
6 | * Class that encapsulates information of a value that has been
7 | * selected/highlighted and its DataSet index. The SelectionDetail objects give
8 | * information about the value at the selected index and the DataSet it belongs
9 | * to. Needed only for highlighting onTouch().
10 | *
11 | * @author Philipp Jahoda
12 | */
13 | public class SelectionDetail {
14 |
15 | public float val;
16 | public int dataSetIndex;
17 | public IDataSet dataSet;
18 |
19 | public SelectionDetail(float val, int dataSetIndex, IDataSet set) {
20 | this.val = val;
21 | this.dataSetIndex = dataSetIndex;
22 | this.dataSet = set;
23 | }
24 | }
--------------------------------------------------------------------------------
/MPChartLib/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.data.BubbleEntry;
4 |
5 | /**
6 | * Created by philipp on 21/10/15.
7 | */
8 | public interface IBubbleDataSet extends IBarLineScatterCandleBubbleDataSet {
9 |
10 | /**
11 | * Sets the width of the circle that surrounds the bubble when highlighted,
12 | * in dp.
13 | *
14 | * @param width
15 | */
16 | void setHighlightCircleWidth(float width);
17 |
18 | float getXMax();
19 |
20 | float getXMin();
21 |
22 | float getMaxSize();
23 |
24 | boolean isNormalizeSizeEnabled();
25 |
26 | /**
27 | * Returns the width of the highlight-circle that surrounds the bubble
28 | * @return
29 | */
30 | float getHighlightCircleWidth();
31 | }
32 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/FillFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
4 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
5 |
6 | /**
7 | * Interface for providing a custom logic to where the filling line of a LineDataSet
8 | * should end. This of course only works if setFillEnabled(...) is set to true.
9 | *
10 | * @author Philipp Jahoda
11 | */
12 | public interface FillFormatter {
13 |
14 | /**
15 | * Returns the vertical (y-axis) position where the filled-line of the
16 | * LineDataSet should end.
17 | *
18 | * @param dataSet the ILineDataSet that is currently drawn
19 | * @param dataProvider
20 | * @return
21 | */
22 | float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider);
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/buffer/ScatterBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.buffer;
3 |
4 | import com.github.mikephil.charting.data.Entry;
5 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
6 |
7 | public class ScatterBuffer extends AbstractBuffer {
8 |
9 | public ScatterBuffer(int size) {
10 | super(size);
11 | }
12 |
13 | protected void addForm(float x, float y) {
14 | buffer[index++] = x;
15 | buffer[index++] = y;
16 | }
17 |
18 | @Override
19 | public void feed(IScatterDataSet data) {
20 |
21 | float size = data.getEntryCount() * phaseX;
22 |
23 | for (int i = 0; i < size; i++) {
24 |
25 | Entry e = data.getEntryForIndex(i);
26 | addForm(e.getXIndex(), e.getVal() * phaseY);
27 | }
28 |
29 | reset();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/XAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.utils.ViewPortHandler;
4 |
5 | /**
6 | * Created by Philipp Jahoda on 14/09/15.
7 | * An interface for providing custom x-axis Strings.
8 | *
9 | * @author Philipp Jahoda
10 | */
11 | public interface XAxisValueFormatter {
12 |
13 | /**
14 | * Returns the customized label that is drawn on the x-axis.
15 | * For performance reasons, avoid excessive calculations
16 | * and memory allocations inside this method.
17 | *
18 | * @param original the original x-axis label to be drawn
19 | * @param index the x-index that is currently being drawn
20 | * @param viewPortHandler provides information about the current chart state (scale, translation, ...)
21 | * @return
22 | */
23 | String getXValue(String original, int index, ViewPortHandler viewPortHandler);
24 | }
25 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/highlight/Range.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.highlight;
2 |
3 | /**
4 | * Created by Philipp Jahoda on 24/07/15. Class that represents the range of one value in a stacked bar entry. e.g.
5 | * stack values are -10, 5, 20 -> then ranges are (-10 - 0, 0 - 5, 5 - 25).
6 | */
7 | public final class Range {
8 |
9 | public float from;
10 | public float to;
11 |
12 | public Range(float from, float to) {
13 | this.from = from;
14 | this.to = to;
15 | }
16 |
17 | /**
18 | * Returns true if this range contains (if the value is in between) the given value, false if not.
19 | *
20 | * @param value
21 | * @return
22 | */
23 | public boolean contains(float value) {
24 |
25 | if (value > from && value <= to)
26 | return true;
27 | else
28 | return false;
29 | }
30 |
31 | public boolean isLarger(float value) {
32 | return value > to;
33 | }
34 |
35 | public boolean isSmaller(float value) {
36 | return value < from;
37 | }
38 | }
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 |
5 | /**
6 | * Created by Philipp Jahoda on 03/11/15.
7 | */
8 | public interface IRadarDataSet extends ILineRadarDataSet {
9 |
10 | /// flag indicating whether highlight circle should be drawn or not
11 | boolean isDrawHighlightCircleEnabled();
12 |
13 | /// Sets whether highlight circle should be drawn or not
14 | void setDrawHighlightCircleEnabled(boolean enabled);
15 |
16 | int getHighlightCircleFillColor();
17 |
18 | /// The stroke color for highlight circle.
19 | /// If Utils.COLOR_NONE, the color of the dataset is taken.
20 | int getHighlightCircleStrokeColor();
21 |
22 | int getHighlightCircleStrokeAlpha();
23 |
24 | float getHighlightCircleInnerRadius();
25 |
26 | float getHighlightCircleOuterRadius();
27 |
28 | float getHighlightCircleStrokeWidth();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IScatterDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.charts.ScatterChart;
4 | import com.github.mikephil.charting.data.Entry;
5 |
6 | /**
7 | * Created by philipp on 21/10/15.
8 | */
9 | public interface IScatterDataSet extends ILineScatterCandleRadarDataSet {
10 |
11 | /**
12 | * Returns the currently set scatter shape size
13 | *
14 | * @return
15 | */
16 | float getScatterShapeSize();
17 |
18 | /**
19 | * Returns all the different scattershapes the chart uses
20 | *
21 | * @return
22 | */
23 | ScatterChart.ScatterShape getScatterShape();
24 |
25 | /**
26 | * Returns radius of the hole in the shape
27 | *
28 | * @return
29 | */
30 | float getScatterShapeHoleRadius();
31 |
32 | /**
33 | * Returns the color for the hole in the shape
34 | *
35 | * @return
36 | */
37 | int getScatterShapeHoleColor();
38 | }
39 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.base;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import io.realm.DynamicRealmObject;
7 | import io.realm.RealmObject;
8 | import io.realm.RealmResults;
9 | /**
10 | * Created by Philipp Jahoda on 19/12/15.
11 | */
12 | public final class RealmUtils {
13 |
14 | /**
15 | * Transforms the given Realm-ResultSet into a String array by using the provided xValuesField.
16 | *
17 | * @param result
18 | * @param xValuesField
19 | * @return
20 | */
21 | public static List toXVals(RealmResults extends RealmObject> result, String xValuesField) {
22 |
23 | List xVals = new ArrayList();
24 |
25 | for (RealmObject object : result) {
26 |
27 | DynamicRealmObject dynamicObject = new DynamicRealmObject(object);
28 | xVals.add(dynamicObject.getString(xValuesField));
29 | }
30 |
31 | return xVals;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/listener/OnChartValueSelectedListener.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.listener;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 | import com.github.mikephil.charting.highlight.Highlight;
5 |
6 | /**
7 | * Listener for callbacks when selecting values inside the chart by
8 | * touch-gesture.
9 | *
10 | * @author Philipp Jahoda
11 | */
12 | public interface OnChartValueSelectedListener {
13 |
14 | /**
15 | * Called when a value has been selected inside the chart.
16 | *
17 | * @param e The selected Entry.
18 | * @param dataSetIndex The index in the datasets array of the data object
19 | * the Entrys DataSet is in.
20 | * @param h the corresponding highlight object that contains information
21 | * about the highlighted position
22 | */
23 | void onValueSelected(Entry e, int dataSetIndex, Highlight h);
24 |
25 | /**
26 | * Called when nothing has been selected or an "un-select" has been made.
27 | */
28 | void onNothingSelected();
29 | }
30 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/listener/OnDrawListener.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.listener;
2 |
3 | import com.github.mikephil.charting.data.DataSet;
4 | import com.github.mikephil.charting.data.Entry;
5 |
6 | /**
7 | * Listener for callbacks when drawing on the chart.
8 | *
9 | * @author Philipp
10 | *
11 | */
12 | public interface OnDrawListener {
13 |
14 | /**
15 | * Called whenever an entry is added with the finger. Note this is also called for entries that are generated by the
16 | * library, when the touch gesture is too fast and skips points.
17 | *
18 | * @param entry
19 | * the last drawn entry
20 | */
21 | void onEntryAdded(Entry entry);
22 |
23 | /**
24 | * Called whenever an entry is moved by the user after beeing highlighted
25 | *
26 | * @param entry
27 | */
28 | void onEntryMoved(Entry entry);
29 |
30 | /**
31 | * Called when drawing finger is lifted and the draw is finished.
32 | *
33 | * @param dataSet
34 | * the last drawn DataSet
35 | */
36 | void onDrawFinished(DataSet> dataSet);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Baseclass for all Line, Bar, Scatter, Candle and Bubble data.
10 | *
11 | * @author Philipp Jahoda
12 | */
13 | public abstract class BarLineScatterCandleBubbleData>
14 | extends ChartData {
15 |
16 | public BarLineScatterCandleBubbleData() {
17 | super();
18 | }
19 |
20 | public BarLineScatterCandleBubbleData(List xVals) {
21 | super(xVals);
22 | }
23 |
24 | public BarLineScatterCandleBubbleData(String[] xVals) {
25 | super(xVals);
26 | }
27 |
28 | public BarLineScatterCandleBubbleData(List xVals, List sets) {
29 | super(xVals, sets);
30 | }
31 |
32 | public BarLineScatterCandleBubbleData(String[] xVals, List sets) {
33 | super(xVals, sets);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedMoveViewJob.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.jobs;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.annotation.SuppressLint;
6 | import android.view.View;
7 |
8 | import com.github.mikephil.charting.utils.Transformer;
9 | import com.github.mikephil.charting.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by Philipp Jahoda on 19/02/16.
13 | */
14 | public class AnimatedMoveViewJob extends AnimatedViewPortJob {
15 |
16 | public AnimatedMoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
17 | super(viewPortHandler, xValue, yValue, trans, v, xOrigin, yOrigin, duration);
18 | }
19 |
20 | @Override
21 | public void onAnimationUpdate(ValueAnimator animation) {
22 |
23 | pts[0] = xOrigin + (xValue - xOrigin) * phase;
24 | pts[1] = yOrigin + (yValue - yOrigin) * phase;
25 |
26 | mTrans.pointValuesToPixel(pts);
27 | mViewPortHandler.centerViewPort(pts, view);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.github.mikephil.charting.data.Entry;
6 |
7 | /**
8 | * Created by Philipp Jahoda on 21/10/15.
9 | */
10 | public interface ILineScatterCandleRadarDataSet extends IBarLineScatterCandleBubbleDataSet {
11 |
12 | /**
13 | * Returns true if vertical highlight indicator lines are enabled (drawn)
14 | * @return
15 | */
16 | boolean isVerticalHighlightIndicatorEnabled();
17 |
18 | /**
19 | * Returns true if vertical highlight indicator lines are enabled (drawn)
20 | * @return
21 | */
22 | boolean isHorizontalHighlightIndicatorEnabled();
23 |
24 | /**
25 | * Returns the line-width in which highlight lines are to be drawn.
26 | * @return
27 | */
28 | float getHighlightLineWidth();
29 |
30 | /**
31 | * Returns the DashPathEffect that is used for highlighting.
32 | * @return
33 | */
34 | DashPathEffect getDashPathEffectHighlight();
35 | }
36 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import android.graphics.Color;
5 |
6 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
12 | *
13 | * @author Philipp Jahoda
14 | */
15 | public abstract class BarLineScatterCandleBubbleDataSet extends DataSet implements IBarLineScatterCandleBubbleDataSet {
16 |
17 | /** default highlight color */
18 | protected int mHighLightColor = Color.rgb(255, 187, 115);
19 |
20 | public BarLineScatterCandleBubbleDataSet(List yVals, String label) {
21 | super(yVals, label);
22 | }
23 |
24 | /**
25 | * Sets the color that is used for drawing the highlight indicators. Dont
26 | * forget to resolve the color using getResources().getColor(...) or
27 | * Color.rgb(...).
28 | *
29 | * @param color
30 | */
31 | public void setHighLightColor(int color) {
32 | mHighLightColor = color;
33 | }
34 |
35 | @Override
36 | public int getHighLightColor() {
37 | return mHighLightColor;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/FSize.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.utils;
3 |
4 | /**
5 | * Immutable class for describing width and height dimensions in some arbitrary
6 | * unit. Replacement for the android.Util.SizeF which is available only on API >= 21.
7 | */
8 | public final class FSize {
9 |
10 | public final float width;
11 | public final float height;
12 |
13 | public FSize(final float width, final float height) {
14 | this.width = width;
15 | this.height = height;
16 | }
17 |
18 | @Override
19 | public boolean equals(final Object obj) {
20 | if (obj == null) {
21 | return false;
22 | }
23 | if (this == obj) {
24 | return true;
25 | }
26 | if (obj instanceof FSize) {
27 | final FSize other = (FSize) obj;
28 | return width == other.width && height == other.height;
29 | }
30 | return false;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return width + "x" + height;
36 | }
37 |
38 | /**
39 | * {@inheritDoc}
40 | */
41 | @Override
42 | public int hashCode() {
43 | return Float.floatToIntBits(width) ^ Float.floatToIntBits(height);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/CandleData.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data;
2 |
3 | import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class CandleData extends BarLineScatterCandleBubbleData {
9 |
10 | public CandleData() {
11 | super();
12 | }
13 |
14 | public CandleData(List xVals) {
15 | super(xVals);
16 | }
17 |
18 | public CandleData(String[] xVals) {
19 | super(xVals);
20 | }
21 |
22 | public CandleData(List xVals, List dataSets) {
23 | super(xVals, dataSets);
24 | }
25 |
26 | public CandleData(String[] xVals, List dataSets) {
27 | super(xVals, dataSets);
28 | }
29 |
30 | public CandleData(List xVals, ICandleDataSet dataSet) {
31 | super(xVals, toList(dataSet));
32 | }
33 |
34 | public CandleData(String[] xVals, ICandleDataSet dataSet) {
35 | super(xVals, toList(dataSet));
36 | }
37 |
38 | private static List toList(ICandleDataSet dataSet) {
39 | List sets = new ArrayList();
40 | sets.add(dataSet);
41 | return sets;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/DefaultYAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.components.YAxis;
4 |
5 | import java.text.DecimalFormat;
6 |
7 | /**
8 | * Created by Philipp Jahoda on 20/09/15.
9 | * Default formatter used for formatting labels of the YAxis. Uses a DecimalFormat with
10 | * pre-calculated number of digits (depending on max and min value).
11 | */
12 | public class DefaultYAxisValueFormatter implements YAxisValueFormatter {
13 |
14 | /** decimalformat for formatting */
15 | private DecimalFormat mFormat;
16 |
17 | /**
18 | * Constructor that specifies to how many digits the value should be
19 | * formatted.
20 | *
21 | * @param digits
22 | */
23 | public DefaultYAxisValueFormatter(int digits) {
24 |
25 | StringBuffer b = new StringBuffer();
26 | for (int i = 0; i < digits; i++) {
27 | if (i == 0)
28 | b.append(".");
29 | b.append("0");
30 | }
31 |
32 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString());
33 | }
34 |
35 | @Override
36 | public String getFormattedValue(float value, YAxis yAxis) {
37 | // avoid memory allocations here (for performance)
38 | return mFormat.format(value);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/RadarData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Data container for the RadarChart.
11 | *
12 | * @author Philipp Jahoda
13 | */
14 | public class RadarData extends ChartData {
15 |
16 | public RadarData() {
17 | super();
18 | }
19 |
20 | public RadarData(List xVals) {
21 | super(xVals);
22 | }
23 |
24 | public RadarData(String[] xVals) {
25 | super(xVals);
26 | }
27 |
28 | public RadarData(List xVals, List dataSets) {
29 | super(xVals, dataSets);
30 | }
31 |
32 | public RadarData(String[] xVals, List dataSets) {
33 | super(xVals, dataSets);
34 | }
35 |
36 | public RadarData(List xVals, IRadarDataSet dataSet) {
37 | super(xVals, toList(dataSet));
38 | }
39 |
40 | public RadarData(String[] xVals, IRadarDataSet dataSet) {
41 | super(xVals, toList(dataSet));
42 | }
43 |
44 | private static List toList(IRadarDataSet dataSet) {
45 | List sets = new ArrayList();
46 | sets.add(dataSet);
47 | return sets;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/PercentFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.formatter;
3 |
4 | import com.github.mikephil.charting.components.YAxis;
5 | import com.github.mikephil.charting.data.Entry;
6 | import com.github.mikephil.charting.utils.ViewPortHandler;
7 |
8 | import java.text.DecimalFormat;
9 |
10 | /**
11 | * This ValueFormatter is just for convenience and simply puts a "%" sign after
12 | * each value. (Recommeded for PieChart)
13 | *
14 | * @author Philipp Jahoda
15 | */
16 | public class PercentFormatter implements ValueFormatter, YAxisValueFormatter {
17 |
18 | protected DecimalFormat mFormat;
19 |
20 | public PercentFormatter() {
21 | mFormat = new DecimalFormat("###,###,##0.0");
22 | }
23 |
24 | /**
25 | * Allow a custom decimalformat
26 | *
27 | * @param format
28 | */
29 | public PercentFormatter(DecimalFormat format) {
30 | this.mFormat = format;
31 | }
32 |
33 | // ValueFormatter
34 | @Override
35 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
36 | return mFormat.format(value) + " %";
37 | }
38 |
39 | // YAxisValueFormatter
40 | @Override
41 | public String getFormattedValue(float value, YAxis yAxis) {
42 | return mFormat.format(value) + " %";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/LineData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Data object that encapsulates all data associated with a LineChart.
11 | *
12 | * @author Philipp Jahoda
13 | */
14 | public class LineData extends BarLineScatterCandleBubbleData {
15 |
16 | public LineData() {
17 | super();
18 | }
19 |
20 | public LineData(List xVals) {
21 | super(xVals);
22 | }
23 |
24 | public LineData(String[] xVals) {
25 | super(xVals);
26 | }
27 |
28 | public LineData(List xVals, List dataSets) {
29 | super(xVals, dataSets);
30 | }
31 |
32 | public LineData(String[] xVals, List dataSets) {
33 | super(xVals, dataSets);
34 | }
35 |
36 | public LineData(List xVals, ILineDataSet dataSet) {
37 | super(xVals, toList(dataSet));
38 | }
39 |
40 | public LineData(String[] xVals, ILineDataSet dataSet) {
41 | super(xVals, toList(dataSet));
42 | }
43 |
44 | private static List toList(ILineDataSet dataSet) {
45 | List sets = new ArrayList();
46 | sets.add(dataSet);
47 | return sets;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/DefaultFillFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 |
4 | import com.github.mikephil.charting.data.LineData;
5 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
6 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
7 |
8 | /**
9 | * Default formatter that calculates the position of the filled line.
10 | *
11 | * @author Philipp Jahoda
12 | */
13 | public class DefaultFillFormatter implements FillFormatter {
14 |
15 | @Override
16 | public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
17 |
18 | float fillMin = 0f;
19 | float chartMaxY = dataProvider.getYChartMax();
20 | float chartMinY = dataProvider.getYChartMin();
21 |
22 | LineData data = dataProvider.getLineData();
23 |
24 | if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) {
25 | fillMin = 0f;
26 | } else {
27 |
28 | float max, min;
29 |
30 | if (data.getYMax() > 0)
31 | max = 0f;
32 | else
33 | max = chartMaxY;
34 | if (data.getYMin() < 0)
35 | min = 0f;
36 | else
37 | min = chartMinY;
38 |
39 | fillMin = dataSet.getYMin() >= 0 ? min : max;
40 | }
41 |
42 | return fillMin;
43 | }
44 | }
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/ValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 | import com.github.mikephil.charting.utils.ViewPortHandler;
5 |
6 | /**
7 | * Interface that allows custom formatting of all values inside the chart before they are
8 | * being drawn to the screen. Simply create your own formatting class and let
9 | * it implement ValueFormatter. Then override the getFormattedValue(...) method
10 | * and return whatever you want.
11 | *
12 | * @author Philipp Jahoda
13 | */
14 | public interface ValueFormatter {
15 |
16 | /**
17 | * Called when a value (from labels inside the chart) is formatted
18 | * before being drawn. For performance reasons, avoid excessive calculations
19 | * and memory allocations inside this method.
20 | *
21 | * @param value the value to be formatted
22 | * @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry
23 | * @param dataSetIndex the index of the DataSet the entry in focus belongs to
24 | * @param viewPortHandler provides information about the current chart state (scale, translation, ...)
25 | * @return the formatted label ready for being drawn
26 | */
27 | String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler);
28 | }
29 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/DefaultValueFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.formatter;
3 |
4 | import com.github.mikephil.charting.data.Entry;
5 | import com.github.mikephil.charting.utils.ViewPortHandler;
6 |
7 | import java.text.DecimalFormat;
8 |
9 | /**
10 | * Default formatter used for formatting values inside the chart. Uses a DecimalFormat with
11 | * pre-calculated number of digits (depending on max and min value).
12 | *
13 | * @author Philipp Jahoda
14 | */
15 | public class DefaultValueFormatter implements ValueFormatter {
16 |
17 | /** decimalformat for formatting */
18 | private DecimalFormat mFormat;
19 |
20 | /**
21 | * Constructor that specifies to how many digits the value should be
22 | * formatted.
23 | *
24 | * @param digits
25 | */
26 | public DefaultValueFormatter(int digits) {
27 |
28 | StringBuffer b = new StringBuffer();
29 | for (int i = 0; i < digits; i++) {
30 | if (i == 0)
31 | b.append(".");
32 | b.append("0");
33 | }
34 |
35 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString());
36 | }
37 |
38 | @Override
39 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
40 |
41 | // put more logic here ...
42 | // avoid memory allocations here (for performance reasons)
43 |
44 | return mFormat.format(value);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/ViewPortJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.jobs;
3 |
4 | import android.view.View;
5 |
6 | import com.github.mikephil.charting.utils.Transformer;
7 | import com.github.mikephil.charting.utils.ViewPortHandler;
8 |
9 | /**
10 | * Runnable that is used for viewport modifications since they cannot be
11 | * executed at any time. This can be used to delay the execution of viewport
12 | * modifications until the onSizeChanged(...) method of the chart-view is called.
13 | * This is especially important if viewport modifying methods are called on the chart
14 | * directly after initialization.
15 | *
16 | * @author Philipp Jahoda
17 | */
18 | public abstract class ViewPortJob implements Runnable {
19 |
20 | protected float[] pts = new float[2];
21 |
22 | protected ViewPortHandler mViewPortHandler;
23 | protected float xValue = 0f;
24 | protected float yValue = 0f;
25 | protected Transformer mTrans;
26 | protected View view;
27 |
28 | public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue,
29 | Transformer trans, View v) {
30 |
31 | this.mViewPortHandler = viewPortHandler;
32 | this.xValue = xValue;
33 | this.yValue = yValue;
34 | this.mTrans = trans;
35 | this.view = v;
36 | }
37 |
38 | public float getXValue() {
39 | return xValue;
40 | }
41 |
42 | public float getYValue() {
43 | return yValue;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/TransformerHorizontalBarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.utils;
3 |
4 | /**
5 | * Transformer class for the HorizontalBarChart.
6 | *
7 | * @author Philipp Jahoda
8 | */
9 | public class TransformerHorizontalBarChart extends Transformer {
10 |
11 | public TransformerHorizontalBarChart(ViewPortHandler viewPortHandler) {
12 | super(viewPortHandler);
13 | }
14 |
15 | /**
16 | * Prepares the matrix that contains all offsets.
17 | *
18 | * @param chart
19 | */
20 | public void prepareMatrixOffset(boolean inverted) {
21 |
22 | mMatrixOffset.reset();
23 |
24 | // offset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom);
25 |
26 | if (!inverted)
27 | mMatrixOffset.postTranslate(mViewPortHandler.offsetLeft(),
28 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom());
29 | else {
30 | mMatrixOffset
31 | .setTranslate(
32 | -(mViewPortHandler.getChartWidth() - mViewPortHandler.offsetRight()),
33 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom());
34 | mMatrixOffset.postScale(-1.0f, 1.0f);
35 | }
36 |
37 | // mMatrixOffset.set(offset);
38 |
39 | // mMatrixOffset.reset();
40 | //
41 | // mMatrixOffset.postTranslate(mOffsetLeft, getHeight() -
42 | // mOffsetBottom);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/charts/CandleStickChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.github.mikephil.charting.data.CandleData;
8 | import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
9 | import com.github.mikephil.charting.renderer.CandleStickChartRenderer;
10 |
11 | /**
12 | * Financial chart type that draws candle-sticks (OHCL chart).
13 | *
14 | * @author Philipp Jahoda
15 | */
16 | public class CandleStickChart extends BarLineChartBase implements CandleDataProvider {
17 |
18 | public CandleStickChart(Context context) {
19 | super(context);
20 | }
21 |
22 | public CandleStickChart(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public CandleStickChart(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 | }
29 |
30 | @Override
31 | protected void init() {
32 | super.init();
33 |
34 | mRenderer = new CandleStickChartRenderer(this, mAnimator, mViewPortHandler);
35 | mXAxis.mAxisMinimum = -0.5f;
36 | }
37 |
38 | @Override
39 | protected void calcMinMax() {
40 | super.calcMinMax();
41 |
42 | mXAxis.mAxisMaximum += 0.5f;
43 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum);
44 | }
45 |
46 | @Override
47 | public CandleData getCandleData() {
48 | return mData;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.dataprovider;
2 |
3 | import android.graphics.PointF;
4 | import android.graphics.RectF;
5 |
6 | import com.github.mikephil.charting.data.ChartData;
7 | import com.github.mikephil.charting.formatter.ValueFormatter;
8 |
9 | /**
10 | * Interface that provides everything there is to know about the dimensions,
11 | * bounds, and range of the chart.
12 | *
13 | * @author Philipp Jahoda
14 | */
15 | public interface ChartInterface {
16 |
17 | /**
18 | * Returns the minimum x-value of the chart, regardless of zoom or translation.
19 | *
20 | * @return
21 | */
22 | float getXChartMin();
23 |
24 | /**
25 | * Returns the maximum x-value of the chart, regardless of zoom or translation.
26 | *
27 | * @return
28 | */
29 | float getXChartMax();
30 |
31 | /**
32 | * Returns the minimum y-value of the chart, regardless of zoom or translation.
33 | *
34 | * @return
35 | */
36 | float getYChartMin();
37 |
38 | /**
39 | * Returns the maximum y-value of the chart, regardless of zoom or translation.
40 | *
41 | * @return
42 | */
43 | float getYChartMax();
44 |
45 | int getXValCount();
46 |
47 | int getWidth();
48 |
49 | int getHeight();
50 |
51 | PointF getCenterOfView();
52 |
53 | PointF getCenterOffsets();
54 |
55 | RectF getContentRect();
56 |
57 | ValueFormatter getDefaultValueFormatter();
58 |
59 | ChartData getData();
60 | }
61 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedViewPortJob.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.jobs;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.annotation.SuppressLint;
6 | import android.view.View;
7 |
8 | import com.github.mikephil.charting.utils.Transformer;
9 | import com.github.mikephil.charting.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by Philipp Jahoda on 19/02/16.
13 | */
14 | @SuppressLint("NewApi")
15 | public abstract class AnimatedViewPortJob extends ViewPortJob implements ValueAnimator.AnimatorUpdateListener {
16 |
17 | protected ObjectAnimator animator;
18 |
19 | protected float phase;
20 |
21 | protected float xOrigin;
22 | protected float yOrigin;
23 |
24 | public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
25 | super(viewPortHandler, xValue, yValue, trans, v);
26 | this.xOrigin = xOrigin;
27 | this.yOrigin = yOrigin;
28 | animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f);
29 | animator.setDuration(duration);
30 | animator.addUpdateListener(this);
31 | }
32 |
33 | @SuppressLint("NewApi")
34 | @Override
35 | public void run() {
36 | animator.start();
37 | }
38 |
39 | public float getPhase() {
40 | return phase;
41 | }
42 |
43 | public void setPhase(float phase) {
44 | this.phase = phase;
45 | }
46 |
47 | public float getXOrigin() {
48 | return xOrigin;
49 | }
50 |
51 | public float getYOrigin() {
52 | return yOrigin;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BubbleData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class BubbleData extends BarLineScatterCandleBubbleData {
10 |
11 | public BubbleData() {
12 | super();
13 | }
14 |
15 | public BubbleData(List xVals) {
16 | super(xVals);
17 | }
18 |
19 | public BubbleData(String[] xVals) {
20 | super(xVals);
21 | }
22 |
23 | public BubbleData(List xVals, List dataSets) {
24 | super(xVals, dataSets);
25 | }
26 |
27 | public BubbleData(String[] xVals, List dataSets) {
28 | super(xVals, dataSets);
29 | }
30 |
31 | public BubbleData(List xVals, IBubbleDataSet dataSet) {
32 | super(xVals, toList(dataSet));
33 | }
34 |
35 | public BubbleData(String[] xVals, IBubbleDataSet dataSet) {
36 | super(xVals, toList(dataSet));
37 | }
38 |
39 | private static List toList(IBubbleDataSet dataSet) {
40 | List sets = new ArrayList();
41 | sets.add(dataSet);
42 | return sets;
43 | }
44 |
45 | /**
46 | * Sets the width of the circle that surrounds the bubble when highlighted
47 | * for all DataSet objects this data object contains, in dp.
48 | *
49 | * @param width
50 | */
51 | public void setHighlightCircleWidth(float width) {
52 | for (IBubbleDataSet set : mDataSets) {
53 | set.setHighlightCircleWidth(width);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BubbleEntry.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | /**
5 | * Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble
6 | * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under
7 | * Apache License 2.0
8 | *
9 | * @author Philipp Jahoda
10 | */
11 | public class BubbleEntry extends Entry {
12 |
13 | /** size value */
14 | private float mSize = 0f;
15 |
16 | /**
17 | * Constructor.
18 | *
19 | * @param xIndex The index on the x-axis.
20 | * @param val The value on the y-axis.
21 | * @param size The size of the bubble.
22 | */
23 | public BubbleEntry(int xIndex, float val, float size) {
24 | super(val, xIndex);
25 |
26 | this.mSize = size;
27 | }
28 |
29 | /**
30 | * Constructor.
31 | *
32 | * @param xIndex The index on the x-axis.
33 | * @param val The value on the y-axis.
34 | * @param size The size of the bubble.
35 | * @param data Spot for additional data this Entry represents.
36 | */
37 | public BubbleEntry(int xIndex, float val, float size, Object data) {
38 | super(val, xIndex, data);
39 |
40 | this.mSize = size;
41 | }
42 |
43 | public BubbleEntry copy() {
44 |
45 | BubbleEntry c = new BubbleEntry(getXIndex(), getVal(), mSize, getData());
46 |
47 | return c;
48 | }
49 |
50 | /**
51 | * Returns the size of this entry (the size of the bubble).
52 | *
53 | * @return
54 | */
55 | public float getSize() {
56 | return mSize;
57 | }
58 |
59 | public void setSize(float size) {
60 | this.mSize = size;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | import com.github.mikephil.charting.data.Entry;
6 |
7 | /**
8 | * Created by Philipp Jahoda on 21/10/15.
9 | */
10 | public interface ILineRadarDataSet extends ILineScatterCandleRadarDataSet {
11 |
12 | /**
13 | * Returns the color that is used for filling the line surface area.
14 | *
15 | * @return
16 | */
17 | int getFillColor();
18 |
19 | /**
20 | * Returns the drawable used for filling the area below the line.
21 | *
22 | * @return
23 | */
24 | Drawable getFillDrawable();
25 |
26 | /**
27 | * Returns the alpha value that is used for filling the line surface,
28 | * default: 85
29 | *
30 | * @return
31 | */
32 | int getFillAlpha();
33 |
34 | /**
35 | * Returns the stroke-width of the drawn line
36 | *
37 | * @return
38 | */
39 | float getLineWidth();
40 |
41 | /**
42 | * Returns true if filled drawing is enabled, false if not
43 | *
44 | * @return
45 | */
46 | boolean isDrawFilledEnabled();
47 |
48 | /**
49 | * Set to true if the DataSet should be drawn filled (surface), and not just
50 | * as a line, disabling this will give great performance boost. Please note that this method
51 | * uses the canvas.clipPath(...) method for drawing the filled area.
52 | * For devices with API level < 18 (Android 4.3), hardware acceleration of the chart should
53 | * be turned off. Default: false
54 | *
55 | * @param enabled
56 | */
57 | void setDrawFilled(boolean enabled);
58 | }
59 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/ScatterData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class ScatterData extends BarLineScatterCandleBubbleData {
10 |
11 | public ScatterData() {
12 | super();
13 | }
14 |
15 | public ScatterData(List xVals) {
16 | super(xVals);
17 | }
18 |
19 | public ScatterData(String[] xVals) {
20 | super(xVals);
21 | }
22 |
23 | public ScatterData(List xVals, List dataSets) {
24 | super(xVals, dataSets);
25 | }
26 |
27 | public ScatterData(String[] xVals, List dataSets) {
28 | super(xVals, dataSets);
29 | }
30 |
31 | public ScatterData(List xVals, IScatterDataSet dataSet) {
32 | super(xVals, toList(dataSet));
33 | }
34 |
35 | public ScatterData(String[] xVals, IScatterDataSet dataSet) {
36 | super(xVals, toList(dataSet));
37 | }
38 |
39 | private static List toList(IScatterDataSet dataSet) {
40 | List sets = new ArrayList();
41 | sets.add(dataSet);
42 | return sets;
43 | }
44 |
45 | /**
46 | * Returns the maximum shape-size across all DataSets.
47 | *
48 | * @return
49 | */
50 | public float getGreatestShapeSize() {
51 |
52 | float max = 0f;
53 |
54 | for (IScatterDataSet set : mDataSets) {
55 | float size = set.getScatterShapeSize();
56 |
57 | if (size > max)
58 | max = size;
59 | }
60 |
61 | return max;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmBarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.base;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.github.mikephil.charting.data.Entry;
6 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
7 |
8 | import io.realm.RealmObject;
9 | import io.realm.RealmResults;
10 |
11 | /**
12 | * Created by Philipp Jahoda on 08/11/15.
13 | */
14 | public abstract class RealmBarLineScatterCandleBubbleDataSet extends RealmBaseDataSet implements IBarLineScatterCandleBubbleDataSet {
15 |
16 | /** default highlight color */
17 | protected int mHighLightColor = Color.rgb(255, 187, 115);
18 |
19 | public RealmBarLineScatterCandleBubbleDataSet(RealmResults results, String yValuesField) {
20 | super(results, yValuesField);
21 | }
22 |
23 | /**
24 | * Constructor that takes the realm RealmResults, sorts & stores them.
25 | *
26 | * @param results
27 | * @param yValuesField
28 | * @param xIndexField
29 | */
30 | public RealmBarLineScatterCandleBubbleDataSet(RealmResults results, String yValuesField, String xIndexField) {
31 | super(results, yValuesField, xIndexField);
32 | }
33 |
34 | /**
35 | * Sets the color that is used for drawing the highlight indicators. Dont
36 | * forget to resolve the color using getResources().getColor(...) or
37 | * Color.rgb(...).
38 | *
39 | * @param color
40 | */
41 | public void setHighLightColor(int color) {
42 | mHighLightColor = color;
43 | }
44 |
45 | @Override
46 | public int getHighLightColor() {
47 | return mHighLightColor;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/charts/LineChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.github.mikephil.charting.data.LineData;
8 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
9 | import com.github.mikephil.charting.renderer.LineChartRenderer;
10 |
11 | /**
12 | * Chart that draws lines, surfaces, circles, ...
13 | *
14 | * @author Philipp Jahoda
15 | */
16 | public class LineChart extends BarLineChartBase implements LineDataProvider {
17 |
18 | public LineChart(Context context) {
19 | super(context);
20 | }
21 |
22 | public LineChart(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public LineChart(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 | }
29 |
30 | @Override
31 | protected void init() {
32 | super.init();
33 |
34 | mRenderer = new LineChartRenderer(this, mAnimator, mViewPortHandler);
35 | }
36 |
37 | @Override
38 | protected void calcMinMax() {
39 | super.calcMinMax();
40 |
41 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0)
42 | mXAxis.mAxisRange = 1;
43 | }
44 |
45 | @Override
46 | public LineData getLineData() {
47 | return mData;
48 | }
49 |
50 | @Override
51 | protected void onDetachedFromWindow() {
52 | // releases the bitmap in the renderer to avoid oom error
53 | if(mRenderer != null && mRenderer instanceof LineChartRenderer) {
54 | ((LineChartRenderer) mRenderer).releaseBitmap();
55 | }
56 | super.onDetachedFromWindow();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/ZoomJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.jobs;
3 |
4 | import android.graphics.Matrix;
5 | import android.view.View;
6 |
7 | import com.github.mikephil.charting.charts.BarLineChartBase;
8 | import com.github.mikephil.charting.components.YAxis;
9 | import com.github.mikephil.charting.utils.Transformer;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/02/16.
14 | */
15 | public class ZoomJob extends ViewPortJob {
16 |
17 | protected float scaleX;
18 | protected float scaleY;
19 |
20 | protected YAxis.AxisDependency axisDependency;
21 |
22 | public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans, YAxis.AxisDependency axis, View v) {
23 | super(viewPortHandler, xValue, yValue, trans, v);
24 |
25 | this.scaleX = scaleX;
26 | this.scaleY = scaleY;
27 | this.axisDependency = axis;
28 | }
29 |
30 | @Override
31 | public void run() {
32 |
33 | Matrix save = mViewPortHandler.zoom(scaleX, scaleY);
34 | mViewPortHandler.refresh(save, view, false);
35 |
36 | float valsInView = ((BarLineChartBase) view).getDeltaY(axisDependency) / mViewPortHandler.getScaleY();
37 | float xsInView = ((BarLineChartBase) view).getXAxis().getValues().size() / mViewPortHandler.getScaleX();
38 |
39 | pts[0] = xValue - xsInView / 2f;
40 | pts[1] = yValue + valsInView / 2f;
41 |
42 | mTrans.pointValuesToPixel(pts);
43 |
44 | save = mViewPortHandler.translate(pts);
45 | mViewPortHandler.refresh(save, view, false);
46 |
47 | ((BarLineChartBase) view).calculateOffsets();
48 | view.postInvalidate();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IPieDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 | import com.github.mikephil.charting.data.PieDataSet;
5 |
6 | /**
7 | * Created by Philipp Jahoda on 03/11/15.
8 | */
9 | public interface IPieDataSet extends IDataSet {
10 |
11 | /**
12 | * Returns the space that is set to be between the piechart-slices of this
13 | * DataSet, in pixels.
14 | *
15 | * @return
16 | */
17 | float getSliceSpace();
18 |
19 | /**
20 | * Returns the distance a highlighted piechart slice is "shifted" away from
21 | * the chart-center in dp.
22 | *
23 | * @return
24 | */
25 | float getSelectionShift();
26 |
27 | PieDataSet.ValuePosition getXValuePosition();
28 | PieDataSet.ValuePosition getYValuePosition();
29 |
30 | /**
31 | * When valuePosition is OutsideSlice, indicates line color
32 | * */
33 | int getValueLineColor();
34 |
35 | /**
36 | * When valuePosition is OutsideSlice, indicates line width
37 | * */
38 | float getValueLineWidth();
39 |
40 | /**
41 | * When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size
42 | * */
43 | float getValueLinePart1OffsetPercentage();
44 |
45 | /**
46 | * When valuePosition is OutsideSlice, indicates length of first half of the line
47 | * */
48 | float getValueLinePart1Length();
49 |
50 | /**
51 | * When valuePosition is OutsideSlice, indicates length of second half of the line
52 | * */
53 | float getValueLinePart2Length();
54 |
55 | /**
56 | * When valuePosition is OutsideSlice, this allows variable line length
57 | * */
58 | boolean isValueLineVariableLength();
59 |
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 | #000000
9 | #eeeeee
10 | #303341
11 | #00000000
12 |
13 | #FFE100
14 | #262733
15 | #194B70
16 | #1E1E26
17 | #40000000
18 | #80000000
19 |
20 | #A7ADBC
21 | #262127
22 |
23 | #2E2C31
24 | #2F3241
25 | #5F5D6A
26 |
27 | #194B70
28 |
29 | #A7ADBC
30 |
31 | #FC0544
32 | #51FFB9
33 | #5E5E6A
34 | #118CDE
35 | #FCAE05
36 |
37 | #118CDE
38 | #0070BB
39 | #545359
40 |
41 | #2C2C37
42 |
43 | #823E66
44 | #B99C7A
45 | #3C7193
46 |
47 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import com.github.mikephil.charting.data.BarEntry;
4 |
5 | /**
6 | * Created by philipp on 21/10/15.
7 | */
8 | public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet {
9 |
10 | /**
11 | * Returns the space between bars as the actual value (0 - 1.0f)
12 | *
13 | * @return
14 | */
15 | float getBarSpace();
16 |
17 | /**
18 | * Returns true if this DataSet is stacked (stacksize > 1) or not.
19 | *
20 | * @return
21 | */
22 | boolean isStacked();
23 |
24 | /**
25 | * Returns the maximum number of bars that can be stacked upon another in
26 | * this DataSet. This should return 1 for non stacked bars, and > 1 for stacked bars.
27 | *
28 | * @return
29 | */
30 | int getStackSize();
31 |
32 | /**
33 | * Returns the color used for drawing the bar-shadows. The bar shadows is a
34 | * surface behind the bar that indicates the maximum value.
35 | *
36 | * @return
37 | */
38 | int getBarShadowColor();
39 |
40 | /**
41 | * Returns the width used for drawing borders around the bars.
42 | * If borderWidth == 0, no border will be drawn.
43 | *
44 | * @return
45 | */
46 | float getBarBorderWidth();
47 |
48 | /**
49 | * Returns the color drawing borders around the bars.
50 | *
51 | * @return
52 | */
53 | int getBarBorderColor();
54 |
55 | /**
56 | * Returns the alpha value (transparency) that is used for drawing the
57 | * highlight indicator.
58 | *
59 | * @return
60 | */
61 | int getHighLightAlpha();
62 |
63 |
64 | /**
65 | * Returns the labels used for the different value-stacks in the legend.
66 | * This is only relevant for stacked bar entries.
67 | *
68 | * @return
69 | */
70 | String[] getStackLabels();
71 | }
72 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ICandleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import android.graphics.Paint;
4 |
5 | import com.github.mikephil.charting.data.CandleEntry;
6 |
7 | /**
8 | * Created by philipp on 21/10/15.
9 | */
10 | public interface ICandleDataSet extends ILineScatterCandleRadarDataSet {
11 |
12 | /**
13 | * Returns the space that is left out on the left and right side of each
14 | * candle.
15 | *
16 | * @return
17 | */
18 | float getBarSpace();
19 |
20 | /**
21 | * Returns whether the candle bars should show?
22 | * When false, only "ticks" will show
23 | *
24 | * - default: true
25 | *
26 | * @return
27 | */
28 | boolean getShowCandleBar();
29 |
30 | /**
31 | * Returns the width of the candle-shadow-line in pixels.
32 | *
33 | * @return
34 | */
35 | float getShadowWidth();
36 |
37 | /**
38 | * Returns shadow color for all entries
39 | *
40 | * @return
41 | */
42 | int getShadowColor();
43 |
44 | /**
45 | * Returns the neutral color (for open == close)
46 | *
47 | * @return
48 | */
49 | int getNeutralColor();
50 |
51 | /**
52 | * Returns the increasing color (for open < close).
53 | *
54 | * @return
55 | */
56 | int getIncreasingColor();
57 |
58 | /**
59 | * Returns the decreasing color (for open > close).
60 | *
61 | * @return
62 | */
63 | int getDecreasingColor();
64 |
65 | /**
66 | * Returns paint style when open < close
67 | *
68 | * @return
69 | */
70 | Paint.Style getIncreasingPaintStyle();
71 |
72 | /**
73 | * Returns paint style when open > close
74 | *
75 | * @return
76 | */
77 | Paint.Style getDecreasingPaintStyle();
78 |
79 | /**
80 | * Is the shadow color same as the candle color?
81 | *
82 | * @return
83 | */
84 | boolean getShadowColorSameAsCandle();
85 | }
86 |
--------------------------------------------------------------------------------
/MPChartLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | //apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion '23.0.2'
8 | // resourcePrefix 'mpcht'
9 | defaultConfig {
10 | minSdkVersion 8
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName '1.0'
14 |
15 | sourceSets {
16 | main {
17 | java.srcDirs = ['src']
18 | res.srcDirs = ['res']
19 | assets.srcDirs = ['assets']
20 | manifest.srcFile 'AndroidManifest.xml'
21 | }
22 | }
23 | }
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | lintOptions {
31 | abortOnError false
32 | }
33 | }
34 |
35 | repositories {
36 | maven {
37 | url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
38 | }
39 | }
40 |
41 | dependencies {
42 | //compile fileTree(dir: 'libs', include: ['*.jar'])
43 | //compile 'com.android.support:support-v4:19.+'
44 | provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API
45 | }
46 |
47 | android.libraryVariants.all { variant ->
48 | def name = variant.buildType.name
49 | def task = project.tasks.create "jar${name.capitalize()}", Jar
50 | task.dependsOn variant.javaCompile
51 | task.from variant.javaCompile.destinationDir
52 | artifacts.add('archives', task);
53 | }
54 |
55 | task sourcesJar(type: Jar) {
56 | from android.sourceSets.main.java.srcDirs
57 | classifier = 'sources'
58 | }
59 |
60 | task javadoc(type: Javadoc) {
61 | failOnError false
62 | source = android.sourceSets.main.java.sourceFiles
63 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
64 | }
65 |
66 | task javadocJar(type: Jar, dependsOn: javadoc) {
67 | classifier = 'javadoc'
68 | from javadoc.destinationDir
69 | }
70 |
71 | artifacts {
72 | archives sourcesJar
73 | archives javadocJar
74 | }
75 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/Renderer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.renderer;
3 |
4 | import android.util.Log;
5 |
6 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
7 | import com.github.mikephil.charting.utils.ViewPortHandler;
8 |
9 | /**
10 | * Abstract baseclass of all Renderers.
11 | *
12 | * @author Philipp Jahoda
13 | */
14 | public abstract class Renderer {
15 |
16 | /**
17 | * the component that handles the drawing area of the chart and it's offsets
18 | */
19 | protected ViewPortHandler mViewPortHandler;
20 |
21 | /** the minimum value on the x-axis that should be plotted */
22 | protected int mMinX = 0;
23 |
24 | /** the maximum value on the x-axis that should be plotted */
25 | protected int mMaxX = 0;
26 |
27 | public Renderer(ViewPortHandler viewPortHandler) {
28 | this.mViewPortHandler = viewPortHandler;
29 | }
30 |
31 | /**
32 | * Returns true if the specified value fits in between the provided min
33 | * and max bounds, false if not.
34 | *
35 | * @param val
36 | * @param min
37 | * @param max
38 | * @return
39 | */
40 | protected boolean fitsBounds(float val, float min, float max) {
41 |
42 | if (val < min || val > max)
43 | return false;
44 | else
45 | return true;
46 | }
47 |
48 | /**
49 | * Calculates the minimum and maximum x-value the chart can currently
50 | * display (with the given zoom level). -> mMinX, mMaxX
51 | *
52 | * @param dataProvider
53 | * @param xAxisModulus
54 | */
55 | public void calcXBounds(BarLineScatterCandleBubbleDataProvider dataProvider, int xAxisModulus) {
56 |
57 | int low = dataProvider.getLowestVisibleXIndex();
58 | int high = dataProvider.getHighestVisibleXIndex();
59 |
60 | int subLow = (low % xAxisModulus == 0) ? xAxisModulus : 0;
61 |
62 | mMinX = Math.max((low / xAxisModulus) * (xAxisModulus) - subLow, 0);
63 | mMaxX = Math.min((high / xAxisModulus) * (xAxisModulus) + xAxisModulus, (int) dataProvider.getXChartMax());
64 | // Log.d("xxx","mMinx="+mMinX+";mMaxX="+mMaxX);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/charts/ScatterChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.github.mikephil.charting.data.ScatterData;
8 | import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
9 | import com.github.mikephil.charting.renderer.ScatterChartRenderer;
10 |
11 | /**
12 | * The ScatterChart. Draws dots, triangles, squares and custom shapes into the
13 | * Chart-View. CIRCLE and SCQUARE offer the best performance, TRIANGLE has the
14 | * worst performance.
15 | *
16 | * @author Philipp Jahoda
17 | */
18 | public class ScatterChart extends BarLineChartBase implements ScatterDataProvider {
19 |
20 | /**
21 | * enum that defines the shape that is drawn where the values are
22 | */
23 | public enum ScatterShape {
24 | SQUARE, CIRCLE, TRIANGLE, CROSS, X,
25 | }
26 |
27 | public ScatterChart(Context context) {
28 | super(context);
29 | }
30 |
31 | public ScatterChart(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | public ScatterChart(Context context, AttributeSet attrs, int defStyle) {
36 | super(context, attrs, defStyle);
37 | }
38 |
39 | @Override
40 | protected void init() {
41 | super.init();
42 |
43 | mRenderer = new ScatterChartRenderer(this, mAnimator, mViewPortHandler);
44 | mXAxis.mAxisMinimum = -0.5f;
45 | }
46 |
47 | @Override
48 | protected void calcMinMax() {
49 | super.calcMinMax();
50 |
51 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0)
52 | mXAxis.mAxisRange = 1;
53 |
54 | mXAxis.mAxisMaximum += 0.5f;
55 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum);
56 | }
57 |
58 | /**
59 | * Returns all possible predefined ScatterShapes.
60 | *
61 | * @return
62 | */
63 | public static ScatterShape[] getAllPossibleShapes() {
64 | return new ScatterShape[] {
65 | ScatterShape.SQUARE, ScatterShape.CIRCLE, ScatterShape.TRIANGLE, ScatterShape.CROSS
66 | };
67 | }
68 |
69 | public ScatterData getScatterData() {
70 | return mData;
71 | };
72 | }
73 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/listener/OnChartGestureListener.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.listener;
2 |
3 | import android.view.MotionEvent;
4 |
5 | /**
6 | * Listener for callbacks when doing gestures on the chart.
7 | *
8 | * @author Philipp Jahoda
9 | */
10 | public interface OnChartGestureListener {
11 |
12 | /**
13 | * Callbacks when a touch-gesture has started on the chart (ACTION_DOWN)
14 | *
15 | * @param me
16 | * @param lastPerformedGesture
17 | */
18 | void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
19 |
20 | /**
21 | * Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL)
22 | *
23 | * @param me
24 | * @param lastPerformedGesture
25 | */
26 | void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
27 |
28 | /**
29 | * Callbacks when the chart is longpressed.
30 | *
31 | * @param me
32 | */
33 | void onChartLongPressed(MotionEvent me);
34 |
35 | /**
36 | * Callbacks when the chart is double-tapped.
37 | *
38 | * @param me
39 | */
40 | void onChartDoubleTapped(MotionEvent me);
41 |
42 | /**
43 | * Callbacks when the chart is single-tapped.
44 | *
45 | * @param me
46 | */
47 | void onChartSingleTapped(MotionEvent me);
48 |
49 | /**
50 | * Callbacks then a fling gesture is made on the chart.
51 | *
52 | * @param me1
53 | * @param me2
54 | * @param velocityX
55 | * @param velocityY
56 | */
57 | void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY);
58 |
59 | /**
60 | * Callbacks when the chart is scaled / zoomed via pinch zoom gesture.
61 | *
62 | * @param me
63 | * @param scaleX scalefactor on the x-axis
64 | * @param scaleY scalefactor on the y-axis
65 | */
66 | void onChartScale(MotionEvent me, float scaleX, float scaleY);
67 |
68 | /**
69 | * Callbacks when the chart is moved / translated via drag gesture.
70 | *
71 | * @param me
72 | * @param dX translation distance on the x-axis
73 | * @param dY translation distance on the y-axis
74 | */
75 | void onChartTranslate(MotionEvent me, float dX, float dY);
76 | }
77 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.renderer;
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.PointF;
6 |
7 | import com.github.mikephil.charting.charts.RadarChart;
8 | import com.github.mikephil.charting.components.XAxis;
9 | import com.github.mikephil.charting.utils.Utils;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | public class XAxisRendererRadarChart extends XAxisRenderer {
13 |
14 | private RadarChart mChart;
15 |
16 | public XAxisRendererRadarChart(ViewPortHandler viewPortHandler, XAxis xAxis, RadarChart chart) {
17 | super(viewPortHandler, xAxis, null);
18 |
19 | mChart = chart;
20 | }
21 |
22 | @Override
23 | public void renderAxisLabels(Canvas c) {
24 |
25 | if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
26 | return;
27 |
28 | final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
29 | final PointF drawLabelAnchor = new PointF(0.5f, 0.0f);
30 |
31 | mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
32 | mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
33 | mAxisLabelPaint.setColor(mXAxis.getTextColor());
34 |
35 | float sliceangle = mChart.getSliceAngle();
36 |
37 | // calculate the factor that is needed for transforming the value to
38 | // pixels
39 | float factor = mChart.getFactor();
40 |
41 | PointF center = mChart.getCenterOffsets();
42 |
43 | int mod = mXAxis.mAxisLabelModulus;
44 | for (int i = 0; i < mXAxis.getValues().size(); i += mod) {
45 | String label = mXAxis.getValues().get(i);
46 |
47 | float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
48 |
49 | PointF p = Utils.getPosition(center, mChart.getYRange() * factor
50 | + mXAxis.mLabelRotatedWidth / 2f, angle);
51 |
52 | drawLabel(c, label, i, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f,
53 | drawLabelAnchor, labelRotationAngleDegrees);
54 | }
55 | }
56 |
57 | /**
58 | * XAxis LimitLines on RadarChart not yet supported.
59 | *
60 | * @param c
61 | */
62 | @Override
63 | public void renderLimitLines(Canvas c) {
64 | // this space intentionally left blank
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/highlight/CombinedHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.highlight;
2 |
3 | import com.github.mikephil.charting.data.ChartData;
4 | import com.github.mikephil.charting.data.CombinedData;
5 | import com.github.mikephil.charting.interfaces.datasets.IDataSet;
6 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
7 | import com.github.mikephil.charting.utils.SelectionDetail;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 12/09/15.
14 | */
15 | public class CombinedHighlighter extends ChartHighlighter {
16 |
17 | public CombinedHighlighter(BarLineScatterCandleBubbleDataProvider chart) {
18 | super(chart);
19 | }
20 |
21 | /**
22 | * Returns a list of SelectionDetail object corresponding to the given xIndex.
23 | *
24 | * @param xIndex
25 | * @return
26 | */
27 | @Override
28 | protected List getSelectionDetailsAtIndex(int xIndex) {
29 |
30 | CombinedData data = (CombinedData) mChart.getData();
31 |
32 | // get all chartdata objects
33 | List dataObjects = data.getAllData();
34 |
35 | List vals = new ArrayList();
36 |
37 | float[] pts = new float[2];
38 |
39 | for (int i = 0; i < dataObjects.size(); i++) {
40 |
41 | for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) {
42 |
43 | IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);
44 |
45 | // dont include datasets that cannot be highlighted
46 | if (!dataSet.isHighlightEnabled())
47 | continue;
48 |
49 | // extract all y-values from all DataSets at the given x-index
50 | final float yVal = dataSet.getYValForXIndex(xIndex);
51 | if (yVal == Float.NaN)
52 | continue;
53 |
54 | pts[1] = yVal;
55 |
56 | mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
57 |
58 | if (!Float.isNaN(pts[1])) {
59 | vals.add(new SelectionDetail(pts[1], j, dataSet));
60 | }
61 | }
62 | }
63 |
64 | return vals;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/charts/BubbleChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.github.mikephil.charting.data.BubbleData;
8 | import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
9 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
10 | import com.github.mikephil.charting.renderer.BubbleChartRenderer;
11 |
12 | /**
13 | * The BubbleChart. Draws bubbles. Bubble chart implementation: Copyright 2015
14 | * Pierre-Marc Airoldi Licensed under Apache License 2.0. In the BubbleChart, it
15 | * is the area of the bubble, not the radius or diameter of the bubble that
16 | * conveys the data.
17 | *
18 | * @author Philipp Jahoda
19 | */
20 | public class BubbleChart extends BarLineChartBase implements BubbleDataProvider {
21 |
22 | public BubbleChart(Context context) {
23 | super(context);
24 | }
25 |
26 | public BubbleChart(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public BubbleChart(Context context, AttributeSet attrs, int defStyle) {
31 | super(context, attrs, defStyle);
32 | }
33 |
34 | @Override
35 | protected void init() {
36 | super.init();
37 |
38 | mRenderer = new BubbleChartRenderer(this, mAnimator, mViewPortHandler);
39 | }
40 |
41 | @Override
42 | protected void calcMinMax() {
43 | super.calcMinMax();
44 |
45 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0)
46 | mXAxis.mAxisRange = 1;
47 |
48 | mXAxis.mAxisMinimum = -0.5f;
49 | mXAxis.mAxisMaximum = (float) mData.getXValCount() - 0.5f;
50 |
51 | if (mRenderer != null) {
52 | for (IBubbleDataSet set : mData.getDataSets()) {
53 |
54 | final float xmin = set.getXMin();
55 | final float xmax = set.getXMax();
56 |
57 | if (xmin < mXAxis.mAxisMinimum)
58 | mXAxis.mAxisMinimum = xmin;
59 |
60 | if (xmax > mXAxis.mAxisMaximum)
61 | mXAxis.mAxisMaximum = xmax;
62 | }
63 | }
64 |
65 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum);
66 | }
67 |
68 | public BubbleData getBubbleData() {
69 | return mData;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/buffer/AbstractBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.buffer;
3 |
4 | import java.util.List;
5 |
6 | /**
7 | * Buffer class to boost performance while drawing. Concept: Replace instead of
8 | * recreate.
9 | *
10 | * @author Philipp Jahoda
11 | * @param The data the buffer accepts to be fed with.
12 | */
13 | public abstract class AbstractBuffer {
14 |
15 | /** index in the buffer */
16 | protected int index = 0;
17 |
18 | /** float-buffer that holds the data points to draw, order: x,y,x,y,... */
19 | public final float[] buffer;
20 |
21 | /** animation phase x-axis */
22 | protected float phaseX = 1f;
23 |
24 | /** animation phase y-axis */
25 | protected float phaseY = 1f;
26 |
27 | /** indicates from which x-index the visible data begins */
28 | protected int mFrom = 0;
29 |
30 | /** indicates to which x-index the visible data ranges */
31 | protected int mTo = 0;
32 |
33 | /**
34 | * Initialization with buffer-size.
35 | *
36 | * @param size
37 | */
38 | public AbstractBuffer(int size) {
39 | index = 0;
40 | buffer = new float[size];
41 | }
42 |
43 | /** limits the drawing on the x-axis */
44 | public void limitFrom(int from) {
45 | if (from < 0)
46 | from = 0;
47 | mFrom = from;
48 | }
49 |
50 | /** limits the drawing on the x-axis */
51 | public void limitTo(int to) {
52 | if (to < 0)
53 | to = 0;
54 | mTo = to;
55 | }
56 |
57 | /**
58 | * Resets the buffer index to 0 and makes the buffer reusable.
59 | */
60 | public void reset() {
61 | index = 0;
62 | }
63 |
64 | /**
65 | * Returns the size (length) of the buffer array.
66 | *
67 | * @return
68 | */
69 | public int size() {
70 | return buffer.length;
71 | }
72 |
73 | /**
74 | * Set the phases used for animations.
75 | *
76 | * @param phaseX
77 | * @param phaseY
78 | */
79 | public void setPhases(float phaseX, float phaseY) {
80 | this.phaseX = phaseX;
81 | this.phaseY = phaseY;
82 | }
83 |
84 | /**
85 | * Builds up the buffer with the provided data and resets the buffer-index
86 | * after feed-completion. This needs to run FAST.
87 | *
88 | * @param data
89 | */
90 | public abstract void feed(T data);
91 | }
92 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/LineScatterCandleRadarRenderer.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.renderer;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Path;
5 |
6 | import com.github.mikephil.charting.animation.ChartAnimator;
7 | import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
8 | import com.github.mikephil.charting.utils.ViewPortHandler;
9 |
10 | /**
11 | * Created by Philipp Jahoda on 11/07/15.
12 | */
13 | public abstract class LineScatterCandleRadarRenderer extends DataRenderer {
14 |
15 | /**
16 | * path that is used for drawing highlight-lines (drawLines(...) cannot be used because of dashes)
17 | */
18 | private Path mHighlightLinePath = new Path();
19 |
20 | public LineScatterCandleRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
21 | super(animator, viewPortHandler);
22 | }
23 |
24 | /**
25 | * Draws vertical & horizontal highlight-lines if enabled.
26 | *
27 | * @param c
28 | * @param pts the transformed x- and y-position of the lines
29 | * @param set the currently drawn dataset
30 | */
31 | protected void drawHighlightLines(Canvas c, float[] pts, ILineScatterCandleRadarDataSet set) {
32 |
33 | // set color and stroke-width
34 | mHighlightPaint.setColor(set.getHighLightColor());
35 | mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth());
36 |
37 | // draw highlighted lines (if enabled)
38 | mHighlightPaint.setPathEffect(set.getDashPathEffectHighlight());
39 |
40 | // draw vertical highlight lines
41 | if (set.isVerticalHighlightIndicatorEnabled()) {
42 |
43 | // create vertical path
44 | mHighlightLinePath.reset();
45 | mHighlightLinePath.moveTo(pts[0], mViewPortHandler.contentTop());
46 | mHighlightLinePath.lineTo(pts[0], mViewPortHandler.contentBottom());
47 |
48 | c.drawPath(mHighlightLinePath, mHighlightPaint);
49 | }
50 |
51 | // draw horizontal highlight lines
52 | if (set.isHorizontalHighlightIndicatorEnabled()) {
53 |
54 | // create horizontal path
55 | mHighlightLinePath.reset();
56 | mHighlightLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]);
57 | mHighlightLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]);
58 |
59 | c.drawPath(mHighlightLinePath, mHighlightPaint);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import android.graphics.DashPathEffect;
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.github.mikephil.charting.data.Entry;
7 | import com.github.mikephil.charting.data.LineDataSet;
8 | import com.github.mikephil.charting.formatter.FillFormatter;
9 |
10 | /**
11 | * Created by Philpp Jahoda on 21/10/15.
12 | */
13 | public interface ILineDataSet extends ILineRadarDataSet {
14 |
15 | /**
16 | * Returns the drawing mode for this line dataset
17 | *
18 | * @return
19 | */
20 | LineDataSet.Mode getMode();
21 |
22 | /**
23 | * Returns the intensity of the cubic lines (the effect intensity).
24 | * Max = 1f = very cubic, Min = 0.05f = low cubic effect, Default: 0.2f
25 | *
26 | * @return
27 | */
28 | float getCubicIntensity();
29 |
30 | @Deprecated
31 | boolean isDrawCubicEnabled();
32 |
33 | @Deprecated
34 | boolean isDrawSteppedEnabled();
35 |
36 | /**
37 | * Returns the size of the drawn circles.
38 | */
39 | float getCircleRadius();
40 |
41 | /**
42 | * Returns the color at the given index of the DataSet's circle-color array.
43 | * Performs a IndexOutOfBounds check by modulus.
44 | *
45 | * @param index
46 | * @return
47 | */
48 | int getCircleColor(int index);
49 |
50 | /**
51 | * Returns true if drawing circles for this DataSet is enabled, false if not
52 | *
53 | * @return
54 | */
55 | boolean isDrawCirclesEnabled();
56 |
57 | /**
58 | * Returns the color of the inner circle (the circle-hole).
59 | *
60 | * @return
61 | */
62 | int getCircleHoleColor();
63 |
64 | /**
65 | * Returns true if drawing the circle-holes is enabled, false if not.
66 | *
67 | * @return
68 | */
69 | boolean isDrawCircleHoleEnabled();
70 |
71 | /**
72 | * Returns the DashPathEffect that is used for drawing the lines.
73 | *
74 | * @return
75 | */
76 | DashPathEffect getDashPathEffect();
77 |
78 | /**
79 | * Returns true if the dashed-line effect is enabled, false if not.
80 | * If the DashPathEffect object is null, also return false here.
81 | *
82 | * @return
83 | */
84 | boolean isDashedLineEnabled();
85 |
86 | /**
87 | * Returns the FillFormatter that is set for this DataSet.
88 | *
89 | * @return
90 | */
91 | FillFormatter getFillFormatter();
92 | }
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/StackedValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.formatter;
2 |
3 | import com.github.mikephil.charting.data.BarEntry;
4 | import com.github.mikephil.charting.data.Entry;
5 | import com.github.mikephil.charting.utils.ViewPortHandler;
6 |
7 | import java.text.DecimalFormat;
8 |
9 | /**
10 | * Created by Philipp Jahoda on 28/01/16.
11 | *
12 | * A formatter specifically for stacked BarChart that allows to specify whether the all stack values
13 | * or just the top value should be drawn.
14 | */
15 | public class StackedValueFormatter implements ValueFormatter {
16 |
17 | /**
18 | * if true, all stack values of the stacked bar entry are drawn, else only top
19 | */
20 | private boolean mDrawWholeStack;
21 |
22 | /**
23 | * a string that should be appended behind the value
24 | */
25 | private String mAppendix;
26 |
27 | private DecimalFormat mFormat;
28 |
29 | /**
30 | * Constructor.
31 | *
32 | * @param drawWholeStack if true, all stack values of the stacked bar entry are drawn, else only top
33 | * @param appendix a string that should be appended behind the value
34 | * @param decimals the number of decimal digits to use
35 | */
36 | public StackedValueFormatter(boolean drawWholeStack, String appendix, int decimals) {
37 | this.mDrawWholeStack = drawWholeStack;
38 | this.mAppendix = appendix;
39 |
40 | StringBuffer b = new StringBuffer();
41 | for (int i = 0; i < decimals; i++) {
42 | if (i == 0)
43 | b.append(".");
44 | b.append("0");
45 | }
46 |
47 | this.mFormat = new DecimalFormat("###,###,###,##0" + b.toString());
48 | }
49 |
50 | @Override
51 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
52 |
53 | if (!mDrawWholeStack && entry instanceof BarEntry) {
54 |
55 | BarEntry barEntry = (BarEntry) entry;
56 | float[] vals = barEntry.getVals();
57 |
58 | if (vals != null) {
59 |
60 | // find out if we are on top of the stack
61 | if (vals[vals.length - 1] == value) {
62 |
63 | // return the "sum" across all stack values
64 | return mFormat.format(barEntry.getVal()) + mAppendix;
65 | } else {
66 | return ""; // return empty
67 | }
68 | }
69 | }
70 |
71 | // return the "proposed" value
72 | return mFormat.format(value) + mAppendix;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/PieData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * A PieData object can only represent one DataSet. Unlike all other charts, the
11 | * legend labels of the PieChart are created from the x-values array, and not
12 | * from the DataSet labels. Each PieData object can only represent one
13 | * PieDataSet (multiple PieDataSets inside a single PieChart are not possible).
14 | *
15 | * @author Philipp Jahoda
16 | */
17 | public class PieData extends ChartData {
18 |
19 | public PieData() {
20 | super();
21 | }
22 |
23 | public PieData(List xVals) {
24 | super(xVals);
25 | }
26 |
27 | public PieData(String[] xVals) {
28 | super(xVals);
29 | }
30 |
31 | public PieData(List xVals, IPieDataSet dataSet) {
32 | super(xVals, toList(dataSet));
33 | }
34 |
35 | public PieData(String[] xVals, IPieDataSet dataSet) {
36 | super(xVals, toList(dataSet));
37 | }
38 |
39 | private static List toList(IPieDataSet dataSet) {
40 | List sets = new ArrayList();
41 | sets.add(dataSet);
42 | return sets;
43 | }
44 |
45 | /**
46 | * Sets the PieDataSet this data object should represent.
47 | *
48 | * @param dataSet
49 | */
50 | public void setDataSet(IPieDataSet dataSet) {
51 | mDataSets.clear();
52 | mDataSets.add(dataSet);
53 | init();
54 | }
55 |
56 | /**
57 | * Returns the DataSet this PieData object represents. A PieData object can
58 | * only contain one DataSet.
59 | *
60 | * @return
61 | */
62 | public IPieDataSet getDataSet() {
63 | return mDataSets.get(0);
64 | }
65 |
66 | /**
67 | * The PieData object can only have one DataSet. Use getDataSet() method instead.
68 | *
69 | * @param index
70 | * @return
71 | */
72 | @Override
73 | public IPieDataSet getDataSetByIndex(int index) {
74 | return index == 0 ? getDataSet() : null;
75 | }
76 |
77 | @Override
78 | public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
79 | return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
80 | : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
81 | }
82 |
83 | /**
84 | * Returns the sum of all values in this PieData object.
85 | *
86 | * @return
87 | */
88 | public float getYValueSum() {
89 |
90 | float sum = 0;
91 |
92 | for (int i = 0; i < getDataSet().getEntryCount(); i++)
93 | sum += getDataSet().getEntryForIndex(i).getVal();
94 |
95 |
96 | return sum;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedZoomJob.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.jobs;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.annotation.SuppressLint;
6 | import android.graphics.Matrix;
7 | import android.view.View;
8 |
9 | import com.github.mikephil.charting.charts.BarLineChartBase;
10 | import com.github.mikephil.charting.components.YAxis;
11 | import com.github.mikephil.charting.utils.Transformer;
12 | import com.github.mikephil.charting.utils.ViewPortHandler;
13 |
14 | /**
15 | * Created by Philipp Jahoda on 19/02/16.
16 | */
17 | @SuppressLint("NewApi")
18 | public class AnimatedZoomJob extends AnimatedViewPortJob implements Animator.AnimatorListener {
19 |
20 | protected float zoomOriginX;
21 | protected float zoomOriginY;
22 |
23 | protected float zoomCenterX;
24 | protected float zoomCenterY;
25 |
26 | protected YAxis yAxis;
27 |
28 | protected float xValCount;
29 |
30 | @SuppressLint("NewApi")
31 | public AnimatedZoomJob(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xValCount, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
32 | super(viewPortHandler, scaleX, scaleY, trans, v, xOrigin, yOrigin, duration);
33 |
34 | this.zoomCenterX = zoomCenterX;
35 | this.zoomCenterY = zoomCenterY;
36 | this.zoomOriginX = zoomOriginX;
37 | this.zoomOriginY = zoomOriginY;
38 | this.animator.addListener(this);
39 | this.yAxis = axis;
40 | this.xValCount = xValCount;
41 | }
42 |
43 | @Override
44 | public void onAnimationUpdate(ValueAnimator animation) {
45 |
46 | float scaleX = xOrigin + (xValue - xOrigin) * phase;
47 | float scaleY = yOrigin + (yValue - yOrigin) * phase;
48 |
49 | Matrix save = mViewPortHandler.setZoom(scaleX, scaleY);
50 | mViewPortHandler.refresh(save, view, false);
51 |
52 | float valsInView = yAxis.mAxisRange / mViewPortHandler.getScaleY();
53 | float xsInView = xValCount / mViewPortHandler.getScaleX();
54 |
55 | pts[0] = zoomOriginX + ((zoomCenterX - xsInView / 2f) - zoomOriginX) * phase;
56 | pts[1] = zoomOriginY + ((zoomCenterY + valsInView / 2f) - zoomOriginY) * phase;
57 |
58 | mTrans.pointValuesToPixel(pts);
59 |
60 | save = mViewPortHandler.translate(pts);
61 | mViewPortHandler.refresh(save, view, true);
62 | }
63 |
64 | @Override
65 | public void onAnimationEnd(Animator animation) {
66 | ((BarLineChartBase) view).calculateOffsets();
67 | view.postInvalidate();
68 | }
69 |
70 | @Override
71 | public void onAnimationCancel(Animator animation) {
72 |
73 | }
74 |
75 | @Override
76 | public void onAnimationRepeat(Animator animation) {
77 |
78 | }
79 |
80 | @Override
81 | public void onAnimationStart(Animator animation) {
82 |
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.highlight;
2 |
3 | import com.github.mikephil.charting.components.YAxis;
4 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
5 | import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
6 |
7 | /**
8 | * Created by Philipp Jahoda on 22/07/15.
9 | */
10 | public class HorizontalBarHighlighter extends BarHighlighter {
11 |
12 | public HorizontalBarHighlighter(BarDataProvider chart) {
13 | super(chart);
14 | }
15 |
16 | @Override
17 | public Highlight getHighlight(float x, float y) {
18 |
19 | Highlight h = super.getHighlight(x, y);
20 |
21 | if (h == null)
22 | return h;
23 | else {
24 |
25 | IBarDataSet set = mChart.getBarData().getDataSetByIndex(h.getDataSetIndex());
26 |
27 | if (set.isStacked()) {
28 |
29 | // create an array of the touch-point
30 | float[] pts = new float[2];
31 | pts[0] = y;
32 |
33 | // take any transformer to determine the x-axis value
34 | mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);
35 |
36 | return getStackedHighlight(h, set, h.getXIndex(), h.getDataSetIndex(), pts[0]);
37 | } else
38 | return h;
39 | }
40 | }
41 |
42 | @Override
43 | protected int getXIndex(float x) {
44 |
45 | if (!mChart.getBarData().isGrouped()) {
46 |
47 | // create an array of the touch-point
48 | float[] pts = new float[2];
49 | pts[1] = x;
50 |
51 | // take any transformer to determine the x-axis value
52 | mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
53 |
54 | return (int) Math.round(pts[1]);
55 | } else {
56 |
57 | float baseNoSpace = getBase(x);
58 |
59 | int setCount = mChart.getBarData().getDataSetCount();
60 | int xIndex = (int) baseNoSpace / setCount;
61 |
62 | int valCount = mChart.getData().getXValCount();
63 |
64 | if (xIndex < 0)
65 | xIndex = 0;
66 | else if (xIndex >= valCount)
67 | xIndex = valCount - 1;
68 |
69 | return xIndex;
70 | }
71 | }
72 |
73 | /**
74 | * Returns the base y-value to the corresponding x-touch value in pixels.
75 | *
76 | * @param y
77 | * @return
78 | */
79 | @Override
80 | protected float getBase(float y) {
81 |
82 | // create an array of the touch-point
83 | float[] pts = new float[2];
84 | pts[1] = y;
85 |
86 | // take any transformer to determine the x-axis value
87 | mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
88 | float yVal = pts[1];
89 |
90 | int setCount = mChart.getBarData().getDataSetCount();
91 |
92 | // calculate how often the group-space appears
93 | int steps = (int) ((float) yVal / ((float) setCount + mChart.getBarData().getGroupSpace()));
94 |
95 | float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps;
96 |
97 | float baseNoSpace = (float) yVal - groupSpaceSum;
98 | return baseNoSpace;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/formatter/LargeValueFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.formatter;
3 |
4 | import com.github.mikephil.charting.components.YAxis;
5 | import com.github.mikephil.charting.data.Entry;
6 | import com.github.mikephil.charting.utils.ViewPortHandler;
7 |
8 | import java.text.DecimalFormat;
9 |
10 | /**
11 | * Predefined value-formatter that formats large numbers in a pretty way.
12 | * Outputs: 856 = 856; 1000 = 1k; 5821 = 5.8k; 10500 = 10k; 101800 = 102k;
13 | * 2000000 = 2m; 7800000 = 7.8m; 92150000 = 92m; 123200000 = 123m; 9999999 =
14 | * 10m; 1000000000 = 1b; Special thanks to Roman Gromov
15 | * (https://github.com/romangromov) for this piece of code.
16 | *
17 | * @author Philipp Jahoda
18 | * @author Oleksandr Tyshkovets
19 | */
20 | public class LargeValueFormatter implements ValueFormatter, YAxisValueFormatter {
21 |
22 | private static String[] SUFFIX = new String[]{
23 | "", "k", "m", "b", "t"
24 | };
25 | private static final int MAX_LENGTH = 4;
26 | private DecimalFormat mFormat;
27 | private String mText = "";
28 |
29 | public LargeValueFormatter() {
30 | mFormat = new DecimalFormat("###E0");
31 | }
32 |
33 | /**
34 | * Creates a formatter that appends a specified text to the result string
35 | *
36 | * @param appendix a text that will be appended
37 | */
38 | public LargeValueFormatter(String appendix) {
39 | this();
40 | mText = appendix;
41 | }
42 |
43 | // ValueFormatter
44 | @Override
45 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
46 | return makePretty(value) + mText;
47 | }
48 |
49 | // YAxisValueFormatter
50 | @Override
51 | public String getFormattedValue(float value, YAxis yAxis) {
52 | return makePretty(value) + mText;
53 | }
54 |
55 | /**
56 | * Set an appendix text to be added at the end of the formatted value.
57 | *
58 | * @param appendix
59 | */
60 | public void setAppendix(String appendix) {
61 | this.mText = appendix;
62 | }
63 |
64 | /**
65 | * Set custom suffix to be appended after the values.
66 | * Default suffix: ["", "k", "m", "b", "t"]
67 | *
68 | * @param suff new suffix
69 | */
70 | public void setSuffix(String[] suff) {
71 | if (suff.length == 5) {
72 | SUFFIX = suff;
73 | }
74 | }
75 |
76 | /**
77 | * Formats each number properly. Special thanks to Roman Gromov
78 | * (https://github.com/romangromov) for this piece of code.
79 | */
80 | private String makePretty(double number) {
81 |
82 | String r = mFormat.format(number);
83 |
84 | r = r.replaceAll("E[0-9]", SUFFIX[Character.getNumericValue(r.charAt(r.length() - 1)) / 3]);
85 |
86 | while (r.length() > MAX_LENGTH || r.matches("[0-9]+\\.[a-z]")) {
87 | r = r.substring(0, r.length() - 2) + r.substring(r.length() - 1);
88 | }
89 |
90 | return r;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/LineRadarRenderer.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.renderer;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.PorterDuff;
7 | import android.graphics.PorterDuffXfermode;
8 | import android.graphics.drawable.Drawable;
9 |
10 | import com.github.mikephil.charting.animation.ChartAnimator;
11 | import com.github.mikephil.charting.utils.Utils;
12 | import com.github.mikephil.charting.utils.ViewPortHandler;
13 |
14 | /**
15 | * Created by Philipp Jahoda on 25/01/16.
16 | */
17 | public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
18 |
19 | public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
20 | super(animator, viewPortHandler);
21 | }
22 |
23 | /**
24 | * Draws the provided path in filled mode with the provided drawable.
25 | *
26 | * @param c
27 | * @param filledPath
28 | * @param drawable
29 | */
30 | protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
31 |
32 | if (clipPathSupported()) {
33 |
34 | c.save();
35 | c.clipPath(filledPath);
36 |
37 | drawable.setBounds((int) mViewPortHandler.contentLeft(),
38 | (int) mViewPortHandler.contentTop(),
39 | (int) mViewPortHandler.contentRight(),
40 | (int) mViewPortHandler.contentBottom());
41 | drawable.draw(c);
42 |
43 | c.restore();
44 | } else {
45 | throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
46 | "this code was run on API level " + Utils.getSDKInt() + ".");
47 | }
48 | }
49 |
50 | /**
51 | * Draws the provided path in filled mode with the provided color and alpha.
52 | * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
53 | *
54 | * @param c
55 | * @param filledPath
56 | * @param fillColor
57 | * @param fillAlpha
58 | */
59 | protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
60 |
61 | int color = (fillAlpha << 24) | (fillColor & 0xffffff);
62 |
63 | if (clipPathSupported()) {
64 |
65 | c.save();
66 | c.clipPath(filledPath);
67 |
68 | c.drawColor(color);
69 | c.restore();
70 | } else {
71 |
72 | // save
73 | Paint.Style previous = mRenderPaint.getStyle();
74 | int previousColor = mRenderPaint.getColor();
75 |
76 | // set
77 | mRenderPaint.setStyle(Paint.Style.FILL);
78 | mRenderPaint.setColor(color);
79 |
80 | c.drawPath(filledPath, mRenderPaint);
81 |
82 | // restore
83 | mRenderPaint.setColor(previousColor);
84 | mRenderPaint.setStyle(previous);
85 | }
86 | }
87 |
88 | /**
89 | * Clip path with hardware acceleration only working properly on API level 18 and above.
90 | *
91 | * @return
92 | */
93 | private boolean clipPathSupported() {
94 | return Utils.getSDKInt() >= 18;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BarData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Data object that represents all data for the BarChart.
11 | *
12 | * @author Philipp Jahoda
13 | */
14 | public class BarData extends BarLineScatterCandleBubbleData {
15 |
16 | /** the space that is left between groups of bars */
17 | private float mGroupSpace = 0.8f;
18 |
19 | // /**
20 | // * The maximum space (in pixels on the screen) a single bar can consume.
21 | // */
22 | // private float mMaximumBarWidth = 100f;
23 |
24 | public BarData() {
25 | super();
26 | }
27 |
28 | public BarData(List xVals) {
29 | super(xVals);
30 | }
31 |
32 | public BarData(String[] xVals) {
33 | super(xVals);
34 | }
35 |
36 | public BarData(List xVals, List dataSets) {
37 | super(xVals, dataSets);
38 | }
39 |
40 | public BarData(String[] xVals, List dataSets) {
41 | super(xVals, dataSets);
42 | }
43 |
44 | public BarData(List xVals, IBarDataSet dataSet) {
45 | super(xVals, toList(dataSet));
46 | }
47 |
48 | public BarData(String[] xVals, IBarDataSet dataSet) {
49 | super(xVals, toList(dataSet));
50 | }
51 |
52 | private static List toList(IBarDataSet dataSet) {
53 | List sets = new ArrayList();
54 | sets.add(dataSet);
55 | return sets;
56 | }
57 |
58 | /**
59 | * Returns the space that is left out between groups of bars. Always returns
60 | * 0 if the BarData object only contains one DataSet (because for one
61 | * DataSet, there is no group-space needed).
62 | *
63 | * @return
64 | */
65 | public float getGroupSpace() {
66 |
67 | if (mDataSets.size() <= 1)
68 | return 0f;
69 | else
70 | return mGroupSpace;
71 | }
72 |
73 | /**
74 | * Sets the space between groups of bars of different datasets in percent of
75 | * the total width of one bar. 100 = space is exactly one bar width,
76 | * default: 80
77 | *
78 | * @param percent
79 | */
80 | public void setGroupSpace(float percent) {
81 | mGroupSpace = percent / 100f;
82 | }
83 |
84 | /**
85 | * Returns true if this BarData object contains grouped DataSets (more than
86 | * 1 DataSet).
87 | *
88 | * @return
89 | */
90 | public boolean isGrouped() {
91 | return mDataSets.size() > 1 ? true : false;
92 | }
93 |
94 | //
95 | // /**
96 | // * Sets the maximum width (in density pixels) a single bar in the barchart
97 | // * should consume.
98 | // *
99 | // * @param max
100 | // */
101 | // public void setBarWidthMaximum(float max) {
102 | // mMaximumBarWidth = Utils.convertDpToPixel(max);
103 | // }
104 | //
105 | // /**
106 | // * Returns the maximum width (in density pixels) a single bar in the
107 | // * barchart should consume.
108 | // *
109 | // * @return
110 | // */
111 | // public float getBarWidthMaximum() {
112 | // return mMaximumBarWidth;
113 | // }
114 | }
115 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/AxisRenderer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.renderer;
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Style;
8 |
9 | import com.github.mikephil.charting.utils.Transformer;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | /**
13 | * Baseclass of all axis renderers.
14 | *
15 | * @author Philipp Jahoda
16 | */
17 | public abstract class AxisRenderer extends Renderer {
18 |
19 | protected Transformer mTrans;
20 |
21 | /** paint object for the grid lines */
22 | protected Paint mGridPaint;
23 |
24 | /** paint for the x-label values */
25 | protected Paint mAxisLabelPaint;
26 |
27 | /** paint for the line surrounding the chart */
28 | protected Paint mAxisLinePaint;
29 |
30 | /** paint used for the limit lines */
31 | protected Paint mLimitLinePaint;
32 |
33 | public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans) {
34 | super(viewPortHandler);
35 |
36 | this.mTrans = trans;
37 |
38 | mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
39 |
40 | mGridPaint = new Paint();
41 | mGridPaint.setColor(Color.GRAY);
42 | mGridPaint.setStrokeWidth(1f);
43 | mGridPaint.setStyle(Style.STROKE);
44 | mGridPaint.setAlpha(90);
45 |
46 | mAxisLinePaint = new Paint();
47 | mAxisLinePaint.setColor(Color.BLACK);
48 | mAxisLinePaint.setStrokeWidth(1f);
49 | mAxisLinePaint.setStyle(Style.STROKE);
50 |
51 | mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
52 | mLimitLinePaint.setStyle(Paint.Style.STROKE);
53 | }
54 |
55 | /**
56 | * Returns the Paint object used for drawing the axis (labels).
57 | *
58 | * @return
59 | */
60 | public Paint getPaintAxisLabels() {
61 | return mAxisLabelPaint;
62 | }
63 |
64 | /**
65 | * Returns the Paint object that is used for drawing the grid-lines of the
66 | * axis.
67 | *
68 | * @return
69 | */
70 | public Paint getPaintGrid() {
71 | return mGridPaint;
72 | }
73 |
74 | /**
75 | * Returns the Paint object that is used for drawing the axis-line that goes
76 | * alongside the axis.
77 | *
78 | * @return
79 | */
80 | public Paint getPaintAxisLine() {
81 | return mAxisLinePaint;
82 | }
83 |
84 | /**
85 | * Returns the Transformer object used for transforming the axis values.
86 | *
87 | * @return
88 | */
89 | public Transformer getTransformer() {
90 | return mTrans;
91 | }
92 |
93 | /**
94 | * Draws the axis labels to the screen.
95 | *
96 | * @param c
97 | */
98 | public abstract void renderAxisLabels(Canvas c);
99 |
100 | /**
101 | * Draws the grid lines belonging to the axis.
102 | *
103 | * @param c
104 | */
105 | public abstract void renderGridLines(Canvas c);
106 |
107 | /**
108 | * Draws the line that goes alongside the axis.
109 | *
110 | * @param c
111 | */
112 | public abstract void renderAxisLine(Canvas c);
113 |
114 | /**
115 | * Draws the LimitLines associated with this axis to the screen.
116 | *
117 | * @param c
118 | */
119 | public abstract void renderLimitLines(Canvas c);
120 | }
121 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/LineRadarDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import android.annotation.TargetApi;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.Drawable;
7 |
8 | import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
9 | import com.github.mikephil.charting.utils.Utils;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Base dataset for line and radar DataSets.
15 | *
16 | * @author Philipp Jahoda
17 | */
18 | public abstract class LineRadarDataSet extends LineScatterCandleRadarDataSet implements ILineRadarDataSet {
19 |
20 | /**
21 | * the color that is used for filling the line surface
22 | */
23 | private int mFillColor = Color.rgb(140, 234, 255);
24 |
25 | /**
26 | * the drawable to be used for filling the line surface
27 | */
28 | protected Drawable mFillDrawable;
29 |
30 | /**
31 | * transparency used for filling line surface
32 | */
33 | private int mFillAlpha = 85;
34 |
35 | /**
36 | * the width of the drawn data lines
37 | */
38 | private float mLineWidth = 2.5f;
39 |
40 | /**
41 | * if true, the data will also be drawn filled
42 | */
43 | private boolean mDrawFilled = false;
44 |
45 |
46 | public LineRadarDataSet(List yVals, String label) {
47 | super(yVals, label);
48 | }
49 |
50 | @Override
51 | public int getFillColor() {
52 | return mFillColor;
53 | }
54 |
55 | /**
56 | * Sets the color that is used for filling the area below the line.
57 | * Resets an eventually set "fillDrawable".
58 | *
59 | * @param color
60 | */
61 | public void setFillColor(int color) {
62 | mFillColor = color;
63 | mFillDrawable = null;
64 | }
65 |
66 | @Override
67 | public Drawable getFillDrawable() {
68 | return mFillDrawable;
69 | }
70 |
71 | /**
72 | * Sets the drawable to be used to fill the area below the line.
73 | *
74 | * @param drawable
75 | */
76 | @TargetApi(18)
77 | public void setFillDrawable(Drawable drawable) {
78 | this.mFillDrawable = drawable;
79 | }
80 |
81 | @Override
82 | public int getFillAlpha() {
83 | return mFillAlpha;
84 | }
85 |
86 | /**
87 | * sets the alpha value (transparency) that is used for filling the line
88 | * surface (0-255), default: 85
89 | *
90 | * @param alpha
91 | */
92 | public void setFillAlpha(int alpha) {
93 | mFillAlpha = alpha;
94 | }
95 |
96 | /**
97 | * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
98 | * thinner line == better performance, thicker line == worse performance
99 | *
100 | * @param width
101 | */
102 | public void setLineWidth(float width) {
103 |
104 | if (width < 0.2f)
105 | width = 0.2f;
106 | if (width > 10.0f)
107 | width = 10.0f;
108 | mLineWidth = Utils.convertDpToPixel(width);
109 | }
110 |
111 | @Override
112 | public float getLineWidth() {
113 | return mLineWidth;
114 | }
115 |
116 | @Override
117 | public void setDrawFilled(boolean filled) {
118 | mDrawFilled = filled;
119 | }
120 |
121 | @Override
122 | public boolean isDrawFilledEnabled() {
123 | return mDrawFilled;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/buffer/HorizontalBarBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.buffer;
3 |
4 | import com.github.mikephil.charting.data.BarEntry;
5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
6 |
7 | public class HorizontalBarBuffer extends BarBuffer {
8 |
9 | public HorizontalBarBuffer(int size, float groupspace, int dataSetCount, boolean containsStacks) {
10 | super(size, groupspace, dataSetCount, containsStacks);
11 | }
12 |
13 | @Override
14 | public void feed(IBarDataSet data) {
15 |
16 | float size = data.getEntryCount() * phaseX;
17 |
18 | int dataSetOffset = (mDataSetCount - 1);
19 | float barSpaceHalf = mBarSpace / 2f;
20 | float groupSpaceHalf = mGroupSpace / 2f;
21 | float barWidth = 0.5f;
22 |
23 | for (int i = 0; i < size; i++) {
24 |
25 | BarEntry e = data.getEntryForIndex(i);
26 |
27 | // calculate the x-position, depending on datasetcount
28 | float x = e.getXIndex() + e.getXIndex() * dataSetOffset + mDataSetIndex
29 | + mGroupSpace * e.getXIndex() + groupSpaceHalf;
30 | float y = e.getVal();
31 | float[] vals = e.getVals();
32 |
33 | if (!mContainsStacks || vals == null) {
34 |
35 | float bottom = x - barWidth + barSpaceHalf;
36 | float top = x + barWidth - barSpaceHalf;
37 | float left, right;
38 | if (mInverted) {
39 | left = y >= 0 ? y : 0;
40 | right = y <= 0 ? y : 0;
41 | } else {
42 | right = y >= 0 ? y : 0;
43 | left = y <= 0 ? y : 0;
44 | }
45 |
46 | // multiply the height of the rect with the phase
47 | if (right > 0)
48 | right *= phaseY;
49 | else
50 | left *= phaseY;
51 |
52 | addBar(left, top, right, bottom);
53 |
54 | } else {
55 |
56 | float posY = 0f;
57 | float negY = -e.getNegativeSum();
58 | float yStart = 0f;
59 |
60 | // fill the stack
61 | for (int k = 0; k < vals.length; k++) {
62 |
63 | float value = vals[k];
64 |
65 | if (value >= 0f) {
66 | y = posY;
67 | yStart = posY + value;
68 | posY = yStart;
69 | } else {
70 | y = negY;
71 | yStart = negY + Math.abs(value);
72 | negY += Math.abs(value);
73 | }
74 |
75 | float bottom = x - barWidth + barSpaceHalf;
76 | float top = x + barWidth - barSpaceHalf;
77 | float left, right;
78 | if (mInverted) {
79 | left = y >= yStart ? y : yStart;
80 | right = y <= yStart ? y : yStart;
81 | } else {
82 | right = y >= yStart ? y : yStart;
83 | left = y <= yStart ? y : yStart;
84 | }
85 |
86 | // multiply the height of the rect with the phase
87 | right *= phaseY;
88 | left *= phaseY;
89 |
90 | addBar(left, top, right, bottom);
91 | }
92 | }
93 | }
94 |
95 | reset();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/CombinedData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Data object that allows the combination of Line-, Bar-, Scatter-, Bubble- and
11 | * CandleData. Used in the CombinedChart class.
12 | *
13 | * @author Philipp Jahoda
14 | */
15 | public class CombinedData extends BarLineScatterCandleBubbleData> {
16 |
17 | private LineData mLineData;
18 | private BarData mBarData;
19 | private ScatterData mScatterData;
20 | private CandleData mCandleData;
21 | private BubbleData mBubbleData;
22 |
23 | public CombinedData() {
24 | super();
25 | }
26 |
27 | public CombinedData(List xVals) {
28 | super(xVals);
29 | }
30 |
31 | public CombinedData(String[] xVals) {
32 | super(xVals);
33 | }
34 |
35 | public void setData(LineData data) {
36 | mLineData = data;
37 | mDataSets.addAll(data.getDataSets());
38 | init();
39 | }
40 |
41 | public void setData(BarData data) {
42 | mBarData = data;
43 | mDataSets.addAll(data.getDataSets());
44 | init();
45 | }
46 |
47 | public void setData(ScatterData data) {
48 | mScatterData = data;
49 | mDataSets.addAll(data.getDataSets());
50 | init();
51 | }
52 |
53 | public void setData(CandleData data) {
54 | mCandleData = data;
55 | mDataSets.addAll(data.getDataSets());
56 | init();
57 | }
58 |
59 | public void setData(BubbleData data) {
60 | mBubbleData = data;
61 | mDataSets.addAll(data.getDataSets());
62 | init();
63 | }
64 |
65 | public BubbleData getBubbleData() {
66 | return mBubbleData;
67 | }
68 |
69 | public LineData getLineData() {
70 | return mLineData;
71 | }
72 |
73 | public BarData getBarData() {
74 | return mBarData;
75 | }
76 |
77 | public ScatterData getScatterData() {
78 | return mScatterData;
79 | }
80 |
81 | public CandleData getCandleData() {
82 | return mCandleData;
83 | }
84 |
85 | /**
86 | * Returns all data objects in row: line-bar-scatter-candle-bubble if not null.
87 | * @return
88 | */
89 | public List getAllData() {
90 |
91 | List data = new ArrayList();
92 | if(mLineData != null)
93 | data.add(mLineData);
94 | if(mBarData != null)
95 | data.add(mBarData);
96 | if(mScatterData != null)
97 | data.add(mScatterData);
98 | if(mCandleData != null)
99 | data.add(mCandleData);
100 | if(mBubbleData != null)
101 | data.add(mBubbleData);
102 |
103 | return data;
104 | }
105 |
106 | @Override
107 | public void notifyDataChanged() {
108 | if (mLineData != null)
109 | mLineData.notifyDataChanged();
110 | if (mBarData != null)
111 | mBarData.notifyDataChanged();
112 | if (mCandleData != null)
113 | mCandleData.notifyDataChanged();
114 | if (mScatterData != null)
115 | mScatterData.notifyDataChanged();
116 | if (mBubbleData != null)
117 | mBubbleData.notifyDataChanged();
118 |
119 | init(); // recalculate everything
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/android/colin/democandlechart/StockListBean.java:
--------------------------------------------------------------------------------
1 | package android.colin.democandlechart;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by Administrator on 2016/4/17.
7 | */
8 | public class StockListBean {
9 | /**
10 | * error : 0
11 | * message :
12 | * content :
13 | */
14 | private int error;
15 | private String message;
16 | private List content;
17 |
18 | public void setError(int error) {
19 | this.error = error;
20 | }
21 |
22 | public void setMessage(String message) {
23 | this.message = message;
24 | }
25 |
26 | public void setContent(List content) {
27 | this.content = content;
28 | }
29 |
30 | public int getError() {
31 | return error;
32 | }
33 |
34 | public String getMessage() {
35 | return message;
36 | }
37 |
38 | public List getContent() {
39 | return content;
40 | }
41 |
42 |
43 | class StockBean {
44 |
45 | /**
46 | * Date : 2016/4/19
47 | * Open : 11.78
48 | * High : 12.3
49 | * Low : 11.55
50 | * Close : 12.07
51 | * Volume : 59186200
52 | * Adj : 12.07
53 | * ma5 : 10.97
54 | * ma10 : 10.735
55 | * ma20 : 10.6785
56 | */
57 |
58 | private String Date;
59 | private float Open;
60 | private float High;
61 | private float Low;
62 | private float Close;
63 | private String Volume;
64 | private float Adj;
65 | private float ma5;
66 | private float ma10;
67 | private float ma20;
68 |
69 | public String getDate() {
70 | return Date;
71 | }
72 |
73 | public void setDate(String date) {
74 | Date = date;
75 | }
76 |
77 | public float getOpen() {
78 | return Open;
79 | }
80 |
81 | public void setOpen(float open) {
82 | Open = open;
83 | }
84 |
85 | public float getHigh() {
86 | return High;
87 | }
88 |
89 | public void setHigh(float high) {
90 | High = high;
91 | }
92 |
93 | public float getLow() {
94 | return Low;
95 | }
96 |
97 | public void setLow(float low) {
98 | Low = low;
99 | }
100 |
101 | public float getClose() {
102 | return Close;
103 | }
104 |
105 | public void setClose(float close) {
106 | Close = close;
107 | }
108 |
109 | public String getVolume() {
110 | return Volume;
111 | }
112 |
113 | public void setVolume(String volume) {
114 | Volume = volume;
115 | }
116 |
117 | public float getAdj() {
118 | return Adj;
119 | }
120 |
121 | public void setAdj(float adj) {
122 | Adj = adj;
123 | }
124 |
125 | public float getMa5() {
126 | return ma5;
127 | }
128 |
129 | public void setMa5(float ma5) {
130 | this.ma5 = ma5;
131 | }
132 |
133 | public float getMa10() {
134 | return ma10;
135 | }
136 |
137 | public void setMa10(float ma10) {
138 | this.ma10 = ma10;
139 | }
140 |
141 | public float getMa20() {
142 | return ma20;
143 | }
144 |
145 | public void setMa20(float ma20) {
146 | this.ma20 = ma20;
147 | }
148 | }
149 | }
150 |
151 |
--------------------------------------------------------------------------------
/MPChartLib/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 4.0.0
20 | 1.4.2-SNAPSHOT
21 | com.github.mikephil
22 | MPAndroidChart
23 | MPAndroidChart
24 | A simple Android chart view/graph view library, supporting line- bar- and piecharts as well as scaling, dragging and animations
25 | https://github.com/PhilJay/MPAndroidChart
26 | apklib
27 |
28 |
29 |
30 | UTF-8
31 |
32 |
33 |
34 | src
35 |
36 |
37 | com.jayway.maven.plugins.android.generation2
38 | android-maven-plugin
39 | 3.9.0-rc.2
40 | true
41 |
42 |
43 |
44 |
45 |
46 | true
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | com.google.android
55 | android
56 | provided
57 | 4.1.1.4
58 |
59 |
60 |
61 |
62 |
63 | https://github.com/PhilJay/MPAndroidChart/issues
64 | GitHub Issues
65 |
66 |
67 |
68 |
69 | Apache License Version 2.0
70 | http://www.apache.org/licenses/LICENSE-2.0.html
71 | repo
72 |
73 |
74 |
75 |
76 | https://github.com/PhilJay/MPAndroidChart
77 | scm:git:git://github.com/PhilJay/MPAndroidChart.git
78 | scm:git:git@github.com:PhilJay/MPAndroidChart.git
79 |
80 |
81 |
82 |
83 | Philipp Jahoda
84 | philjay.librarysup@gmail.com
85 | http://stackoverflow.com/users/1590502/philipp-jahoda
86 | PhilJay
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/components/MarkerView.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.components;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.RelativeLayout;
8 |
9 | import com.github.mikephil.charting.data.Entry;
10 | import com.github.mikephil.charting.highlight.Highlight;
11 |
12 | /**
13 | * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your
14 | * markers.
15 | *
16 | * @author Philipp Jahoda
17 | */
18 | public abstract class MarkerView extends RelativeLayout {
19 |
20 | /**
21 | * Constructor. Sets up the MarkerView with a custom layout resource.
22 | *
23 | * @param context
24 | * @param layoutResource the layout resource to use for the MarkerView
25 | */
26 | public MarkerView(Context context, int layoutResource) {
27 | super(context);
28 | setupLayoutResource(layoutResource);
29 | }
30 |
31 | /**
32 | * Sets the layout resource for a custom MarkerView.
33 | *
34 | * @param layoutResource
35 | */
36 | private void setupLayoutResource(int layoutResource) {
37 |
38 | View inflated = LayoutInflater.from(getContext()).inflate(layoutResource, this);
39 |
40 | inflated.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
41 | inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
42 |
43 | // measure(getWidth(), getHeight());
44 | inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight());
45 | }
46 |
47 | /**
48 | * Draws the MarkerView on the given position on the screen with the given Canvas object.
49 | *
50 | * @param canvas
51 | * @param posx
52 | * @param posy
53 | */
54 | public void draw(Canvas canvas, float posx, float posy) {
55 |
56 | // take offsets into consideration
57 | posx += getXOffset(posx);
58 | posy += getYOffset(posy);
59 |
60 | // translate to the correct position and draw
61 | canvas.translate(posx, posy);
62 | draw(canvas);
63 | canvas.translate(-posx, -posy);
64 | }
65 |
66 | /**
67 | * This method enables a specified custom MarkerView to update it's content everytime the MarkerView is redrawn.
68 | *
69 | * @param e The Entry the MarkerView belongs to. This can also be any subclass of Entry, like BarEntry or
70 | * CandleEntry, simply cast it at runtime.
71 | * @param highlight the highlight object contains information about the highlighted value such as it's dataset-index, the
72 | * selected range or stack-index (only stacked bar entries).
73 | */
74 | public abstract void refreshContent(Entry e, Highlight highlight);
75 |
76 | /**
77 | * Use this to return the desired offset you wish the MarkerView to have on the x-axis. By returning -(getWidth() /
78 | * 2) you will center the MarkerView horizontally.
79 | *
80 | * @param xpos the position on the x-axis in pixels where the marker is drawn
81 | * @return
82 | */
83 | public abstract int getXOffset(float xpos);
84 |
85 | /**
86 | * Use this to return the desired position offset you wish the MarkerView to have on the y-axis. By returning
87 | * -getHeight() you will cause the MarkerView to be above the selected value.
88 | *
89 | * @param ypos the position on the y-axis in pixels where the marker is drawn
90 | * @return
91 | */
92 | public abstract int getYOffset(float ypos);
93 | }
94 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/highlight/ChartHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.highlight;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.github.mikephil.charting.components.YAxis;
7 | import com.github.mikephil.charting.interfaces.datasets.IDataSet;
8 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
9 | import com.github.mikephil.charting.utils.SelectionDetail;
10 | import com.github.mikephil.charting.utils.Utils;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 21/07/15.
14 | */
15 | public class ChartHighlighter {
16 |
17 | /** instance of the data-provider */
18 | protected T mChart;
19 |
20 | public ChartHighlighter(T chart) {
21 | this.mChart = chart;
22 | }
23 |
24 | /**
25 | * Returns a Highlight object corresponding to the given x- and y- touch positions in pixels.
26 | *
27 | * @param x
28 | * @param y
29 | * @return
30 | */
31 | public Highlight getHighlight(float x, float y) {
32 |
33 | int xIndex = getXIndex(x);
34 | if (xIndex == -Integer.MAX_VALUE)
35 | return null;
36 |
37 | int dataSetIndex = getDataSetIndex(xIndex, x, y);
38 | if (dataSetIndex == -Integer.MAX_VALUE)
39 | return null;
40 |
41 | return new Highlight(xIndex, dataSetIndex);
42 | }
43 |
44 | /**
45 | * Returns the corresponding x-index for a given touch-position in pixels.
46 | *
47 | * @param x
48 | * @return
49 | */
50 | protected int getXIndex(float x) {
51 |
52 | // create an array of the touch-point
53 | float[] pts = new float[2];
54 | pts[0] = x;
55 |
56 | // take any transformer to determine the x-axis value
57 | mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
58 |
59 | return (int) Math.round(pts[0]);
60 | }
61 |
62 | /**
63 | * Returns the corresponding dataset-index for a given xIndex and xy-touch position in pixels.
64 | *
65 | * @param xIndex
66 | * @param x
67 | * @param y
68 | * @return
69 | */
70 | protected int getDataSetIndex(int xIndex, float x, float y) {
71 |
72 | List valsAtIndex = getSelectionDetailsAtIndex(xIndex);
73 |
74 | float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT);
75 | float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT);
76 |
77 | YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;
78 |
79 | int dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, y, axis);
80 |
81 | return dataSetIndex;
82 | }
83 |
84 | /**
85 | * Returns a list of SelectionDetail object corresponding to the given xIndex.
86 | *
87 | * @param xIndex
88 | * @return
89 | */
90 | protected List getSelectionDetailsAtIndex(int xIndex) {
91 |
92 | List vals = new ArrayList();
93 |
94 | float[] pts = new float[2];
95 |
96 | for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {
97 |
98 | IDataSet dataSet = mChart.getData().getDataSetByIndex(i);
99 |
100 | // dont include datasets that cannot be highlighted
101 | if (!dataSet.isHighlightEnabled())
102 | continue;
103 |
104 | // extract all y-values from all DataSets at the given x-index
105 | final float yVal = dataSet.getYValForXIndex(xIndex);
106 | if (yVal == Float.NaN)
107 | continue;
108 |
109 | pts[1] = yVal;
110 |
111 | mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
112 |
113 | if (!Float.isNaN(pts[1])) {
114 | vals.add(new SelectionDetail(pts[1], i, dataSet));
115 | }
116 | }
117 |
118 | return vals;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/matrix/Vector3.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.matrix;
3 |
4 | /**
5 | * Simple 3D vector class. Handles basic vector math for 3D vectors.
6 | */
7 | public final class Vector3 {
8 | public float x;
9 | public float y;
10 | public float z;
11 |
12 | public static final Vector3 ZERO = new Vector3(0, 0, 0);
13 | public static final Vector3 UNIT_X = new Vector3(1, 0, 0);
14 | public static final Vector3 UNIT_Y = new Vector3(0, 1, 0);
15 | public static final Vector3 UNIT_Z = new Vector3(0, 0, 1);
16 |
17 | public Vector3() {
18 | }
19 |
20 | public Vector3(float[] array)
21 | {
22 | set(array[0], array[1], array[2]);
23 | }
24 |
25 | public Vector3(float xValue, float yValue, float zValue) {
26 | set(xValue, yValue, zValue);
27 | }
28 |
29 | public Vector3(Vector3 other) {
30 | set(other);
31 | }
32 |
33 | public final void add(Vector3 other) {
34 | x += other.x;
35 | y += other.y;
36 | z += other.z;
37 | }
38 |
39 | public final void add(float otherX, float otherY, float otherZ) {
40 | x += otherX;
41 | y += otherY;
42 | z += otherZ;
43 | }
44 |
45 | public final void subtract(Vector3 other) {
46 | x -= other.x;
47 | y -= other.y;
48 | z -= other.z;
49 | }
50 |
51 | public final void subtractMultiple(Vector3 other, float multiplicator)
52 | {
53 | x -= other.x * multiplicator;
54 | y -= other.y * multiplicator;
55 | z -= other.z * multiplicator;
56 | }
57 |
58 | public final void multiply(float magnitude) {
59 | x *= magnitude;
60 | y *= magnitude;
61 | z *= magnitude;
62 | }
63 |
64 | public final void multiply(Vector3 other) {
65 | x *= other.x;
66 | y *= other.y;
67 | z *= other.z;
68 | }
69 |
70 | public final void divide(float magnitude) {
71 | if (magnitude != 0.0f) {
72 | x /= magnitude;
73 | y /= magnitude;
74 | z /= magnitude;
75 | }
76 | }
77 |
78 | public final void set(Vector3 other) {
79 | x = other.x;
80 | y = other.y;
81 | z = other.z;
82 | }
83 |
84 | public final void set(float xValue, float yValue, float zValue) {
85 | x = xValue;
86 | y = yValue;
87 | z = zValue;
88 | }
89 |
90 | public final float dot(Vector3 other) {
91 | return (x * other.x) + (y * other.y) + (z * other.z);
92 | }
93 |
94 | public final Vector3 cross(Vector3 other) {
95 | return new Vector3(y * other.z - z * other.y,
96 | z * other.x - x * other.z,
97 | x * other.y - y * other.x);
98 | }
99 |
100 | public final float length() {
101 | return (float) Math.sqrt(length2());
102 | }
103 |
104 | public final float length2() {
105 | return (x * x) + (y * y) + (z * z);
106 | }
107 |
108 | public final float distance2(Vector3 other) {
109 | float dx = x - other.x;
110 | float dy = y - other.y;
111 | float dz = z - other.z;
112 | return (dx * dx) + (dy * dy) + (dz * dz);
113 | }
114 |
115 | public final float normalize() {
116 | final float magnitude = length();
117 |
118 | // TODO: I'm choosing safety over speed here.
119 | if (magnitude != 0.0f) {
120 | x /= magnitude;
121 | y /= magnitude;
122 | z /= magnitude;
123 | }
124 |
125 | return magnitude;
126 | }
127 |
128 | public final void zero() {
129 | set(0.0f, 0.0f, 0.0f);
130 | }
131 |
132 | public final boolean pointsInSameDirection(Vector3 other) {
133 | return this.dot(other) > 0;
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/highlight/Highlight.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.highlight;
3 |
4 | /**
5 | * Contains information needed to determine the highlighted value.
6 | *
7 | * @author Philipp Jahoda
8 | */
9 | public class Highlight {
10 |
11 | /** the x-index of the highlighted value */
12 | private int mXIndex;
13 |
14 | /** the index of the dataset the highlighted value is in */
15 | private int mDataSetIndex;
16 |
17 | /** index which value of a stacked bar entry is highlighted, default -1 */
18 | private int mStackIndex = -1;
19 |
20 | /** the range of the bar that is selected (only for stacked-barchart) */
21 | private Range mRange;
22 |
23 | /**
24 | * constructor
25 | *
26 | * @param x the index of the highlighted value on the x-axis
27 | * @param dataSet the index of the DataSet the highlighted value belongs to
28 | */
29 | public Highlight(int x, int dataSet) {
30 | this.mXIndex = x;
31 | this.mDataSetIndex = dataSet;
32 | }
33 |
34 | /**
35 | * Constructor, only used for stacked-barchart.
36 | *
37 | * @param x the index of the highlighted value on the x-axis
38 | * @param dataSet the index of the DataSet the highlighted value belongs to
39 | * @param stackIndex references which value of a stacked-bar entry has been
40 | * selected
41 | */
42 | public Highlight(int x, int dataSet, int stackIndex) {
43 | this(x, dataSet);
44 | mStackIndex = stackIndex;
45 | }
46 |
47 | /**
48 | * Constructor, only used for stacked-barchart.
49 | *
50 | * @param x the index of the highlighted value on the x-axis
51 | * @param dataSet the index of the DataSet the highlighted value belongs to
52 | * @param stackIndex references which value of a stacked-bar entry has been
53 | * selected
54 | * @param range the range the selected stack-value is in
55 | */
56 | public Highlight(int x, int dataSet, int stackIndex, Range range) {
57 | this(x, dataSet, stackIndex);
58 | this.mRange = range;
59 | }
60 |
61 | /**
62 | * returns the index of the DataSet the highlighted value is in
63 | *
64 | * @return
65 | */
66 | public int getDataSetIndex() {
67 | return mDataSetIndex;
68 | }
69 |
70 | /**
71 | * returns the index of the highlighted value on the x-axis
72 | *
73 | * @return
74 | */
75 | public int getXIndex() {
76 | return mXIndex;
77 | }
78 |
79 | /**
80 | * Only needed if a stacked-barchart entry was highlighted. References the
81 | * selected value within the stacked-entry.
82 | *
83 | * @return
84 | */
85 | public int getStackIndex() {
86 | return mStackIndex;
87 | }
88 |
89 | /**
90 | * Returns the range of values the selected value of a stacked bar is in. (this is only relevant for stacked-barchart)
91 | * @return
92 | */
93 | public Range getRange() {
94 | return mRange;
95 | }
96 |
97 | /**
98 | * returns true if this highlight object is equal to the other (compares
99 | * xIndex and dataSetIndex)
100 | *
101 | * @param h
102 | * @return
103 | */
104 | public boolean equalTo(Highlight h) {
105 |
106 | if (h == null)
107 | return false;
108 | else {
109 | if (this.mDataSetIndex == h.mDataSetIndex && this.mXIndex == h.mXIndex
110 | && this.mStackIndex == h.mStackIndex)
111 | return true;
112 | else
113 | return false;
114 | }
115 | }
116 |
117 | @Override
118 | public String toString() {
119 | return "Highlight, xIndex: " + mXIndex + ", dataSetIndex: " + mDataSetIndex
120 | + ", stackIndex (only stacked barentry): " + mStackIndex;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/CandleEntry.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | /**
5 | * Subclass of Entry that holds all values for one entry in a CandleStickChart.
6 | *
7 | * @author Philipp Jahoda
8 | */
9 | public class CandleEntry extends Entry {
10 |
11 | /** shadow-high value */
12 | private float mShadowHigh = 0f;
13 |
14 | /** shadow-low value */
15 | private float mShadowLow = 0f;
16 |
17 | /** close value */
18 | private float mClose = 0f;
19 |
20 | /** open value */
21 | private float mOpen = 0f;
22 |
23 | /**
24 | * Constructor.
25 | *
26 | * @param xIndex The index on the x-axis.
27 | * @param shadowH The (shadow) high value.
28 | * @param shadowL The (shadow) low value.
29 | * @param open The open value.
30 | * @param close The close value.
31 | */
32 | public CandleEntry(int xIndex, float shadowH, float shadowL, float open, float close) {
33 | super((shadowH + shadowL) / 2f, xIndex);
34 |
35 | this.mShadowHigh = shadowH;
36 | this.mShadowLow = shadowL;
37 | this.mOpen = open;
38 | this.mClose = close;
39 | }
40 |
41 | /**
42 | * Constructor.
43 | *
44 | * @param xIndex The index on the x-axis.
45 | * @param shadowH The (shadow) high value.
46 | * @param shadowL The (shadow) low value.
47 | * @param open
48 | * @param close
49 | * @param data Spot for additional data this Entry represents.
50 | */
51 | public CandleEntry(int xIndex, float shadowH, float shadowL, float open, float close,
52 | Object data) {
53 | super((shadowH + shadowL) / 2f, xIndex, data);
54 |
55 | this.mShadowHigh = shadowH;
56 | this.mShadowLow = shadowL;
57 | this.mOpen = open;
58 | this.mClose = close;
59 | }
60 |
61 | /**
62 | * Returns the overall range (difference) between shadow-high and
63 | * shadow-low.
64 | *
65 | * @return
66 | */
67 | public float getShadowRange() {
68 | return Math.abs(mShadowHigh - mShadowLow);
69 | }
70 |
71 | /**
72 | * Returns the body size (difference between open and close).
73 | *
74 | * @return
75 | */
76 | public float getBodyRange() {
77 | return Math.abs(mOpen - mClose);
78 | }
79 |
80 | /**
81 | * Returns the center value of the candle. (Middle value between high and
82 | * low)
83 | */
84 | @Override
85 | public float getVal() {
86 | return super.getVal();
87 | }
88 |
89 | public CandleEntry copy() {
90 |
91 | CandleEntry c = new CandleEntry(getXIndex(), mShadowHigh, mShadowLow, mOpen,
92 | mClose, getData());
93 |
94 | return c;
95 | }
96 |
97 | /**
98 | * Returns the upper shadows highest value.
99 | *
100 | * @return
101 | */
102 | public float getHigh() {
103 | return mShadowHigh;
104 | }
105 |
106 | public void setHigh(float mShadowHigh) {
107 | this.mShadowHigh = mShadowHigh;
108 | }
109 |
110 | /**
111 | * Returns the lower shadows lowest value.
112 | *
113 | * @return
114 | */
115 | public float getLow() {
116 | return mShadowLow;
117 | }
118 |
119 | public void setLow(float mShadowLow) {
120 | this.mShadowLow = mShadowLow;
121 | }
122 |
123 | /**
124 | * Returns the bodys close value.
125 | *
126 | * @return
127 | */
128 | public float getClose() {
129 | return mClose;
130 | }
131 |
132 | public void setClose(float mClose) {
133 | this.mClose = mClose;
134 | }
135 |
136 | /**
137 | * Returns the bodys open value.
138 | *
139 | * @return
140 | */
141 | public float getOpen() {
142 | return mOpen;
143 | }
144 |
145 | public void setOpen(float mOpen) {
146 | this.mOpen = mOpen;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/LineScatterCandleRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
6 | import com.github.mikephil.charting.utils.Utils;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by Philipp Jahoda on 11/07/15.
12 | */
13 | public abstract class LineScatterCandleRadarDataSet extends BarLineScatterCandleBubbleDataSet implements ILineScatterCandleRadarDataSet {
14 |
15 | protected boolean mDrawVerticalHighlightIndicator = true;
16 | protected boolean mDrawHorizontalHighlightIndicator = true;
17 |
18 | /** the width of the highlight indicator lines */
19 | protected float mHighlightLineWidth = 0.5f;
20 |
21 | /** the path effect for dashed highlight-lines */
22 | protected DashPathEffect mHighlightDashPathEffect = null;
23 |
24 |
25 | public LineScatterCandleRadarDataSet(List yVals, String label) {
26 | super(yVals, label);
27 | mHighlightLineWidth = Utils.convertDpToPixel(0.5f);
28 | }
29 |
30 | /**
31 | * Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
32 | * @param enabled
33 | */
34 | public void setDrawHorizontalHighlightIndicator(boolean enabled) {
35 | this.mDrawHorizontalHighlightIndicator = enabled;
36 | }
37 |
38 | /**
39 | * Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
40 | * @param enabled
41 | */
42 | public void setDrawVerticalHighlightIndicator(boolean enabled) {
43 | this.mDrawVerticalHighlightIndicator = enabled;
44 | }
45 |
46 | /**
47 | * Enables / disables both vertical and horizontal highlight-indicators.
48 | * @param enabled
49 | */
50 | public void setDrawHighlightIndicators(boolean enabled) {
51 | setDrawVerticalHighlightIndicator(enabled);
52 | setDrawHorizontalHighlightIndicator(enabled);
53 | }
54 |
55 | @Override
56 | public boolean isVerticalHighlightIndicatorEnabled() {
57 | return mDrawVerticalHighlightIndicator;
58 | }
59 |
60 | @Override
61 | public boolean isHorizontalHighlightIndicatorEnabled() {
62 | return mDrawHorizontalHighlightIndicator;
63 | }
64 |
65 | /**
66 | * Sets the width of the highlight line in dp.
67 | * @param width
68 | */
69 | public void setHighlightLineWidth(float width) {
70 | mHighlightLineWidth = Utils.convertDpToPixel(width);
71 | }
72 |
73 | @Override
74 | public float getHighlightLineWidth() {
75 | return mHighlightLineWidth;
76 | }
77 |
78 | /**
79 | * Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -"
80 | *
81 | * @param lineLength the length of the line pieces
82 | * @param spaceLength the length of space inbetween the line-pieces
83 | * @param phase offset, in degrees (normally, use 0)
84 | */
85 | public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) {
86 | mHighlightDashPathEffect = new DashPathEffect(new float[] {
87 | lineLength, spaceLength
88 | }, phase);
89 | }
90 |
91 | /**
92 | * Disables the highlight-line to be drawn in dashed mode.
93 | */
94 | public void disableDashedHighlightLine() {
95 | mHighlightDashPathEffect = null;
96 | }
97 |
98 | /**
99 | * Returns true if the dashed-line effect is enabled for highlight lines, false if not.
100 | * Default: disabled
101 | *
102 | * @return
103 | */
104 | public boolean isDashedHighlightLineEnabled() {
105 | return mHighlightDashPathEffect == null ? false : true;
106 | }
107 |
108 | @Override
109 | public DashPathEffect getDashPathEffectHighlight() {
110 | return mHighlightDashPathEffect;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/ScatterDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import com.github.mikephil.charting.charts.ScatterChart.ScatterShape;
5 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
6 | import com.github.mikephil.charting.utils.ColorTemplate;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | public class ScatterDataSet extends LineScatterCandleRadarDataSet implements IScatterDataSet {
12 |
13 | /**
14 | * the size the scattershape will have, in density pixels
15 | */
16 | private float mShapeSize = 15f;
17 |
18 | /**
19 | * the type of shape that is set to be drawn where the values are at,
20 | * default ScatterShape.SQUARE
21 | */
22 | private ScatterShape mScatterShape = ScatterShape.SQUARE;
23 |
24 | /**
25 | * The radius of the hole in the shape (applies to Square, Circle and Triangle)
26 | * - default: 0.0
27 | */
28 | private float mScatterShapeHoleRadius = 0f;
29 |
30 | /**
31 | * Color for the hole in the shape.
32 | * Setting to `ColorTemplate.COLOR_NONE` will behave as transparent.
33 | * - default: ColorTemplate.COLOR_NONE
34 | */
35 | private int mScatterShapeHoleColor = ColorTemplate.COLOR_NONE;
36 |
37 | /**
38 | * Custom path object the user can provide that is drawn where the values
39 | * are at. This is used when ScatterShape.CUSTOM is set for a DataSet.
40 | */
41 | //private Path mCustomScatterPath = null;
42 | public ScatterDataSet(List yVals, String label) {
43 | super(yVals, label);
44 | }
45 |
46 | @Override
47 | public DataSet copy() {
48 |
49 | List yVals = new ArrayList();
50 |
51 | for (int i = 0; i < mYVals.size(); i++) {
52 | yVals.add(mYVals.get(i).copy());
53 | }
54 |
55 | ScatterDataSet copied = new ScatterDataSet(yVals, getLabel());
56 | copied.mColors = mColors;
57 | copied.mShapeSize = mShapeSize;
58 | copied.mScatterShape = mScatterShape;
59 | copied.mScatterShapeHoleRadius = mScatterShapeHoleRadius;
60 | copied.mScatterShapeHoleColor = mScatterShapeHoleColor;
61 | //copied.mCustomScatterPath = mCustomScatterPath;
62 | copied.mHighLightColor = mHighLightColor;
63 |
64 | return copied;
65 | }
66 |
67 | /**
68 | * Sets the size in density pixels the drawn scattershape will have. This
69 | * only applies for non custom shapes.
70 | *
71 | * @param size
72 | */
73 | public void setScatterShapeSize(float size) {
74 | mShapeSize = size;
75 | }
76 |
77 | @Override
78 | public float getScatterShapeSize() {
79 | return mShapeSize;
80 | }
81 |
82 | /**
83 | * Sets the shape that is drawn on the position where the values are at.
84 | *
85 | * @param shape
86 | */
87 | public void setScatterShape(ScatterShape shape) {
88 | mScatterShape = shape;
89 | }
90 |
91 | @Override
92 | public ScatterShape getScatterShape() {
93 | return mScatterShape;
94 | }
95 |
96 | /**
97 | * Sets the radius of the hole in the shape (applies to Square, Circle and Triangle)
98 | * Set this to <= 0 to remove holes.
99 | *
100 | * @param holeRadius
101 | */
102 | public void setScatterShapeHoleRadius(float holeRadius) {
103 | mScatterShapeHoleRadius = holeRadius;
104 | }
105 |
106 | @Override
107 | public float getScatterShapeHoleRadius() {
108 | return mScatterShapeHoleRadius;
109 | }
110 |
111 | /**
112 | * Sets the color for the hole in the shape.
113 | *
114 | * @param holeColor
115 | */
116 | public void setScatterShapeHoleColor(int holeColor) {
117 | mScatterShapeHoleColor = holeColor;
118 | }
119 |
120 | @Override
121 | public int getScatterShapeHoleColor() {
122 | return mScatterShapeHoleColor;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/RadarDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import android.graphics.Color;
5 |
6 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
7 | import com.github.mikephil.charting.utils.ColorTemplate;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class RadarDataSet extends LineRadarDataSet implements IRadarDataSet {
13 |
14 | /// flag indicating whether highlight circle should be drawn or not
15 | protected boolean mDrawHighlightCircleEnabled = false;
16 |
17 | protected int mHighlightCircleFillColor = Color.WHITE;
18 |
19 | /// The stroke color for highlight circle.
20 | /// If Utils.COLOR_NONE, the color of the dataset is taken.
21 | protected int mHighlightCircleStrokeColor = ColorTemplate.COLOR_NONE;
22 |
23 | protected int mHighlightCircleStrokeAlpha = (int)(0.3 * 255);
24 | protected float mHighlightCircleInnerRadius = 3.0f;
25 | protected float mHighlightCircleOuterRadius = 4.0f;
26 | protected float mHighlightCircleStrokeWidth = 2.0f;
27 |
28 | public RadarDataSet(List yVals, String label) {
29 | super(yVals, label);
30 | }
31 |
32 | /// Returns true if highlight circle should be drawn, false if not
33 | @Override
34 | public boolean isDrawHighlightCircleEnabled()
35 | {
36 | return mDrawHighlightCircleEnabled;
37 | }
38 |
39 | /// Sets whether highlight circle should be drawn or not
40 | @Override
41 | public void setDrawHighlightCircleEnabled(boolean enabled)
42 | {
43 | mDrawHighlightCircleEnabled = enabled;
44 | }
45 |
46 | @Override
47 | public int getHighlightCircleFillColor()
48 | {
49 | return mHighlightCircleFillColor;
50 | }
51 |
52 | public void setHighlightCircleFillColor(int color)
53 | {
54 | mHighlightCircleFillColor = color;
55 | }
56 |
57 | /// Returns the stroke color for highlight circle.
58 | /// If Utils.COLOR_NONE, the color of the dataset is taken.
59 | @Override
60 | public int getHighlightCircleStrokeColor()
61 | {
62 | return mHighlightCircleStrokeColor;
63 | }
64 |
65 | /// Sets the stroke color for highlight circle.
66 | /// Set to Utils.COLOR_NONE in order to use the color of the dataset;
67 | public void setHighlightCircleStrokeColor(int color)
68 | {
69 | mHighlightCircleStrokeColor = color;
70 | }
71 |
72 | @Override
73 | public int getHighlightCircleStrokeAlpha()
74 | {
75 | return mHighlightCircleStrokeAlpha;
76 | }
77 |
78 | public void setHighlightCircleStrokeAlpha(int alpha)
79 | {
80 | mHighlightCircleStrokeAlpha = alpha;
81 | }
82 |
83 | @Override
84 | public float getHighlightCircleInnerRadius()
85 | {
86 | return mHighlightCircleInnerRadius;
87 | }
88 |
89 | public void setHighlightCircleInnerRadius(float radius)
90 | {
91 | mHighlightCircleInnerRadius = radius;
92 | }
93 |
94 | @Override
95 | public float getHighlightCircleOuterRadius()
96 | {
97 | return mHighlightCircleOuterRadius;
98 | }
99 |
100 | public void setHighlightCircleOuterRadius(float radius)
101 | {
102 | mHighlightCircleOuterRadius = radius;
103 | }
104 |
105 | @Override
106 | public float getHighlightCircleStrokeWidth()
107 | {
108 | return mHighlightCircleStrokeWidth;
109 | }
110 |
111 | public void setHighlightCircleStrokeWidth(float strokeWidth)
112 | {
113 | mHighlightCircleStrokeWidth = strokeWidth;
114 | }
115 |
116 | @Override
117 | public DataSet copy() {
118 |
119 | List yVals = new ArrayList();
120 |
121 | for (int i = 0; i < mYVals.size(); i++) {
122 | yVals.add(mYVals.get(i).copy());
123 | }
124 |
125 | RadarDataSet copied = new RadarDataSet(yVals, getLabel());
126 | copied.mColors = mColors;
127 | copied.mHighLightColor = mHighLightColor;
128 |
129 | return copied;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/utils/ColorTemplate.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.utils;
3 |
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * Class that holds predefined color integer arrays (e.g.
12 | * ColorTemplate.VORDIPLOM_COLORS) and convenience methods for loading colors
13 | * from resources.
14 | *
15 | * @author Philipp Jahoda
16 | */
17 | public class ColorTemplate {
18 |
19 | /**
20 | * an "invalid" color that indicates that no color is set
21 | */
22 | public static final int COLOR_NONE = 0x00112233;
23 |
24 | /**
25 | * this "color" is used for the Legend creation and indicates that the next
26 | * form should be skipped
27 | */
28 | public static final int COLOR_SKIP = 0x00112234;
29 |
30 | /**
31 | * THE COLOR THEMES ARE PREDEFINED (predefined color integer arrays), FEEL
32 | * FREE TO CREATE YOUR OWN WITH AS MANY DIFFERENT COLORS AS YOU WANT
33 | */
34 | public static final int[] LIBERTY_COLORS = {
35 | Color.rgb(207, 248, 246), Color.rgb(148, 212, 212), Color.rgb(136, 180, 187),
36 | Color.rgb(118, 174, 175), Color.rgb(42, 109, 130)
37 | };
38 | public static final int[] JOYFUL_COLORS = {
39 | Color.rgb(217, 80, 138), Color.rgb(254, 149, 7), Color.rgb(254, 247, 120),
40 | Color.rgb(106, 167, 134), Color.rgb(53, 194, 209)
41 | };
42 | public static final int[] PASTEL_COLORS = {
43 | Color.rgb(64, 89, 128), Color.rgb(149, 165, 124), Color.rgb(217, 184, 162),
44 | Color.rgb(191, 134, 134), Color.rgb(179, 48, 80)
45 | };
46 | public static final int[] COLORFUL_COLORS = {
47 | Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0),
48 | Color.rgb(106, 150, 31), Color.rgb(179, 100, 53)
49 | };
50 | public static final int[] VORDIPLOM_COLORS = {
51 | Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140),
52 | Color.rgb(140, 234, 255), Color.rgb(255, 140, 157)
53 | };
54 | public static final int[] MATERIAL_COLORS = {
55 | rgb("#2ecc71"), rgb("#f1c40f"), rgb("#e74c3c"), rgb("#3498db")
56 | };
57 |
58 | /**
59 | * Converts the given hex-color-string to rgb.
60 | *
61 | * @param hex
62 | * @return
63 | */
64 | public static int rgb(String hex) {
65 | int color = (int) Long.parseLong(hex.replace("#", ""), 16);
66 | int r = (color >> 16) & 0xFF;
67 | int g = (color >> 8) & 0xFF;
68 | int b = (color >> 0) & 0xFF;
69 | return Color.rgb(r, g, b);
70 | }
71 |
72 | /**
73 | * Returns the Android ICS holo blue light color.
74 | *
75 | * @return
76 | */
77 | public static int getHoloBlue() {
78 | return Color.rgb(51, 181, 229);
79 | }
80 |
81 | public static int getColorWithAlphaComponent(int color, int alpha) {
82 | return (color & 0xffffff) | ((alpha & 0xff) << 24);
83 | }
84 |
85 | /**
86 | * turn an array of resource-colors (contains resource-id integers) into an
87 | * array list of actual color integers
88 | *
89 | * @param r
90 | * @param colors an integer array of resource id's of colors
91 | * @return
92 | */
93 | public static List createColors(Resources r, int[] colors) {
94 |
95 | List result = new ArrayList();
96 |
97 | for (int i : colors) {
98 | result.add(r.getColor(i));
99 | }
100 |
101 | return result;
102 | }
103 |
104 | /**
105 | * Turns an array of colors (integer color values) into an ArrayList of
106 | * colors.
107 | *
108 | * @param colors
109 | * @return
110 | */
111 | public static List createColors(int[] colors) {
112 |
113 | List result = new ArrayList();
114 |
115 | for (int i : colors) {
116 | result.add(i);
117 | }
118 |
119 | return result;
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererBarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.renderer;
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.PointF;
6 |
7 | import com.github.mikephil.charting.charts.BarChart;
8 | import com.github.mikephil.charting.components.XAxis;
9 | import com.github.mikephil.charting.data.BarData;
10 | import com.github.mikephil.charting.utils.Transformer;
11 | import com.github.mikephil.charting.utils.Utils;
12 | import com.github.mikephil.charting.utils.ViewPortHandler;
13 |
14 | public class XAxisRendererBarChart extends XAxisRenderer {
15 |
16 | protected BarChart mChart;
17 |
18 | public XAxisRendererBarChart(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans,
19 | BarChart chart) {
20 | super(viewPortHandler, xAxis, trans);
21 |
22 | this.mChart = chart;
23 | }
24 |
25 | /**
26 | * draws the x-labels on the specified y-position
27 | *
28 | * @param pos
29 | */
30 | @Override
31 | protected void drawLabels(Canvas c, float pos, PointF anchor) {
32 |
33 | final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
34 |
35 | // pre allocate to save performance (dont allocate in loop)
36 | float[] position = new float[] {
37 | 0f, 0f
38 | };
39 |
40 | BarData bd = mChart.getData();
41 | int step = bd.getDataSetCount();
42 |
43 | for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
44 |
45 | position[0] = i * step + i * bd.getGroupSpace()
46 | + bd.getGroupSpace() / 2f;
47 |
48 | // consider groups (center label for each group)
49 | if (step > 1) {
50 | position[0] += ((float) step - 1f) / 2f;
51 | }
52 |
53 | mTrans.pointValuesToPixel(position);
54 |
55 | if (mViewPortHandler.isInBoundsX(position[0]) && i >= 0
56 | && i < mXAxis.getValues().size()) {
57 |
58 | String label = mXAxis.getValues().get(i);
59 |
60 | if (mXAxis.isAvoidFirstLastClippingEnabled()) {
61 |
62 | // avoid clipping of the last
63 | if (i == mXAxis.getValues().size() - 1) {
64 | float width = Utils.calcTextWidth(mAxisLabelPaint, label);
65 |
66 | if (position[0] + width / 2.f > mViewPortHandler.contentRight())
67 | position[0] = mViewPortHandler.contentRight() - (width / 2.f);
68 |
69 | // avoid clipping of the first
70 | } else if (i == 0) {
71 |
72 | float width = Utils.calcTextWidth(mAxisLabelPaint, label);
73 |
74 | if (position[0] - width / 2.f < mViewPortHandler.contentLeft())
75 | position[0] = mViewPortHandler.contentLeft() + (width / 2.f);
76 | }
77 | }
78 |
79 | drawLabel(c, label, i, position[0], pos, anchor, labelRotationAngleDegrees);
80 | }
81 | }
82 | }
83 |
84 | @Override
85 | public void renderGridLines(Canvas c) {
86 |
87 | if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
88 | return;
89 |
90 | float[] position = new float[] {
91 | 0f, 0f
92 | };
93 |
94 | mGridPaint.setColor(mXAxis.getGridColor());
95 | mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
96 |
97 | BarData bd = mChart.getData();
98 | int step = bd.getDataSetCount();
99 |
100 | for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {
101 |
102 | position[0] = i * step + i * bd.getGroupSpace() - 0.5f;
103 |
104 | mTrans.pointValuesToPixel(position);
105 |
106 | if (mViewPortHandler.isInBoundsX(position[0])) {
107 |
108 | c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
109 | mViewPortHandler.contentBottom(), mGridPaint);
110 | }
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/BubbleDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data;
3 |
4 | import android.graphics.Color;
5 |
6 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
7 | import com.github.mikephil.charting.utils.Utils;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet implements IBubbleDataSet {
13 |
14 | // NOTE: Do not initialize these, as the calculate is called by the super,
15 | // and the initializers are called after that and can reset the values
16 | protected float mXMax;
17 | protected float mXMin;
18 | protected float mMaxSize;
19 | protected boolean mNormalizeSize = true;
20 |
21 | private float mHighlightCircleWidth = 2.5f;
22 |
23 | public BubbleDataSet(List yVals, String label) {
24 | super(yVals, label);
25 | }
26 |
27 | @Override
28 | public void setHighlightCircleWidth(float width) {
29 | mHighlightCircleWidth = Utils.convertDpToPixel(width);
30 | }
31 |
32 | @Override
33 | public float getHighlightCircleWidth() {
34 | return mHighlightCircleWidth;
35 | }
36 |
37 | @Override
38 | public void calcMinMax(int start, int end) {
39 |
40 | if (mYVals == null)
41 | return;
42 |
43 | if (mYVals.size() == 0)
44 | return;
45 |
46 | int endValue;
47 |
48 | if (end == 0 || end >= mYVals.size())
49 | endValue = mYVals.size() - 1;
50 | else
51 | endValue = end;
52 |
53 | mYMin = yMin(mYVals.get(start));
54 | mYMax = yMax(mYVals.get(start));
55 |
56 | // need chart width to guess this properly
57 |
58 | for (int i = start; i <= endValue; i++) {
59 |
60 | final BubbleEntry entry = mYVals.get(i);
61 |
62 | float ymin = yMin(entry);
63 | float ymax = yMax(entry);
64 |
65 | if (ymin < mYMin) {
66 | mYMin = ymin;
67 | }
68 |
69 | if (ymax > mYMax) {
70 | mYMax = ymax;
71 | }
72 |
73 | final float xmin = xMin(entry);
74 | final float xmax = xMax(entry);
75 |
76 | if (xmin < mXMin) {
77 | mXMin = xmin;
78 | }
79 |
80 | if (xmax > mXMax) {
81 | mXMax = xmax;
82 | }
83 |
84 | final float size = largestSize(entry);
85 |
86 | if (size > mMaxSize) {
87 | mMaxSize = size;
88 | }
89 | }
90 | }
91 |
92 | @Override
93 | public DataSet copy() {
94 |
95 | List yVals = new ArrayList();
96 |
97 | for (int i = 0; i < mYVals.size(); i++) {
98 | yVals.add(mYVals.get(i).copy());
99 | }
100 |
101 | BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
102 | copied.mColors = mColors;
103 | copied.mHighLightColor = mHighLightColor;
104 |
105 | return copied;
106 | }
107 |
108 | @Override
109 | public float getXMax() {
110 | return mXMax;
111 | }
112 |
113 | @Override
114 | public float getXMin() {
115 | return mXMin;
116 | }
117 |
118 | @Override
119 | public float getMaxSize() {
120 | return mMaxSize;
121 | }
122 |
123 | @Override
124 | public boolean isNormalizeSizeEnabled() {
125 | return mNormalizeSize;
126 | }
127 |
128 | public void setNormalizeSizeEnabled(boolean normalizeSize) {
129 | mNormalizeSize = normalizeSize;
130 | }
131 |
132 | private float yMin(BubbleEntry entry) {
133 | return entry.getVal();
134 | }
135 |
136 | private float yMax(BubbleEntry entry) {
137 | return entry.getVal();
138 | }
139 |
140 | private float xMin(BubbleEntry entry) {
141 | return (float) entry.getXIndex();
142 | }
143 |
144 | private float xMax(BubbleEntry entry) {
145 | return (float) entry.getXIndex();
146 | }
147 |
148 | private float largestSize(BubbleEntry entry) {
149 | return entry.getSize();
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/listener/ChartTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.listener;
2 |
3 | import android.view.GestureDetector;
4 | import android.view.MotionEvent;
5 | import android.view.View;
6 |
7 | import com.github.mikephil.charting.charts.Chart;
8 | import com.github.mikephil.charting.highlight.Highlight;
9 |
10 | /**
11 | * Created by philipp on 12/06/15.
12 | */
13 | public abstract class ChartTouchListener> extends GestureDetector.SimpleOnGestureListener implements View.OnTouchListener {
14 |
15 | public enum ChartGesture {
16 | NONE, DRAG, X_ZOOM, Y_ZOOM, PINCH_ZOOM, ROTATE, SINGLE_TAP, DOUBLE_TAP, LONG_PRESS, FLING
17 | }
18 |
19 | /**
20 | * the last touch gesture that has been performed
21 | **/
22 | protected ChartGesture mLastGesture = ChartGesture.NONE;
23 |
24 | // states
25 | protected static final int NONE = 0;
26 | protected static final int DRAG = 1;
27 | protected static final int X_ZOOM = 2;
28 | protected static final int Y_ZOOM = 3;
29 | protected static final int PINCH_ZOOM = 4;
30 | protected static final int POST_ZOOM = 5;
31 | protected static final int ROTATE = 6;
32 |
33 | /**
34 | * integer field that holds the current touch-state
35 | */
36 | protected int mTouchMode = NONE;
37 |
38 | /**
39 | * the last highlighted object (via touch)
40 | */
41 | protected Highlight mLastHighlighted;
42 |
43 | /**
44 | * the gesturedetector used for detecting taps and longpresses, ...
45 | */
46 | protected GestureDetector mGestureDetector;
47 |
48 | /**
49 | * the chart the listener represents
50 | */
51 | protected T mChart;
52 |
53 | public ChartTouchListener(T chart) {
54 | this.mChart = chart;
55 |
56 | mGestureDetector = new GestureDetector(chart.getContext(), this);
57 | }
58 |
59 | /**
60 | * Calls the OnChartGestureListener to do the start callback
61 | *
62 | * @param me
63 | */
64 | public void startAction(MotionEvent me) {
65 |
66 | OnChartGestureListener l = mChart.getOnChartGestureListener();
67 |
68 | if (l != null)
69 | l.onChartGestureStart(me, mLastGesture);
70 | }
71 |
72 | /**
73 | * Calls the OnChartGestureListener to do the end callback
74 | *
75 | * @param me
76 | */
77 | public void endAction(MotionEvent me) {
78 |
79 | OnChartGestureListener l = mChart.getOnChartGestureListener();
80 |
81 | if (l != null)
82 | l.onChartGestureEnd(me, mLastGesture);
83 | }
84 |
85 | /**
86 | * Sets the last value that was highlighted via touch.
87 | *
88 | * @param high
89 | */
90 | public void setLastHighlighted(Highlight high) {
91 | mLastHighlighted = high;
92 | }
93 |
94 | /**
95 | * returns the touch mode the listener is currently in
96 | *
97 | * @return
98 | */
99 | public int getTouchMode() {
100 | return mTouchMode;
101 | }
102 |
103 | /**
104 | * Returns the last gesture that has been performed on the chart.
105 | *
106 | * @return
107 | */
108 | public ChartGesture getLastGesture() {
109 | return mLastGesture;
110 | }
111 |
112 |
113 | /**
114 | * Perform a highlight operation.
115 | *
116 | * @param e
117 | */
118 | protected void performHighlight(Highlight h, MotionEvent e) {
119 |
120 | if (h == null || h.equalTo(mLastHighlighted)) {
121 | mChart.highlightTouch(null);
122 | mLastHighlighted = null;
123 | } else {
124 | mLastHighlighted = h;
125 | mChart.highlightTouch(h);
126 | }
127 | }
128 |
129 | /**
130 | * returns the distance between two points
131 | *
132 | * @param eventX
133 | * @param startX
134 | * @param eventY
135 | * @param startY
136 | * @return
137 | */
138 | protected static float distance(float eventX, float startX, float eventY, float startY) {
139 | float dx = eventX - startX;
140 | float dy = eventY - startY;
141 | return (float) Math.sqrt(dx * dx + dy * dy);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmLineScatterCandleRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.data.realm.base;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.github.mikephil.charting.data.Entry;
6 | import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet;
7 | import com.github.mikephil.charting.utils.Utils;
8 |
9 | import io.realm.RealmObject;
10 | import io.realm.RealmResults;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 08/11/15.
14 | */
15 | public abstract class RealmLineScatterCandleRadarDataSet extends RealmBarLineScatterCandleBubbleDataSet implements ILineScatterCandleRadarDataSet {
16 |
17 | protected boolean mDrawVerticalHighlightIndicator = true;
18 | protected boolean mDrawHorizontalHighlightIndicator = true;
19 |
20 | /** the width of the highlight indicator lines */
21 | protected float mHighlightLineWidth = 0.5f;
22 |
23 | /** the path effect for dashed highlight-lines */
24 | protected DashPathEffect mHighlightDashPathEffect = null;
25 |
26 |
27 | public RealmLineScatterCandleRadarDataSet(RealmResults results, String yValuesField) {
28 | super(results, yValuesField);
29 | }
30 |
31 | /**
32 | * Constructor that takes the realm RealmResults, sorts & stores them.
33 | *
34 | * @param results
35 | * @param yValuesField
36 | * @param xIndexField
37 | */
38 | public RealmLineScatterCandleRadarDataSet(RealmResults results, String yValuesField, String xIndexField) {
39 | super(results, yValuesField, xIndexField);
40 | }
41 |
42 | /**
43 | * Enables / disables the horizontal highlight-indicator. If disabled, the indicator is not drawn.
44 | * @param enabled
45 | */
46 | public void setDrawHorizontalHighlightIndicator(boolean enabled) {
47 | this.mDrawHorizontalHighlightIndicator = enabled;
48 | }
49 |
50 | /**
51 | * Enables / disables the vertical highlight-indicator. If disabled, the indicator is not drawn.
52 | * @param enabled
53 | */
54 | public void setDrawVerticalHighlightIndicator(boolean enabled) {
55 | this.mDrawVerticalHighlightIndicator = enabled;
56 | }
57 |
58 | /**
59 | * Enables / disables both vertical and horizontal highlight-indicators.
60 | * @param enabled
61 | */
62 | public void setDrawHighlightIndicators(boolean enabled) {
63 | setDrawVerticalHighlightIndicator(enabled);
64 | setDrawHorizontalHighlightIndicator(enabled);
65 | }
66 |
67 | @Override
68 | public boolean isVerticalHighlightIndicatorEnabled() {
69 | return mDrawVerticalHighlightIndicator;
70 | }
71 |
72 | @Override
73 | public boolean isHorizontalHighlightIndicatorEnabled() {
74 | return mDrawHorizontalHighlightIndicator;
75 | }
76 |
77 | /**
78 | * Sets the width of the highlight line in dp.
79 | * @param width
80 | */
81 | public void setHighlightLineWidth(float width) {
82 | mHighlightLineWidth = Utils.convertDpToPixel(width);
83 | }
84 |
85 | @Override
86 | public float getHighlightLineWidth() {
87 | return mHighlightLineWidth;
88 | }
89 |
90 | /**
91 | * Enables the highlight-line to be drawn in dashed mode, e.g. like this "- - - - - -"
92 | *
93 | * @param lineLength the length of the line pieces
94 | * @param spaceLength the length of space inbetween the line-pieces
95 | * @param phase offset, in degrees (normally, use 0)
96 | */
97 | public void enableDashedHighlightLine(float lineLength, float spaceLength, float phase) {
98 | mHighlightDashPathEffect = new DashPathEffect(new float[] {
99 | lineLength, spaceLength
100 | }, phase);
101 | }
102 |
103 | /**
104 | * Disables the highlight-line to be drawn in dashed mode.
105 | */
106 | public void disableDashedHighlightLine() {
107 | mHighlightDashPathEffect = null;
108 | }
109 |
110 | /**
111 | * Returns true if the dashed-line effect is enabled for highlight lines, false if not.
112 | * Default: disabled
113 | *
114 | * @return
115 | */
116 | public boolean isDashedHighlightLineEnabled() {
117 | return mHighlightDashPathEffect == null ? false : true;
118 | }
119 |
120 | @Override
121 | public DashPathEffect getDashPathEffectHighlight() {
122 | return mHighlightDashPathEffect;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/MPChartLib/src/com/github/mikephil/charting/buffer/BarBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.buffer;
3 |
4 | import com.github.mikephil.charting.data.BarEntry;
5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
6 |
7 | public class BarBuffer extends AbstractBuffer {
8 |
9 | protected float mBarSpace = 0f;
10 | protected float mGroupSpace = 0f;
11 | protected int mDataSetIndex = 0;
12 | protected int mDataSetCount = 1;
13 | protected boolean mContainsStacks = false;
14 | protected boolean mInverted = false;
15 |
16 | public BarBuffer(int size, float groupspace, int dataSetCount, boolean containsStacks) {
17 | super(size);
18 | this.mGroupSpace = groupspace;
19 | this.mDataSetCount = dataSetCount;
20 | this.mContainsStacks = containsStacks;
21 | }
22 |
23 | public void setBarSpace(float barspace) {
24 | this.mBarSpace = barspace;
25 | }
26 |
27 | public void setDataSet(int index) {
28 | this.mDataSetIndex = index;
29 | }
30 |
31 | public void setInverted(boolean inverted) {
32 | this.mInverted = inverted;
33 | }
34 |
35 | protected void addBar(float left, float top, float right, float bottom) {
36 |
37 | buffer[index++] = left;
38 | buffer[index++] = top;
39 | buffer[index++] = right;
40 | buffer[index++] = bottom;
41 | }
42 |
43 | @Override
44 | public void feed(IBarDataSet data) {
45 |
46 | float size = data.getEntryCount() * phaseX;
47 |
48 | int dataSetOffset = (mDataSetCount - 1);
49 | float barSpaceHalf = mBarSpace / 2f;
50 | float groupSpaceHalf = mGroupSpace / 2f;
51 | float barWidth = 0.5f;
52 |
53 | for (int i = 0; i < size; i++) {
54 |
55 | BarEntry e = data.getEntryForIndex(i);
56 |
57 | // calculate the x-position, depending on datasetcount
58 | float x = e.getXIndex() + e.getXIndex() * dataSetOffset + mDataSetIndex
59 | + mGroupSpace * e.getXIndex() + groupSpaceHalf;
60 | float y = e.getVal();
61 | float [] vals = e.getVals();
62 |
63 | if (!mContainsStacks || vals == null) {
64 |
65 | float left = x - barWidth + barSpaceHalf;
66 | float right = x + barWidth - barSpaceHalf;
67 | float bottom, top;
68 | if (mInverted) {
69 | bottom = y >= 0 ? y : 0;
70 | top = y <= 0 ? y : 0;
71 | } else {
72 | top = y >= 0 ? y : 0;
73 | bottom = y <= 0 ? y : 0;
74 | }
75 |
76 | // multiply the height of the rect with the phase
77 | if (top > 0)
78 | top *= phaseY;
79 | else
80 | bottom *= phaseY;
81 |
82 | addBar(left, top, right, bottom);
83 |
84 | } else {
85 |
86 | float posY = 0f;
87 | float negY = -e.getNegativeSum();
88 | float yStart = 0f;
89 |
90 | // fill the stack
91 | for (int k = 0; k < vals.length; k++) {
92 |
93 | float value = vals[k];
94 |
95 | if(value >= 0f) {
96 | y = posY;
97 | yStart = posY + value;
98 | posY = yStart;
99 | } else {
100 | y = negY;
101 | yStart = negY + Math.abs(value);
102 | negY += Math.abs(value);
103 | }
104 |
105 | float left = x - barWidth + barSpaceHalf;
106 | float right = x + barWidth - barSpaceHalf;
107 | float bottom, top;
108 | if (mInverted) {
109 | bottom = y >= yStart ? y : yStart;
110 | top = y <= yStart ? y : yStart;
111 | } else {
112 | top = y >= yStart ? y : yStart;
113 | bottom = y <= yStart ? y : yStart;
114 | }
115 |
116 | // multiply the height of the rect with the phase
117 | top *= phaseY;
118 | bottom *= phaseY;
119 |
120 | addBar(left, top, right, bottom);
121 | }
122 | }
123 | }
124 |
125 | reset();
126 | }
127 | }
128 |
--------------------------------------------------------------------------------