├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.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_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── pyz
│ │ │ │ └── retrofitdemo
│ │ │ │ ├── Constant.java
│ │ │ │ ├── bean
│ │ │ │ ├── WeatherInfo.java
│ │ │ │ ├── WeatherInfoReq.java
│ │ │ │ ├── DailyForecast.java
│ │ │ │ ├── Temperature.java
│ │ │ │ └── WeatherResult.java
│ │ │ │ ├── netrequest
│ │ │ │ └── NetRequest.java
│ │ │ │ ├── RetrofitWrapper.java
│ │ │ │ └── model
│ │ │ │ └── WeatherInfoModel.java
│ │ ├── AndroidManifest.xml
│ │ └── assets
│ │ │ └── MyEcharts
│ │ │ └── myEcharts.html
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── pyz
│ │ │ └── retrofitdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── pyz
│ │ └── retrofitdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── libraries
│ ├── junit_4_12.xml
│ ├── gson_2_4.xml
│ ├── support_annotations_23_3_0.xml
│ ├── okio_1_6_0.xml
│ ├── rxjava_1_1_1.xml
│ ├── okhttp_3_2_0.xml
│ ├── hamcrest_core_1_3.xml
│ ├── retrofit_2_0_1.xml
│ ├── realm_android_0_87_5.xml
│ ├── adapter_rxjava_2_0_1.xml
│ ├── logger_1_11.xml
│ ├── rxandroid_1_1_0.xml
│ ├── converter_gson_2_0_0_beta4.xml
│ ├── support_vector_drawable_23_3_0.xml
│ ├── animated_vector_drawable_23_3_0.xml
│ ├── appcompat_v7_23_3_0.xml
│ └── support_v4_23_3_0.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── JNChartLib
├── .gitignore
├── ic_launcher-web.png
├── .settings
│ └── gradle
│ │ └── org.springsource.ide.eclipse.gradle.core.prefs
├── src
│ └── com
│ │ └── jn
│ │ └── chart
│ │ ├── interfaces
│ │ ├── dataprovider
│ │ │ ├── BubbleDataProvider.java
│ │ │ ├── CandleDataProvider.java
│ │ │ ├── LineDataProvider.java
│ │ │ ├── BarDataProvider.java
│ │ │ ├── BarLineScatterCandleBubbleDataProvider.java
│ │ │ ├── ScatterDataProvider.java
│ │ │ └── ChartInterface.java
│ │ └── datasets
│ │ │ ├── IBarLineScatterCandleBubbleDataSet.java
│ │ │ ├── IBubbleDataSet.java
│ │ │ ├── IScatterDataSet.java
│ │ │ ├── IRadarDataSet.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
│ │ ├── utils
│ │ ├── EntryXIndexComparator.java
│ │ ├── PointD.java
│ │ ├── FSize.java
│ │ ├── SelectionDetail.java
│ │ └── TransformerHorizontalBarChart.java
│ │ ├── data
│ │ ├── realm
│ │ │ ├── implementation
│ │ │ │ ├── RealmPieData.java
│ │ │ │ ├── RealmBarData.java
│ │ │ │ ├── RealmLineData.java
│ │ │ │ ├── RealmRadarData.java
│ │ │ │ ├── RealmBubbleData.java
│ │ │ │ ├── RealmCandleData.java
│ │ │ │ └── RealmScatterData.java
│ │ │ └── base
│ │ │ │ ├── RealmUtils.java
│ │ │ │ ├── RealmBarLineScatterCandleBubbleDataSet.java
│ │ │ │ └── RealmLineRadarDataSet.java
│ │ ├── BarLineScatterCandleBubbleData.java
│ │ ├── BarLineScatterCandleBubbleDataSet.java
│ │ ├── CandleData.java
│ │ ├── RadarData.java
│ │ ├── LineData.java
│ │ ├── BubbleData.java
│ │ ├── BubbleEntry.java
│ │ ├── ScatterData.java
│ │ ├── PieData.java
│ │ ├── BarData.java
│ │ ├── LineRadarDataSet.java
│ │ ├── CandleEntry.java
│ │ └── LineScatterCandleRadarDataSet.java
│ │ ├── jobs
│ │ ├── MoveViewJob.java
│ │ ├── AnimatedMoveViewJob.java
│ │ ├── ViewPortJob.java
│ │ ├── AnimatedViewPortJob.java
│ │ ├── ZoomJob.java
│ │ └── AnimatedZoomJob.java
│ │ ├── manager
│ │ ├── MyYValueFormatter.java
│ │ ├── MyValueFormatter.java
│ │ ├── MyMakerView.java
│ │ └── BarChartManager.java
│ │ ├── buffer
│ │ ├── ScatterBuffer.java
│ │ ├── AbstractBuffer.java
│ │ └── HorizontalBarBuffer.java
│ │ ├── renderer
│ │ ├── scatter
│ │ │ ├── ShapeRenderer.java
│ │ │ ├── CrossShapeRenderer.java
│ │ │ ├── ChevronUpShapeRenderer.java
│ │ │ ├── XShapeRenderer.java
│ │ │ ├── ChevronDownShapeRenderer.java
│ │ │ ├── CircleShapeRenderer.java
│ │ │ ├── SquareShapeRenderer.java
│ │ │ └── TriangleShapeRenderer.java
│ │ ├── Renderer.java
│ │ ├── XAxisRendererRadarChart.java
│ │ ├── LineScatterCandleRadarRenderer.java
│ │ ├── LineRadarRenderer.java
│ │ ├── AxisRenderer.java
│ │ └── XAxisRendererBarChart.java
│ │ ├── highlight
│ │ ├── Range.java
│ │ ├── CombinedHighlighter.java
│ │ └── HorizontalBarHighlighter.java
│ │ ├── charts
│ │ ├── CandleStickChart.java
│ │ ├── LineChart.java
│ │ └── BubbleChart.java
│ │ ├── components
│ │ └── MarkerView.java
│ │ └── matrix
│ │ └── Vector3.java
├── AndroidManifest.xml
├── project.properties
├── proguard-project.txt
├── build.gradle
└── pom.xml
├── settings.gradle
├── rxjava-essentials-cn.pdf
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
└── gradlew.bat
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Retrofit-RxJavaDemo
--------------------------------------------------------------------------------
/JNChartLib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':JNChartLib'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RetrofitDemo
3 |
4 |
--------------------------------------------------------------------------------
/rxjava-essentials-cn.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/rxjava-essentials-cn.pdf
--------------------------------------------------------------------------------
/JNChartLib/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/JNChartLib/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/panyz/Retrofit-RxJava-MPAndroidChart/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/JNChartLib/.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/BubbleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.data.BubbleData;
4 |
5 | public interface BubbleDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | BubbleData getBubbleData();
8 | }
9 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/CandleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.data.CandleData;
4 |
5 | public interface CandleDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | CandleData getCandleData();
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/Constant.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo;
2 |
3 |
4 | public class Constant {
5 |
6 | public static final String BASE_URL = "http://apis.baidu.com";//服务器地址
7 | public static final String API_KEY = "2600907be4021f9979ecc9554a4065ac";//开发密钥
8 | public static final String CITY = "guangzhou";
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/LineDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.components.YAxis;
4 | import com.jn.chart.data.LineData;
5 |
6 | public interface LineDataProvider extends BarLineScatterCandleBubbleDataProvider {
7 |
8 | LineData getLineData();
9 |
10 | YAxis getAxis(YAxis.AxisDependency dependency);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/ColorFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.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 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/pyz/retrofitdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo;
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 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/BarDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.data.BarData;
4 |
5 | public interface BarDataProvider extends BarLineScatterCandleBubbleDataProvider {
6 |
7 | BarData getBarData();
8 | boolean isDrawBarShadowEnabled();
9 | boolean isDrawValueAboveBarEnabled();
10 | boolean isDrawHighlightArrowEnabled();
11 | }
12 |
--------------------------------------------------------------------------------
/JNChartLib/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/pyz/retrofitdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo;
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 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/exception/DrawingDataSetNotCreatedException.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/animation/EasingFunction.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/listener/OnDrawLineChartTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/utils/EntryXIndexComparator.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.utils;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/gson_2_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/okio_1_6_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/rxjava_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/okhttp_3_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/utils/PointD.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/retrofit_2_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/realm_android_0_87_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/adapter_rxjava_2_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/logger_1_11.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/DefaultXAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/.idea/libraries/rxandroid_1_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/.idea/libraries/converter_gson_2_0_0_beta4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/bean/WeatherInfo.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.bean;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by pyz on 2016/5/4.
9 | */
10 | public class WeatherInfo {
11 | @SerializedName("HeWeather data service 3.0")
12 | public List HeWeatherDataList;
13 |
14 | public List getHeWeatherDataList() {
15 | return HeWeatherDataList;
16 | }
17 |
18 | public void setHeWeatherDataList(List heWeatherDataList) {
19 | HeWeatherDataList = heWeatherDataList;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmPieData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.PieData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/bean/WeatherInfoReq.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by pyz on 2016/5/4.
7 | */
8 | public class WeatherInfoReq implements Serializable {
9 |
10 | public String apiKey;
11 | public String city;
12 |
13 | public String getApiKey() {
14 | return apiKey;
15 | }
16 |
17 | public void setApiKey(String apiKey) {
18 | this.apiKey = apiKey;
19 | }
20 |
21 | public String getCity() {
22 | return city;
23 | }
24 |
25 | public void setCity(String city) {
26 | this.city = city;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/JNChartLib/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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/BarLineScatterCandleBubbleDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.components.YAxis.AxisDependency;
4 | import com.jn.chart.data.BarLineScatterCandleBubbleData;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmBarData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.BarData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmLineData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.LineData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/bean/DailyForecast.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.bean;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Created by pyz on 2016/5/4.
7 | */
8 | public class DailyForecast {
9 | @SerializedName("date")
10 | public String date;
11 | @SerializedName("tmp")
12 | public Temperature tmp;
13 |
14 | public String getDate() {
15 | return date;
16 | }
17 |
18 | public void setDate(String date) {
19 | this.date = date;
20 | }
21 |
22 | public Temperature getTmp() {
23 | return tmp;
24 | }
25 |
26 | public void setTmp(Temperature tmp) {
27 | this.tmp = tmp;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmRadarData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.RadarData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/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 E:\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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/netrequest/NetRequest.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.netrequest;
2 |
3 | import com.pyz.retrofitdemo.bean.WeatherInfo;
4 |
5 | import retrofit2.Call;
6 | import retrofit2.http.GET;
7 | import retrofit2.http.Header;
8 | import retrofit2.http.Query;
9 | import rx.Observable;
10 |
11 | /**
12 | * Created by pyz on 2016/4/29.
13 | */
14 | public interface NetRequest {
15 |
16 | @GET("/heweather/weather/free?/")
17 | Call getWeather(@Header("apiKey")String apiKey, @Query("city")String city);
18 |
19 | @GET("/heweather/weather/free?/")
20 | Observable getWeatherByRxJava(@Header("apiKey")String apiKey, @Query("city")String city);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmBubbleData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.BubbleData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmCandleData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.CandleData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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/java/com/pyz/retrofitdemo/bean/Temperature.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.bean;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Created by pyz on 2016/5/4.
7 | */
8 | public class Temperature {
9 | @SerializedName("max")
10 | public String maxTem;
11 | @SerializedName("min")
12 | public String minTem;
13 |
14 | public String getMaxTem() {
15 | return maxTem;
16 | }
17 |
18 | public void setMaxTem(String maxTem) {
19 | this.maxTem = maxTem;
20 | }
21 |
22 | public String getMinTem() {
23 | return minTem;
24 | }
25 |
26 | public void setMinTem(String minTem) {
27 | this.minTem = minTem;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/implementation/RealmScatterData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.implementation;
2 |
3 | import com.jn.chart.data.ScatterData;
4 | import com.jn.chart.data.realm.base.RealmUtils;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/MoveViewJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.jobs;
3 |
4 | import android.view.View;
5 |
6 | import com.jn.chart.utils.Transformer;
7 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/manager/MyYValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.manager;
2 |
3 | import com.jn.chart.components.YAxis;
4 | import com.jn.chart.formatter.YAxisValueFormatter;
5 |
6 | import java.text.DecimalFormat;
7 |
8 | /**
9 | * @Author: pyz
10 | * @Package: com.pyz.retrofitdemo
11 | * @Description: TODO
12 | * @Project: Retrofit-RxJavaDemo
13 | * @Date: 2016/8/8 11:59
14 | */
15 | public class MyYValueFormatter implements YAxisValueFormatter {
16 | private DecimalFormat mFormat;
17 |
18 | public MyYValueFormatter(){
19 | mFormat = new DecimalFormat("###,###,###,##0");
20 | }
21 |
22 | @Override
23 | public String getFormattedValue(float value, YAxis yAxis) {
24 | return mFormat.format(value)+"℃";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/YAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/FillFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.interfaces.datasets.ILineDataSet;
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/buffer/ScatterBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.buffer;
3 |
4 | import com.jn.chart.data.Entry;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/bean/WeatherResult.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.bean;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Created by pyz on 2016/5/4.
9 | */
10 | public class WeatherResult {
11 |
12 | @SerializedName("status")
13 | public String status;
14 | @SerializedName("daily_forecast")
15 | public ArrayList daily_forecast;
16 |
17 | public String getStatus() {
18 | return status;
19 | }
20 |
21 | public void setStatus(String status) {
22 | this.status = status;
23 | }
24 |
25 | public ArrayList getDaily_forecast() {
26 | return daily_forecast;
27 | }
28 |
29 | public void setDaily_forecast(ArrayList daily_forecast) {
30 | this.daily_forecast = daily_forecast;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/ShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.ViewPortHandler;
9 |
10 | /**
11 | * Created by wajdic on 15/06/2016.
12 | * Created at Time 09:07
13 | */
14 | public interface ShapeRenderer {
15 |
16 | /**
17 | * Renders the provided ScatterDataSet with a shape.
18 | *
19 | * @param c
20 | * @param dataSet
21 | * @param viewPortHandler
22 | * @param buffer
23 | * @param renderPaint
24 | * @param shapeSize
25 | */
26 | void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, ScatterBuffer buffer, Paint
27 | renderPaint, final float shapeSize);
28 | }
29 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IScatterDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import com.jn.chart.data.Entry;
4 |
5 | /**
6 | * Created by philipp on 21/10/15.
7 | */
8 | public interface IScatterDataSet extends ILineScatterCandleRadarDataSet {
9 |
10 | /**
11 | * Returns the currently set scatter shape size
12 | *
13 | * @return
14 | */
15 | float getScatterShapeSize();
16 |
17 | /**
18 | * Returns all the different scattershapes the chart uses
19 | *
20 | * @return
21 | */
22 | String getScatterShape();
23 |
24 | /**
25 | * Returns radius of the hole in the shape
26 | *
27 | * @return
28 | */
29 | float getScatterShapeHoleRadius();
30 |
31 | /**
32 | * Returns the color for the hole in the shape
33 | *
34 | * @return
35 | */
36 | int getScatterShapeHoleColor();
37 | }
38 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/XAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/ScatterDataProvider.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import com.jn.chart.data.ScatterData;
4 | import com.jn.chart.renderer.scatter.ShapeRenderer;
5 |
6 | public interface ScatterDataProvider extends BarLineScatterCandleBubbleDataProvider {
7 |
8 | ScatterData getScatterData();
9 |
10 | /**
11 | * Adds a new ShapeRenderer and the shapeIdentifier it is responsible for drawing.
12 | * This shapeIdentifier should correspond to a DataSet with the same identifier.
13 | *
14 | * @param shapeRenderer
15 | * @param shapeIdentifier
16 | */
17 | void addShapeRenderer(ShapeRenderer shapeRenderer, String shapeIdentifier);
18 |
19 | /**
20 | * Returns the corresponding ShapeRenderer for the given identifier.
21 | *
22 | * @param shapeIdentifier
23 | * @return
24 | */
25 | ShapeRenderer getShapeRenderer(String shapeIdentifier);
26 | }
27 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/manager/MyValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.manager;
2 |
3 | import com.jn.chart.data.Entry;
4 | import com.jn.chart.formatter.ValueFormatter;
5 | import com.jn.chart.utils.ViewPortHandler;
6 |
7 | import java.text.DecimalFormat;
8 |
9 | /**
10 | * @Author: pyz
11 | * @Package: com.jn.chart.manager
12 | * @Description: TODO
13 | * @Project: Retrofit-RxJavaDemo
14 | * @Date: 2016/8/8 14:51
15 | */
16 | public class MyValueFormatter implements ValueFormatter {
17 | protected DecimalFormat mFormat;
18 |
19 | public MyValueFormatter() {
20 | mFormat = new DecimalFormat("###,###,##0");
21 | }
22 |
23 | public MyValueFormatter(DecimalFormat format) {
24 | this.mFormat = format;
25 | }
26 |
27 | @Override
28 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
29 | return mFormat.format(value) + " ℃";
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/highlight/Range.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/AnimatedMoveViewJob.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.jobs;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.view.View;
5 |
6 | import com.jn.chart.utils.Transformer;
7 | import com.jn.chart.utils.ViewPortHandler;
8 |
9 | /**
10 | * Created by Philipp Jahoda on 19/02/16.
11 | */
12 | public class AnimatedMoveViewJob extends AnimatedViewPortJob {
13 |
14 | public AnimatedMoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
15 | super(viewPortHandler, xValue, yValue, trans, v, xOrigin, yOrigin, duration);
16 | }
17 |
18 | @Override
19 | public void onAnimationUpdate(ValueAnimator animation) {
20 |
21 | pts[0] = xOrigin + (xValue - xOrigin) * phase;
22 | pts[1] = yOrigin + (yValue - yOrigin) * phase;
23 |
24 | mTrans.pointValuesToPixel(pts);
25 | mViewPortHandler.centerViewPort(pts, view);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/listener/OnChartValueSelectedListener.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.listener;
2 |
3 | import com.jn.chart.data.Entry;
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/base/RealmUtils.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/listener/OnDrawListener.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.listener;
2 |
3 | import com.jn.chart.data.DataSet;
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/BarLineScatterCandleBubbleData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/ILineScatterCandleRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.pyz.retrofitdemo"
9 | minSdkVersion 15
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(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
27 | compile 'com.squareup.retrofit2:retrofit:2.0.1'
28 | compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
29 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
30 | compile 'io.reactivex:rxandroid:1.1.0'
31 | compile 'io.reactivex:rxjava:1.1.0'
32 | compile 'com.orhanobut:logger:1.11'
33 | compile project(':JNChartLib')
34 | }
35 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/BarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import android.graphics.Color;
5 |
6 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/utils/FSize.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/utils/SelectionDetail.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.utils;
2 |
3 | import com.jn.chart.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 y;
16 | public float value;
17 | public int dataIndex;
18 | public int dataSetIndex;
19 | public IDataSet dataSet;
20 |
21 | public SelectionDetail(float y, float value, int dataIndex, int dataSetIndex, IDataSet set) {
22 | this.y = y;
23 | this.value = value;
24 | this.dataIndex = dataIndex;
25 | this.dataSetIndex = dataSetIndex;
26 | this.dataSet = set;
27 | }
28 |
29 | public SelectionDetail(float y, float value, int dataSetIndex, IDataSet set) {
30 | this(y, value, 0, dataSetIndex, set);
31 | }
32 |
33 | public SelectionDetail(float value, int dataSetIndex, IDataSet set) {
34 | this(Float.NaN, value, 0, dataSetIndex, set);
35 | }
36 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/CandleData.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/DefaultYAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/PercentFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.formatter;
3 |
4 | import com.jn.chart.components.YAxis;
5 | import com.jn.chart.data.Entry;
6 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/RadarData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/DefaultFillFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 |
4 | import com.jn.chart.data.LineData;
5 | import com.jn.chart.interfaces.dataprovider.LineDataProvider;
6 | import com.jn.chart.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 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/ValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.data.Entry;
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/LineData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/src/main/assets/MyEcharts/myEcharts.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
60 |
61 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/DefaultValueFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.formatter;
3 |
4 | import com.jn.chart.data.Entry;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/ViewPortJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.jobs;
3 |
4 | import android.view.View;
5 |
6 | import com.jn.chart.utils.Transformer;
7 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/utils/TransformerHorizontalBarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/dataprovider/ChartInterface.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.dataprovider;
2 |
3 | import android.graphics.PointF;
4 | import android.graphics.RectF;
5 |
6 | import com.jn.chart.data.ChartData;
7 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/RetrofitWrapper.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.Gson;
6 |
7 | import retrofit2.Retrofit;
8 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
9 | import retrofit2.converter.gson.GsonConverterFactory;
10 |
11 | /**
12 | * Retrofit 网络接口服务的包装类
13 | */
14 | public class RetrofitWrapper {
15 | private static RetrofitWrapper instance;
16 | private Context mContext;
17 | private Retrofit retrofit;
18 |
19 | private RetrofitWrapper() {
20 | Gson gson = new Gson();
21 | //创建Retrofit对象
22 | retrofit = new Retrofit.Builder().baseUrl(Constant.BASE_URL)
23 | //配置转化库,默认是GSON
24 | .addConverterFactory(GsonConverterFactory.create(gson))
25 | //配置回调库,采用RxJava
26 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
27 | .build();
28 | }
29 |
30 | public static RetrofitWrapper getInstance() {
31 | if (instance == null) {
32 | synchronized (RetrofitWrapper.class){
33 | if (instance==null){
34 | instance = new RetrofitWrapper();
35 | }
36 | }
37 | }
38 | return instance;
39 | }
40 |
41 | /**
42 | * 创建请求接口的对象
43 | * @param service
44 | * @param
45 | * @return
46 | */
47 | public T create(final Class service) {
48 | return retrofit.create(service);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/manager/MyMakerView.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.manager;
2 |
3 | import android.content.Context;
4 | import android.widget.TextView;
5 |
6 | import com.jn.chart.components.MarkerView;
7 | import com.jn.chart.data.Entry;
8 | import com.jn.chart.highlight.Highlight;
9 |
10 | /**
11 | * @Author: pyz
12 | * @Package: com.pyz.myproject.utils
13 | * @Description: TODO
14 | * @Project: JNChartDemo
15 | * @Date: 2016/7/20 17:50
16 | */
17 | public class MyMakerView extends MarkerView {
18 | /**
19 | * Constructor. Sets up the MarkerView with a custom layout resource.
20 | *
21 | * @param context
22 | * @param layoutResource the layout resource to use for the MarkerView
23 | */
24 | private TextView tvContent;
25 |
26 | public MyMakerView (Context context, int layoutResource) {
27 | super(context, layoutResource);
28 | // tvContent = (TextView) findViewById(R.id.tvContent);
29 | }
30 |
31 | /* 每次畫 MakerView 時都會觸發這個 Callback 方法,通常會在此方法內更新 View 的內容 */
32 | @Override
33 | public void refreshContent(Entry e, Highlight highlight) {
34 | tvContent.setText("" + e.getVal());
35 |
36 | }
37 | /*
38 | * offset 是以點到的那個點作為 (0,0) 中心然後往右下角畫出來
39 | * 所以如果要顯示在點的上方
40 | * X=寬度的一半,負數
41 | * Y=高度的負數
42 | */
43 | @Override
44 | public int getXOffset(float xpos) {
45 | return -(getWidth() / 2);
46 | }
47 |
48 | @Override
49 | public int getYOffset(float ypos) {
50 | return -getHeight();
51 | }
52 |
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/charts/CandleStickChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.chart.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.jn.chart.interfaces.dataprovider.CandleDataProvider;
8 | import com.jn.chart.renderer.CandleStickChartRenderer;
9 | import com.jn.chart.charts.BarLineChartBase;
10 | import com.jn.chart.data.CandleData;
11 |
12 | /**
13 | * Financial chart type that draws candle-sticks (OHCL chart).
14 | *
15 | * @author Philipp Jahoda
16 | */
17 | public class CandleStickChart extends BarLineChartBase implements CandleDataProvider {
18 |
19 | public CandleStickChart(Context context) {
20 | super(context);
21 | }
22 |
23 | public CandleStickChart(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public CandleStickChart(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | }
30 |
31 | @Override
32 | protected void init() {
33 | super.init();
34 |
35 | mRenderer = new CandleStickChartRenderer(this, mAnimator, mViewPortHandler);
36 | mXAxis.mAxisMinimum = -0.5f;
37 | }
38 |
39 | @Override
40 | protected void calcMinMax() {
41 | super.calcMinMax();
42 |
43 | mXAxis.mAxisMaximum += 0.5f;
44 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum);
45 | }
46 |
47 | @Override
48 | public CandleData getCandleData() {
49 | return mData;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pyz/retrofitdemo/model/WeatherInfoModel.java:
--------------------------------------------------------------------------------
1 | package com.pyz.retrofitdemo.model;
2 |
3 | import android.content.Context;
4 |
5 | import com.pyz.retrofitdemo.RetrofitWrapper;
6 | import com.pyz.retrofitdemo.bean.WeatherInfo;
7 | import com.pyz.retrofitdemo.bean.WeatherInfoReq;
8 | import com.pyz.retrofitdemo.netrequest.NetRequest;
9 |
10 | import retrofit2.Call;
11 | import rx.Observable;
12 |
13 | /**
14 | * Created by pyz on 2016/5/4.
15 | */
16 | public class WeatherInfoModel {
17 | private static WeatherInfoModel weatherInfoModel;
18 | private NetRequest netRequest;
19 |
20 | public WeatherInfoModel(Context context) {
21 | netRequest = (NetRequest) RetrofitWrapper.getInstance().create(NetRequest.class);
22 | }
23 |
24 | public static WeatherInfoModel getInstance(Context context) {
25 | if (weatherInfoModel == null) {
26 | weatherInfoModel = new WeatherInfoModel(context);
27 | }
28 | return weatherInfoModel;
29 | }
30 |
31 | /**
32 | * 查询天气
33 | *
34 | * @param weatherInfoReq
35 | * @return
36 | */
37 | public Call queryWeather(WeatherInfoReq weatherInfoReq) {
38 | Call infoCall = netRequest.getWeather(weatherInfoReq.apiKey, weatherInfoReq.city);
39 | return infoCall;
40 | }
41 |
42 | public Observable queryWeatherByRxJava(WeatherInfoReq weatherInfoReq) {
43 | Observable infoCall = netRequest.getWeatherByRxJava(weatherInfoReq.apiKey, weatherInfoReq.city);
44 | return infoCall;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/AnimatedViewPortJob.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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.jn.chart.utils.Transformer;
9 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/BubbleData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/BubbleEntry.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/ZoomJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.jobs;
3 |
4 | import android.graphics.Matrix;
5 | import android.view.View;
6 |
7 | import com.jn.chart.charts.BarLineChartBase;
8 | import com.jn.chart.components.YAxis;
9 | import com.jn.chart.utils.Transformer;
10 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/ILineRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/base/RealmBarLineScatterCandleBubbleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.base;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.jn.chart.data.Entry;
6 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/ScatterData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/charts/LineChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.jn.chart.interfaces.dataprovider.LineDataProvider;
8 | import com.jn.chart.renderer.LineChartRenderer;
9 | import com.jn.chart.charts.BarLineChartBase;
10 | import com.jn.chart.data.LineData;
11 |
12 | /**
13 | * Chart that draws lines, surfaces, circles, ...
14 | *
15 | * @author Philipp Jahoda
16 | */
17 | public class LineChart extends BarLineChartBase implements LineDataProvider {
18 |
19 | public LineChart(Context context) {
20 | super(context);
21 | }
22 |
23 | public LineChart(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public LineChart(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | }
30 |
31 | @Override
32 | protected void init() {
33 | super.init();
34 |
35 | mRenderer = new LineChartRenderer(this, mAnimator, mViewPortHandler);
36 | }
37 |
38 | @Override
39 | protected void calcMinMax() {
40 | super.calcMinMax();
41 |
42 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0)
43 | mXAxis.mAxisRange = 1;
44 | }
45 |
46 | @Override
47 | public LineData getLineData() {
48 | return mData;
49 | }
50 |
51 | @Override
52 | protected void onDetachedFromWindow() {
53 | // releases the bitmap in the renderer to avoid oom error
54 | if(mRenderer != null && mRenderer instanceof LineChartRenderer) {
55 | ((LineChartRenderer) mRenderer).releaseBitmap();
56 | }
57 | super.onDetachedFromWindow();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IPieDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 | import com.jn.chart.data.Entry;
3 | import com.jn.chart.data.PieDataSet;
4 |
5 | /**
6 | * Created by Philipp Jahoda on 03/11/15.
7 | */
8 | public interface IPieDataSet extends IDataSet {
9 |
10 | /**
11 | * Returns the space that is set to be between the piechart-slices of this
12 | * DataSet, in pixels.
13 | *
14 | * @return
15 | */
16 | float getSliceSpace();
17 |
18 | /**
19 | * Returns the distance a highlighted piechart slice is "shifted" away from
20 | * the chart-center in dp.
21 | *
22 | * @return
23 | */
24 | float getSelectionShift();
25 |
26 | PieDataSet.ValuePosition getXValuePosition();
27 |
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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/CrossShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.Utils;
9 | import com.jn.chart.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by wajdic on 15/06/2016.
13 | * Created at Time 09:08
14 | */
15 | public class CrossShapeRenderer implements ShapeRenderer {
16 |
17 |
18 | @Override
19 | public void renderShape(
20 | Canvas c, IScatterDataSet dataSet,
21 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
22 |
23 | final float shapeHalf = shapeSize / 2f;
24 |
25 |
26 | mRenderPaint.setStyle(Paint.Style.STROKE);
27 | mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
28 |
29 | for (int i = 0; i < buffer.size(); i += 2) {
30 |
31 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
32 | break;
33 |
34 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
35 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
36 | continue;
37 |
38 | mRenderPaint.setColor(dataSet.getColor(i / 2));
39 |
40 | c.drawLine(
41 | buffer.buffer[i] - shapeHalf,
42 | buffer.buffer[i + 1],
43 | buffer.buffer[i] + shapeHalf,
44 | buffer.buffer[i + 1],
45 | mRenderPaint);
46 | c.drawLine(
47 | buffer.buffer[i],
48 | buffer.buffer[i + 1] - shapeHalf,
49 | buffer.buffer[i],
50 | buffer.buffer[i + 1] + shapeHalf,
51 | mRenderPaint);
52 | }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/ChevronUpShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.Utils;
9 | import com.jn.chart.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by wajdic on 15/06/2016.
13 | * Created at Time 09:08
14 | */
15 | public class ChevronUpShapeRenderer implements ShapeRenderer {
16 |
17 |
18 | @Override
19 | public void renderShape(Canvas c, IScatterDataSet dataSet,
20 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
21 |
22 | final float shapeHalf = shapeSize / 2f;
23 |
24 | mRenderPaint.setStyle(Paint.Style.STROKE);
25 | mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
26 |
27 | for (int i = 0; i < buffer.size(); i += 2) {
28 |
29 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
30 | break;
31 |
32 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
33 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
34 | continue;
35 |
36 | mRenderPaint.setColor(dataSet.getColor(i / 2));
37 |
38 | c.drawLine(
39 | buffer.buffer[i],
40 | buffer.buffer[i + 1] - (2 * shapeHalf),
41 | buffer.buffer[i] + (2 * shapeHalf),
42 | buffer.buffer[i + 1],
43 | mRenderPaint);
44 |
45 | c.drawLine(
46 | buffer.buffer[i],
47 | buffer.buffer[i + 1] - (2 * shapeHalf),
48 | buffer.buffer[i] - (2 * shapeHalf),
49 | buffer.buffer[i + 1],
50 | mRenderPaint);
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/IBarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/XShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.Utils;
9 | import com.jn.chart.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by wajdic on 15/06/2016.
13 | * Created at Time 09:08
14 | */
15 | public class XShapeRenderer implements ShapeRenderer {
16 |
17 |
18 | @Override
19 | public void renderShape(
20 | Canvas c, IScatterDataSet dataSet,
21 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
22 |
23 | final float shapeHalf = shapeSize / 2f;
24 |
25 | mRenderPaint.setStyle(Paint.Style.STROKE);
26 | mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
27 |
28 | for (int i = 0; i < buffer.size(); i += 2) {
29 |
30 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
31 | break;
32 |
33 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
34 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
35 | continue;
36 |
37 | mRenderPaint.setColor(dataSet.getColor(i / 2));
38 |
39 | c.drawLine(
40 | buffer.buffer[i] - shapeHalf,
41 | buffer.buffer[i + 1] - shapeHalf,
42 | buffer.buffer[i] + shapeHalf,
43 | buffer.buffer[i + 1] + shapeHalf,
44 | mRenderPaint);
45 | c.drawLine(
46 | buffer.buffer[i] + shapeHalf,
47 | buffer.buffer[i + 1] - shapeHalf,
48 | buffer.buffer[i] - shapeHalf,
49 | buffer.buffer[i + 1] + shapeHalf,
50 | mRenderPaint);
51 | }
52 |
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/ChevronDownShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.Utils;
9 | import com.jn.chart.utils.ViewPortHandler;
10 |
11 | /**
12 | * Created by wajdic on 15/06/2016.
13 | * Created at Time 09:08
14 | */
15 | public class ChevronDownShapeRenderer implements ShapeRenderer {
16 |
17 |
18 | @Override
19 | public void renderShape(
20 | Canvas c, IScatterDataSet dataSet,
21 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
22 |
23 | final float shapeHalf = shapeSize / 2f;
24 |
25 | mRenderPaint.setStyle(Paint.Style.STROKE);
26 | mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
27 |
28 | for (int i = 0; i < buffer.size(); i += 2) {
29 |
30 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
31 | break;
32 |
33 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
34 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
35 | continue;
36 |
37 | mRenderPaint.setColor(dataSet.getColor(i / 2));
38 |
39 | c.drawLine(
40 | buffer.buffer[i],
41 | buffer.buffer[i + 1] + (2 * shapeHalf),
42 | buffer.buffer[i] + (2 * shapeHalf),
43 | buffer.buffer[i + 1],
44 | mRenderPaint);
45 |
46 | c.drawLine(
47 | buffer.buffer[i],
48 | buffer.buffer[i + 1] + (2 * shapeHalf),
49 | buffer.buffer[i] - (2 * shapeHalf),
50 | buffer.buffer[i + 1],
51 | mRenderPaint);
52 | }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/ICandleDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import android.graphics.Paint;
4 |
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/Renderer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.renderer;
3 |
4 | import com.jn.chart.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
5 | import com.jn.chart.utils.ViewPortHandler;
6 |
7 | /**
8 | * Abstract baseclass of all Renderers.
9 | *
10 | * @author Philipp Jahoda
11 | */
12 | public abstract class Renderer {
13 |
14 | /**
15 | * the component that handles the drawing area of the chart and it's offsets
16 | */
17 | protected ViewPortHandler mViewPortHandler;
18 |
19 | /** the minimum value on the x-axis that should be plotted */
20 | protected int mMinX = 0;
21 |
22 | /** the maximum value on the x-axis that should be plotted */
23 | protected int mMaxX = 0;
24 |
25 | public Renderer(ViewPortHandler viewPortHandler) {
26 | this.mViewPortHandler = viewPortHandler;
27 | }
28 |
29 | /**
30 | * Returns true if the specified value fits in between the provided min
31 | * and max bounds, false if not.
32 | *
33 | * @param val
34 | * @param min
35 | * @param max
36 | * @return
37 | */
38 | protected boolean fitsBounds(float val, float min, float max) {
39 |
40 | if (val < min || val > max)
41 | return false;
42 | else
43 | return true;
44 | }
45 |
46 | /**
47 | * Calculates the minimum and maximum x-value the chart can currently
48 | * display (with the given zoom level). -> mMinX, mMaxX
49 | *
50 | * @param dataProvider
51 | * @param xAxisModulus
52 | */
53 | public void calcXBounds(BarLineScatterCandleBubbleDataProvider dataProvider, int xAxisModulus) {
54 |
55 | int low = dataProvider.getLowestVisibleXIndex();
56 | int high = dataProvider.getHighestVisibleXIndex();
57 |
58 | int subLow = (low % xAxisModulus == 0) ? xAxisModulus : 0;
59 |
60 | mMinX = Math.max((low / xAxisModulus) * (xAxisModulus) - subLow, 0);
61 | mMaxX = Math.min((high / xAxisModulus) * (xAxisModulus) + xAxisModulus, (int) dataProvider.getXChartMax());
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/JNChartLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | //apply plugin: 'com.github.dcendents.android-maven'
4 | //apply plugin: 'realm-android'
5 |
6 | android {
7 | compileSdkVersion 23
8 | buildToolsVersion '23.0.2'
9 | // resourcePrefix 'mpcht'
10 | defaultConfig {
11 | minSdkVersion 8
12 | targetSdkVersion 23
13 | versionCode 1
14 | versionName '1.0'
15 |
16 | sourceSets {
17 | main {
18 | java.srcDirs = ['src']
19 | res.srcDirs = ['res']
20 | assets.srcDirs = ['assets']
21 | manifest.srcFile 'AndroidManifest.xml'
22 | }
23 | }
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | lintOptions {
32 | abortOnError false
33 | }
34 | }
35 |
36 | repositories {
37 | maven {
38 | url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
39 | }
40 | }
41 |
42 | dependencies {
43 | //compile fileTree(dir: 'libs', include: ['*.jar'])
44 | //compile 'com.android.support:support-v4:19.+'
45 | provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API
46 |
47 | }
48 |
49 | android.libraryVariants.all { variant ->
50 | def name = variant.buildType.name
51 | def task = project.tasks.create "jar${name.capitalize()}", Jar
52 | task.dependsOn variant.javaCompile
53 | task.from variant.javaCompile.destinationDir
54 | artifacts.add('archives', task);
55 | }
56 |
57 | task sourcesJar(type: Jar) {
58 | from android.sourceSets.main.java.srcDirs
59 | classifier = 'sources'
60 | }
61 |
62 | task javadoc(type: Javadoc) {
63 | failOnError false
64 | source = android.sourceSets.main.java.sourceFiles
65 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
66 | }
67 |
68 | task javadocJar(type: Jar, dependsOn: javadoc) {
69 | classifier = 'javadoc'
70 | from javadoc.destinationDir
71 | }
72 |
73 | artifacts {
74 | archives sourcesJar
75 | archives javadocJar
76 | }
77 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/XAxisRendererRadarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.renderer;
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.PointF;
6 |
7 | import com.jn.chart.charts.RadarChart;
8 | import com.jn.chart.components.XAxis;
9 | import com.jn.chart.utils.Utils;
10 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/listener/OnChartGestureListener.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/charts/BubbleChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.charts;
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.jn.chart.data.BubbleData;
8 | import com.jn.chart.interfaces.dataprovider.BubbleDataProvider;
9 | import com.jn.chart.interfaces.datasets.IBubbleDataSet;
10 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/highlight/CombinedHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.highlight;
2 |
3 | import com.jn.chart.data.ChartData;
4 | import com.jn.chart.data.CombinedData;
5 | import com.jn.chart.interfaces.datasets.IDataSet;
6 | import com.jn.chart.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
7 | import com.jn.chart.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, int dataSetIndex) {
29 |
30 | List vals = new ArrayList();
31 | float[] pts = new float[2];
32 |
33 | CombinedData data = (CombinedData) mChart.getData();
34 |
35 | // get all chartdata objects
36 | List dataObjects = data.getAllData();
37 |
38 | for (int i = 0; i < dataObjects.size(); i++) {
39 |
40 | for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) {
41 |
42 | IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);
43 |
44 | // dont include datasets that cannot be highlighted
45 | if (!dataSet.isHighlightEnabled())
46 | continue;
47 |
48 | // extract all y-values from all DataSets at the given x-index
49 | final float yVals[] = dataSet.getYValsForXIndex(xIndex);
50 | for (float yVal : yVals) {
51 | pts[1] = yVal;
52 |
53 | mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
54 |
55 | if (!Float.isNaN(pts[1])) {
56 | vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet));
57 | }
58 | }
59 | }
60 | }
61 |
62 | return vals;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/buffer/AbstractBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.buffer;
3 |
4 | /**
5 | * Buffer class to boost performance while drawing. Concept: Replace instead of
6 | * recreate.
7 | *
8 | * @author Philipp Jahoda
9 | * @param The data the buffer accepts to be fed with.
10 | */
11 | public abstract class AbstractBuffer {
12 |
13 | /** index in the buffer */
14 | protected int index = 0;
15 |
16 | /** float-buffer that holds the data points to draw, order: x,y,x,y,... */
17 | public final float[] buffer;
18 |
19 | /** animation phase x-axis */
20 | protected float phaseX = 1f;
21 |
22 | /** animation phase y-axis */
23 | protected float phaseY = 1f;
24 |
25 | /** indicates from which x-index the visible data begins */
26 | protected int mFrom = 0;
27 |
28 | /** indicates to which x-index the visible data ranges */
29 | protected int mTo = 0;
30 |
31 | /**
32 | * Initialization with buffer-size.
33 | *
34 | * @param size
35 | */
36 | public AbstractBuffer(int size) {
37 | index = 0;
38 | buffer = new float[size];
39 | }
40 |
41 | /** limits the drawing on the x-axis */
42 | public void limitFrom(int from) {
43 | if (from < 0)
44 | from = 0;
45 | mFrom = from;
46 | }
47 |
48 | /** limits the drawing on the x-axis */
49 | public void limitTo(int to) {
50 | if (to < 0)
51 | to = 0;
52 | mTo = to;
53 | }
54 |
55 | /**
56 | * Resets the buffer index to 0 and makes the buffer reusable.
57 | */
58 | public void reset() {
59 | index = 0;
60 | }
61 |
62 | /**
63 | * Returns the size (length) of the buffer array.
64 | *
65 | * @return
66 | */
67 | public int size() {
68 | return buffer.length;
69 | }
70 |
71 | /**
72 | * Set the phases used for animations.
73 | *
74 | * @param phaseX
75 | * @param phaseY
76 | */
77 | public void setPhases(float phaseX, float phaseY) {
78 | this.phaseX = phaseX;
79 | this.phaseY = phaseY;
80 | }
81 |
82 | /**
83 | * Builds up the buffer with the provided data and resets the buffer-index
84 | * after feed-completion. This needs to run FAST.
85 | *
86 | * @param data
87 | */
88 | public abstract void feed(T data);
89 | }
90 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/LineScatterCandleRadarRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Path;
5 |
6 | import com.jn.chart.animation.ChartAnimator;
7 | import com.jn.chart.interfaces.datasets.ILineScatterCandleRadarDataSet;
8 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/StackedValueFormatter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.formatter;
2 |
3 | import com.jn.chart.data.BarEntry;
4 | import com.jn.chart.data.Entry;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/interfaces/datasets/ILineDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.interfaces.datasets;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.jn.chart.data.Entry;
6 | import com.jn.chart.data.LineDataSet;
7 | import com.jn.chart.formatter.FillFormatter;
8 |
9 | /**
10 | * Created by Philpp Jahoda on 21/10/15.
11 | */
12 | public interface ILineDataSet extends ILineRadarDataSet {
13 |
14 | /**
15 | * Returns the drawing mode for this line dataset
16 | *
17 | * @return
18 | */
19 | LineDataSet.Mode getMode();
20 |
21 | /**
22 | * Returns the intensity of the cubic lines (the effect intensity).
23 | * Max = 1f = very cubic, Min = 0.05f = low cubic effect, Default: 0.2f
24 | *
25 | * @return
26 | */
27 | float getCubicIntensity();
28 |
29 | @Deprecated
30 | boolean isDrawCubicEnabled();
31 |
32 | @Deprecated
33 | boolean isDrawSteppedEnabled();
34 |
35 | /**
36 | * Returns the size of the drawn circles.
37 | */
38 | float getCircleRadius();
39 |
40 | /**
41 | * Returns the hole radius of the drawn circles.
42 | */
43 | float getCircleHoleRadius();
44 |
45 | /**
46 | * Returns the color at the given index of the DataSet's circle-color array.
47 | * Performs a IndexOutOfBounds check by modulus.
48 | *
49 | * @param index
50 | * @return
51 | */
52 | int getCircleColor(int index);
53 |
54 | /**
55 | * Returns true if drawing circles for this DataSet is enabled, false if not
56 | *
57 | * @return
58 | */
59 | boolean isDrawCirclesEnabled();
60 |
61 | /**
62 | * Returns the color of the inner circle (the circle-hole).
63 | *
64 | * @return
65 | */
66 | int getCircleHoleColor();
67 |
68 | /**
69 | * Returns true if drawing the circle-holes is enabled, false if not.
70 | *
71 | * @return
72 | */
73 | boolean isDrawCircleHoleEnabled();
74 |
75 | /**
76 | * Returns the DashPathEffect that is used for drawing the lines.
77 | *
78 | * @return
79 | */
80 | DashPathEffect getDashPathEffect();
81 |
82 | /**
83 | * Returns true if the dashed-line effect is enabled, false if not.
84 | * If the DashPathEffect object is null, also return false here.
85 | *
86 | * @return
87 | */
88 | boolean isDashedLineEnabled();
89 |
90 | /**
91 | * Returns the FillFormatter that is set for this DataSet.
92 | *
93 | * @return
94 | */
95 | FillFormatter getFillFormatter();
96 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/PieData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/CircleShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.ColorTemplate;
9 | import com.jn.chart.utils.Utils;
10 | import com.jn.chart.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by wajdic on 15/06/2016.
14 | * Created at Time 09:08
15 | */
16 | public class CircleShapeRenderer implements ShapeRenderer {
17 |
18 |
19 | @Override
20 | public void renderShape(
21 | Canvas c, IScatterDataSet dataSet,
22 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
23 |
24 | final float shapeHalf = shapeSize / 2f;
25 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
26 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
27 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
28 | final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
29 |
30 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
31 |
32 | for (int i = 0; i < buffer.size(); i += 2) {
33 |
34 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
35 | break;
36 |
37 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
38 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
39 | continue;
40 |
41 | mRenderPaint.setColor(dataSet.getColor(i / 2));
42 |
43 | if (shapeSize > 0.0) {
44 | mRenderPaint.setStyle(Paint.Style.STROKE);
45 | mRenderPaint.setStrokeWidth(shapeStrokeSize);
46 |
47 | c.drawCircle(
48 | buffer.buffer[i],
49 | buffer.buffer[i + 1],
50 | shapeHoleSizeHalf + shapeStrokeSizeHalf,
51 | mRenderPaint);
52 |
53 | if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
54 | mRenderPaint.setStyle(Paint.Style.FILL);
55 |
56 | mRenderPaint.setColor(shapeHoleColor);
57 | c.drawCircle(
58 | buffer.buffer[i],
59 | buffer.buffer[i + 1],
60 | shapeHoleSizeHalf,
61 | mRenderPaint);
62 | }
63 | } else {
64 | mRenderPaint.setStyle(Paint.Style.FILL);
65 |
66 | c.drawCircle(
67 | buffer.buffer[i],
68 | buffer.buffer[i + 1],
69 | shapeHalf,
70 | mRenderPaint);
71 | }
72 | }
73 |
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/jobs/AnimatedZoomJob.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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.jn.chart.charts.BarLineChartBase;
10 | import com.jn.chart.components.YAxis;
11 | import com.jn.chart.utils.Transformer;
12 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/formatter/LargeValueFormatter.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.formatter;
3 |
4 | import com.jn.chart.components.YAxis;
5 | import com.jn.chart.data.Entry;
6 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/LineRadarRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.drawable.Drawable;
7 |
8 | import com.jn.chart.animation.ChartAnimator;
9 | import com.jn.chart.utils.Utils;
10 | import com.jn.chart.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 25/01/16.
14 | */
15 | public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
16 |
17 | public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
18 | super(animator, viewPortHandler);
19 | }
20 |
21 | /**
22 | * Draws the provided path in filled mode with the provided drawable.
23 | *
24 | * @param c
25 | * @param filledPath
26 | * @param drawable
27 | */
28 | protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
29 |
30 | if (clipPathSupported()) {
31 |
32 | c.save();
33 | c.clipPath(filledPath);
34 |
35 | drawable.setBounds((int) mViewPortHandler.contentLeft(),
36 | (int) mViewPortHandler.contentTop(),
37 | (int) mViewPortHandler.contentRight(),
38 | (int) mViewPortHandler.contentBottom());
39 | drawable.draw(c);
40 |
41 | c.restore();
42 | } else {
43 | throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
44 | "this code was run on API level " + Utils.getSDKInt() + ".");
45 | }
46 | }
47 |
48 | /**
49 | * Draws the provided path in filled mode with the provided color and alpha.
50 | * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
51 | *
52 | * @param c
53 | * @param filledPath
54 | * @param fillColor
55 | * @param fillAlpha
56 | */
57 | protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
58 |
59 | int color = (fillAlpha << 24) | (fillColor & 0xffffff);
60 |
61 | if (clipPathSupported()) {
62 |
63 | c.save();
64 | c.clipPath(filledPath);
65 |
66 | c.drawColor(color);
67 | c.restore();
68 | } else {
69 |
70 | // save
71 | Paint.Style previous = mRenderPaint.getStyle();
72 | int previousColor = mRenderPaint.getColor();
73 |
74 | // set
75 | mRenderPaint.setStyle(Paint.Style.FILL);
76 | mRenderPaint.setColor(color);
77 |
78 | c.drawPath(filledPath, mRenderPaint);
79 |
80 | // restore
81 | mRenderPaint.setColor(previousColor);
82 | mRenderPaint.setStyle(previous);
83 | }
84 | }
85 |
86 | /**
87 | * Clip path with hardware acceleration only working properly on API level 18 and above.
88 | *
89 | * @return
90 | */
91 | private boolean clipPathSupported() {
92 | return Utils.getSDKInt() >= 18;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/SquareShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.jn.chart.buffer.ScatterBuffer;
7 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
8 | import com.jn.chart.utils.ColorTemplate;
9 | import com.jn.chart.utils.Utils;
10 | import com.jn.chart.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by wajdic on 15/06/2016.
14 | * Created at Time 09:08
15 | */
16 | public class SquareShapeRenderer implements ShapeRenderer {
17 |
18 |
19 | @Override
20 | public void renderShape(
21 | Canvas c, IScatterDataSet dataSet,
22 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
23 |
24 | final float shapeHalf = shapeSize / 2f;
25 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
26 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
27 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
28 | final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;
29 |
30 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
31 |
32 | for (int i = 0; i < buffer.size(); i += 2) {
33 |
34 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
35 | break;
36 |
37 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
38 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
39 | continue;
40 |
41 | mRenderPaint.setColor(dataSet.getColor(i / 2));
42 |
43 | if (shapeSize > 0.0) {
44 | mRenderPaint.setStyle(Paint.Style.STROKE);
45 | mRenderPaint.setStrokeWidth(shapeStrokeSize);
46 |
47 | c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
48 | buffer.buffer[i + 1] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
49 | buffer.buffer[i] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
50 | buffer.buffer[i + 1] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
51 | mRenderPaint);
52 |
53 | if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
54 | mRenderPaint.setStyle(Paint.Style.FILL);
55 |
56 | mRenderPaint.setColor(shapeHoleColor);
57 | c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf,
58 | buffer.buffer[i + 1] - shapeHoleSizeHalf,
59 | buffer.buffer[i] + shapeHoleSizeHalf,
60 | buffer.buffer[i + 1] + shapeHoleSizeHalf,
61 | mRenderPaint);
62 | }
63 |
64 | } else {
65 | mRenderPaint.setStyle(Paint.Style.FILL);
66 |
67 | c.drawRect(buffer.buffer[i] - shapeHalf,
68 | buffer.buffer[i + 1] - shapeHalf,
69 | buffer.buffer[i] + shapeHalf,
70 | buffer.buffer[i + 1] + shapeHalf,
71 | mRenderPaint);
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/manager/BarChartManager.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.manager;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 |
6 | import com.jn.chart.animation.Easing;
7 | import com.jn.chart.charts.BarChart;
8 | import com.jn.chart.components.Legend;
9 | import com.jn.chart.components.XAxis;
10 | import com.jn.chart.components.YAxis;
11 | import com.jn.chart.data.BarData;
12 | import com.jn.chart.data.BarDataSet;
13 | import com.jn.chart.data.BarEntry;
14 | import com.jn.chart.interfaces.datasets.IBarDataSet;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * @Author: pyz
20 | * @Package: com.pyz.myproject.utils
21 | * @Description: TODO
22 | * @Project: JNChartDemo
23 | * @Date: 2016/7/21 10:09
24 | */
25 | public class BarChartManager {
26 | private static String unit = null;
27 |
28 | public static void initBarChart(Context context, BarChart barChart,
29 | ArrayList xValues, ArrayList yValues) {
30 | initDataStyle(context,barChart);
31 | //设置柱状图的样式
32 | BarDataSet dataSet = new BarDataSet(yValues, unit);
33 | dataSet.setColor(Color.parseColor("#7EC0EE"));
34 | dataSet.setDrawValues(true);
35 | dataSet.setValueTextColor(Color.RED);
36 |
37 | // dataSet.setValueFormatter(new PercentFormatter(new DecimalFormat("%").format()));
38 |
39 | ArrayList dataSets = new ArrayList<>();
40 | dataSets.add(dataSet);
41 |
42 | //构建一个barData 将dataSets放入
43 | BarData barData = new BarData(xValues, dataSets);
44 | //将数据插入
45 | barChart.setData(barData);
46 |
47 | //设置动画效果
48 | barChart.animateY(2000, Easing.EasingOption.Linear);
49 | // barChart.animateX(2000, Easing.EasingOption.Linear);
50 | barChart.invalidate();
51 | }
52 |
53 | /**
54 | * @Description:初始化图表的样式
55 | * @param context
56 | * @param barChart
57 |
58 | */
59 | private static void initDataStyle(Context context, BarChart barChart) {
60 | //设置图表是否支持触控操作
61 | barChart.setTouchEnabled(false);
62 | //设置点击折时,显示其数值
63 | /* MyMakerView mv = new MyMakerView(context, R.layout.item_mark_layout);
64 | barChart.setMarkerView(mv);*/
65 | //设置柱状的描述的样式(默认在图表的左下角)
66 | Legend title = barChart.getLegend();
67 | title.setForm(Legend.LegendForm.SQUARE);
68 | //设置x轴的样式
69 | XAxis xAxis = barChart.getXAxis();
70 | xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
71 | xAxis.setAxisLineColor(Color.parseColor("#66CDAA"));
72 | xAxis.setAxisLineWidth(5);
73 | xAxis.setDrawGridLines(false);
74 | //设置是否显示x轴
75 | xAxis.setEnabled(true);
76 |
77 | //设置左边y轴的样式
78 | YAxis yAxisLeft = barChart.getAxisLeft();
79 | yAxisLeft.setAxisLineColor(Color.parseColor("#66CDAA"));
80 | yAxisLeft.setAxisLineWidth(5);
81 | yAxisLeft.setDrawGridLines(false);
82 |
83 | //设置右边y轴的样式
84 | YAxis yAxisRight = barChart.getAxisRight();
85 | yAxisRight.setEnabled(false);
86 |
87 | }
88 |
89 | /**
90 | * 设置单位值
91 | * @param barUnit
92 | */
93 | public static void setUnit(String barUnit){
94 | unit = barUnit;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/.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 | C:\Users\pyz\AppData\Roaming\Subversion
48 |
49 |
50 |
51 |
52 |
53 | 1.7
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/BarData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/AxisRenderer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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.jn.chart.utils.Transformer;
10 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/LineRadarDataSet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.data;
3 |
4 | import android.annotation.TargetApi;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.Drawable;
7 |
8 | import com.jn.chart.interfaces.datasets.ILineRadarDataSet;
9 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/buffer/HorizontalBarBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.buffer;
3 |
4 | import com.jn.chart.data.BarEntry;
5 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/highlight/HorizontalBarHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.highlight;
2 |
3 | import com.jn.chart.components.YAxis;
4 | import com.jn.chart.data.BarData;
5 | import com.jn.chart.interfaces.datasets.IBarDataSet;
6 | import com.jn.chart.interfaces.dataprovider.BarDataProvider;
7 | import com.jn.chart.utils.SelectionDetail;
8 |
9 | /**
10 | * Created by Philipp Jahoda on 22/07/15.
11 | */
12 | public class HorizontalBarHighlighter extends BarHighlighter {
13 |
14 | public HorizontalBarHighlighter(BarDataProvider chart) {
15 | super(chart);
16 | }
17 |
18 | @Override
19 | public Highlight getHighlight(float x, float y) {
20 |
21 | BarData barData = mChart.getBarData();
22 |
23 | final int xIndex = getXIndex(x);
24 | final float baseNoSpace = getBase(x);
25 | final int setCount = barData.getDataSetCount();
26 | int dataSetIndex = ((int)baseNoSpace) % setCount;
27 |
28 | if (dataSetIndex < 0) {
29 | dataSetIndex = 0;
30 | } else if (dataSetIndex >= setCount) {
31 | dataSetIndex = setCount - 1;
32 | }
33 |
34 | SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex);
35 | if (selectionDetail == null)
36 | return null;
37 |
38 | IBarDataSet set = barData.getDataSetByIndex(dataSetIndex);
39 | if (set.isStacked()) {
40 |
41 | float[] pts = new float[2];
42 | pts[0] = y;
43 |
44 | // take any transformer to determine the x-axis value
45 | mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);
46 |
47 | return getStackedHighlight(selectionDetail,
48 | set,
49 | xIndex,
50 | pts[0]);
51 | }
52 |
53 | return new Highlight(
54 | xIndex,
55 | selectionDetail.value,
56 | selectionDetail.dataIndex,
57 | selectionDetail.dataSetIndex,
58 | -1);
59 | }
60 |
61 | @Override
62 | protected int getXIndex(float x) {
63 |
64 | if (!mChart.getBarData().isGrouped()) {
65 |
66 | // create an array of the touch-point
67 | float[] pts = new float[2];
68 | pts[1] = x;
69 |
70 | // take any transformer to determine the x-axis value
71 | mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
72 |
73 | return (int) Math.round(pts[1]);
74 | } else {
75 |
76 | float baseNoSpace = getBase(x);
77 |
78 | int setCount = mChart.getBarData().getDataSetCount();
79 | int xIndex = (int) baseNoSpace / setCount;
80 |
81 | int valCount = mChart.getData().getXValCount();
82 |
83 | if (xIndex < 0)
84 | xIndex = 0;
85 | else if (xIndex >= valCount)
86 | xIndex = valCount - 1;
87 |
88 | return xIndex;
89 | }
90 | }
91 |
92 | /**
93 | * Returns the base y-value to the corresponding x-touch value in pixels.
94 | *
95 | * @param y
96 | * @return
97 | */
98 | @Override
99 | protected float getBase(float y) {
100 |
101 | // create an array of the touch-point
102 | float[] pts = new float[2];
103 | pts[1] = y;
104 |
105 | // take any transformer to determine the x-axis value
106 | mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
107 | float yVal = pts[1];
108 |
109 | int setCount = mChart.getBarData().getDataSetCount();
110 |
111 | // calculate how often the group-space appears
112 | int steps = (int) ((float) yVal / ((float) setCount + mChart.getBarData().getGroupSpace()));
113 |
114 | float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps;
115 |
116 | float baseNoSpace = (float) yVal - groupSpaceSum;
117 | return baseNoSpace;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/JNChartLib/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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/scatter/TriangleShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 |
7 | import com.jn.chart.buffer.ScatterBuffer;
8 | import com.jn.chart.interfaces.datasets.IScatterDataSet;
9 | import com.jn.chart.utils.ColorTemplate;
10 | import com.jn.chart.utils.Utils;
11 | import com.jn.chart.utils.ViewPortHandler;
12 |
13 | /**
14 | * Created by wajdic on 15/06/2016.
15 | * Created at Time 09:08
16 | */
17 | public class TriangleShapeRenderer implements ShapeRenderer {
18 |
19 |
20 | @Override
21 | public void renderShape(
22 | Canvas c, IScatterDataSet dataSet,
23 | ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {
24 |
25 |
26 | final float shapeHalf = shapeSize / 2f;
27 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
28 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
29 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
30 |
31 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
32 |
33 | mRenderPaint.setStyle(Paint.Style.FILL);
34 |
35 | // create a triangle path
36 | Path tri = new Path();
37 |
38 | for (int i = 0; i < buffer.size(); i += 2) {
39 |
40 | if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
41 | break;
42 |
43 | if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
44 | || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
45 | continue;
46 |
47 | mRenderPaint.setColor(dataSet.getColor(i / 2));
48 |
49 | tri.moveTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
50 | tri.lineTo(buffer.buffer[i] + shapeHalf, buffer.buffer[i + 1] + shapeHalf);
51 | tri.lineTo(buffer.buffer[i] - shapeHalf, buffer.buffer[i + 1] + shapeHalf);
52 |
53 | if (shapeSize > 0.0) {
54 | tri.lineTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
55 |
56 | tri.moveTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
57 | buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
58 | tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
59 | buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
60 | tri.lineTo(buffer.buffer[i],
61 | buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
62 | tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
63 | buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
64 | }
65 |
66 | tri.close();
67 |
68 | c.drawPath(tri, mRenderPaint);
69 | tri.reset();
70 |
71 | if (shapeSize > 0.0 &&
72 | shapeHoleColor != ColorTemplate.COLOR_NONE) {
73 |
74 | mRenderPaint.setColor(shapeHoleColor);
75 |
76 | tri.moveTo(buffer.buffer[i],
77 | buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
78 | tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
79 | buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
80 | tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
81 | buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
82 | tri.close();
83 |
84 | c.drawPath(tri, mRenderPaint);
85 | tri.reset();
86 | }
87 | }
88 |
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/components/MarkerView.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.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.jn.chart.data.Entry;
10 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/realm/base/RealmLineRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data.realm.base;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.jn.chart.data.Entry;
7 | import com.jn.chart.interfaces.datasets.ILineRadarDataSet;
8 | import com.jn.chart.utils.Utils;
9 |
10 | import io.realm.RealmObject;
11 | import io.realm.RealmResults;
12 |
13 | /**
14 | * Created by Philipp Jahoda on 08/11/15.
15 | */
16 | public abstract class RealmLineRadarDataSet extends RealmLineScatterCandleRadarDataSet implements ILineRadarDataSet {
17 |
18 | /** the color that is used for filling the line surface */
19 | private int mFillColor = Color.rgb(140, 234, 255);
20 |
21 | /** the drawable to be used for filling the line surface*/
22 | protected Drawable mFillDrawable;
23 |
24 | /** transparency used for filling line surface */
25 | private int mFillAlpha = 85;
26 |
27 | /** the width of the drawn data lines */
28 | private float mLineWidth = 2.5f;
29 |
30 | /** if true, the data will also be drawn filled */
31 | private boolean mDrawFilled = false;
32 |
33 |
34 | public RealmLineRadarDataSet(RealmResults results, String yValuesField) {
35 | super(results, yValuesField);
36 | }
37 |
38 | /**
39 | * Constructor that takes the realm RealmResults, sorts & stores them.
40 | *
41 | * @param results
42 | * @param yValuesField
43 | * @param xIndexField
44 | */
45 | public RealmLineRadarDataSet(RealmResults results, String yValuesField, String xIndexField) {
46 | super(results, yValuesField, xIndexField);
47 | }
48 |
49 | @Override
50 | public int getFillColor() {
51 | return mFillColor;
52 | }
53 |
54 | /**
55 | * sets the color that is used for filling the line surface
56 | *
57 | * @param color
58 | */
59 | public void setFillColor(int color) {
60 | mFillColor = color;
61 | mFillDrawable = null;
62 | }
63 |
64 | @Override
65 | public Drawable getFillDrawable() {
66 | return mFillDrawable;
67 | }
68 |
69 | /**
70 | * Sets the drawable to be used to fill the area below the line.
71 | *
72 | * @param drawable
73 | */
74 | public void setFillDrawable(Drawable drawable) {
75 | this.mFillDrawable = drawable;
76 | }
77 |
78 | @Override
79 | public int getFillAlpha() {
80 | return mFillAlpha;
81 | }
82 |
83 | /**
84 | * sets the alpha value (transparency) that is used for filling the line
85 | * surface (0-255), default: 85
86 | *
87 | * @param alpha
88 | */
89 | public void setFillAlpha(int alpha) {
90 | mFillAlpha = alpha;
91 | }
92 |
93 | /**
94 | * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
95 | * thinner line == better performance, thicker line == worse performance
96 | *
97 | * @param width
98 | */
99 | public void setLineWidth(float width) {
100 |
101 | if (width < 0.2f)
102 | width = 0.2f;
103 | if (width > 10.0f)
104 | width = 10.0f;
105 | mLineWidth = Utils.convertDpToPixel(width);
106 | }
107 |
108 | @Override
109 | public float getLineWidth() {
110 | return mLineWidth;
111 | }
112 |
113 | @Override
114 | public void setDrawFilled(boolean filled) {
115 | mDrawFilled = filled;
116 | }
117 |
118 | @Override
119 | public boolean isDrawFilledEnabled() {
120 | return mDrawFilled;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/matrix/Vector3.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/CandleEntry.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/data/LineScatterCandleRadarDataSet.java:
--------------------------------------------------------------------------------
1 | package com.jn.chart.data;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.jn.chart.interfaces.datasets.ILineScatterCandleRadarDataSet;
6 | import com.jn.chart.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 |
--------------------------------------------------------------------------------
/JNChartLib/src/com/jn/chart/renderer/XAxisRendererBarChart.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jn.chart.renderer;
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.PointF;
6 |
7 | import com.jn.chart.charts.BarChart;
8 | import com.jn.chart.components.XAxis;
9 | import com.jn.chart.data.BarData;
10 | import com.jn.chart.utils.Transformer;
11 | import com.jn.chart.utils.Utils;
12 | import com.jn.chart.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 |
--------------------------------------------------------------------------------