├── .gitignore ├── .idea ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── MPChartLib ├── .gitignore ├── .settings │ └── gradle │ │ └── org.springsource.ide.eclipse.gradle.core.prefs ├── AndroidManifest.xml ├── MPChartLib.iml ├── build.gradle ├── ic_launcher-web.png ├── pom.xml ├── proguard-project.txt ├── project.properties └── src │ └── com │ └── github │ └── mikephil │ └── charting │ ├── animation │ ├── ChartAnimator.java │ ├── Easing.java │ └── EasingFunction.java │ ├── buffer │ ├── AbstractBuffer.java │ ├── BarBuffer.java │ ├── HorizontalBarBuffer.java │ └── ScatterBuffer.java │ ├── charts │ ├── BarChart.java │ ├── BarLineChartBase.java │ ├── BubbleChart.java │ ├── CandleStickChart.java │ ├── Chart.java │ ├── CombinedChart.java │ ├── HorizontalBarChart.java │ ├── LineChart.java │ ├── PieChart.java │ ├── PieRadarChartBase.java │ ├── RadarChart.java │ └── ScatterChart.java │ ├── components │ ├── AxisBase.java │ ├── ComponentBase.java │ ├── Legend.java │ ├── LimitLine.java │ ├── MarkerView.java │ ├── XAxis.java │ └── YAxis.java │ ├── data │ ├── BarData.java │ ├── BarDataSet.java │ ├── BarEntry.java │ ├── BarLineScatterCandleBubbleData.java │ ├── BarLineScatterCandleBubbleDataSet.java │ ├── BaseDataSet.java │ ├── BubbleData.java │ ├── BubbleDataSet.java │ ├── BubbleEntry.java │ ├── CandleData.java │ ├── CandleDataSet.java │ ├── CandleEntry.java │ ├── ChartData.java │ ├── CombinedData.java │ ├── DataSet.java │ ├── Entry.java │ ├── LineData.java │ ├── LineDataSet.java │ ├── LineRadarDataSet.java │ ├── LineScatterCandleRadarDataSet.java │ ├── PieData.java │ ├── PieDataSet.java │ ├── RadarData.java │ ├── RadarDataSet.java │ ├── ScatterData.java │ ├── ScatterDataSet.java │ ├── filter │ │ └── Approximator.java │ └── realm │ │ ├── base │ │ ├── RealmBarLineScatterCandleBubbleDataSet.java │ │ ├── RealmBaseDataSet.java │ │ ├── RealmLineRadarDataSet.java │ │ ├── RealmLineScatterCandleRadarDataSet.java │ │ └── RealmUtils.java │ │ └── implementation │ │ ├── RealmBarData.java │ │ ├── RealmBarDataSet.java │ │ ├── RealmBubbleData.java │ │ ├── RealmBubbleDataSet.java │ │ ├── RealmCandleData.java │ │ ├── RealmCandleDataSet.java │ │ ├── RealmLineData.java │ │ ├── RealmLineDataSet.java │ │ ├── RealmPieData.java │ │ ├── RealmPieDataSet.java │ │ ├── RealmRadarData.java │ │ ├── RealmRadarDataSet.java │ │ ├── RealmScatterData.java │ │ └── RealmScatterDataSet.java │ ├── exception │ └── DrawingDataSetNotCreatedException.java │ ├── formatter │ ├── ColorFormatter.java │ ├── DefaultFillFormatter.java │ ├── DefaultValueFormatter.java │ ├── DefaultXAxisValueFormatter.java │ ├── DefaultYAxisValueFormatter.java │ ├── FillFormatter.java │ ├── LargeValueFormatter.java │ ├── PercentFormatter.java │ ├── StackedValueFormatter.java │ ├── ValueFormatter.java │ ├── XAxisValueFormatter.java │ └── YAxisValueFormatter.java │ ├── highlight │ ├── BarHighlighter.java │ ├── ChartHighlighter.java │ ├── CombinedHighlighter.java │ ├── Highlight.java │ ├── HorizontalBarHighlighter.java │ └── Range.java │ ├── interfaces │ ├── dataprovider │ │ ├── BarDataProvider.java │ │ ├── BarLineScatterCandleBubbleDataProvider.java │ │ ├── BubbleDataProvider.java │ │ ├── CandleDataProvider.java │ │ ├── ChartInterface.java │ │ ├── LineDataProvider.java │ │ └── ScatterDataProvider.java │ └── datasets │ │ ├── IBarDataSet.java │ │ ├── IBarLineScatterCandleBubbleDataSet.java │ │ ├── IBubbleDataSet.java │ │ ├── ICandleDataSet.java │ │ ├── IDataSet.java │ │ ├── ILineDataSet.java │ │ ├── ILineRadarDataSet.java │ │ ├── ILineScatterCandleRadarDataSet.java │ │ ├── IPieDataSet.java │ │ ├── IRadarDataSet.java │ │ └── IScatterDataSet.java │ ├── jobs │ ├── AnimatedMoveViewJob.java │ ├── AnimatedViewPortJob.java │ ├── AnimatedZoomJob.java │ ├── MoveViewJob.java │ ├── ViewPortJob.java │ └── ZoomJob.java │ ├── listener │ ├── BarLineChartTouchListener.java │ ├── ChartTouchListener.java │ ├── OnChartGestureListener.java │ ├── OnChartValueSelectedListener.java │ ├── OnDrawLineChartTouchListener.java │ ├── OnDrawListener.java │ └── PieRadarChartTouchListener.java │ ├── matrix │ └── Vector3.java │ ├── renderer │ ├── AxisRenderer.java │ ├── BarChartRenderer.java │ ├── BubbleChartRenderer.java │ ├── CandleStickChartRenderer.java │ ├── CombinedChartRenderer.java │ ├── DataRenderer.java │ ├── HorizontalBarChartRenderer.java │ ├── LegendRenderer.java │ ├── LineChartRenderer.java │ ├── LineRadarRenderer.java │ ├── LineScatterCandleRadarRenderer.java │ ├── PieChartRenderer.java │ ├── RadarChartRenderer.java │ ├── Renderer.java │ ├── ScatterChartRenderer.java │ ├── XAxisRenderer.java │ ├── XAxisRendererBarChart.java │ ├── XAxisRendererHorizontalBarChart.java │ ├── XAxisRendererRadarChart.java │ ├── YAxisRenderer.java │ ├── YAxisRendererHorizontalBarChart.java │ └── YAxisRendererRadarChart.java │ └── utils │ ├── ColorTemplate.java │ ├── EntryXIndexComparator.java │ ├── FSize.java │ ├── FileUtils.java │ ├── PointD.java │ ├── SelectionDetail.java │ ├── Transformer.java │ ├── TransformerHorizontalBarChart.java │ ├── Utils.java │ └── ViewPortHandler.java ├── README.md ├── StockChart-master.iml ├── StockChart.iml ├── StockChart2.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── yanjiang │ │ └── stockchart │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── yanjiang │ │ │ └── stockchart │ │ │ ├── BaseActivity.java │ │ │ ├── KLineActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MinutesActivity.java │ │ │ ├── Test.java │ │ │ ├── api │ │ │ ├── ClientApi.java │ │ │ ├── Constant.java │ │ │ ├── ConstantTest.java │ │ │ └── DownLoadApi.java │ │ │ ├── application │ │ │ └── App.java │ │ │ ├── bean │ │ │ ├── DataParse.java │ │ │ ├── KLineBean.java │ │ │ └── MinutesBean.java │ │ │ ├── event │ │ │ └── ProgressUpdateEvent.java │ │ │ ├── inject │ │ │ ├── component │ │ │ │ ├── ActivityComponent.java │ │ │ │ ├── AppComponent.java │ │ │ │ ├── FragmentComponent.java │ │ │ │ └── ServiceComponent.java │ │ │ ├── modules │ │ │ │ ├── ActivityModule.java │ │ │ │ ├── AppModule.java │ │ │ │ ├── ClientApiModule.java │ │ │ │ ├── FragmentModule.java │ │ │ │ └── ServiceModule.java │ │ │ └── others │ │ │ │ ├── ApplicationScope.java │ │ │ │ ├── PerActivity.java │ │ │ │ ├── PerFragment.java │ │ │ │ ├── PerService.java │ │ │ │ └── StringQuali.java │ │ │ ├── interceptor │ │ │ ├── HttpInterceptor.java │ │ │ ├── LoggingInterceptor.java │ │ │ ├── ProgressInterceptor.java │ │ │ └── ProgressResponseBody.java │ │ │ ├── mychart │ │ │ ├── CoupleChartGestureListener.java │ │ │ ├── MyBarChart.java │ │ │ ├── MyBottomMarkerView.java │ │ │ ├── MyLeftMarkerView.java │ │ │ ├── MyLineChart.java │ │ │ ├── MyRightMarkerView.java │ │ │ ├── MyXAxis.java │ │ │ ├── MyXAxisRenderer.java │ │ │ ├── MyYAxis.java │ │ │ └── MyYAxisRenderer.java │ │ │ ├── rxutils │ │ │ ├── CommonUtil.java │ │ │ ├── ExecutorManager.java │ │ │ ├── FileUtils.java │ │ │ ├── MyUtils.java │ │ │ ├── SchedulersCompat.java │ │ │ └── VolFormatter.java │ │ │ └── service │ │ │ └── DownLoadService.java │ └── res │ │ ├── jdfw.gif │ │ ├── layout │ │ ├── activity_fix.xml │ │ ├── activity_kline.xml │ │ ├── activity_main.xml │ │ ├── activity_minutes.xml │ │ └── mymarkerview.xml │ │ ├── mipmap │ │ └── ic_launcher.jpg │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── yanjiang │ └── stockchart │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /app/app-release.apk 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | /.idea/ 10 | /MPChartLib/MPChartLib.iml 11 | /MPChartLib/proguard-project.txt 12 | /MPChartLib/pom.xml 13 | /MPChartLib/project.properties 14 | /gradle.properties 15 | /gradlew 16 | /gradlew.bat 17 | /StockChart2.iml 18 | 19 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Android 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /MPChartLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /MPChartLib/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs: -------------------------------------------------------------------------------- 1 | #org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences 2 | #Mon Jan 18 23:02:46 CET 2016 3 | org.springsource.ide.eclipse.gradle.linkedresources= 4 | org.springsource.ide.eclipse.gradle.rootprojectloc=.. 5 | -------------------------------------------------------------------------------- /MPChartLib/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /MPChartLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'maven' 3 | 4 | 5 | android { 6 | compileSdkVersion 23 7 | buildToolsVersion '23.0.2' 8 | // resourcePrefix 'mpcht' 9 | defaultConfig { 10 | minSdkVersion 8 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName '1.0' 14 | 15 | sourceSets { 16 | main { 17 | java.srcDirs = ['src'] 18 | res.srcDirs = ['res'] 19 | assets.srcDirs = ['assets'] 20 | manifest.srcFile 'AndroidManifest.xml' 21 | } 22 | } 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | lintOptions { 31 | abortOnError false 32 | } 33 | } 34 | 35 | repositories { 36 | maven { 37 | url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' 38 | } 39 | } 40 | 41 | dependencies { 42 | //compile fileTree(dir: 'libs', include: ['*.jar']) 43 | //compile 'com.android.support:support-v4:19.+' 44 | provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API 45 | } 46 | 47 | android.libraryVariants.all { variant -> 48 | def name = variant.buildType.name 49 | def task = project.tasks.create "jar${name.capitalize()}", Jar 50 | task.dependsOn variant.javaCompile 51 | task.from variant.javaCompile.destinationDir 52 | artifacts.add('archives', task); 53 | } 54 | 55 | task sourcesJar(type: Jar) { 56 | from android.sourceSets.main.java.srcDirs 57 | classifier = 'sources' 58 | } 59 | 60 | task javadoc(type: Javadoc) { 61 | failOnError false 62 | source = android.sourceSets.main.java.sourceFiles 63 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 64 | } 65 | 66 | task javadocJar(type: Jar, dependsOn: javadoc) { 67 | classifier = 'javadoc' 68 | from javadoc.destinationDir 69 | } 70 | 71 | artifacts { 72 | archives sourcesJar 73 | archives javadocJar 74 | } 75 | -------------------------------------------------------------------------------- /MPChartLib/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndroidJiang/StockChart/c2ce9d52e20b0c20d04bfa3a9dd8167f0101f2a2/MPChartLib/ic_launcher-web.png -------------------------------------------------------------------------------- /MPChartLib/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 4.0.0 20 | 1.4.2-SNAPSHOT 21 | com.github.mikephil 22 | MPAndroidChart 23 | MPAndroidChart 24 | A simple Android chart view/graph view library, supporting line- bar- and piecharts as well as scaling, dragging and animations 25 | https://github.com/PhilJay/MPAndroidChart 26 | apklib 27 | 28 | 29 | 30 | UTF-8 31 | 32 | 33 | 34 | src 35 | 36 | 37 | com.jayway.maven.plugins.android.generation2 38 | android-maven-plugin 39 | 3.9.0-rc.2 40 | true 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | com.google.android 55 | android 56 | provided 57 | 4.1.1.4 58 | 59 | 60 | 61 | 62 | 63 | https://github.com/PhilJay/MPAndroidChart/issues 64 | GitHub Issues 65 | 66 | 67 | 68 | 69 | Apache License Version 2.0 70 | http://www.apache.org/licenses/LICENSE-2.0.html 71 | repo 72 | 73 | 74 | 75 | 76 | https://github.com/PhilJay/MPAndroidChart 77 | scm:git:git://github.com/PhilJay/MPAndroidChart.git 78 | scm:git:git@github.com:PhilJay/MPAndroidChart.git 79 | 80 | 81 | 82 | 83 | Philipp Jahoda 84 | philjay.librarysup@gmail.com 85 | http://stackoverflow.com/users/1590502/philipp-jahoda 86 | PhilJay 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /MPChartLib/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /MPChartLib/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-23 15 | android.library=true 16 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/animation/EasingFunction.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.animation; 2 | 3 | import android.animation.TimeInterpolator; 4 | import android.annotation.SuppressLint; 5 | 6 | /** 7 | * Interface for creating custom made easing functions. Uses the 8 | * TimeInterpolator interface provided by Android. 9 | */ 10 | @SuppressLint("NewApi") 11 | public interface EasingFunction extends TimeInterpolator { 12 | 13 | @Override 14 | float getInterpolation(float input); 15 | } 16 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/buffer/AbstractBuffer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.buffer; 3 | 4 | 5 | /** 6 | * Buffer class to boost performance while drawing. Concept: Replace instead of 7 | * recreate. 8 | * 9 | * @author Philipp Jahoda 10 | * @param The data the buffer accepts to be fed with. 11 | */ 12 | public abstract class AbstractBuffer { 13 | 14 | /** index in the buffer */ 15 | protected int index = 0; 16 | 17 | /** float-buffer that holds the data points to draw, order: x,y,x,y,... */ 18 | public final float[] buffer; 19 | 20 | /** animation phase x-axis */ 21 | protected float phaseX = 1f; 22 | 23 | /** animation phase y-axis */ 24 | protected float phaseY = 1f; 25 | 26 | /** indicates from which x-index the visible data begins */ 27 | protected int mFrom = 0; 28 | 29 | /** indicates to which x-index the visible data ranges */ 30 | protected int mTo = 0; 31 | 32 | /** 33 | * Initialization with buffer-size. 34 | * 35 | * @param size 36 | */ 37 | public AbstractBuffer(int size) { 38 | index = 0; 39 | buffer = new float[size]; 40 | } 41 | 42 | /** limits the drawing on the x-axis */ 43 | public void limitFrom(int from) { 44 | if (from < 0) 45 | from = 0; 46 | mFrom = from; 47 | } 48 | 49 | /** limits the drawing on the x-axis */ 50 | public void limitTo(int to) { 51 | if (to < 0) 52 | to = 0; 53 | mTo = to; 54 | } 55 | 56 | /** 57 | * Resets the buffer index to 0 and makes the buffer reusable. 58 | */ 59 | public void reset() { 60 | index = 0; 61 | } 62 | 63 | /** 64 | * Returns the size (length) of the buffer array. 65 | * 66 | * @return 67 | */ 68 | public int size() { 69 | return buffer.length; 70 | } 71 | 72 | /** 73 | * Set the phases used for animations. 74 | * 75 | * @param phaseX 76 | * @param phaseY 77 | */ 78 | public void setPhases(float phaseX, float phaseY) { 79 | this.phaseX = phaseX; 80 | this.phaseY = phaseY; 81 | } 82 | 83 | /** 84 | * Builds up the buffer with the provided data and resets the buffer-index 85 | * after feed-completion. This needs to run FAST. 86 | * 87 | * @param data 88 | */ 89 | public abstract void feed(T data); 90 | } 91 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/buffer/HorizontalBarBuffer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.buffer; 3 | 4 | import com.github.mikephil.charting.data.BarEntry; 5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 6 | 7 | public class HorizontalBarBuffer extends BarBuffer { 8 | 9 | public HorizontalBarBuffer(int size, float groupspace, int dataSetCount, boolean containsStacks) { 10 | super(size, groupspace, dataSetCount, containsStacks); 11 | } 12 | 13 | @Override 14 | public void feed(IBarDataSet data) { 15 | 16 | float size = data.getEntryCount() * phaseX; 17 | 18 | int dataSetOffset = (mDataSetCount - 1); 19 | float barSpaceHalf = mBarSpace / 2f; 20 | float groupSpaceHalf = mGroupSpace / 2f; 21 | float barWidth = 0.5f; 22 | 23 | for (int i = 0; i < size; i++) { 24 | 25 | BarEntry e = data.getEntryForIndex(i); 26 | 27 | // calculate the x-position, depending on datasetcount 28 | float x = e.getXIndex() + e.getXIndex() * dataSetOffset + mDataSetIndex 29 | + mGroupSpace * e.getXIndex() + groupSpaceHalf; 30 | float y = e.getVal(); 31 | float[] vals = e.getVals(); 32 | 33 | if (!mContainsStacks || vals == null) { 34 | 35 | float bottom = x - barWidth + barSpaceHalf; 36 | float top = x + barWidth - barSpaceHalf; 37 | float left, right; 38 | if (mInverted) { 39 | left = y >= 0 ? y : 0; 40 | right = y <= 0 ? y : 0; 41 | } else { 42 | right = y >= 0 ? y : 0; 43 | left = y <= 0 ? y : 0; 44 | } 45 | 46 | // multiply the height of the rect with the phase 47 | if (right > 0) 48 | right *= phaseY; 49 | else 50 | left *= phaseY; 51 | 52 | addBar(left, top, right, bottom); 53 | 54 | } else { 55 | 56 | float posY = 0f; 57 | float negY = -e.getNegativeSum(); 58 | float yStart; 59 | 60 | // fill the stack 61 | for (int k = 0; k < vals.length; k++) { 62 | 63 | float value = vals[k]; 64 | 65 | if (value >= 0f) { 66 | y = posY; 67 | yStart = posY + value; 68 | posY = yStart; 69 | } else { 70 | y = negY; 71 | yStart = negY + Math.abs(value); 72 | negY += Math.abs(value); 73 | } 74 | 75 | float bottom = x - barWidth + barSpaceHalf; 76 | float top = x + barWidth - barSpaceHalf; 77 | float left, right; 78 | if (mInverted) { 79 | left = y >= yStart ? y : yStart; 80 | right = y <= yStart ? y : yStart; 81 | } else { 82 | right = y >= yStart ? y : yStart; 83 | left = y <= yStart ? y : yStart; 84 | } 85 | 86 | // multiply the height of the rect with the phase 87 | right *= phaseY; 88 | left *= phaseY; 89 | 90 | addBar(left, top, right, bottom); 91 | } 92 | } 93 | } 94 | 95 | reset(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/buffer/ScatterBuffer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.buffer; 3 | 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 6 | 7 | public class ScatterBuffer extends AbstractBuffer { 8 | 9 | public ScatterBuffer(int size) { 10 | super(size); 11 | } 12 | 13 | protected void addForm(float x, float y) { 14 | buffer[index++] = x; 15 | buffer[index++] = y; 16 | } 17 | 18 | @Override 19 | public void feed(IScatterDataSet data) { 20 | 21 | float size = data.getEntryCount() * phaseX; 22 | 23 | for (int i = 0; i < size; i++) { 24 | 25 | Entry e = data.getEntryForIndex(i); 26 | addForm(e.getXIndex(), e.getVal() * phaseY); 27 | } 28 | 29 | reset(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/charts/BubbleChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.BubbleData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider; 9 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; 10 | import com.github.mikephil.charting.renderer.BubbleChartRenderer; 11 | 12 | /** 13 | * The BubbleChart. Draws bubbles. Bubble chart implementation: Copyright 2015 14 | * Pierre-Marc Airoldi Licensed under Apache License 2.0. In the BubbleChart, it 15 | * is the area of the bubble, not the radius or diameter of the bubble that 16 | * conveys the data. 17 | * 18 | * @author Philipp Jahoda 19 | */ 20 | public class BubbleChart extends BarLineChartBase implements BubbleDataProvider { 21 | 22 | public BubbleChart(Context context) { 23 | super(context); 24 | } 25 | 26 | public BubbleChart(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public BubbleChart(Context context, AttributeSet attrs, int defStyle) { 31 | super(context, attrs, defStyle); 32 | } 33 | 34 | @Override 35 | protected void init() { 36 | super.init(); 37 | 38 | mRenderer = new BubbleChartRenderer(this, mAnimator, mViewPortHandler); 39 | } 40 | 41 | @Override 42 | protected void calcMinMax() { 43 | super.calcMinMax(); 44 | 45 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0) 46 | mXAxis.mAxisRange = 1; 47 | 48 | mXAxis.mAxisMinimum = -0.5f; 49 | mXAxis.mAxisMaximum = (float) mData.getXValCount() - 0.5f; 50 | 51 | if (mRenderer != null) { 52 | for (IBubbleDataSet set : mData.getDataSets()) { 53 | 54 | final float xmin = set.getXMin(); 55 | final float xmax = set.getXMax(); 56 | 57 | if (xmin < mXAxis.mAxisMinimum) 58 | mXAxis.mAxisMinimum = xmin; 59 | 60 | if (xmax > mXAxis.mAxisMaximum) 61 | mXAxis.mAxisMaximum = xmax; 62 | } 63 | } 64 | 65 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum); 66 | } 67 | 68 | public BubbleData getBubbleData() { 69 | return mData; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/charts/CandleStickChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.CandleData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider; 9 | import com.github.mikephil.charting.renderer.CandleStickChartRenderer; 10 | 11 | /** 12 | * Financial chart type that draws candle-sticks (OHCL chart). 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class CandleStickChart extends BarLineChartBase implements CandleDataProvider { 17 | 18 | public CandleStickChart(Context context) { 19 | super(context); 20 | } 21 | 22 | public CandleStickChart(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public CandleStickChart(Context context, AttributeSet attrs, int defStyle) { 27 | super(context, attrs, defStyle); 28 | } 29 | 30 | @Override 31 | protected void init() { 32 | super.init(); 33 | 34 | 35 | 36 | 37 | mRenderer = new CandleStickChartRenderer(this, mAnimator, mViewPortHandler); 38 | mXAxis.mAxisMinimum = -0.5f; 39 | } 40 | 41 | @Override 42 | protected void calcMinMax() { 43 | super.calcMinMax(); 44 | 45 | mXAxis.mAxisMaximum += 0.5f; 46 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum); 47 | } 48 | 49 | @Override 50 | public CandleData getCandleData() { 51 | return mData; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/charts/LineChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.LineData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 9 | import com.github.mikephil.charting.renderer.LineChartRenderer; 10 | 11 | /** 12 | * Chart that draws lines, surfaces, circles, ... 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class LineChart extends BarLineChartBase implements LineDataProvider { 17 | 18 | public LineChart(Context context) { 19 | super(context); 20 | } 21 | 22 | public LineChart(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public LineChart(Context context, AttributeSet attrs, int defStyle) { 27 | super(context, attrs, defStyle); 28 | } 29 | 30 | @Override 31 | protected void init() { 32 | super.init(); 33 | 34 | mRenderer = new LineChartRenderer(this, mAnimator, mViewPortHandler); 35 | } 36 | 37 | @Override 38 | protected void calcMinMax() { 39 | super.calcMinMax(); 40 | 41 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0) 42 | mXAxis.mAxisRange = 1; 43 | } 44 | 45 | @Override 46 | public LineData getLineData() { 47 | return mData; 48 | } 49 | 50 | @Override 51 | protected void onDetachedFromWindow() { 52 | // releases the bitmap in the renderer to avoid oom error 53 | if(mRenderer != null && mRenderer instanceof LineChartRenderer) { 54 | ((LineChartRenderer) mRenderer).releaseBitmap(); 55 | } 56 | super.onDetachedFromWindow(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/charts/ScatterChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.ScatterData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider; 9 | import com.github.mikephil.charting.renderer.ScatterChartRenderer; 10 | 11 | /** 12 | * The ScatterChart. Draws dots, triangles, squares and custom shapes into the 13 | * Chart-View. CIRCLE and SCQUARE offer the best performance, TRIANGLE has the 14 | * worst performance. 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public class ScatterChart extends BarLineChartBase implements ScatterDataProvider { 19 | 20 | /** 21 | * enum that defines the shape that is drawn where the values are 22 | */ 23 | public enum ScatterShape { 24 | SQUARE, CIRCLE, TRIANGLE, CROSS, X, 25 | } 26 | 27 | public ScatterChart(Context context) { 28 | super(context); 29 | } 30 | 31 | public ScatterChart(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | public ScatterChart(Context context, AttributeSet attrs, int defStyle) { 36 | super(context, attrs, defStyle); 37 | } 38 | 39 | @Override 40 | protected void init() { 41 | super.init(); 42 | 43 | mRenderer = new ScatterChartRenderer(this, mAnimator, mViewPortHandler); 44 | mXAxis.mAxisMinimum = -0.5f; 45 | } 46 | 47 | @Override 48 | protected void calcMinMax() { 49 | super.calcMinMax(); 50 | 51 | if (mXAxis.mAxisRange == 0 && mData.getYValCount() > 0) 52 | mXAxis.mAxisRange = 1; 53 | 54 | mXAxis.mAxisMaximum += 0.5f; 55 | mXAxis.mAxisRange = Math.abs(mXAxis.mAxisMaximum - mXAxis.mAxisMinimum); 56 | } 57 | 58 | /** 59 | * Returns all possible predefined ScatterShapes. 60 | * 61 | * @return 62 | */ 63 | public static ScatterShape[] getAllPossibleShapes() { 64 | return new ScatterShape[] { 65 | ScatterShape.SQUARE, ScatterShape.CIRCLE, ScatterShape.TRIANGLE, ScatterShape.CROSS 66 | }; 67 | } 68 | 69 | public ScatterData getScatterData() { 70 | return mData; 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/components/MarkerView.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.components; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.widget.RelativeLayout; 8 | 9 | import com.github.mikephil.charting.data.Entry; 10 | import com.github.mikephil.charting.highlight.Highlight; 11 | 12 | /** 13 | * View that can be displayed when selecting values in the chart. Extend this class to provide custom layouts for your 14 | * markers. 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public abstract class MarkerView extends RelativeLayout { 19 | 20 | /** 21 | * Constructor. Sets up the MarkerView with a custom layout resource. 22 | * 23 | * @param context 24 | * @param layoutResource the layout resource to use for the MarkerView 25 | */ 26 | public MarkerView(Context context, int layoutResource) { 27 | super(context); 28 | setupLayoutResource(layoutResource); 29 | } 30 | 31 | /** 32 | * Sets the layout resource for a custom MarkerView. 33 | * 34 | * @param layoutResource 35 | */ 36 | private void setupLayoutResource(int layoutResource) { 37 | 38 | View inflated = LayoutInflater.from(getContext()).inflate(layoutResource, this); 39 | 40 | inflated.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 41 | inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 42 | 43 | // measure(getWidth(), getHeight()); 44 | inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight()); 45 | } 46 | 47 | /** 48 | * Draws the MarkerView on the given position on the screen with the given Canvas object. 49 | * 50 | * @param canvas 51 | * @param posx 52 | * @param posy 53 | */ 54 | public void draw(Canvas canvas, float posx, float posy) { 55 | 56 | // take offsets into consideration 57 | posx += getXOffset(posx); 58 | posy += getYOffset(posy); 59 | 60 | // translate to the correct position and draw 61 | canvas.translate(posx, posy); 62 | draw(canvas); 63 | canvas.translate(-posx, -posy); 64 | } 65 | 66 | /** 67 | * This method enables a specified custom MarkerView to update it's content everytime the MarkerView is redrawn. 68 | * 69 | * @param e The Entry the MarkerView belongs to. This can also be any subclass of Entry, like BarEntry or 70 | * CandleEntry, simply cast it at runtime. 71 | * @param highlight the highlight object contains information about the highlighted value such as it's dataset-index, the 72 | * selected range or stack-index (only stacked bar entries). 73 | */ 74 | public abstract void refreshContent(Entry e, Highlight highlight); 75 | 76 | /** 77 | * Use this to return the desired offset you wish the MarkerView to have on the x-axis. By returning -(getWidth() / 78 | * 2) you will center the MarkerView horizontally. 79 | * 80 | * @param xpos the position on the x-axis in pixels where the marker is drawn 81 | * @return 82 | */ 83 | public abstract int getXOffset(float xpos); 84 | 85 | /** 86 | * Use this to return the desired position offset you wish the MarkerView to have on the y-axis. By returning 87 | * -getHeight() you will cause the MarkerView to be above the selected value. 88 | * 89 | * @param ypos the position on the y-axis in pixels where the marker is drawn 90 | * @return 91 | */ 92 | public abstract int getYOffset(float ypos); 93 | } 94 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/BarData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Data object that represents all data for the BarChart. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public class BarData extends BarLineScatterCandleBubbleData { 15 | 16 | /** the space that is left between groups of bars */ 17 | private float mGroupSpace = 0.8f; 18 | 19 | // /** 20 | // * The maximum space (in pixels on the screen) a single bar can consume. 21 | // */ 22 | // private float mMaximumBarWidth = 100f; 23 | 24 | public BarData() { 25 | super(); 26 | } 27 | 28 | public BarData(List xVals) { 29 | super(xVals); 30 | } 31 | 32 | public BarData(String[] xVals) { 33 | super(xVals); 34 | } 35 | 36 | public BarData(List xVals, List dataSets) { 37 | super(xVals, dataSets); 38 | } 39 | 40 | public BarData(String[] xVals, List dataSets) { 41 | super(xVals, dataSets); 42 | } 43 | 44 | public BarData(List xVals, IBarDataSet dataSet) { 45 | super(xVals, toList(dataSet)); 46 | } 47 | 48 | public BarData(String[] xVals, IBarDataSet dataSet) { 49 | super(xVals, toList(dataSet)); 50 | } 51 | 52 | private static List toList(IBarDataSet dataSet) { 53 | List sets = new ArrayList<>(); 54 | sets.add(dataSet); 55 | return sets; 56 | } 57 | 58 | /** 59 | * Returns the space that is left out between groups of bars. Always returns 60 | * 0 if the BarData object only contains one DataSet (because for one 61 | * DataSet, there is no group-space needed). 62 | * 63 | * @return 64 | */ 65 | public float getGroupSpace() { 66 | 67 | if (mDataSets.size() <= 1) 68 | return 0f; 69 | else 70 | return mGroupSpace; 71 | } 72 | 73 | /** 74 | * Sets the space between groups of bars of different datasets in percent of 75 | * the total width of one bar. 100 = space is exactly one bar width, 76 | * default: 80 77 | * 78 | * @param percent 79 | */ 80 | public void setGroupSpace(float percent) { 81 | mGroupSpace = percent / 100f; 82 | } 83 | 84 | /** 85 | * Returns true if this BarData object contains grouped DataSets (more than 86 | * 1 DataSet). 87 | * 88 | * @return 89 | */ 90 | public boolean isGrouped() { 91 | return mDataSets.size() > 1 ? true : false; 92 | } 93 | 94 | // 95 | // /** 96 | // * Sets the maximum width (in density pixels) a single bar in the barchart 97 | // * should consume. 98 | // * 99 | // * @param max 100 | // */ 101 | // public void setBarWidthMaximum(float max) { 102 | // mMaximumBarWidth = Utils.convertDpToPixel(max); 103 | // } 104 | // 105 | // /** 106 | // * Returns the maximum width (in density pixels) a single bar in the 107 | // * barchart should consume. 108 | // * 109 | // * @return 110 | // */ 111 | // public float getBarWidthMaximum() { 112 | // return mMaximumBarWidth; 113 | // } 114 | } 115 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public abstract class BarLineScatterCandleBubbleData> 14 | extends ChartData { 15 | 16 | public BarLineScatterCandleBubbleData() { 17 | super(); 18 | } 19 | 20 | public BarLineScatterCandleBubbleData(List xVals) { 21 | super(xVals); 22 | } 23 | 24 | public BarLineScatterCandleBubbleData(String[] xVals) { 25 | super(xVals); 26 | } 27 | 28 | public BarLineScatterCandleBubbleData(List xVals, List sets) { 29 | super(xVals, sets); 30 | } 31 | 32 | public BarLineScatterCandleBubbleData(String[] xVals, List sets) { 33 | super(xVals, sets); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import android.graphics.Color; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public abstract class BarLineScatterCandleBubbleDataSet extends DataSet implements IBarLineScatterCandleBubbleDataSet { 16 | 17 | /** default highlight color */ 18 | protected int mHighLightColor = Color.rgb(255, 187, 115); 19 | 20 | public BarLineScatterCandleBubbleDataSet(List yVals, String label) { 21 | super(yVals, label); 22 | } 23 | 24 | /** 25 | * Sets the color that is used for drawing the highlight indicators. Dont 26 | * forget to resolve the color using getResources().getColor(...) or 27 | * Color.rgb(...). 28 | * 29 | * @param color 30 | */ 31 | public void setHighLightColor(int color) { 32 | mHighLightColor = color; 33 | } 34 | 35 | @Override 36 | public int getHighLightColor() { 37 | return mHighLightColor; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/BubbleData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class BubbleData extends BarLineScatterCandleBubbleData { 10 | 11 | public BubbleData() { 12 | super(); 13 | } 14 | 15 | public BubbleData(List xVals) { 16 | super(xVals); 17 | } 18 | 19 | public BubbleData(String[] xVals) { 20 | super(xVals); 21 | } 22 | 23 | public BubbleData(List xVals, List dataSets) { 24 | super(xVals, dataSets); 25 | } 26 | 27 | public BubbleData(String[] xVals, List dataSets) { 28 | super(xVals, dataSets); 29 | } 30 | 31 | public BubbleData(List xVals, IBubbleDataSet dataSet) { 32 | super(xVals, toList(dataSet)); 33 | } 34 | 35 | public BubbleData(String[] xVals, IBubbleDataSet dataSet) { 36 | super(xVals, toList(dataSet)); 37 | } 38 | 39 | private static List toList(IBubbleDataSet dataSet) { 40 | List sets = new ArrayList<>(); 41 | sets.add(dataSet); 42 | return sets; 43 | } 44 | 45 | /** 46 | * Sets the width of the circle that surrounds the bubble when highlighted 47 | * for all DataSet objects this data object contains, in dp. 48 | * 49 | * @param width 50 | */ 51 | public void setHighlightCircleWidth(float width) { 52 | for (IBubbleDataSet set : mDataSets) { 53 | set.setHighlightCircleWidth(width); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/BubbleEntry.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | /** 5 | * Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble 6 | * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under 7 | * Apache License 2.0 8 | * 9 | * @author Philipp Jahoda 10 | */ 11 | public class BubbleEntry extends Entry { 12 | 13 | /** size value */ 14 | private float mSize = 0f; 15 | 16 | /** 17 | * Constructor. 18 | * 19 | * @param xIndex The index on the x-axis. 20 | * @param val The value on the y-axis. 21 | * @param size The size of the bubble. 22 | */ 23 | public BubbleEntry(int xIndex, float val, float size) { 24 | super(val, xIndex); 25 | 26 | this.mSize = size; 27 | } 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param xIndex The index on the x-axis. 33 | * @param val The value on the y-axis. 34 | * @param size The size of the bubble. 35 | * @param data Spot for additional data this Entry represents. 36 | */ 37 | public BubbleEntry(int xIndex, float val, float size, Object data) { 38 | super(val, xIndex, data); 39 | 40 | this.mSize = size; 41 | } 42 | 43 | public BubbleEntry copy() { 44 | 45 | return new BubbleEntry(getXIndex(), getVal(), mSize, getData()); 46 | } 47 | 48 | /** 49 | * Returns the size of this entry (the size of the bubble). 50 | * 51 | * @return 52 | */ 53 | public float getSize() { 54 | return mSize; 55 | } 56 | 57 | public void setSize(float size) { 58 | this.mSize = size; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/CandleData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data; 2 | 3 | import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class CandleData extends BarLineScatterCandleBubbleData { 9 | 10 | public CandleData() { 11 | super(); 12 | } 13 | 14 | public CandleData(List xVals) { 15 | super(xVals); 16 | } 17 | 18 | public CandleData(String[] xVals) { 19 | super(xVals); 20 | } 21 | 22 | public CandleData(List xVals, List dataSets) { 23 | super(xVals, dataSets); 24 | } 25 | 26 | public CandleData(String[] xVals, List dataSets) { 27 | super(xVals, dataSets); 28 | } 29 | 30 | public CandleData(List xVals, ICandleDataSet dataSet) { 31 | super(xVals, toList(dataSet)); 32 | } 33 | 34 | public CandleData(String[] xVals, ICandleDataSet dataSet) { 35 | super(xVals, toList(dataSet)); 36 | } 37 | 38 | private static List toList(ICandleDataSet dataSet) { 39 | List sets = new ArrayList<>(); 40 | sets.add(dataSet); 41 | return sets; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/LineData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Data object that encapsulates all data associated with a LineChart. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public class LineData extends BarLineScatterCandleBubbleData { 15 | 16 | public LineData() { 17 | super(); 18 | } 19 | 20 | public LineData(List xVals) { 21 | super(xVals); 22 | } 23 | 24 | public LineData(String[] xVals) { 25 | super(xVals); 26 | } 27 | 28 | public LineData(List xVals, List dataSets) { 29 | super(xVals, dataSets); 30 | } 31 | 32 | public LineData(String[] xVals, List dataSets) { 33 | super(xVals, dataSets); 34 | } 35 | 36 | public LineData(List xVals, ILineDataSet dataSet) { 37 | super(xVals, toList(dataSet)); 38 | } 39 | 40 | public LineData(String[] xVals, ILineDataSet dataSet) { 41 | super(xVals, toList(dataSet)); 42 | } 43 | 44 | private static List toList(ILineDataSet dataSet) { 45 | List sets = new ArrayList<>(); 46 | sets.add(dataSet); 47 | return sets; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/LineRadarDataSet.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import android.annotation.TargetApi; 5 | import android.graphics.Color; 6 | import android.graphics.drawable.Drawable; 7 | 8 | import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet; 9 | import com.github.mikephil.charting.utils.Utils; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Base dataset for line and radar DataSets. 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public abstract class LineRadarDataSet extends LineScatterCandleRadarDataSet implements ILineRadarDataSet { 19 | 20 | /** 21 | * the color that is used for filling the line surface 22 | */ 23 | private int mFillColor = Color.rgb(140, 234, 255); 24 | 25 | /** 26 | * the drawable to be used for filling the line surface 27 | */ 28 | protected Drawable mFillDrawable; 29 | 30 | /** 31 | * transparency used for filling line surface 32 | */ 33 | private int mFillAlpha = 85; 34 | 35 | /** 36 | * the width of the drawn data lines 37 | */ 38 | private float mLineWidth = 2.5f; 39 | 40 | /** 41 | * if true, the data will also be drawn filled 42 | */ 43 | private boolean mDrawFilled = false; 44 | 45 | 46 | public LineRadarDataSet(List yVals, String label) { 47 | super(yVals, label); 48 | } 49 | 50 | @Override 51 | public int getFillColor() { 52 | return mFillColor; 53 | } 54 | 55 | /** 56 | * Sets the color that is used for filling the area below the line. 57 | * Resets an eventually set "fillDrawable". 58 | * 59 | * @param color 60 | */ 61 | public void setFillColor(int color) { 62 | mFillColor = color; 63 | mFillDrawable = null; 64 | } 65 | 66 | @Override 67 | public Drawable getFillDrawable() { 68 | return mFillDrawable; 69 | } 70 | 71 | /** 72 | * Sets the drawable to be used to fill the area below the line. 73 | * 74 | * @param drawable 75 | */ 76 | @TargetApi(18) 77 | public void setFillDrawable(Drawable drawable) { 78 | this.mFillDrawable = drawable; 79 | } 80 | 81 | @Override 82 | public int getFillAlpha() { 83 | return mFillAlpha; 84 | } 85 | 86 | /** 87 | * sets the alpha value (transparency) that is used for filling the line 88 | * surface (0-255), default: 85 89 | * 90 | * @param alpha 91 | */ 92 | public void setFillAlpha(int alpha) { 93 | mFillAlpha = alpha; 94 | } 95 | 96 | /** 97 | * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE: 98 | * thinner line == better performance, thicker line == worse performance 99 | * 100 | * @param width 101 | */ 102 | public void setLineWidth(float width) { 103 | 104 | if (width < 0.2f) 105 | width = 0.2f; 106 | if (width > 10.0f) 107 | width = 10.0f; 108 | mLineWidth = Utils.convertDpToPixel(width); 109 | } 110 | 111 | @Override 112 | public float getLineWidth() { 113 | return mLineWidth; 114 | } 115 | 116 | @Override 117 | public void setDrawFilled(boolean filled) { 118 | mDrawFilled = filled; 119 | } 120 | 121 | @Override 122 | public boolean isDrawFilledEnabled() { 123 | return mDrawFilled; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/PieData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * A PieData object can only represent one DataSet. Unlike all other charts, the 11 | * legend labels of the PieChart are created from the x-values array, and not 12 | * from the DataSet labels. Each PieData object can only represent one 13 | * PieDataSet (multiple PieDataSets inside a single PieChart are not possible). 14 | * 15 | * @author Philipp Jahoda 16 | */ 17 | public class PieData extends ChartData { 18 | 19 | public PieData() { 20 | super(); 21 | } 22 | 23 | public PieData(List xVals) { 24 | super(xVals); 25 | } 26 | 27 | public PieData(String[] xVals) { 28 | super(xVals); 29 | } 30 | 31 | public PieData(List xVals, IPieDataSet dataSet) { 32 | super(xVals, toList(dataSet)); 33 | } 34 | 35 | public PieData(String[] xVals, IPieDataSet dataSet) { 36 | super(xVals, toList(dataSet)); 37 | } 38 | 39 | private static List toList(IPieDataSet dataSet) { 40 | List sets = new ArrayList<>(); 41 | sets.add(dataSet); 42 | return sets; 43 | } 44 | 45 | /** 46 | * Sets the PieDataSet this data object should represent. 47 | * 48 | * @param dataSet 49 | */ 50 | public void setDataSet(IPieDataSet dataSet) { 51 | mDataSets.clear(); 52 | mDataSets.add(dataSet); 53 | init(); 54 | } 55 | 56 | /** 57 | * Returns the DataSet this PieData object represents. A PieData object can 58 | * only contain one DataSet. 59 | * 60 | * @return 61 | */ 62 | public IPieDataSet getDataSet() { 63 | return mDataSets.get(0); 64 | } 65 | 66 | /** 67 | * The PieData object can only have one DataSet. Use getDataSet() method instead. 68 | * 69 | * @param index 70 | * @return 71 | */ 72 | @Override 73 | public IPieDataSet getDataSetByIndex(int index) { 74 | return index == 0 ? getDataSet() : null; 75 | } 76 | 77 | @Override 78 | public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) { 79 | return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0) 80 | : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null; 81 | } 82 | 83 | /** 84 | * Returns the sum of all values in this PieData object. 85 | * 86 | * @return 87 | */ 88 | public float getYValueSum() { 89 | 90 | float sum = 0; 91 | 92 | for (int i = 0; i < getDataSet().getEntryCount(); i++) 93 | sum += getDataSet().getEntryForIndex(i).getVal(); 94 | 95 | 96 | return sum; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/RadarData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Data container for the RadarChart. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public class RadarData extends ChartData { 15 | 16 | public RadarData() { 17 | super(); 18 | } 19 | 20 | public RadarData(List xVals) { 21 | super(xVals); 22 | } 23 | 24 | public RadarData(String[] xVals) { 25 | super(xVals); 26 | } 27 | 28 | public RadarData(List xVals, List dataSets) { 29 | super(xVals, dataSets); 30 | } 31 | 32 | public RadarData(String[] xVals, List dataSets) { 33 | super(xVals, dataSets); 34 | } 35 | 36 | public RadarData(List xVals, IRadarDataSet dataSet) { 37 | super(xVals, toList(dataSet)); 38 | } 39 | 40 | public RadarData(String[] xVals, IRadarDataSet dataSet) { 41 | super(xVals, toList(dataSet)); 42 | } 43 | 44 | private static List toList(IRadarDataSet dataSet) { 45 | List sets = new ArrayList<>(); 46 | sets.add(dataSet); 47 | return sets; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/ScatterData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class ScatterData extends BarLineScatterCandleBubbleData { 10 | 11 | public ScatterData() { 12 | super(); 13 | } 14 | 15 | public ScatterData(List xVals) { 16 | super(xVals); 17 | } 18 | 19 | public ScatterData(String[] xVals) { 20 | super(xVals); 21 | } 22 | 23 | public ScatterData(List xVals, List dataSets) { 24 | super(xVals, dataSets); 25 | } 26 | 27 | public ScatterData(String[] xVals, List dataSets) { 28 | super(xVals, dataSets); 29 | } 30 | 31 | public ScatterData(List xVals, IScatterDataSet dataSet) { 32 | super(xVals, toList(dataSet)); 33 | } 34 | 35 | public ScatterData(String[] xVals, IScatterDataSet dataSet) { 36 | super(xVals, toList(dataSet)); 37 | } 38 | 39 | private static List toList(IScatterDataSet dataSet) { 40 | List sets = new ArrayList<>(); 41 | sets.add(dataSet); 42 | return sets; 43 | } 44 | 45 | /** 46 | * Returns the maximum shape-size across all DataSets. 47 | * 48 | * @return 49 | */ 50 | public float getGreatestShapeSize() { 51 | 52 | float max = 0f; 53 | 54 | for (IScatterDataSet set : mDataSets) { 55 | float size = set.getScatterShapeSize(); 56 | 57 | if (size > max) 58 | max = size; 59 | } 60 | 61 | return max; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmBarLineScatterCandleBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.base; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; 7 | 8 | import io.realm.RealmObject; 9 | import io.realm.RealmResults; 10 | 11 | /** 12 | * Created by Philipp Jahoda on 08/11/15. 13 | */ 14 | public abstract class RealmBarLineScatterCandleBubbleDataSet extends RealmBaseDataSet implements IBarLineScatterCandleBubbleDataSet { 15 | 16 | /** default highlight color */ 17 | protected int mHighLightColor = Color.rgb(255, 187, 115); 18 | 19 | public RealmBarLineScatterCandleBubbleDataSet(RealmResults results, String yValuesField) { 20 | super(results, yValuesField); 21 | } 22 | 23 | /** 24 | * Constructor that takes the realm RealmResults, sorts & stores them. 25 | * 26 | * @param results 27 | * @param yValuesField 28 | * @param xIndexField 29 | */ 30 | public RealmBarLineScatterCandleBubbleDataSet(RealmResults results, String yValuesField, String xIndexField) { 31 | super(results, yValuesField, xIndexField); 32 | } 33 | 34 | /** 35 | * Sets the color that is used for drawing the highlight indicators. Dont 36 | * forget to resolve the color using getResources().getColor(...) or 37 | * Color.rgb(...). 38 | * 39 | * @param color 40 | */ 41 | public void setHighLightColor(int color) { 42 | mHighLightColor = color; 43 | } 44 | 45 | @Override 46 | public int getHighLightColor() { 47 | return mHighLightColor; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmLineRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.base; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.Drawable; 5 | 6 | import com.github.mikephil.charting.data.Entry; 7 | import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet; 8 | import com.github.mikephil.charting.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 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/base/RealmUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.base; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import io.realm.DynamicRealmObject; 7 | import io.realm.RealmObject; 8 | import io.realm.RealmResults; 9 | /** 10 | * Created by Philipp Jahoda on 19/12/15. 11 | */ 12 | public final class RealmUtils { 13 | 14 | /** 15 | * Prevent class instantiation. 16 | */ 17 | private RealmUtils() { 18 | } 19 | 20 | /** 21 | * Transforms the given Realm-ResultSet into a String array by using the provided xValuesField. 22 | * 23 | * @param result 24 | * @param xValuesField 25 | * @return 26 | */ 27 | public static List toXVals(RealmResults result, String xValuesField) { 28 | 29 | List xVals = new ArrayList<>(); 30 | 31 | for (RealmObject object : result) { 32 | 33 | DynamicRealmObject dynamicObject = new DynamicRealmObject(object); 34 | xVals.add(dynamicObject.getString(xValuesField)); 35 | } 36 | 37 | return xVals; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBarData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.BarData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmBarData extends BarData { 16 | 17 | public RealmBarData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmBubbleData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.BubbleData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmBubbleData extends BubbleData { 16 | 17 | public RealmBubbleData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmCandleData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.CandleData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmCandleData extends CandleData { 16 | 17 | public RealmCandleData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmLineData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.LineData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmLineData extends LineData { 16 | 17 | public RealmLineData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmPieData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.PieData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; 6 | 7 | import io.realm.RealmObject; 8 | import io.realm.RealmResults; 9 | 10 | /** 11 | * Created by Philipp Jahoda on 19/12/15. 12 | */ 13 | public class RealmPieData extends PieData { 14 | 15 | public RealmPieData(RealmResults result, String xValuesField, IPieDataSet dataSet) { 16 | super(RealmUtils.toXVals(result, xValuesField), dataSet); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmRadarData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.RadarData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmRadarData extends RadarData{ 16 | 17 | public RealmRadarData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/data/realm/implementation/RealmScatterData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data.realm.implementation; 2 | 3 | import com.github.mikephil.charting.data.ScatterData; 4 | import com.github.mikephil.charting.data.realm.base.RealmUtils; 5 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.RealmObject; 10 | import io.realm.RealmResults; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/12/15. 14 | */ 15 | public class RealmScatterData extends ScatterData { 16 | 17 | public RealmScatterData(RealmResults result, String xValuesField, List dataSets) { 18 | super(RealmUtils.toXVals(result, xValuesField), dataSets); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/exception/DrawingDataSetNotCreatedException.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.exception; 2 | 3 | public class DrawingDataSetNotCreatedException extends RuntimeException { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 1L; 9 | 10 | public DrawingDataSetNotCreatedException() { 11 | super("Have to create a new drawing set first. Call ChartData's createNewDrawingDataSet() method"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/ColorFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | /** 6 | * Interface that can be used to return a customized color instead of setting 7 | * colors via the setColor(...) method of the DataSet. 8 | * 9 | * @author Philipp Jahoda 10 | */ 11 | public interface ColorFormatter { 12 | 13 | int getColor(Entry e, int index); 14 | } -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/DefaultFillFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | 4 | import com.github.mikephil.charting.data.LineData; 5 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 6 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 7 | 8 | /** 9 | * Default formatter that calculates the position of the filled line. 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public class DefaultFillFormatter implements FillFormatter { 14 | 15 | @Override 16 | public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) { 17 | 18 | float fillMin; 19 | float chartMaxY = dataProvider.getYChartMax(); 20 | float chartMinY = dataProvider.getYChartMin(); 21 | 22 | LineData data = dataProvider.getLineData(); 23 | 24 | if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) { 25 | fillMin = 0f; 26 | } else { 27 | 28 | float max, min; 29 | 30 | if (data.getYMax() > 0) 31 | max = 0f; 32 | else 33 | max = chartMaxY; 34 | if (data.getYMin() < 0) 35 | min = 0f; 36 | else 37 | min = chartMinY; 38 | 39 | fillMin = dataSet.getYMin() >= 0 ? min : max; 40 | } 41 | 42 | return fillMin; 43 | } 44 | } -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/DefaultValueFormatter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.formatter; 3 | 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.utils.ViewPortHandler; 6 | 7 | import java.text.DecimalFormat; 8 | 9 | /** 10 | * Default formatter used for formatting values inside the chart. Uses a DecimalFormat with 11 | * pre-calculated number of digits (depending on max and min value). 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public class DefaultValueFormatter implements ValueFormatter { 16 | 17 | /** decimalformat for formatting */ 18 | private DecimalFormat mFormat; 19 | 20 | /** 21 | * Constructor that specifies to how many digits the value should be 22 | * formatted. 23 | * 24 | * @param digits 25 | */ 26 | public DefaultValueFormatter(int digits) { 27 | 28 | StringBuilder b = new StringBuilder(); 29 | for (int i = 0; i < digits; i++) { 30 | if (i == 0) 31 | b.append("."); 32 | b.append("0"); 33 | } 34 | 35 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); 36 | } 37 | 38 | @Override 39 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 40 | 41 | // put more logic here ... 42 | // avoid memory allocations here (for performance reasons) 43 | 44 | return mFormat.format(value); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/DefaultXAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.utils.ViewPortHandler; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 14/09/15. 7 | * Default formatter class for adjusting x-values before drawing them. 8 | * This simply returns the original value unmodified. 9 | */ 10 | public class DefaultXAxisValueFormatter implements XAxisValueFormatter { 11 | 12 | @Override 13 | public String getXValue(String original, int index, ViewPortHandler viewPortHandler) { 14 | return original; // just return original, no adjustments 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/DefaultYAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | 5 | import java.text.DecimalFormat; 6 | 7 | /** 8 | * Created by Philipp Jahoda on 20/09/15. 9 | * Default formatter used for formatting labels of the YAxis. Uses a DecimalFormat with 10 | * pre-calculated number of digits (depending on max and min value). 11 | */ 12 | public class DefaultYAxisValueFormatter implements YAxisValueFormatter { 13 | 14 | /** decimalformat for formatting */ 15 | private DecimalFormat mFormat; 16 | 17 | /** 18 | * Constructor that specifies to how many digits the value should be 19 | * formatted. 20 | * 21 | * @param digits 22 | */ 23 | public DefaultYAxisValueFormatter(int digits) { 24 | 25 | StringBuilder b = new StringBuilder(); 26 | for (int i = 0; i < digits; i++) { 27 | if (i == 0) 28 | b.append("."); 29 | b.append("0"); 30 | } 31 | 32 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); 33 | } 34 | 35 | @Override 36 | public String getFormattedValue(float value, YAxis yAxis) { 37 | // avoid memory allocations here (for performance) 38 | return mFormat.format(value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/FillFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 4 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 5 | 6 | /** 7 | * Interface for providing a custom logic to where the filling line of a LineDataSet 8 | * should end. This of course only works if setFillEnabled(...) is set to true. 9 | * 10 | * @author Philipp Jahoda 11 | */ 12 | public interface FillFormatter { 13 | 14 | /** 15 | * Returns the vertical (y-axis) position where the filled-line of the 16 | * LineDataSet should end. 17 | * 18 | * @param dataSet the ILineDataSet that is currently drawn 19 | * @param dataProvider 20 | * @return 21 | */ 22 | float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider); 23 | } 24 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/LargeValueFormatter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.formatter; 3 | 4 | import com.github.mikephil.charting.components.YAxis; 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.utils.ViewPortHandler; 7 | 8 | import java.text.DecimalFormat; 9 | 10 | /** 11 | * Predefined value-formatter that formats large numbers in a pretty way. 12 | * Outputs: 856 = 856; 1000 = 1k; 5821 = 5.8k; 10500 = 10k; 101800 = 102k; 13 | * 2000000 = 2m; 7800000 = 7.8m; 92150000 = 92m; 123200000 = 123m; 9999999 = 14 | * 10m; 1000000000 = 1b; Special thanks to Roman Gromov 15 | * (https://github.com/romangromov) for this piece of code. 16 | * 17 | * @author Philipp Jahoda 18 | * @author Oleksandr Tyshkovets 19 | */ 20 | public class LargeValueFormatter implements ValueFormatter, YAxisValueFormatter { 21 | 22 | private static String[] SUFFIX = new String[]{ 23 | "", "k", "m", "b", "t" 24 | }; 25 | private static final int MAX_LENGTH = 4; 26 | private DecimalFormat mFormat; 27 | private String mText = ""; 28 | 29 | public LargeValueFormatter() { 30 | mFormat = new DecimalFormat("###E0"); 31 | } 32 | 33 | /** 34 | * Creates a formatter that appends a specified text to the result string 35 | * 36 | * @param appendix a text that will be appended 37 | */ 38 | public LargeValueFormatter(String appendix) { 39 | this(); 40 | mText = appendix; 41 | } 42 | 43 | // ValueFormatter 44 | @Override 45 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 46 | return makePretty(value) + mText; 47 | } 48 | 49 | // YAxisValueFormatter 50 | @Override 51 | public String getFormattedValue(float value, YAxis yAxis) { 52 | return makePretty(value) + mText; 53 | } 54 | 55 | /** 56 | * Set an appendix text to be added at the end of the formatted value. 57 | * 58 | * @param appendix 59 | */ 60 | public void setAppendix(String appendix) { 61 | this.mText = appendix; 62 | } 63 | 64 | /** 65 | * Set custom suffix to be appended after the values. 66 | * Default suffix: ["", "k", "m", "b", "t"] 67 | * 68 | * @param suff new suffix 69 | */ 70 | public void setSuffix(String[] suff) { 71 | if (suff.length == 5) { 72 | SUFFIX = suff; 73 | } 74 | } 75 | 76 | /** 77 | * Formats each number properly. Special thanks to Roman Gromov 78 | * (https://github.com/romangromov) for this piece of code. 79 | */ 80 | private String makePretty(double number) { 81 | 82 | String r = mFormat.format(number); 83 | 84 | r = r.replaceAll("E[0-9]", SUFFIX[Character.getNumericValue(r.charAt(r.length() - 1)) / 3]); 85 | 86 | while (r.length() > MAX_LENGTH || r.matches("[0-9]+\\.[a-z]")) { 87 | r = r.substring(0, r.length() - 2) + r.substring(r.length() - 1); 88 | } 89 | 90 | return r; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/PercentFormatter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.formatter; 3 | 4 | import com.github.mikephil.charting.components.YAxis; 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.utils.ViewPortHandler; 7 | 8 | import java.text.DecimalFormat; 9 | 10 | /** 11 | * This ValueFormatter is just for convenience and simply puts a "%" sign after 12 | * each value. (Recommeded for PieChart) 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class PercentFormatter implements ValueFormatter, YAxisValueFormatter { 17 | 18 | protected DecimalFormat mFormat; 19 | 20 | public PercentFormatter() { 21 | mFormat = new DecimalFormat("###,###,##0.0"); 22 | } 23 | 24 | /** 25 | * Allow a custom decimalformat 26 | * 27 | * @param format 28 | */ 29 | public PercentFormatter(DecimalFormat format) { 30 | this.mFormat = format; 31 | } 32 | 33 | // ValueFormatter 34 | @Override 35 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 36 | return mFormat.format(value) + " %"; 37 | } 38 | 39 | // YAxisValueFormatter 40 | @Override 41 | public String getFormattedValue(float value, YAxis yAxis) { 42 | return mFormat.format(value) + " %"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/StackedValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.BarEntry; 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.utils.ViewPortHandler; 6 | 7 | import java.text.DecimalFormat; 8 | 9 | /** 10 | * Created by Philipp Jahoda on 28/01/16. 11 | *

12 | * A formatter specifically for stacked BarChart that allows to specify whether the all stack values 13 | * or just the top value should be drawn. 14 | */ 15 | public class StackedValueFormatter implements ValueFormatter { 16 | 17 | /** 18 | * if true, all stack values of the stacked bar entry are drawn, else only top 19 | */ 20 | private boolean mDrawWholeStack; 21 | 22 | /** 23 | * a string that should be appended behind the value 24 | */ 25 | private String mAppendix; 26 | 27 | private DecimalFormat mFormat; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param drawWholeStack if true, all stack values of the stacked bar entry are drawn, else only top 33 | * @param appendix a string that should be appended behind the value 34 | * @param decimals the number of decimal digits to use 35 | */ 36 | public StackedValueFormatter(boolean drawWholeStack, String appendix, int decimals) { 37 | this.mDrawWholeStack = drawWholeStack; 38 | this.mAppendix = appendix; 39 | 40 | StringBuilder b = new StringBuilder(); 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 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/ValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.utils.ViewPortHandler; 5 | 6 | /** 7 | * Interface that allows custom formatting of all values inside the chart before they are 8 | * being drawn to the screen. Simply create your own formatting class and let 9 | * it implement ValueFormatter. Then override the getFormattedValue(...) method 10 | * and return whatever you want. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public interface ValueFormatter { 15 | 16 | /** 17 | * Called when a value (from labels inside the chart) is formatted 18 | * before being drawn. For performance reasons, avoid excessive calculations 19 | * and memory allocations inside this method. 20 | * 21 | * @param value the value to be formatted 22 | * @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry 23 | * @param dataSetIndex the index of the DataSet the entry in focus belongs to 24 | * @param viewPortHandler provides information about the current chart state (scale, translation, ...) 25 | * @return the formatted label ready for being drawn 26 | */ 27 | String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler); 28 | } 29 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/XAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.utils.ViewPortHandler; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 14/09/15. 7 | * An interface for providing custom x-axis Strings. 8 | * 9 | * @author Philipp Jahoda 10 | */ 11 | public interface XAxisValueFormatter { 12 | 13 | /** 14 | * Returns the customized label that is drawn on the x-axis. 15 | * For performance reasons, avoid excessive calculations 16 | * and memory allocations inside this method. 17 | * 18 | * @param original the original x-axis label to be drawn 19 | * @param index the x-index that is currently being drawn 20 | * @param viewPortHandler provides information about the current chart state (scale, translation, ...) 21 | * @return 22 | */ 23 | String getXValue(String original, int index, ViewPortHandler viewPortHandler); 24 | } 25 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/formatter/YAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 20/09/15. 7 | * Custom formatter interface that allows formatting of 8 | * YAxis labels before they are being drawn. 9 | */ 10 | public interface YAxisValueFormatter { 11 | 12 | /** 13 | * Called when a value from the YAxis is formatted 14 | * before being drawn. For performance reasons, avoid excessive calculations 15 | * and memory allocations inside this method. 16 | * 17 | * @param value the YAxis value to be formatted 18 | * @param yAxis the YAxis object the value belongs to 19 | * @return 20 | */ 21 | String getFormattedValue(float value, YAxis yAxis); 22 | } 23 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/highlight/CombinedHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.data.ChartData; 4 | import com.github.mikephil.charting.data.CombinedData; 5 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 6 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider; 7 | import com.github.mikephil.charting.utils.SelectionDetail; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 12/09/15. 14 | */ 15 | public class CombinedHighlighter extends ChartHighlighter { 16 | 17 | public CombinedHighlighter(BarLineScatterCandleBubbleDataProvider chart) { 18 | super(chart); 19 | } 20 | 21 | /** 22 | * Returns a list of SelectionDetail object corresponding to the given xIndex. 23 | * 24 | * @param xIndex 25 | * @return 26 | */ 27 | @Override 28 | protected List getSelectionDetailsAtIndex(int xIndex, 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 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | import com.github.mikephil.charting.data.BarData; 5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 6 | import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider; 7 | import com.github.mikephil.charting.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 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) (yVal / ((float) setCount + mChart.getBarData().getGroupSpace())); 113 | 114 | float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps; 115 | 116 | return yVal - groupSpaceSum; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/highlight/Range.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | /** 4 | * Created by Philipp Jahoda on 24/07/15. Class that represents the range of one value in a stacked bar entry. e.g. 5 | * stack values are -10, 5, 20 -> then ranges are (-10 - 0, 0 - 5, 5 - 25). 6 | */ 7 | public final class Range { 8 | 9 | public float from; 10 | public float to; 11 | 12 | public Range(float from, float to) { 13 | this.from = from; 14 | this.to = to; 15 | } 16 | 17 | /** 18 | * Returns true if this range contains (if the value is in between) the given value, false if not. 19 | * 20 | * @param value 21 | * @return 22 | */ 23 | public boolean contains(float value) { 24 | 25 | return (value > from && value <= to); 26 | } 27 | 28 | public boolean isLarger(float value) { 29 | return value > to; 30 | } 31 | 32 | public boolean isSmaller(float value) { 33 | return value < from; 34 | } 35 | } -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BarDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.BarData; 4 | 5 | public interface BarDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | BarData getBarData(); 8 | boolean isDrawBarShadowEnabled(); 9 | boolean isDrawValueAboveBarEnabled(); 10 | boolean isDrawHighlightArrowEnabled(); 11 | } 12 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BarLineScatterCandleBubbleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.components.YAxis.AxisDependency; 4 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData; 5 | import com.github.mikephil.charting.utils.Transformer; 6 | 7 | public interface BarLineScatterCandleBubbleDataProvider extends ChartInterface { 8 | 9 | Transformer getTransformer(AxisDependency axis); 10 | int getMaxVisibleCount(); 11 | boolean isInverted(AxisDependency axis); 12 | 13 | int getLowestVisibleXIndex(); 14 | int getHighestVisibleXIndex(); 15 | 16 | BarLineScatterCandleBubbleData getData(); 17 | } 18 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/BubbleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.BubbleData; 4 | 5 | public interface BubbleDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | BubbleData getBubbleData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/CandleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.CandleData; 4 | 5 | public interface CandleDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | CandleData getCandleData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import android.graphics.PointF; 4 | import android.graphics.RectF; 5 | 6 | import com.github.mikephil.charting.data.ChartData; 7 | import com.github.mikephil.charting.formatter.ValueFormatter; 8 | 9 | /** 10 | * Interface that provides everything there is to know about the dimensions, 11 | * bounds, and range of the chart. 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public interface ChartInterface { 16 | 17 | /** 18 | * Returns the minimum x-value of the chart, regardless of zoom or translation. 19 | * 20 | * @return 21 | */ 22 | float getXChartMin(); 23 | 24 | /** 25 | * Returns the maximum x-value of the chart, regardless of zoom or translation. 26 | * 27 | * @return 28 | */ 29 | float getXChartMax(); 30 | 31 | /** 32 | * Returns the minimum y-value of the chart, regardless of zoom or translation. 33 | * 34 | * @return 35 | */ 36 | float getYChartMin(); 37 | 38 | /** 39 | * Returns the maximum y-value of the chart, regardless of zoom or translation. 40 | * 41 | * @return 42 | */ 43 | float getYChartMax(); 44 | 45 | int getXValCount(); 46 | 47 | int getWidth(); 48 | 49 | int getHeight(); 50 | 51 | PointF getCenterOfView(); 52 | 53 | PointF getCenterOffsets(); 54 | 55 | RectF getContentRect(); 56 | 57 | ValueFormatter getDefaultValueFormatter(); 58 | 59 | ChartData getData(); 60 | } 61 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/LineDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | import com.github.mikephil.charting.data.LineData; 5 | 6 | public interface LineDataProvider extends BarLineScatterCandleBubbleDataProvider { 7 | 8 | LineData getLineData(); 9 | 10 | YAxis getAxis(YAxis.AxisDependency dependency); 11 | } 12 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/dataprovider/ScatterDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.ScatterData; 4 | 5 | public interface ScatterDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | ScatterData getScatterData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.BarEntry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet { 9 | 10 | /** 11 | * Returns the space between bars as the actual value (0 - 1.0f) 12 | * 13 | * @return 14 | */ 15 | float getBarSpace(); 16 | 17 | /** 18 | * Returns true if this DataSet is stacked (stacksize > 1) or not. 19 | * 20 | * @return 21 | */ 22 | boolean isStacked(); 23 | 24 | /** 25 | * Returns the maximum number of bars that can be stacked upon another in 26 | * this DataSet. This should return 1 for non stacked bars, and > 1 for stacked bars. 27 | * 28 | * @return 29 | */ 30 | int getStackSize(); 31 | 32 | /** 33 | * Returns the color used for drawing the bar-shadows. The bar shadows is a 34 | * surface behind the bar that indicates the maximum value. 35 | * 36 | * @return 37 | */ 38 | int getBarShadowColor(); 39 | 40 | /** 41 | * Returns the width used for drawing borders around the bars. 42 | * If borderWidth == 0, no border will be drawn. 43 | * 44 | * @return 45 | */ 46 | float getBarBorderWidth(); 47 | 48 | /** 49 | * Returns the color drawing borders around the bars. 50 | * 51 | * @return 52 | */ 53 | int getBarBorderColor(); 54 | 55 | /** 56 | * Returns the alpha value (transparency) that is used for drawing the 57 | * highlight indicator. 58 | * 59 | * @return 60 | */ 61 | int getHighLightAlpha(); 62 | 63 | 64 | /** 65 | * Returns the labels used for the different value-stacks in the legend. 66 | * This is only relevant for stacked bar entries. 67 | * 68 | * @return 69 | */ 70 | String[] getStackLabels(); 71 | } 72 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBarLineScatterCandleBubbleDataSet extends IDataSet { 9 | 10 | /** 11 | * Returns the color that is used for drawing the highlight indicators. 12 | * 13 | * @return 14 | */ 15 | int getHighLightColor(); 16 | } 17 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.BubbleEntry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBubbleDataSet extends IBarLineScatterCandleBubbleDataSet { 9 | 10 | /** 11 | * Sets the width of the circle that surrounds the bubble when highlighted, 12 | * in dp. 13 | * 14 | * @param width 15 | */ 16 | void setHighlightCircleWidth(float width); 17 | 18 | float getXMax(); 19 | 20 | float getXMin(); 21 | 22 | float getMaxSize(); 23 | 24 | boolean isNormalizeSizeEnabled(); 25 | 26 | /** 27 | * Returns the width of the highlight-circle that surrounds the bubble 28 | * @return 29 | */ 30 | float getHighlightCircleWidth(); 31 | } 32 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ICandleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.Paint; 4 | 5 | import com.github.mikephil.charting.data.CandleEntry; 6 | 7 | /** 8 | * Created by philipp on 21/10/15. 9 | */ 10 | public interface ICandleDataSet extends ILineScatterCandleRadarDataSet { 11 | 12 | /** 13 | * Returns the space that is left out on the left and right side of each 14 | * candle. 15 | * 16 | * @return 17 | */ 18 | float getBarSpace(); 19 | 20 | /** 21 | * Returns whether the candle bars should show? 22 | * When false, only "ticks" will show 23 | * 24 | * - default: true 25 | * 26 | * @return 27 | */ 28 | boolean getShowCandleBar(); 29 | 30 | /** 31 | * Returns the width of the candle-shadow-line in pixels. 32 | * 33 | * @return 34 | */ 35 | float getShadowWidth(); 36 | 37 | /** 38 | * Returns shadow color for all entries 39 | * 40 | * @return 41 | */ 42 | int getShadowColor(); 43 | 44 | /** 45 | * Returns the neutral color (for open == close) 46 | * 47 | * @return 48 | */ 49 | int getNeutralColor(); 50 | 51 | /** 52 | * Returns the increasing color (for open < close). 53 | * 54 | * @return 55 | */ 56 | int getIncreasingColor(); 57 | 58 | /** 59 | * Returns the decreasing color (for open > close). 60 | * 61 | * @return 62 | */ 63 | int getDecreasingColor(); 64 | 65 | /** 66 | * Returns paint style when open < close 67 | * 68 | * @return 69 | */ 70 | Paint.Style getIncreasingPaintStyle(); 71 | 72 | /** 73 | * Returns paint style when open > close 74 | * 75 | * @return 76 | */ 77 | Paint.Style getDecreasingPaintStyle(); 78 | 79 | /** 80 | * Is the shadow color same as the candle color? 81 | * 82 | * @return 83 | */ 84 | boolean getShadowColorSameAsCandle(); 85 | } 86 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.DashPathEffect; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.data.LineDataSet; 7 | import com.github.mikephil.charting.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 | /** 30 | * @deprecated Kept for backward compatibility. 31 | * @return 32 | */ 33 | @Deprecated 34 | boolean isDrawCubicEnabled(); 35 | 36 | /** 37 | * @deprecated Kept for backward compatibility. 38 | * @return 39 | */ 40 | @Deprecated 41 | boolean isDrawSteppedEnabled(); 42 | 43 | /** 44 | * Returns the size of the drawn circles. 45 | */ 46 | float getCircleRadius(); 47 | 48 | /** 49 | * Returns the hole radius of the drawn circles. 50 | */ 51 | float getCircleHoleRadius(); 52 | 53 | /** 54 | * Returns the color at the given index of the DataSet's circle-color array. 55 | * Performs a IndexOutOfBounds check by modulus. 56 | * 57 | * @param index 58 | * @return 59 | */ 60 | int getCircleColor(int index); 61 | 62 | /** 63 | * Returns true if drawing circles for this DataSet is enabled, false if not 64 | * 65 | * @return 66 | */ 67 | boolean isDrawCirclesEnabled(); 68 | 69 | /** 70 | * Returns the color of the inner circle (the circle-hole). 71 | * 72 | * @return 73 | */ 74 | int getCircleHoleColor(); 75 | 76 | /** 77 | * Returns true if drawing the circle-holes is enabled, false if not. 78 | * 79 | * @return 80 | */ 81 | boolean isDrawCircleHoleEnabled(); 82 | 83 | /** 84 | * Returns the DashPathEffect that is used for drawing the lines. 85 | * 86 | * @return 87 | */ 88 | DashPathEffect getDashPathEffect(); 89 | 90 | /** 91 | * Returns true if the dashed-line effect is enabled, false if not. 92 | * If the DashPathEffect object is null, also return false here. 93 | * 94 | * @return 95 | */ 96 | boolean isDashedLineEnabled(); 97 | 98 | /** 99 | * Returns the FillFormatter that is set for this DataSet. 100 | * 101 | * @return 102 | */ 103 | FillFormatter getFillFormatter(); 104 | } -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | 7 | /** 8 | * Created by Philipp Jahoda on 21/10/15. 9 | */ 10 | public interface ILineRadarDataSet extends ILineScatterCandleRadarDataSet { 11 | 12 | /** 13 | * Returns the color that is used for filling the line surface area. 14 | * 15 | * @return 16 | */ 17 | int getFillColor(); 18 | 19 | /** 20 | * Returns the drawable used for filling the area below the line. 21 | * 22 | * @return 23 | */ 24 | Drawable getFillDrawable(); 25 | 26 | /** 27 | * Returns the alpha value that is used for filling the line surface, 28 | * default: 85 29 | * 30 | * @return 31 | */ 32 | int getFillAlpha(); 33 | 34 | /** 35 | * Returns the stroke-width of the drawn line 36 | * 37 | * @return 38 | */ 39 | float getLineWidth(); 40 | 41 | /** 42 | * Returns true if filled drawing is enabled, false if not 43 | * 44 | * @return 45 | */ 46 | boolean isDrawFilledEnabled(); 47 | 48 | /** 49 | * Set to true if the DataSet should be drawn filled (surface), and not just 50 | * as a line, disabling this will give great performance boost. Please note that this method 51 | * uses the canvas.clipPath(...) method for drawing the filled area. 52 | * For devices with API level < 18 (Android 4.3), hardware acceleration of the chart should 53 | * be turned off. Default: false 54 | * 55 | * @param enabled 56 | */ 57 | void setDrawFilled(boolean enabled); 58 | } 59 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.DashPathEffect; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | 7 | /** 8 | * Created by Philipp Jahoda on 21/10/15. 9 | */ 10 | public interface ILineScatterCandleRadarDataSet extends IBarLineScatterCandleBubbleDataSet { 11 | 12 | /** 13 | * Returns true if vertical highlight indicator lines are enabled (drawn) 14 | * @return 15 | */ 16 | boolean isVerticalHighlightIndicatorEnabled(); 17 | 18 | /** 19 | * Returns true if vertical highlight indicator lines are enabled (drawn) 20 | * @return 21 | */ 22 | boolean isHorizontalHighlightIndicatorEnabled(); 23 | 24 | /** 25 | * Returns the line-width in which highlight lines are to be drawn. 26 | * @return 27 | */ 28 | float getHighlightLineWidth(); 29 | 30 | /** 31 | * Returns the DashPathEffect that is used for highlighting. 32 | * @return 33 | */ 34 | DashPathEffect getDashPathEffectHighlight(); 35 | } 36 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IPieDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.data.PieDataSet; 5 | 6 | /** 7 | * Created by Philipp Jahoda on 03/11/15. 8 | */ 9 | public interface IPieDataSet extends IDataSet { 10 | 11 | /** 12 | * Returns the space that is set to be between the piechart-slices of this 13 | * DataSet, in pixels. 14 | * 15 | * @return 16 | */ 17 | float getSliceSpace(); 18 | 19 | /** 20 | * Returns the distance a highlighted piechart slice is "shifted" away from 21 | * the chart-center in dp. 22 | * 23 | * @return 24 | */ 25 | float getSelectionShift(); 26 | 27 | PieDataSet.ValuePosition getXValuePosition(); 28 | PieDataSet.ValuePosition getYValuePosition(); 29 | 30 | /** 31 | * When valuePosition is OutsideSlice, indicates line color 32 | * */ 33 | int getValueLineColor(); 34 | 35 | /** 36 | * When valuePosition is OutsideSlice, indicates line width 37 | * */ 38 | float getValueLineWidth(); 39 | 40 | /** 41 | * When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size 42 | * */ 43 | float getValueLinePart1OffsetPercentage(); 44 | 45 | /** 46 | * When valuePosition is OutsideSlice, indicates length of first half of the line 47 | * */ 48 | float getValueLinePart1Length(); 49 | 50 | /** 51 | * When valuePosition is OutsideSlice, indicates length of second half of the line 52 | * */ 53 | float getValueLinePart2Length(); 54 | 55 | /** 56 | * When valuePosition is OutsideSlice, this allows variable line length 57 | * */ 58 | boolean isValueLineVariableLength(); 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 03/11/15. 7 | */ 8 | public interface IRadarDataSet extends ILineRadarDataSet { 9 | 10 | /// flag indicating whether highlight circle should be drawn or not 11 | boolean isDrawHighlightCircleEnabled(); 12 | 13 | /// Sets whether highlight circle should be drawn or not 14 | void setDrawHighlightCircleEnabled(boolean enabled); 15 | 16 | int getHighlightCircleFillColor(); 17 | 18 | /// The stroke color for highlight circle. 19 | /// If Utils.COLOR_NONE, the color of the dataset is taken. 20 | int getHighlightCircleStrokeColor(); 21 | 22 | int getHighlightCircleStrokeAlpha(); 23 | 24 | float getHighlightCircleInnerRadius(); 25 | 26 | float getHighlightCircleOuterRadius(); 27 | 28 | float getHighlightCircleStrokeWidth(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/interfaces/datasets/IScatterDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.charts.ScatterChart; 4 | import com.github.mikephil.charting.data.Entry; 5 | 6 | /** 7 | * Created by philipp on 21/10/15. 8 | */ 9 | public interface IScatterDataSet extends ILineScatterCandleRadarDataSet { 10 | 11 | /** 12 | * Returns the currently set scatter shape size 13 | * 14 | * @return 15 | */ 16 | float getScatterShapeSize(); 17 | 18 | /** 19 | * Returns all the different scattershapes the chart uses 20 | * 21 | * @return 22 | */ 23 | ScatterChart.ScatterShape getScatterShape(); 24 | 25 | /** 26 | * Returns radius of the hole in the shape 27 | * 28 | * @return 29 | */ 30 | float getScatterShapeHoleRadius(); 31 | 32 | /** 33 | * Returns the color for the hole in the shape 34 | * 35 | * @return 36 | */ 37 | int getScatterShapeHoleColor(); 38 | } 39 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedMoveViewJob.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.jobs; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.view.View; 5 | 6 | import com.github.mikephil.charting.utils.Transformer; 7 | import com.github.mikephil.charting.utils.ViewPortHandler; 8 | 9 | /** 10 | * Created by Philipp Jahoda on 19/02/16. 11 | */ 12 | public class 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 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedViewPortJob.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.jobs; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.animation.ValueAnimator; 5 | import android.annotation.SuppressLint; 6 | import android.view.View; 7 | 8 | import com.github.mikephil.charting.utils.Transformer; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * Created by Philipp Jahoda on 19/02/16. 13 | */ 14 | @SuppressLint("NewApi") 15 | public abstract class AnimatedViewPortJob extends ViewPortJob implements ValueAnimator.AnimatorUpdateListener { 16 | 17 | protected ObjectAnimator animator; 18 | 19 | protected float phase; 20 | 21 | protected float xOrigin; 22 | protected float yOrigin; 23 | 24 | public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) { 25 | super(viewPortHandler, xValue, yValue, trans, v); 26 | this.xOrigin = xOrigin; 27 | this.yOrigin = yOrigin; 28 | animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f); 29 | animator.setDuration(duration); 30 | animator.addUpdateListener(this); 31 | } 32 | 33 | @SuppressLint("NewApi") 34 | @Override 35 | public void run() { 36 | animator.start(); 37 | } 38 | 39 | public float getPhase() { 40 | return phase; 41 | } 42 | 43 | public void setPhase(float phase) { 44 | this.phase = phase; 45 | } 46 | 47 | public float getXOrigin() { 48 | return xOrigin; 49 | } 50 | 51 | public float getYOrigin() { 52 | return yOrigin; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/AnimatedZoomJob.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.jobs; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.annotation.SuppressLint; 6 | import android.graphics.Matrix; 7 | import android.view.View; 8 | 9 | import com.github.mikephil.charting.charts.BarLineChartBase; 10 | import com.github.mikephil.charting.components.YAxis; 11 | import com.github.mikephil.charting.utils.Transformer; 12 | import com.github.mikephil.charting.utils.ViewPortHandler; 13 | 14 | /** 15 | * Created by Philipp Jahoda on 19/02/16. 16 | */ 17 | @SuppressLint("NewApi") 18 | public class AnimatedZoomJob extends AnimatedViewPortJob implements Animator.AnimatorListener { 19 | 20 | protected float zoomOriginX; 21 | protected float zoomOriginY; 22 | 23 | protected float zoomCenterX; 24 | protected float zoomCenterY; 25 | 26 | protected YAxis yAxis; 27 | 28 | protected float xValCount; 29 | 30 | @SuppressLint("NewApi") 31 | public AnimatedZoomJob(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xValCount, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) { 32 | super(viewPortHandler, scaleX, scaleY, trans, v, xOrigin, yOrigin, duration); 33 | 34 | this.zoomCenterX = zoomCenterX; 35 | this.zoomCenterY = zoomCenterY; 36 | this.zoomOriginX = zoomOriginX; 37 | this.zoomOriginY = zoomOriginY; 38 | this.animator.addListener(this); 39 | this.yAxis = axis; 40 | this.xValCount = xValCount; 41 | } 42 | 43 | @Override 44 | public void onAnimationUpdate(ValueAnimator animation) { 45 | 46 | float scaleX = xOrigin + (xValue - xOrigin) * phase; 47 | float scaleY = yOrigin + (yValue - yOrigin) * phase; 48 | 49 | Matrix save = mViewPortHandler.setZoom(scaleX, scaleY); 50 | mViewPortHandler.refresh(save, view, false); 51 | 52 | float valsInView = yAxis.mAxisRange / mViewPortHandler.getScaleY(); 53 | float xsInView = xValCount / mViewPortHandler.getScaleX(); 54 | 55 | pts[0] = zoomOriginX + ((zoomCenterX - xsInView / 2f) - zoomOriginX) * phase; 56 | pts[1] = zoomOriginY + ((zoomCenterY + valsInView / 2f) - zoomOriginY) * phase; 57 | 58 | mTrans.pointValuesToPixel(pts); 59 | 60 | save = mViewPortHandler.translate(pts); 61 | mViewPortHandler.refresh(save, view, true); 62 | } 63 | 64 | @Override 65 | public void onAnimationEnd(Animator animation) { 66 | ((BarLineChartBase) view).calculateOffsets(); 67 | view.postInvalidate(); 68 | } 69 | 70 | @Override 71 | public void onAnimationCancel(Animator animation) { 72 | 73 | } 74 | 75 | @Override 76 | public void onAnimationRepeat(Animator animation) { 77 | 78 | } 79 | 80 | @Override 81 | public void onAnimationStart(Animator animation) { 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/MoveViewJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.view.View; 5 | 6 | import com.github.mikephil.charting.utils.Transformer; 7 | import com.github.mikephil.charting.utils.ViewPortHandler; 8 | 9 | /** 10 | * Created by Philipp Jahoda on 19/02/16. 11 | */ 12 | public class MoveViewJob extends ViewPortJob { 13 | 14 | public MoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v) { 15 | super(viewPortHandler, xValue, yValue, trans, v); 16 | } 17 | 18 | @Override 19 | public void run() { 20 | 21 | pts[0] = xValue; 22 | pts[1] = yValue; 23 | 24 | mTrans.pointValuesToPixel(pts); 25 | mViewPortHandler.centerViewPort(pts, view); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/ViewPortJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.view.View; 5 | 6 | import com.github.mikephil.charting.utils.Transformer; 7 | import com.github.mikephil.charting.utils.ViewPortHandler; 8 | 9 | /** 10 | * Runnable that is used for viewport modifications since they cannot be 11 | * executed at any time. This can be used to delay the execution of viewport 12 | * modifications until the onSizeChanged(...) method of the chart-view is called. 13 | * This is especially important if viewport modifying methods are called on the chart 14 | * directly after initialization. 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public abstract class ViewPortJob implements Runnable { 19 | 20 | protected float[] pts = new float[2]; 21 | 22 | protected ViewPortHandler mViewPortHandler; 23 | protected float xValue = 0f; 24 | protected float yValue = 0f; 25 | protected Transformer mTrans; 26 | protected View view; 27 | 28 | public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, 29 | Transformer trans, View v) { 30 | 31 | this.mViewPortHandler = viewPortHandler; 32 | this.xValue = xValue; 33 | this.yValue = yValue; 34 | this.mTrans = trans; 35 | this.view = v; 36 | } 37 | 38 | public float getXValue() { 39 | return xValue; 40 | } 41 | 42 | public float getYValue() { 43 | return yValue; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/jobs/ZoomJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.graphics.Matrix; 5 | import android.view.View; 6 | 7 | import com.github.mikephil.charting.charts.BarLineChartBase; 8 | import com.github.mikephil.charting.components.YAxis; 9 | import com.github.mikephil.charting.utils.Transformer; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/02/16. 14 | */ 15 | public class ZoomJob extends ViewPortJob { 16 | 17 | protected float scaleX; 18 | protected float scaleY; 19 | 20 | protected YAxis.AxisDependency axisDependency; 21 | 22 | public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans, YAxis.AxisDependency axis, View v) { 23 | super(viewPortHandler, xValue, yValue, trans, v); 24 | 25 | this.scaleX = scaleX; 26 | this.scaleY = scaleY; 27 | this.axisDependency = axis; 28 | } 29 | 30 | @Override 31 | public void run() { 32 | 33 | Matrix save = mViewPortHandler.zoom(scaleX, scaleY); 34 | mViewPortHandler.refresh(save, view, false); 35 | 36 | float valsInView = ((BarLineChartBase) view).getDeltaY(axisDependency) / mViewPortHandler.getScaleY(); 37 | float xsInView = ((BarLineChartBase) view).getXAxis().getValues().size() / mViewPortHandler.getScaleX(); 38 | 39 | pts[0] = xValue - xsInView / 2f; 40 | pts[1] = yValue + valsInView / 2f; 41 | 42 | mTrans.pointValuesToPixel(pts); 43 | 44 | save = mViewPortHandler.translate(pts); 45 | mViewPortHandler.refresh(save, view, false); 46 | 47 | ((BarLineChartBase) view).calculateOffsets(); 48 | view.postInvalidate(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/listener/OnChartGestureListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import android.view.MotionEvent; 4 | 5 | /** 6 | * Listener for callbacks when doing gestures on the chart. 7 | * 8 | * @author Philipp Jahoda 9 | */ 10 | public interface OnChartGestureListener { 11 | 12 | /** 13 | * Callbacks when a touch-gesture has started on the chart (ACTION_DOWN) 14 | * 15 | * @param me 16 | * @param lastPerformedGesture 17 | */ 18 | void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 19 | 20 | /** 21 | * Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL) 22 | * 23 | * @param me 24 | * @param lastPerformedGesture 25 | */ 26 | void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 27 | 28 | /** 29 | * Callbacks when the chart is longpressed. 30 | * 31 | * @param me 32 | */ 33 | void onChartLongPressed(MotionEvent me); 34 | 35 | /** 36 | * Callbacks when the chart is double-tapped. 37 | * 38 | * @param me 39 | */ 40 | void onChartDoubleTapped(MotionEvent me); 41 | 42 | /** 43 | * Callbacks when the chart is single-tapped. 44 | * 45 | * @param me 46 | */ 47 | void onChartSingleTapped(MotionEvent me); 48 | 49 | /** 50 | * Callbacks then a fling gesture is made on the chart. 51 | * 52 | * @param me1 53 | * @param me2 54 | * @param velocityX 55 | * @param velocityY 56 | */ 57 | void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY); 58 | 59 | /** 60 | * Callbacks when the chart is scaled / zoomed via pinch zoom gesture. 61 | * 62 | * @param me 63 | * @param scaleX scalefactor on the x-axis 64 | * @param scaleY scalefactor on the y-axis 65 | */ 66 | void onChartScale(MotionEvent me, float scaleX, float scaleY); 67 | 68 | /** 69 | * Callbacks when the chart is moved / translated via drag gesture. 70 | * 71 | * @param me 72 | * @param dX translation distance on the x-axis 73 | * @param dY translation distance on the y-axis 74 | */ 75 | void onChartTranslate(MotionEvent me, float dX, float dY); 76 | } 77 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/listener/OnChartValueSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.highlight.Highlight; 5 | 6 | /** 7 | * Listener for callbacks when selecting values inside the chart by 8 | * touch-gesture. 9 | * 10 | * @author Philipp Jahoda 11 | */ 12 | public interface OnChartValueSelectedListener { 13 | 14 | /** 15 | * Called when a value has been selected inside the chart. 16 | * 17 | * @param e The selected Entry. 18 | * @param dataSetIndex The index in the datasets array of the data object 19 | * the Entrys DataSet is in. 20 | * @param h the corresponding highlight object that contains information 21 | * about the highlighted position 22 | */ 23 | void onValueSelected(Entry e, int dataSetIndex, Highlight h); 24 | 25 | /** 26 | * Called when nothing has been selected or an "un-select" has been made. 27 | */ 28 | void onNothingSelected(); 29 | } 30 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/listener/OnDrawLineChartTouchListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import android.view.GestureDetector.SimpleOnGestureListener; 4 | import android.view.MotionEvent; 5 | import android.view.View; 6 | import android.view.View.OnTouchListener; 7 | 8 | public class OnDrawLineChartTouchListener extends SimpleOnGestureListener implements OnTouchListener { 9 | 10 | @Override 11 | public boolean onTouch(View v, MotionEvent event) { 12 | return false; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/listener/OnDrawListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import com.github.mikephil.charting.data.DataSet; 4 | import com.github.mikephil.charting.data.Entry; 5 | 6 | /** 7 | * Listener for callbacks when drawing on the chart. 8 | * 9 | * @author Philipp 10 | * 11 | */ 12 | public interface OnDrawListener { 13 | 14 | /** 15 | * Called whenever an entry is added with the finger. Note this is also called for entries that are generated by the 16 | * library, when the touch gesture is too fast and skips points. 17 | * 18 | * @param entry 19 | * the last drawn entry 20 | */ 21 | void onEntryAdded(Entry entry); 22 | 23 | /** 24 | * Called whenever an entry is moved by the user after beeing highlighted 25 | * 26 | * @param entry 27 | */ 28 | void onEntryMoved(Entry entry); 29 | 30 | /** 31 | * Called when drawing finger is lifted and the draw is finished. 32 | * 33 | * @param dataSet 34 | * the last drawn DataSet 35 | */ 36 | void onDrawFinished(DataSet dataSet); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/renderer/AxisRenderer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.renderer; 3 | 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Paint.Style; 8 | 9 | import com.github.mikephil.charting.utils.Transformer; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | /** 13 | * Baseclass of all axis renderers. 14 | * 15 | * @author Philipp Jahoda 16 | */ 17 | public abstract class AxisRenderer extends Renderer { 18 | 19 | protected Transformer mTrans; 20 | 21 | /** paint object for the grid lines */ 22 | protected Paint mGridPaint; 23 | 24 | /** paint for the x-label values */ 25 | protected Paint mAxisLabelPaint; 26 | 27 | /** paint for the line surrounding the chart */ 28 | protected Paint mAxisLinePaint; 29 | 30 | /** paint used for the limit lines */ 31 | protected Paint mLimitLinePaint; 32 | 33 | public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans) { 34 | super(viewPortHandler); 35 | 36 | this.mTrans = trans; 37 | 38 | mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 39 | 40 | mGridPaint = new Paint(); 41 | mGridPaint.setColor(Color.GRAY); 42 | mGridPaint.setStrokeWidth(1f); 43 | mGridPaint.setStyle(Style.STROKE); 44 | mGridPaint.setAlpha(90); 45 | 46 | mAxisLinePaint = new Paint(); 47 | mAxisLinePaint.setColor(Color.BLACK); 48 | mAxisLinePaint.setStrokeWidth(1f); 49 | mAxisLinePaint.setStyle(Style.STROKE); 50 | 51 | mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 52 | mLimitLinePaint.setStyle(Style.STROKE); 53 | } 54 | 55 | /** 56 | * Returns the Paint object used for drawing the axis (labels). 57 | * 58 | * @return 59 | */ 60 | public Paint getPaintAxisLabels() { 61 | return mAxisLabelPaint; 62 | } 63 | 64 | /** 65 | * Returns the Paint object that is used for drawing the grid-lines of the 66 | * axis. 67 | * 68 | * @return 69 | */ 70 | public Paint getPaintGrid() { 71 | return mGridPaint; 72 | } 73 | 74 | /** 75 | * Returns the Paint object that is used for drawing the axis-line that goes 76 | * alongside the axis. 77 | * 78 | * @return 79 | */ 80 | public Paint getPaintAxisLine() { 81 | return mAxisLinePaint; 82 | } 83 | 84 | /** 85 | * Returns the Transformer object used for transforming the axis values. 86 | * 87 | * @return 88 | */ 89 | public Transformer getTransformer() { 90 | return mTrans; 91 | } 92 | 93 | /** 94 | * Draws the axis labels to the screen. 95 | * 96 | * @param c 97 | */ 98 | public abstract void renderAxisLabels(Canvas c); 99 | 100 | /** 101 | * Draws the grid lines belonging to the axis. 102 | * 103 | * @param c 104 | */ 105 | public abstract void renderGridLines(Canvas c); 106 | 107 | /** 108 | * Draws the line that goes alongside the axis. 109 | * 110 | * @param c 111 | */ 112 | public abstract void renderAxisLine(Canvas c); 113 | 114 | /** 115 | * Draws the LimitLines associated with this axis to the screen. 116 | * 117 | * @param c 118 | */ 119 | public abstract void renderLimitLines(Canvas c); 120 | } 121 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/renderer/LineRadarRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | import android.graphics.Path; 6 | import android.graphics.drawable.Drawable; 7 | 8 | import com.github.mikephil.charting.animation.ChartAnimator; 9 | import com.github.mikephil.charting.utils.Utils; 10 | import com.github.mikephil.charting.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 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/renderer/LineScatterCandleRadarRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Path; 5 | import android.util.Log; 6 | 7 | import com.github.mikephil.charting.animation.ChartAnimator; 8 | import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * Created by Philipp Jahoda on 11/07/15. 13 | * 高亮 14 | */ 15 | public abstract class LineScatterCandleRadarRenderer extends DataRenderer { 16 | 17 | /** 18 | * path that is used for drawing highlight-lines (drawLines(...) cannot be used because of dashes) 19 | */ 20 | private Path mHighlightLinePath = new Path(); 21 | 22 | public LineScatterCandleRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) { 23 | super(animator, viewPortHandler); 24 | } 25 | 26 | /** 27 | * Draws vertical & horizontal highlight-lines if enabled. 28 | * 29 | * @param c 30 | * @param pts the transformed x- and y-position of the lines 31 | * @param set the currently drawn dataset 32 | */ 33 | protected void drawHighlightLines(Canvas c, float[] pts, ILineScatterCandleRadarDataSet set) { 34 | 35 | // set color and stroke-width 36 | mHighlightPaint.setColor(set.getHighLightColor()); 37 | mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth()); 38 | 39 | // draw highlighted lines (if enabled) 40 | mHighlightPaint.setPathEffect(set.getDashPathEffectHighlight()); 41 | 42 | // draw vertical highlight lines 43 | if (set.isVerticalHighlightIndicatorEnabled()) { 44 | 45 | // create vertical path 46 | mHighlightLinePath.reset(); 47 | mHighlightLinePath.moveTo(pts[0], mViewPortHandler.contentTop()); 48 | mHighlightLinePath.lineTo(pts[0], mViewPortHandler.contentBottom()); 49 | 50 | c.drawPath(mHighlightLinePath, mHighlightPaint); 51 | 52 | 53 | } 54 | 55 | // draw horizontal highlight lines 56 | if (set.isHorizontalHighlightIndicatorEnabled()) { 57 | 58 | // create horizontal path 59 | mHighlightLinePath.reset(); 60 | mHighlightLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]); 61 | mHighlightLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]); 62 | 63 | c.drawPath(mHighlightLinePath, mHighlightPaint); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/renderer/Renderer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.renderer; 3 | 4 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider; 5 | import com.github.mikephil.charting.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 | return !(val < min || val > max); 41 | } 42 | 43 | /** 44 | * Calculates the minimum and maximum x-value the chart can currently 45 | * display (with the given zoom level). -> mMinX, mMaxX 46 | * 47 | * @param dataProvider 48 | * @param xAxisModulus 49 | */ 50 | public void calcXBounds(BarLineScatterCandleBubbleDataProvider dataProvider, int xAxisModulus) { 51 | 52 | int low = dataProvider.getLowestVisibleXIndex(); 53 | int high = dataProvider.getHighestVisibleXIndex(); 54 | 55 | int subLow = (low % xAxisModulus == 0) ? xAxisModulus : 0; 56 | 57 | mMinX = Math.max((low / xAxisModulus) * (xAxisModulus) - subLow, 0); 58 | mMaxX = Math.min((high / xAxisModulus) * (xAxisModulus) + xAxisModulus, (int) dataProvider.getXChartMax()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.renderer; 3 | 4 | import android.graphics.Canvas; 5 | import android.graphics.PointF; 6 | 7 | import com.github.mikephil.charting.charts.RadarChart; 8 | import com.github.mikephil.charting.components.XAxis; 9 | import com.github.mikephil.charting.utils.Utils; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | public class XAxisRendererRadarChart extends XAxisRenderer { 13 | 14 | private RadarChart mChart; 15 | 16 | public XAxisRendererRadarChart(ViewPortHandler viewPortHandler, XAxis xAxis, RadarChart chart) { 17 | super(viewPortHandler, xAxis, null); 18 | 19 | mChart = chart; 20 | } 21 | 22 | @Override 23 | public void renderAxisLabels(Canvas c) { 24 | 25 | if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled()) 26 | return; 27 | 28 | final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle(); 29 | final PointF drawLabelAnchor = new PointF(0.5f, 0.0f); 30 | 31 | mAxisLabelPaint.setTypeface(mXAxis.getTypeface()); 32 | mAxisLabelPaint.setTextSize(mXAxis.getTextSize()); 33 | mAxisLabelPaint.setColor(mXAxis.getTextColor()); 34 | 35 | float sliceangle = mChart.getSliceAngle(); 36 | 37 | // calculate the factor that is needed for transforming the value to 38 | // pixels 39 | float factor = mChart.getFactor(); 40 | 41 | PointF center = mChart.getCenterOffsets(); 42 | 43 | int mod = mXAxis.mAxisLabelModulus; 44 | for (int i = 0; i < mXAxis.getValues().size(); i += mod) { 45 | String label = mXAxis.getValues().get(i); 46 | 47 | float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f; 48 | 49 | PointF p = Utils.getPosition(center, mChart.getYRange() * factor 50 | + mXAxis.mLabelRotatedWidth / 2f, angle); 51 | 52 | drawLabel(c, label, i, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f, 53 | drawLabelAnchor, labelRotationAngleDegrees); 54 | } 55 | } 56 | 57 | /** 58 | * XAxis LimitLines on RadarChart not yet supported. 59 | * 60 | * @param c 61 | */ 62 | @Override 63 | public void renderLimitLines(Canvas c) { 64 | // this space intentionally left blank 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/utils/EntryXIndexComparator.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | import java.util.Comparator; 6 | 7 | /** 8 | * Comparator for comparing Entry-objects by their x-index. 9 | * Created by philipp on 17/06/15. 10 | */ 11 | public class EntryXIndexComparator implements Comparator { 12 | @Override 13 | public int compare(Entry entry1, Entry entry2) { 14 | return entry1.getXIndex() - entry2.getXIndex(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/utils/FSize.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | /** 5 | * Immutable class for describing width and height dimensions in some arbitrary 6 | * unit. Replacement for the android.Util.SizeF which is available only on API >= 21. 7 | */ 8 | public final class FSize { 9 | 10 | public final float width; 11 | public final float height; 12 | 13 | public FSize(final float width, final float height) { 14 | this.width = width; 15 | this.height = height; 16 | } 17 | 18 | @Override 19 | public boolean equals(final Object obj) { 20 | if (obj == null) { 21 | return false; 22 | } 23 | if (this == obj) { 24 | return true; 25 | } 26 | if (obj instanceof FSize) { 27 | final FSize other = (FSize) obj; 28 | return width == other.width && height == other.height; 29 | } 30 | return false; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return width + "x" + height; 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public int hashCode() { 43 | return Float.floatToIntBits(width) ^ Float.floatToIntBits(height); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/utils/PointD.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | /** 5 | * Point encapsulating two double values. 6 | * 7 | * @author Philipp Jahoda 8 | */ 9 | public class PointD { 10 | 11 | public double x; 12 | public double y; 13 | 14 | public PointD(double x, double y) { 15 | this.x = x; 16 | this.y = y; 17 | } 18 | 19 | /** 20 | * returns a string representation of the object 21 | */ 22 | @Override 23 | public String toString() { 24 | return "PointD, x: " + x + ", y: " + y; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/utils/SelectionDetail.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 4 | 5 | /** 6 | * Class that encapsulates information of a value that has been 7 | * selected/highlighted and its DataSet index. The SelectionDetail objects give 8 | * information about the value at the selected index and the DataSet it belongs 9 | * to. Needed only for highlighting onTouch(). 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public class SelectionDetail { 14 | 15 | public float 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 | } -------------------------------------------------------------------------------- /MPChartLib/src/com/github/mikephil/charting/utils/TransformerHorizontalBarChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | /** 5 | * Transformer class for the HorizontalBarChart. 6 | * 7 | * @author Philipp Jahoda 8 | */ 9 | public class TransformerHorizontalBarChart extends Transformer { 10 | 11 | public TransformerHorizontalBarChart(ViewPortHandler viewPortHandler) { 12 | super(viewPortHandler); 13 | } 14 | 15 | /** 16 | * Prepares the matrix that contains all offsets. 17 | * 18 | * @param chart 19 | */ 20 | public void prepareMatrixOffset(boolean inverted) { 21 | 22 | mMatrixOffset.reset(); 23 | 24 | // offset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom); 25 | 26 | if (!inverted) 27 | mMatrixOffset.postTranslate(mViewPortHandler.offsetLeft(), 28 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom()); 29 | else { 30 | mMatrixOffset 31 | .setTranslate( 32 | -(mViewPortHandler.getChartWidth() - mViewPortHandler.offsetRight()), 33 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom()); 34 | mMatrixOffset.postScale(-1.0f, 1.0f); 35 | } 36 | 37 | // mMatrixOffset.set(offset); 38 | 39 | // mMatrixOffset.reset(); 40 | // 41 | // mMatrixOffset.postTranslate(mOffsetLeft, getHeight() - 42 | // mOffsetBottom); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 若本demo不能满足您的需要 2 | 3 | - **商业版 K 线图源码**:功能更加完善,满足更高需求。 4 | - **定制开发服务**:如果商业版仍无法满足您的特定需求,我们可以提供您定制开发服务。 5 | 6 | 如需咨询或获取更多详情,请添加我的wx联系方式:**1025065158**。 7 | 8 | ### 商业版演示 9 | 请添加图片描述 10 | -------------------------------------------------------------------------------- /StockChart-master.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StockChart.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StockChart2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.example.yanjiang.stockchart" 9 | minSdkVersion 9 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3' 26 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3' 27 | compile 'com.android.support:appcompat-v7:23.3.0' 28 | compile 'com.google.code.gson:gson:2.6.2' 29 | compile 'org.greenrobot:eventbus:3.0.0' 30 | compile 'com.squareup.okhttp:okhttp:2.6.0' 31 | compile 'com.jakewharton:butterknife:7.0.1' 32 | compile 'com.squareup.retrofit2:retrofit:2.0.1' 33 | compile 'com.squareup.retrofit2:converter-gson:2.0.1' 34 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0' 35 | compile 'io.reactivex:rxjava:1.1.3' 36 | compile 'io.reactivex:rxandroid:1.1.0' 37 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' 38 | compile 'com.google.dagger:dagger:2.0.2' 39 | // dagger2 40 | apt 'com.google.dagger:dagger-compiler:2.0.2' 41 | // dagger2 42 | provided 'org.glassfish:javax.annotation:10.0-b28' 43 | compile project(':MPChartLib') 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/yanjiang/stockchart/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart; 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 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 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 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart; 2 | 3 | import android.app.Activity; 4 | import android.content.SharedPreferences; 5 | import android.os.Bundle; 6 | import android.widget.Toast; 7 | 8 | import com.example.yanjiang.stockchart.api.ClientApi; 9 | import com.example.yanjiang.stockchart.application.App; 10 | import com.example.yanjiang.stockchart.inject.component.ActivityComponent; 11 | import com.example.yanjiang.stockchart.inject.component.DaggerActivityComponent; 12 | import com.example.yanjiang.stockchart.inject.modules.ActivityModule; 13 | 14 | import javax.inject.Inject; 15 | 16 | import butterknife.ButterKnife; 17 | import rx.subscriptions.CompositeSubscription; 18 | 19 | public class BaseActivity extends Activity { 20 | public final String TAG =this.getClass().getSimpleName(); 21 | protected CompositeSubscription mCompositeSubscription; 22 | protected Activity activity; 23 | protected Toast mToast = null; 24 | protected ActivityComponent activityComponent; 25 | @Inject 26 | public ClientApi clientApi; 27 | @Inject 28 | public SharedPreferences sharedPreferences; 29 | /*@Inject 30 | Activity activity;*/ 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | activity = this; 36 | mCompositeSubscription = new CompositeSubscription(); 37 | activityComponent = DaggerActivityComponent.builder() 38 | .appComponent(((App) getApplication()).getApplicationComponent()) 39 | .activityModule(new ActivityModule(this)) 40 | .build(); 41 | activityComponent.inject(this); 42 | } 43 | 44 | @Override 45 | public void setContentView(int layoutResID) { 46 | super.setContentView(layoutResID); 47 | ButterKnife.bind(this); 48 | 49 | } 50 | 51 | public void showToast(String content) { 52 | if (mToast == null) { 53 | mToast = Toast.makeText(this, content, Toast.LENGTH_SHORT); 54 | } else { 55 | mToast.setText(content); 56 | } 57 | mToast.show(); 58 | } 59 | 60 | 61 | @Override 62 | protected void onResume() { 63 | super.onResume(); 64 | } 65 | 66 | @Override 67 | protected void onDestroy() { 68 | super.onDestroy(); 69 | ButterKnife.unbind(BaseActivity.this); 70 | if (mCompositeSubscription.hasSubscriptions()) { 71 | mCompositeSubscription.unsubscribe(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Button; 7 | 8 | import butterknife.Bind; 9 | import butterknife.ButterKnife; 10 | import butterknife.OnClick; 11 | 12 | public class MainActivity extends BaseActivity { 13 | @Bind(R.id.btn) 14 | Button btn; 15 | @Bind(R.id.btn_k) 16 | Button btnK; 17 | @Bind(R.id.btn_fix) 18 | Button btnFix; 19 | 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | ButterKnife.bind(this); 26 | /* Intent intent = new Intent(MainActivity.this, KLineActivity.class); 27 | startActivity(intent);*/ 28 | } 29 | 30 | 31 | @OnClick({R.id.btn, R.id.btn_k,R.id.btn_fix}) 32 | public void onClick(View view) { 33 | switch (view.getId()) { 34 | case R.id.btn: 35 | Intent intent = new Intent(MainActivity.this, MinutesActivity.class); 36 | startActivity(intent); 37 | break; 38 | case R.id.btn_k: 39 | Intent intentK = new Intent(MainActivity.this, KLineActivity.class); 40 | startActivity(intentK); 41 | break; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/Test.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart; 2 | 3 | /** 4 | * author:ajiang 5 | * mail:1025065158@qq.com 6 | * blog:http://blog.csdn.net/qqyanjiang 7 | */ 8 | public class Test { 9 | 10 | 11 | 12 | /* private ArrayList listA, listB; 13 | private int sum; 14 | 15 | public static void main(String[] args) { 16 | Test test=new Test(); 17 | test.listA = new ArrayList<>(); 18 | test.listB = new ArrayList<>(); 19 | for (int i = 0; i < 10; i++) { 20 | test.listA.add(i, i); 21 | } 22 | 23 | for (int i = 0; i < 10; i++) { 24 | 25 | if (i >= 4) { 26 | test.sum = 0; 27 | test.listB.add(i, test.fund(i - 4, i)); 28 | } else { 29 | test.listB.add(i, 0); 30 | } 31 | } 32 | 33 | for (int i = 0; i < 10; i++) { 34 | System.out.print(test.listB.get(i) + " "); 35 | } 36 | 37 | } 38 | 39 | public Integer fund(Integer a, Integer b) { 40 | 41 | for (int i = a; i <= b; i++) { 42 | sum += listA.get(i); 43 | } 44 | return sum; 45 | } 46 | */ 47 | /*public boolean foo(char c) { 48 | System.out.print(c); 49 | return true; 50 | } 51 | public static void main(String[] argv) { 52 | Test test=new Test(); 53 | 54 | int i = 0; 55 | for (test.foo('A'); test.foo('B') && (i < 2); test.foo('C')) { 56 | i++; 57 | test.foo('D'); 58 | } 59 | }*/ 60 | 61 | /*public static void main(String[] argv) { 62 | int[] a={2,3,1,6,4}; 63 | for(int i=0;ia[j+1]){ 66 | int temp=a[j+1]; 67 | a[j+1]=a[j]; 68 | a[j]=temp; 69 | } 70 | } 71 | } 72 | 73 | for (int i:a) { 74 | System.out.print(i+","); 75 | 76 | } 77 | }*/ 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/api/ClientApi.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.api; 2 | 3 | import okhttp3.ResponseBody; 4 | import retrofit2.http.GET; 5 | import retrofit2.http.Query; 6 | import rx.Observable; 7 | 8 | /** 9 | * Created by yanjiang on 2016/3/15. 10 | * 示例1 11 | * 12 | * @GET("Advertisement") Observable> getWeatherData(@Query("instID") String id); 13 | *

14 | * 示例2 15 | * @GET("FundPaperTrade/AppUserLogin") Observable getTransData(@QueryMap Map map); 16 | *

17 | * 示例3 18 | * @FormUrlEncoded 19 | * @POST("/newfind/index_ask") Observable getDaJia(@Field("page") int page, 20 | * @Field("pageSize") int size, 21 | * @Field("tokenMark") long tokenMark, 22 | * @Field("token") String token 23 | * ); 24 | *

25 | * 示例4 26 | * @FormUrlEncoded 27 | * @POST("FundPaperTrade/AppUserLogin") Observable getTransData(@FieldMap Map map); 28 | */ 29 | 30 | public interface ClientApi { 31 | 32 | 33 | /*分时图url*/ 34 | @GET(Constant.DETAILURL) 35 | Observable getMinutes(@Query("code") String code); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/api/Constant.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.api; 2 | 3 | import android.os.Environment; 4 | 5 | /** 6 | * Created by Administrator on 2016/6/13. 7 | */ 8 | public class Constant { 9 | public static final String MINUTESURL="http://test/"; 10 | public static final String DETAILURL="test/"; 11 | 12 | public static final String APATCH_PATH = "/out.apatch"; 13 | public static final String EXTERNALPATH = Environment.getExternalStorageDirectory().getAbsolutePath(); 14 | public static final String HTTP_BASE = "http://7xrnuc.com1.z0.glb.clouddn.com/";/*http://f5.market.xiaomi.com/download/AppStore/";*/ 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/api/DownLoadApi.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.api; 2 | 3 | import okhttp3.ResponseBody; 4 | import retrofit2.http.GET; 5 | import retrofit2.http.Streaming; 6 | import rx.Observable; 7 | 8 | /** 9 | * Created by yanjiang on 2016/4/20. 10 | * 恩恩 11 | */ 12 | public interface DownLoadApi { 13 | /*http://7xrnuc.com1.z0.glb.clouddn.com/out.apatch*/ 14 | @Streaming 15 | @GET("out.apatch") 16 | Observable getDownApk(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/application/App.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.application; 2 | 3 | import android.app.Application; 4 | 5 | import com.example.yanjiang.stockchart.BuildConfig; 6 | import com.example.yanjiang.stockchart.inject.component.AppComponent; 7 | import com.example.yanjiang.stockchart.inject.component.DaggerAppComponent; 8 | import com.example.yanjiang.stockchart.inject.modules.AppModule; 9 | import com.squareup.leakcanary.LeakCanary; 10 | 11 | import org.greenrobot.eventbus.EventBus; 12 | 13 | 14 | public class App extends Application { 15 | private static final int SHOW_TIME_MIN = 1000; 16 | private static App mApp; 17 | private static EventBus sBus; 18 | private AppComponent applicationComponent; 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | if (BuildConfig.DEBUG) { 23 | LeakCanary.install(this); 24 | } 25 | initComponent(); 26 | mApp=this; 27 | sBus = EventBus.getDefault(); 28 | } 29 | public static App getApp() { 30 | return mApp; 31 | } 32 | private void initComponent() { 33 | applicationComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); 34 | applicationComponent.inject(this); 35 | } 36 | 37 | public AppComponent getApplicationComponent() { 38 | return applicationComponent; 39 | } 40 | 41 | public static EventBus getBus() { 42 | return sBus; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/bean/KLineBean.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.bean; 2 | 3 | /** 4 | * author:ajiang 5 | * mail:1025065158@qq.com 6 | * blog:http://blog.csdn.net/qqyanjiang 7 | */ 8 | public class KLineBean { 9 | public String date; 10 | public float open; 11 | public float close; 12 | public float high; 13 | public float low; 14 | public float vol; 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/bean/MinutesBean.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.bean; 2 | 3 | 4 | public class MinutesBean { 5 | public String time; 6 | public float cjprice; 7 | public float cjnum; 8 | public float avprice = Float.NaN; 9 | public float per; 10 | public float cha; 11 | public float total; 12 | public int color = 0xff000000; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/event/ProgressUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.event; 2 | 3 | public class ProgressUpdateEvent { 4 | private long bytesRead,contentLength; 5 | private boolean done; 6 | 7 | public ProgressUpdateEvent(long bytesRead, long contentLength, boolean done){ 8 | this.bytesRead = bytesRead; 9 | this.contentLength=contentLength; 10 | this.done=done; 11 | } 12 | public long getbytesRead(){ 13 | return bytesRead; 14 | } 15 | public long getcontentLength(){ 16 | return contentLength; 17 | } 18 | public boolean getdone(){ 19 | return done; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/component/ActivityComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.component; 2 | 3 | import android.app.Activity; 4 | 5 | import com.example.yanjiang.stockchart.BaseActivity; 6 | import com.example.yanjiang.stockchart.inject.modules.ActivityModule; 7 | import com.example.yanjiang.stockchart.inject.others.PerActivity; 8 | 9 | import dagger.Component; 10 | 11 | @PerActivity 12 | @Component(dependencies = AppComponent.class, modules = ActivityModule.class) 13 | public interface ActivityComponent { 14 | 15 | Activity getActivityContext(); 16 | 17 | void inject(BaseActivity mBaseActivity); 18 | 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/component/AppComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.component; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import com.example.yanjiang.stockchart.api.ClientApi; 7 | import com.example.yanjiang.stockchart.api.DownLoadApi; 8 | import com.example.yanjiang.stockchart.application.App; 9 | import com.example.yanjiang.stockchart.inject.modules.AppModule; 10 | import com.example.yanjiang.stockchart.inject.modules.ClientApiModule; 11 | 12 | import javax.inject.Singleton; 13 | 14 | import dagger.Component; 15 | 16 | @Singleton 17 | @Component(modules = {AppModule.class, ClientApiModule.class}) 18 | public interface AppComponent { 19 | Context context(); 20 | 21 | ClientApi clientApi(); 22 | 23 | DownLoadApi downLoadApi(); 24 | SharedPreferences sharedPreferences(); 25 | 26 | void inject(App application); 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/component/FragmentComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.component; 2 | 3 | import android.app.Activity; 4 | 5 | import com.example.yanjiang.stockchart.inject.modules.FragmentModule; 6 | import com.example.yanjiang.stockchart.inject.others.PerFragment; 7 | 8 | import dagger.Component; 9 | 10 | @PerFragment 11 | @Component(modules = FragmentModule.class, dependencies = AppComponent.class) 12 | public interface FragmentComponent { 13 | 14 | Activity getActivity(); 15 | 16 | // void inject(BaseFragment mBaseFragment); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/component/ServiceComponent.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.component; 2 | 3 | import android.app.Service; 4 | 5 | import com.example.yanjiang.stockchart.inject.modules.ServiceModule; 6 | import com.example.yanjiang.stockchart.inject.others.PerService; 7 | import com.example.yanjiang.stockchart.service.DownLoadService; 8 | 9 | import dagger.Component; 10 | 11 | /** 12 | * author:ajiang 13 | * mail:1025065158@qq.com 14 | * blog:http://blog.csdn.net/qqyanjiang 15 | */ 16 | @PerService 17 | @Component(dependencies = AppComponent.class, modules = ServiceModule.class) 18 | public interface ServiceComponent { 19 | Service getService(); 20 | 21 | void inject(DownLoadService downLoadService); 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ActivityModule.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.modules; 2 | 3 | import android.app.Activity; 4 | 5 | import com.example.yanjiang.stockchart.inject.others.PerActivity; 6 | 7 | import dagger.Module; 8 | import dagger.Provides; 9 | 10 | @Module 11 | public class ActivityModule { 12 | 13 | private Activity mActivity; 14 | 15 | 16 | public ActivityModule(Activity mActivity) { 17 | this.mActivity = mActivity; 18 | } 19 | 20 | @Provides 21 | @PerActivity 22 | public Activity provideActivity() { 23 | return mActivity; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/modules/AppModule.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.modules; 2 | 3 | import android.content.Context; 4 | 5 | import com.example.yanjiang.stockchart.application.App; 6 | 7 | import javax.inject.Singleton; 8 | 9 | import dagger.Module; 10 | import dagger.Provides; 11 | 12 | @Module 13 | public class AppModule { 14 | 15 | App application; 16 | 17 | public AppModule(App application) { 18 | this.application = application; 19 | } 20 | 21 | @Provides 22 | @Singleton 23 | public Context provideContext() { 24 | return application; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ClientApiModule.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.modules; 2 | 3 | 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.preference.PreferenceManager; 7 | 8 | import com.example.yanjiang.stockchart.BuildConfig; 9 | import com.example.yanjiang.stockchart.api.ClientApi; 10 | import com.example.yanjiang.stockchart.api.Constant; 11 | import com.example.yanjiang.stockchart.api.DownLoadApi; 12 | 13 | import java.util.concurrent.TimeUnit; 14 | 15 | import javax.inject.Singleton; 16 | 17 | import dagger.Module; 18 | import dagger.Provides; 19 | import okhttp3.OkHttpClient; 20 | import okhttp3.logging.HttpLoggingInterceptor; 21 | import retrofit2.Retrofit; 22 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 23 | import retrofit2.converter.gson.GsonConverterFactory; 24 | 25 | /** 26 | * Created by yanjiang on 2016/3/25. 27 | */ 28 | @Module 29 | public class ClientApiModule { 30 | @Provides 31 | @Singleton 32 | public DownLoadApi provideDownLoadApi(OkHttpClient client) { 33 | Retrofit retrofit = new Retrofit.Builder() 34 | .baseUrl(Constant.HTTP_BASE) 35 | .client(client) 36 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 37 | .build(); 38 | 39 | return retrofit.create(DownLoadApi.class); 40 | } 41 | @Provides 42 | @Singleton 43 | public ClientApi provideClientApi(OkHttpClient client, GsonConverterFactory gsonConverterFactory) { 44 | Retrofit retrofit = new Retrofit.Builder() 45 | .baseUrl(Constant.MINUTESURL) 46 | .client(client) 47 | .addConverterFactory(gsonConverterFactory) 48 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 49 | .build(); 50 | 51 | return retrofit.create(ClientApi.class); 52 | } 53 | 54 | 55 | @Provides 56 | @Singleton 57 | public GsonConverterFactory provideGsonConverterFactory() { 58 | return GsonConverterFactory.create(); 59 | } 60 | 61 | 62 | @Provides 63 | @Singleton 64 | public OkHttpClient provideOkHttpClient(Context context, HttpLoggingInterceptor httpLoggingInterceptor) { 65 | return new OkHttpClient.Builder() 66 | .connectTimeout(10, TimeUnit.SECONDS) 67 | .writeTimeout(10, TimeUnit.SECONDS) 68 | .readTimeout(30, TimeUnit.SECONDS) 69 | .addInterceptor(httpLoggingInterceptor) 70 | .build(); 71 | } 72 | 73 | @Provides 74 | @Singleton 75 | public HttpLoggingInterceptor provideHttpLoggingInterceptor() { 76 | HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); 77 | if (BuildConfig.DEBUG) { 78 | httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 79 | } else { 80 | httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE); 81 | } 82 | return httpLoggingInterceptor; 83 | } 84 | 85 | 86 | 87 | @Provides 88 | @Singleton 89 | public SharedPreferences providesSharedPreferences(Context context) { 90 | return PreferenceManager.getDefaultSharedPreferences(context); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/modules/FragmentModule.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.modules; 2 | 3 | import android.app.Activity; 4 | import android.support.v4.app.Fragment; 5 | 6 | import com.example.yanjiang.stockchart.inject.others.PerFragment; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | @Module 12 | public class FragmentModule { 13 | private Fragment mFragment; 14 | 15 | public FragmentModule(Fragment fragment) { 16 | mFragment = fragment; 17 | } 18 | 19 | @Provides 20 | @PerFragment 21 | public Activity provideActivity() { 22 | return mFragment.getActivity(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/modules/ServiceModule.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.modules; 2 | 3 | import android.app.Service; 4 | 5 | import com.example.yanjiang.stockchart.inject.others.PerService; 6 | import com.example.yanjiang.stockchart.service.DownLoadService; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | /** 12 | * author:ajiang 13 | * mail:1025065158@qq.com 14 | * blog:http://blog.csdn.net/qqyanjiang 15 | */ 16 | @Module 17 | public class ServiceModule { 18 | private DownLoadService m_service; 19 | 20 | public ServiceModule(DownLoadService service) { 21 | m_service = service; 22 | } 23 | 24 | @Provides 25 | @PerService 26 | public Service provideService() { 27 | return m_service; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/others/ApplicationScope.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.others; 2 | 3 | import javax.inject.Scope; 4 | 5 | @Scope 6 | public @interface ApplicationScope { 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/others/PerActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.others; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Scope 10 | @Retention(RUNTIME) 11 | public @interface PerActivity { 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/others/PerFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.others; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Scope 10 | @Retention(RUNTIME) 11 | public @interface PerFragment { 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/others/PerService.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.others; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Scope 10 | @Retention(RUNTIME) 11 | public @interface PerService { 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/inject/others/StringQuali.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.inject.others; 2 | 3 | import javax.inject.Qualifier; 4 | 5 | /** 6 | * Created by yanjiang on 2016/3/28. 7 | */ 8 | @Qualifier 9 | 10 | public @interface StringQuali { 11 | String value() default ""; 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/interceptor/ProgressInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.interceptor; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | import okhttp3.Interceptor; 7 | import okhttp3.Response; 8 | 9 | 10 | public class ProgressInterceptor implements Interceptor 11 | { 12 | // private ProgressListener progressListener; 13 | 14 | 15 | /* public ProgressInterceptor(ProgressListener progressListener) 16 | { 17 | this.progressListener = progressListener; 18 | }*/ 19 | 20 | @Override 21 | public Response intercept(Chain chain) throws IOException 22 | { 23 | Response originalResponse = chain.proceed(chain.request()); 24 | return originalResponse.newBuilder().body(new ProgressResponseBody(originalResponse.body())).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/interceptor/ProgressResponseBody.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.interceptor; 2 | 3 | 4 | import com.example.yanjiang.stockchart.application.App; 5 | import com.example.yanjiang.stockchart.event.ProgressUpdateEvent; 6 | 7 | import java.io.IOException; 8 | 9 | import okhttp3.MediaType; 10 | import okhttp3.ResponseBody; 11 | import okio.Buffer; 12 | import okio.BufferedSource; 13 | import okio.ForwardingSource; 14 | import okio.Okio; 15 | import okio.Source; 16 | 17 | public class ProgressResponseBody extends ResponseBody 18 | { 19 | private final ResponseBody responseBody; 20 | // private final ProgressListener progressListener; 21 | private BufferedSource bufferedSource; 22 | 23 | public ProgressResponseBody(ResponseBody responseBody) 24 | { 25 | this.responseBody = responseBody; 26 | // this.progressListener = progressListener; 27 | } 28 | 29 | @Override 30 | public MediaType contentType() 31 | { 32 | return responseBody.contentType(); 33 | } 34 | 35 | @Override 36 | public long contentLength() { 37 | return responseBody.contentLength(); 38 | } 39 | 40 | @Override 41 | public BufferedSource source() 42 | { 43 | if(bufferedSource == null) 44 | { 45 | bufferedSource = Okio.buffer(source(responseBody.source())); 46 | } 47 | return bufferedSource; 48 | } 49 | 50 | private Source source(Source source) 51 | { 52 | return new ForwardingSource(source) 53 | { 54 | long totalBytesRead = 0L; 55 | 56 | @Override 57 | public long read(Buffer sink, long byteCount) throws IOException 58 | { 59 | long bytesRead = super.read(sink, byteCount); 60 | // read() returns the number of bytes read, or -1 if this source is exhausted. 61 | totalBytesRead += bytesRead != -1 ? bytesRead : 0; 62 | App.getBus().post(new ProgressUpdateEvent(totalBytesRead, responseBody.contentLength(), bytesRead == -1)); 63 | // progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1); 64 | return bytesRead; 65 | } 66 | }; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/CoupleChartGestureListener.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | 4 | import android.graphics.Matrix; 5 | import android.view.MotionEvent; 6 | import android.view.View; 7 | 8 | import com.github.mikephil.charting.charts.Chart; 9 | import com.github.mikephil.charting.listener.ChartTouchListener; 10 | import com.github.mikephil.charting.listener.OnChartGestureListener; 11 | 12 | /** 13 | * http://stackoverflow.com/questions/28521004/mpandroidchart-have-one-graph-mirror-the-zoom-swipes-on-a-sister-graph 14 | */ 15 | public class CoupleChartGestureListener implements OnChartGestureListener { 16 | 17 | private static final String TAG = CoupleChartGestureListener.class.getSimpleName(); 18 | 19 | private Chart srcChart; 20 | private Chart[] dstCharts; 21 | 22 | public CoupleChartGestureListener(Chart srcChart, Chart[] dstCharts) { 23 | this.srcChart = srcChart; 24 | this.dstCharts = dstCharts; 25 | } 26 | 27 | @Override 28 | public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) { 29 | syncCharts(); 30 | } 31 | 32 | @Override 33 | public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) { 34 | syncCharts(); 35 | } 36 | 37 | @Override 38 | public void onChartLongPressed(MotionEvent me) { 39 | syncCharts(); 40 | } 41 | 42 | @Override 43 | public void onChartDoubleTapped(MotionEvent me) { 44 | syncCharts(); 45 | } 46 | 47 | @Override 48 | public void onChartSingleTapped(MotionEvent me) { 49 | syncCharts(); 50 | } 51 | 52 | @Override 53 | public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) { 54 | syncCharts(); 55 | } 56 | 57 | @Override 58 | public void onChartScale(MotionEvent me, float scaleX, float scaleY) { 59 | // Log.d(TAG, "onChartScale " + scaleX + "/" + scaleY + " X=" + me.getX() + "Y=" + me.getY()); 60 | syncCharts(); 61 | } 62 | 63 | @Override 64 | public void onChartTranslate(MotionEvent me, float dX, float dY) { 65 | // Log.d(TAG, "onChartTranslate " + dX + "/" + dY + " X=" + me.getX() + "Y=" + me.getY()); 66 | syncCharts(); 67 | } 68 | 69 | public void syncCharts() { 70 | Matrix srcMatrix; 71 | float[] srcVals = new float[9]; 72 | Matrix dstMatrix; 73 | float[] dstVals = new float[9]; 74 | // get src chart translation matrix: 75 | srcMatrix = srcChart.getViewPortHandler().getMatrixTouch(); 76 | srcMatrix.getValues(srcVals); 77 | // apply X axis scaling and position to dst charts: 78 | for (Chart dstChart : dstCharts) { 79 | if (dstChart.getVisibility() == View.VISIBLE) { 80 | dstMatrix = dstChart.getViewPortHandler().getMatrixTouch(); 81 | dstMatrix.getValues(dstVals); 82 | 83 | dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X]; 84 | dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X]; 85 | dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X]; 86 | dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y]; 87 | dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y]; 88 | dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y]; 89 | dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0]; 90 | dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1]; 91 | dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2]; 92 | 93 | dstMatrix.setValues(dstVals); 94 | dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true); 95 | } 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyBottomMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import android.content.Context; 4 | import android.widget.TextView; 5 | 6 | import com.example.yanjiang.stockchart.R; 7 | import com.github.mikephil.charting.components.MarkerView; 8 | import com.github.mikephil.charting.data.Entry; 9 | import com.github.mikephil.charting.highlight.Highlight; 10 | 11 | import java.text.DecimalFormat; 12 | 13 | /** 14 | * author:ajiang 15 | * mail:1025065158@qq.com 16 | * blog:http://blog.csdn.net/qqyanjiang 17 | */ 18 | public class MyBottomMarkerView extends MarkerView { 19 | /** 20 | * Constructor. Sets up the MarkerView with a custom layout resource. 21 | * 22 | * @param context 23 | * @param layoutResource the layout resource to use for the MarkerView 24 | */ 25 | private TextView markerTv; 26 | private String time; 27 | public MyBottomMarkerView(Context context, int layoutResource) { 28 | super(context, layoutResource); 29 | markerTv = (TextView) findViewById(R.id.marker_tv); 30 | markerTv.setTextSize(10); 31 | } 32 | 33 | public void setData(String time){ 34 | 35 | this.time=time; 36 | } 37 | @Override 38 | public void refreshContent(Entry e, Highlight highlight) { 39 | markerTv.setText(time); 40 | } 41 | 42 | @Override 43 | public int getXOffset(float xpos) { 44 | return 0; 45 | } 46 | 47 | @Override 48 | public int getYOffset(float ypos) { 49 | return 0; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyLeftMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import android.content.Context; 4 | import android.widget.TextView; 5 | 6 | import com.example.yanjiang.stockchart.R; 7 | import com.github.mikephil.charting.components.MarkerView; 8 | import com.github.mikephil.charting.data.Entry; 9 | import com.github.mikephil.charting.highlight.Highlight; 10 | 11 | import java.text.DecimalFormat; 12 | 13 | /** 14 | * author:ajiang 15 | * mail:1025065158@qq.com 16 | * blog:http://blog.csdn.net/qqyanjiang 17 | */ 18 | public class MyLeftMarkerView extends MarkerView { 19 | /** 20 | * Constructor. Sets up the MarkerView with a custom layout resource. 21 | * 22 | * @param context 23 | * @param layoutResource the layout resource to use for the MarkerView 24 | */ 25 | private TextView markerTv; 26 | private float num; 27 | private DecimalFormat mFormat; 28 | public MyLeftMarkerView(Context context, int layoutResource) { 29 | super(context, layoutResource); 30 | mFormat=new DecimalFormat("#0.00"); 31 | markerTv = (TextView) findViewById(R.id.marker_tv); 32 | markerTv.setTextSize(10); 33 | } 34 | 35 | public void setData(float num){ 36 | 37 | this.num=num; 38 | } 39 | @Override 40 | public void refreshContent(Entry e, Highlight highlight) { 41 | markerTv.setText(mFormat.format(num)); 42 | } 43 | 44 | @Override 45 | public int getXOffset(float xpos) { 46 | return 0; 47 | } 48 | 49 | @Override 50 | public int getYOffset(float ypos) { 51 | return 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyRightMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import android.content.Context; 4 | import android.widget.TextView; 5 | 6 | import com.example.yanjiang.stockchart.R; 7 | import com.github.mikephil.charting.components.MarkerView; 8 | import com.github.mikephil.charting.data.Entry; 9 | import com.github.mikephil.charting.highlight.Highlight; 10 | 11 | import java.text.DecimalFormat; 12 | 13 | /** 14 | * author:ajiang 15 | * mail:1025065158@qq.com 16 | * blog:http://blog.csdn.net/qqyanjiang 17 | */ 18 | public class MyRightMarkerView extends MarkerView { 19 | /** 20 | * Constructor. Sets up the MarkerView with a custom layout resource. 21 | * 22 | * @param context 23 | * @param layoutResource the layout resource to use for the MarkerView 24 | */ 25 | private TextView markerTv; 26 | private float num; 27 | private DecimalFormat mFormat; 28 | public MyRightMarkerView(Context context, int layoutResource) { 29 | super(context, layoutResource); 30 | mFormat = new DecimalFormat("#0.00"); 31 | markerTv = (TextView) findViewById(R.id.marker_tv); 32 | markerTv.setTextSize(10); 33 | 34 | } 35 | 36 | public void setData(float num){ 37 | this.num=num; 38 | } 39 | @Override 40 | public void refreshContent(Entry e, Highlight highlight) { 41 | markerTv.setText(mFormat.format(num*100)+"%"); 42 | } 43 | 44 | @Override 45 | public int getXOffset(float xpos) { 46 | 47 | return 0; 48 | } 49 | 50 | @Override 51 | public int getYOffset(float ypos) { 52 | return 0; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyXAxis.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import android.util.SparseArray; 4 | 5 | import com.github.mikephil.charting.components.XAxis; 6 | 7 | /** 8 | * author:ajiang 9 | * mail:1025065158@qq.com 10 | * blog:http://blog.csdn.net/qqyanjiang 11 | */ 12 | public class MyXAxis extends XAxis { 13 | private SparseArray labels; 14 | public SparseArray getXLabels() { 15 | return labels; 16 | } 17 | public void setXLabels(SparseArray labels) { 18 | this.labels = labels; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyYAxis.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | 5 | /** 6 | * 作者:ajiang 7 | * 邮箱:1025065158 8 | * 博客:http://blog.csdn.net/qqyanjiang 9 | */ 10 | public class MyYAxis extends YAxis { 11 | private float baseValue=Float.NaN; 12 | private String minValue; 13 | public MyYAxis() { 14 | super(); 15 | } 16 | public MyYAxis(AxisDependency axis) { 17 | super(axis); 18 | } 19 | public void setShowMaxAndUnit(String minValue) { 20 | setShowOnlyMinMax(true); 21 | this.minValue = minValue; 22 | } 23 | public float getBaseValue() { 24 | return baseValue; 25 | } 26 | 27 | public String getMinValue(){ 28 | return minValue; 29 | } 30 | public void setBaseValue(float baseValue) { 31 | this.baseValue = baseValue; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/mychart/MyYAxisRenderer.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.mychart; 2 | 3 | import android.graphics.Canvas; 4 | import android.text.TextUtils; 5 | 6 | import com.github.mikephil.charting.renderer.YAxisRenderer; 7 | import com.github.mikephil.charting.utils.Transformer; 8 | import com.github.mikephil.charting.utils.Utils; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * author:ajiang 13 | * mail:1025065158@qq.com 14 | * blog:http://blog.csdn.net/qqyanjiang 15 | * 16 | * 重写y轴labels 17 | */ 18 | public class MyYAxisRenderer extends YAxisRenderer { 19 | protected MyYAxis mYAxis; 20 | public MyYAxisRenderer(ViewPortHandler viewPortHandler, MyYAxis yAxis, Transformer trans) { 21 | super(viewPortHandler, yAxis, trans); 22 | mYAxis = yAxis; 23 | } 24 | 25 | @Override 26 | protected void computeAxisValues(float min, float max) { 27 | /*只显示最大最小情况下*/ 28 | if (mYAxis.isShowOnlyMinMaxEnabled()) { 29 | mYAxis.mEntryCount = 2; 30 | mYAxis.mEntries = new float[2]; 31 | mYAxis.mEntries[0] = min; 32 | mYAxis.mEntries[1] = max; 33 | return; 34 | } 35 | /*折线图左边没有basevalue,则调用系统*/ 36 | if (Float.isNaN(mYAxis.getBaseValue())) { 37 | super.computeAxisValues(min, max); 38 | return; 39 | } 40 | float base = mYAxis.getBaseValue(); 41 | float yMin = min; 42 | int labelCount = mYAxis.getLabelCount(); 43 | float interval = (base - yMin) / labelCount; 44 | int n = labelCount * 2 + 1; 45 | mYAxis.mEntryCount = n; 46 | mYAxis.mEntries = new float[n]; 47 | int i; 48 | float f; 49 | for (f = min, i = 0; i < n; f += interval, i++) { 50 | mYAxis.mEntries[i] = f; 51 | } 52 | } 53 | @Override 54 | protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) { 55 | /*当有最小text的时候*/ 56 | if (!TextUtils.isEmpty(mYAxis.getMinValue()) && mYAxis.isShowOnlyMinMaxEnabled()) { 57 | for (int i = 0; i < mYAxis.mEntryCount; i++) { 58 | /*获取对应位置的值*/ 59 | String text = mYAxis.getFormattedLabel(i); 60 | if (i == 0) { 61 | text = mYAxis.getMinValue(); 62 | } 63 | if (i == 1) { 64 | c.drawText(text, fixedPosition, mViewPortHandler.offsetTop()+2*offset+5 , mAxisLabelPaint); 65 | } else if (i == 0) { 66 | c.drawText(text, fixedPosition, mViewPortHandler.contentBottom() - 3, mAxisLabelPaint); 67 | } 68 | } 69 | } 70 | else { 71 | for (int i = 0; i < mYAxis.mEntryCount; i++) { 72 | 73 | String text = mYAxis.getFormattedLabel(i); 74 | if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1) 75 | return; 76 | 77 | int labelHeight = Utils.calcTextHeight(mAxisLabelPaint, text); 78 | float pos = positions[i * 2 + 1] + offset; 79 | 80 | if ((pos - labelHeight) < mViewPortHandler.contentTop()) { 81 | 82 | pos = mViewPortHandler.contentTop() + offset * 2.5f + 3; 83 | } else if ((pos + labelHeight / 2) > mViewPortHandler.contentBottom()) { 84 | pos = mViewPortHandler.contentBottom() - 3; 85 | } 86 | c.drawText(text, fixedPosition, pos, mAxisLabelPaint); 87 | } 88 | 89 | 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/rxutils/ExecutorManager.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.rxutils; 2 | 3 | import android.os.Build; 4 | import android.support.annotation.NonNull; 5 | 6 | import java.io.File; 7 | import java.io.FileFilter; 8 | import java.util.concurrent.BlockingQueue; 9 | import java.util.concurrent.ExecutorService; 10 | import java.util.concurrent.LinkedBlockingQueue; 11 | import java.util.concurrent.RejectedExecutionHandler; 12 | import java.util.concurrent.ThreadFactory; 13 | import java.util.concurrent.ThreadPoolExecutor; 14 | import java.util.concurrent.TimeUnit; 15 | import java.util.concurrent.atomic.AtomicInteger; 16 | 17 | public class ExecutorManager { 18 | 19 | public static final int DEVICE_INFO_UNKNOWN = 0; 20 | public static ExecutorService eventExecutor; 21 | //private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); 22 | private static final int CPU_COUNT = ExecutorManager.getCountOfCPU(); 23 | private static final int CORE_POOL_SIZE = CPU_COUNT + 1; 24 | private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1; 25 | private static final int KEEP_ALIVE = 1; 26 | private static final BlockingQueue eventPoolWaitQueue = new LinkedBlockingQueue<>(128); 27 | private static final ThreadFactory eventThreadFactory = new ThreadFactory() { 28 | private final AtomicInteger mCount = new AtomicInteger(1); 29 | 30 | @Override 31 | public Thread newThread(@NonNull Runnable r) { 32 | return new Thread(r, "eventAsyncAndBackground #" + mCount.getAndIncrement()); 33 | } 34 | }; 35 | 36 | private static final RejectedExecutionHandler eventHandler = 37 | new ThreadPoolExecutor.CallerRunsPolicy(); 38 | 39 | static { 40 | eventExecutor = 41 | new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, 42 | eventPoolWaitQueue, eventThreadFactory, eventHandler); 43 | } 44 | 45 | /** 46 | * Linux中的设备都是以文件的形式存在,CPU也不例外,因此CPU的文件个数就等价与核数。 47 | * Android的CPU 设备文件位于/sys/devices/system/cpu/目录,文件名的的格式为cpu\d+。 48 | * 49 | * 引用:http://www.jianshu.com/p/f7add443cd32#,感谢 liangfeizc :) 50 | * https://github.com/facebook/device-year-class 51 | */ 52 | public static int getCountOfCPU() { 53 | 54 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { 55 | return 1; 56 | } 57 | int count; 58 | try { 59 | count = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length; 60 | } catch (SecurityException | NullPointerException e) { 61 | count = DEVICE_INFO_UNKNOWN; 62 | } 63 | return count; 64 | } 65 | 66 | private static final FileFilter CPU_FILTER = new FileFilter() { 67 | @Override 68 | public boolean accept(File pathname) { 69 | 70 | String path = pathname.getName(); 71 | if (path.startsWith("cpu")) { 72 | for (int i = 3; i < path.length(); i++) { 73 | if (path.charAt(i) < '0' || path.charAt(i) > '9') { 74 | return false; 75 | } 76 | } 77 | return true; 78 | } 79 | return false; 80 | } 81 | }; 82 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/rxutils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.rxutils; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | import android.util.Log; 6 | 7 | import com.example.yanjiang.stockchart.api.Constant; 8 | 9 | import java.io.File; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.OutputStream; 14 | 15 | import okhttp3.ResponseBody; 16 | 17 | public class FileUtils { 18 | 19 | /*返回体写入磁盘*/ 20 | public static boolean writeResponseBodyToDisk(ResponseBody body,Context context) { 21 | try { 22 | String patchPath = Constant.EXTERNALPATH + Constant.APATCH_PATH;///storage/emulated/0/out.apatch 23 | // todo change the file location/name according to your needs 24 | File futureStudioIconFile = new File(patchPath); 25 | 26 | InputStream inputStream = null; 27 | OutputStream outputStream = null; 28 | 29 | try { 30 | byte[] fileReader = new byte[4096]; 31 | 32 | long fileSize = body.contentLength(); 33 | long fileSizeDownloaded = 0; 34 | 35 | inputStream = body.byteStream(); 36 | outputStream = new FileOutputStream(futureStudioIconFile); 37 | 38 | while (true) { 39 | int read = inputStream.read(fileReader); 40 | 41 | if (read == -1) { 42 | break; 43 | } 44 | 45 | outputStream.write(fileReader, 0, read); 46 | 47 | fileSizeDownloaded += read; 48 | 49 | Log.e("@@@", "file download: " + fileSizeDownloaded + " of " + fileSize + futureStudioIconFile.getPath()); 50 | } 51 | 52 | outputStream.flush(); 53 | 54 | return true; 55 | } catch (IOException e) { 56 | return false; 57 | } finally { 58 | if (inputStream != null) { 59 | inputStream.close(); 60 | } 61 | 62 | if (outputStream != null) { 63 | outputStream.close(); 64 | } 65 | } 66 | } catch (IOException e) { 67 | return false; 68 | } 69 | } 70 | 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/rxutils/MyUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.rxutils; 2 | 3 | /** 4 | * author:ajiang 5 | * mail:1025065158@qq.com 6 | * blog:http://blog.csdn.net/qqyanjiang 7 | */ 8 | public class MyUtils { 9 | /** 10 | * Prevent class instantiation. 11 | */ 12 | private MyUtils() { 13 | } 14 | 15 | public static String getVolUnit(float num) { 16 | 17 | int e = (int) Math.floor(Math.log10(num)); 18 | 19 | if (e >= 8) { 20 | return "亿手"; 21 | } else if (e >= 4) { 22 | return "万手"; 23 | } else { 24 | return "手"; 25 | } 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yanjiang/stockchart/rxutils/VolFormatter.java: -------------------------------------------------------------------------------- 1 | package com.example.yanjiang.stockchart.rxutils; 2 | 3 | 4 | import android.util.Log; 5 | 6 | import com.github.mikephil.charting.components.YAxis; 7 | import com.github.mikephil.charting.formatter.YAxisValueFormatter; 8 | 9 | import java.text.DecimalFormat; 10 | 11 | public class VolFormatter implements YAxisValueFormatter { 12 | 13 | private final int unit; 14 | private DecimalFormat mFormat; 15 | private String u; 16 | public VolFormatter(int unit) { 17 | if (unit == 1) { 18 | mFormat = new DecimalFormat("#0"); 19 | } else { 20 | mFormat = new DecimalFormat("#0.00"); 21 | } 22 | this.unit = unit; 23 | this.u=MyUtils.getVolUnit(unit); 24 | } 25 | 26 | 27 | @Override 28 | public String getFormattedValue(float value, YAxis yAxis) { 29 | value = value / unit; 30 | if(value==0){ 31 | return u; 32 | } 33 | return mFormat.format(value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/jdfw.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndroidJiang/StockChart/c2ce9d52e20b0c20d04bfa3a9dd8167f0101f2a2/app/src/main/res/jdfw.gif -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_fix.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |