From addd319253ae2d65533b1faabbb4241e05744cbf Mon Sep 17 00:00:00 2001 From: Aman Verma Date: 2023年3月13日 23:45:59 +0530 Subject: [PATCH 01/11] fix: remove publish plugin --- MPChartLib/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index 0fb6dc7036..16d3e3ce10 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' group='com.github.philjay' From 55558e74e6bb15d36a1bdd304ef6d3769f06bb5a Mon Sep 17 00:00:00 2001 From: Faisal Date: Thu, 4 May 2023 13:20:57 +0530 Subject: [PATCH 02/11] feat: add custom axis label style formatter (#1) Co-authored-by: Faisal Ahmed --- .../charting/components/AxisBase.java | 15 ++++++++++ .../formatter/IAxisStyleFormatter.java | 30 +++++++++++++++++++ .../charting/renderer/XAxisRenderer.java | 19 ++++++++++++ settings.gradle | 1 + 4 files changed, 65 insertions(+) create mode 100644 MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisStyleFormatter.java diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java index c90b4fc9b9..2cd56cb571 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java @@ -6,6 +6,7 @@ import android.util.Log; import com.github.mikephil.charting.formatter.DefaultAxisValueFormatter; +import com.github.mikephil.charting.formatter.IAxisStyleFormatter; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.utils.Utils; @@ -24,6 +25,8 @@ public abstract class AxisBase extends ComponentBase { */ protected IAxisValueFormatter mAxisValueFormatter; + protected IAxisStyleFormatter mAxisLabelStyleFormatter; + private int mGridColor = Color.GRAY; private float mGridLineWidth = 1f; @@ -554,6 +557,18 @@ public IAxisValueFormatter getValueFormatter() { return mAxisValueFormatter; } + + public void setAxisLabelStyleFormatter(IAxisStyleFormatter f) { + mAxisLabelStyleFormatter = f; + } + + public IAxisStyleFormatter getAxisLabelStyleFormatter() { + // return null if not set + if(mAxisLabelStyleFormatter == null) + return null; + return mAxisLabelStyleFormatter; + } + /** * Enables the grid line to be drawn in dashed mode, e.g. like this * "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF. diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisStyleFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisStyleFormatter.java new file mode 100644 index 0000000000..63804cafb5 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisStyleFormatter.java @@ -0,0 +1,30 @@ +package com.github.mikephil.charting.formatter; + +import android.graphics.Typeface; + +import com.github.mikephil.charting.components.AxisBase; + +public interface IAxisStyleFormatter { + /** + * Called when a value from an axis is to be formatted visually ( typeface, textSize, color, etc. ). + * before being drawn. For performance reasons, avoid excessive calculations + * and memory allocations inside this method. + * + * @param value the value to be formatted + * @param axis the axis the value belongs to + * @return + */ + Typeface getTypefaceForAxisValue(float value, AxisBase axis); + + /** + * Called when a value from an axis is to be formatted visually ( typeface, textSize, color, etc. ). + * before being drawn. For performance reasons, avoid excessive calculations + * and memory allocations inside this method. + * + * @param value the value to be formatted + * @param axis the axis the value belongs to + * @return + */ + int getTextColorForAxisValue(float value, AxisBase axis); +} + diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java index 8adb56c73a..2b1e4f578b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java @@ -7,10 +7,12 @@ import android.graphics.Paint.Align; import android.graphics.Path; import android.graphics.RectF; +import android.graphics.Typeface; import com.github.mikephil.charting.components.LimitLine; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.XAxis.XAxisPosition; +import com.github.mikephil.charting.formatter.IAxisStyleFormatter; import com.github.mikephil.charting.utils.FSize; import com.github.mikephil.charting.utils.MPPointD; import com.github.mikephil.charting.utils.MPPointF; @@ -204,6 +206,23 @@ protected void drawLabels(Canvas c, float pos, MPPointF anchor) { String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis); + // get the custom axis label style formatter if set + IAxisStyleFormatter axisLabelStyleFormatter = mXAxis.getAxisLabelStyleFormatter(); + + if(axisLabelStyleFormatter != null) { + // get label Text Style + Typeface tf = axisLabelStyleFormatter.getTypefaceForAxisValue( mXAxis.mEntries[i / 2], mXAxis); + if (tf != null) { + mAxisLabelPaint.setTypeface(tf); + } + + // get label text color + int color = axisLabelStyleFormatter.getTextColorForAxisValue( mXAxis.mEntries[i / 2], mXAxis); + if (color != 0) { + mAxisLabelPaint.setColor(color); + } + } + if (mXAxis.isAvoidFirstLastClippingEnabled()) { // avoid clipping of the last diff --git a/settings.gradle b/settings.gradle index 32efe09de1..7d3cd868ac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,3 +5,4 @@ include 'MPChartExample' //project(':MPChartLib-Realm').projectDir = new File('../MPAndroidChart-Realm/MPChartLib-Realm') + From 3731aba4b8287e4aac3fd8d25ac42534a0eef3df Mon Sep 17 00:00:00 2001 From: Faisal Date: Mon, 8 May 2023 14:11:30 +0530 Subject: [PATCH 03/11] Added feature to draw a static centered vertical line in YAxis (#2) Co-authored-by: Faisal Ahmed --- .../mikephil/charting/components/YAxis.java | 50 ++++++++++++++----- .../charting/renderer/YAxisRenderer.java | 21 ++++++++ 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java index d2071ec5a8..6efdb27371 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java @@ -104,6 +104,12 @@ public enum YAxisLabelPosition { */ protected float mMaxWidth = Float.POSITIVE_INFINITY; + protected Boolean mDrawStaticCenterVerticalLine = false; + + protected int mStaticCenterVerticalLineColor = Color.GRAY; + + protected float mStaticCenterVerticalLineWidth = 1f; + /** * Enum that specifies the axis a DataSet should be plotted against, either LEFT or RIGHT. * @@ -334,6 +340,30 @@ public void setZeroLineWidth(float width) { this.mZeroLineWidth = Utils.convertDpToPixel(width); } + public Boolean isDrawStaticCenterVerticalLineEnabled() { + return mDrawStaticCenterVerticalLine; + } + + public void setDrawStaticCenterVerticalLine(Boolean enabled) { + this.mDrawStaticCenterVerticalLine = enabled; + } + + public int getStaticCenterVerticalLineColor() { + return mStaticCenterVerticalLineColor; + } + + public void setStaticCenterVerticalLineColor(int color) { + this.mStaticCenterVerticalLineColor = color; + } + + public float getStaticCenterVerticalLineWidth() { + return mStaticCenterVerticalLineWidth; + } + + public void setStaticCenterVerticalLineWidth(float width) { + this.mStaticCenterVerticalLineWidth = Utils.convertDpToPixel(width); + } + /** * This is for normal (not horizontal) charts horizontal spacing. * @@ -392,7 +422,7 @@ public boolean needsOffset() { * Returns true if autoscale restriction for axis min value is enabled */ @Deprecated - public boolean isUseAutoScaleMinRestriction( ) { + public boolean isUseAutoScaleMinRestriction() { return mUseAutoScaleRestrictionMin; } @@ -400,7 +430,7 @@ public boolean isUseAutoScaleMinRestriction( ) { * Sets autoscale restriction for axis min value as enabled/disabled */ @Deprecated - public void setUseAutoScaleMinRestriction( boolean isEnabled ) { + public void setUseAutoScaleMinRestriction(boolean isEnabled) { mUseAutoScaleRestrictionMin = isEnabled; } @@ -416,7 +446,7 @@ public boolean isUseAutoScaleMaxRestriction() { * Sets autoscale restriction for axis max value as enabled/disabled */ @Deprecated - public void setUseAutoScaleMaxRestriction( boolean isEnabled ) { + public void setUseAutoScaleMaxRestriction(boolean isEnabled) { mUseAutoScaleRestrictionMax = isEnabled; } @@ -429,20 +459,14 @@ public void calculate(float dataMin, float dataMax) { // Make sure max is greater than min // Discussion: https://github.com/danielgindi/Charts/pull/3650#discussion_r221409991 - if (min> max) - { - if (mCustomAxisMax && mCustomAxisMin) - { + if (min> max) { + if (mCustomAxisMax && mCustomAxisMin) { float t = min; min = max; max = t; - } - else if (mCustomAxisMax) - { + } else if (mCustomAxisMax) { min = max < 0f ? max * 1.5f : max * 0.5f; - } - else if (mCustomAxisMin) - { + } else if (mCustomAxisMin) { max = min < 0f ? min * 0.5f : min * 1.5f; } } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java index 53cca7ee03..7da5731a9b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java @@ -24,6 +24,8 @@ public class YAxisRenderer extends AxisRenderer { protected Paint mZeroLinePaint; + protected Paint mCenterLinePaint; + public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) { super(viewPortHandler, trans, yAxis); @@ -38,6 +40,11 @@ public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer t mZeroLinePaint.setColor(Color.GRAY); mZeroLinePaint.setStrokeWidth(1f); mZeroLinePaint.setStyle(Paint.Style.STROKE); + + mCenterLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); + mCenterLinePaint.setColor(Color.GRAY); + mCenterLinePaint.setStrokeWidth(1f); + mCenterLinePaint.setStyle(Paint.Style.STROKE); } } @@ -168,6 +175,10 @@ public void renderGridLines(Canvas c) { if (mYAxis.isDrawZeroLineEnabled()) { drawZeroLine(c); } + + if(mYAxis.isDrawStaticCenterVerticalLineEnabled()) { + drawCenteredHighlightLine(c); + } } protected RectF mGridClippingRect = new RectF(); @@ -349,4 +360,14 @@ public void renderLimitLines(Canvas c) { c.restoreToCount(clipRestoreCount); } } + + public void drawCenteredHighlightLine(Canvas c) { + // change paint configuration to values from yAxis + mCenterLinePaint.setColor(mYAxis.getStaticCenterVerticalLineColor()); + mCenterLinePaint.setStrokeWidth(mYAxis.getStaticCenterVerticalLineWidth()); + // draw a vertical line at the center of the screen + c.drawLine(mViewPortHandler.getChartWidth() / 2f, mViewPortHandler.offsetTop(), + mViewPortHandler.getChartWidth() / 2f, mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom(), + mCenterLinePaint); + } } From 3947eb1ce1984cb4717f620a322e6fdcdb933293 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: 2023年5月25日 13:22:59 +0530 Subject: [PATCH 04/11] fix: warnings for old build_tools version (#3) --- MPChartExample/build.gradle | 9 +++++---- MPChartExample/src/main/AndroidManifest.xml | 4 ++-- MPChartLib/build.gradle | 20 +++++++++----------- MPChartLib/src/main/AndroidManifest.xml | 2 +- build.gradle | 7 +++---- gradle.properties | 3 +++ gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle index 2d607e9991..4dc72be95e 100644 --- a/MPChartExample/build.gradle +++ b/MPChartExample/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 defaultConfig { applicationId "com.xxmassdeveloper.mpchartexample" + compileSdk 33 minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 33 versionCode 57 versionName '3.1.0' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -17,10 +17,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + namespace 'com.xxmassdeveloper.mpchartexample' } dependencies { - implementation "androidx.appcompat:appcompat:1.0.2" - implementation 'com.google.android.material:material:1.0.0' + implementation "androidx.appcompat:appcompat:1.6.1" + implementation 'com.google.android.material:material:1.9.0' implementation project(':MPChartLib') } diff --git a/MPChartExample/src/main/AndroidManifest.xml b/MPChartExample/src/main/AndroidManifest.xml index 99334e601a..f67419bf07 100644 --- a/MPChartExample/src/main/AndroidManifest.xml +++ b/MPChartExample/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + @@ -12,6 +11,7 @@ android:theme="@style/AppTheme"> diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index 16d3e3ce10..1e58d9b20d 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -1,15 +1,12 @@ apply plugin: 'com.android.library' -group='com.github.philjay' +group = 'com.github.philjay' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' defaultConfig { + compileSdk 33 minSdkVersion 14 - targetSdkVersion 28 - versionCode 3 - versionName '3.1.0' + targetSdkVersion 33 } buildTypes { release { @@ -20,27 +17,28 @@ android { testOptions { unitTests.returnDefaultValues = true // this prevents "not mocked" error } + namespace 'com.github.mikephil.charting' } dependencies { - implementation 'androidx.annotation:annotation:1.0.0' - testImplementation 'junit:junit:4.12' + implementation 'androidx.annotation:annotation:1.5.0' + testImplementation 'junit:junit:4.13.2' } task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs - classifier = 'sources' + archiveClassifier.set("sources") } task javadoc(type: Javadoc) { options.charSet = 'UTF-8' - failOnError false + failOnError false source = android.sourceSets.main.java.sourceFiles classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier.set('javadoc') from javadoc.destinationDir } diff --git a/MPChartLib/src/main/AndroidManifest.xml b/MPChartLib/src/main/AndroidManifest.xml index d75f87c7e2..af45ebcb44 100644 --- a/MPChartLib/src/main/AndroidManifest.xml +++ b/MPChartLib/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - +