Skip to content

Commit 1ffb41f

Browse files
committed
Merge pull request #573 from AppDevNext/UnneededVariance
Remove unneded variance
2 parents ef72c8f + f6e4976 commit 1ffb41f

16 files changed

Lines changed: 741 additions & 728 deletions

File tree

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarChart.kt

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,22 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
8080
}
8181

8282
protected override fun calcMinMax() {
83-
if (mFitBars) {
84-
mXAxis.calculate(mData.xMin - mData.barWidth / 2f, mData.xMax + mData.barWidth / 2f)
85-
} else {
86-
mXAxis.calculate(mData.xMin, mData.xMax)
87-
}
88-
89-
// calculate axis range (min / max) according to provided data
90-
mAxisLeft.calculate(mData.getYMin(YAxis.AxisDependency.LEFT), mData.getYMax(YAxis.AxisDependency.LEFT))
91-
mAxisRight.calculate(
92-
mData.getYMin(YAxis.AxisDependency.RIGHT), mData.getYMax(
93-
YAxis.AxisDependency
94-
.RIGHT
83+
mData?.let { barData ->
84+
if (mFitBars) {
85+
mXAxis.calculate(barData.xMin - barData.barWidth / 2f, barData.xMax + barData.barWidth / 2f)
86+
} else {
87+
mXAxis.calculate(barData.xMin, barData.xMax)
88+
}
89+
90+
// calculate axis range (min / max) according to provided data
91+
mAxisLeft.calculate(barData.getYMin(YAxis.AxisDependency.LEFT), barData.getYMax(YAxis.AxisDependency.LEFT))
92+
mAxisRight.calculate(
93+
barData.getYMin(YAxis.AxisDependency.RIGHT), barData.getYMax(
94+
YAxis.AxisDependency
95+
.RIGHT
96+
)
9597
)
96-
)
98+
}
9799
}
98100

99101
/**
@@ -134,26 +136,28 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
134136
* The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
135137
*/
136138
open fun getBarBounds(barEntry: BarEntry, outputRect: RectF) {
137-
val set = mData.getDataSetForEntry(barEntry)
139+
mData?.let { barData ->
140+
val set = barData.getDataSetForEntry(barEntry)
138141

139-
if (set == null) {
140-
outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE)
141-
return
142-
}
142+
if (set == null) {
143+
outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE)
144+
return
145+
}
143146

144-
val y = barEntry.y
145-
val x = barEntry.x
147+
val y = barEntry.y
148+
val x = barEntry.x
146149

147-
val barWidth = mData.barWidth
150+
val barWidth = barData.barWidth
148151

149-
val left = x - barWidth / 2f
150-
val right = x + barWidth / 2f
151-
val top = if (y >= 0) y else 0f
152-
val bottom = if (y <= 0) y else 0f
152+
val left = x - barWidth / 2f
153+
val right = x + barWidth / 2f
154+
val top = if (y >= 0) y else 0f
155+
val bottom = if (y <= 0) y else 0f
153156

154-
outputRect.set(left, top, right, bottom)
157+
outputRect.set(left, top, right, bottom)
155158

156-
getTransformer(set.axisDependency)!!.rectValueToPixel(outputRect)
159+
getTransformer(set.axisDependency)!!.rectValueToPixel(outputRect)
160+
}
157161
}
158162

159163
/**
@@ -182,7 +186,7 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
182186
highlightValue(Highlight(x, dataSetIndex, stackIndex), false)
183187
}
184188

185-
override val barData: BarData
189+
override val barData: BarData?
186190
get() = mData
187191

188192
/**
@@ -206,7 +210,7 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
206210
* @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f
207211
*/
208212
fun groupBars(fromX: Float, groupSpace: Float, barSpace: Float) {
209-
barData.groupBars(fromX, groupSpace, barSpace)
213+
barData?.groupBars(fromX, groupSpace, barSpace)
210214
notifyDataSetChanged()
211215
}
212216

@@ -222,28 +226,29 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
222226
}
223227

224228
override fun getAccessibilityDescription(): String {
225-
val barData = barData
226-
227-
val entryCount = barData.entryCount
228-
229-
// Find the min and max index
230-
val yAxisValueFormatter = axisLeft.valueFormatter
231-
val minVal = yAxisValueFormatter!!.getFormattedValue(barData.yMin, null)
232-
val maxVal = yAxisValueFormatter.getFormattedValue(barData.yMax, null)
233-
234-
// Data range...
235-
val xAxisValueFormatter = xAxis.valueFormatter
236-
val minRange = xAxisValueFormatter!!.getFormattedValue(barData.xMin, null)
237-
val maxRange = xAxisValueFormatter.getFormattedValue(barData.xMax, null)
238-
239-
val entries = if (entryCount == 1) "entry" else "entries"
240-
241-
// Format the values of min and max; to recite them back
242-
return String.format(
243-
Locale.getDefault(), "The bar chart has %d %s. " +
244-
"The minimum value is %s and maximum value is %s." +
245-
"Data ranges from %s to %s.",
246-
entryCount, entries, minVal, maxVal, minRange, maxRange
247-
)
229+
barData?.let { barData ->
230+
val entryCount = barData.entryCount
231+
232+
// Find the min and max index
233+
val yAxisValueFormatter = axisLeft.valueFormatter
234+
val minVal = yAxisValueFormatter!!.getFormattedValue(barData.yMin, null)
235+
val maxVal = yAxisValueFormatter.getFormattedValue(barData.yMax, null)
236+
237+
// Data range...
238+
val xAxisValueFormatter = xAxis.valueFormatter
239+
val minRange = xAxisValueFormatter!!.getFormattedValue(barData.xMin, null)
240+
val maxRange = xAxisValueFormatter.getFormattedValue(barData.xMax, null)
241+
242+
val entries = if (entryCount == 1) "entry" else "entries"
243+
244+
// Format the values of min and max; to recite them back
245+
return String.format(
246+
Locale.getDefault(), "The bar chart has %d %s. " +
247+
"The minimum value is %s and maximum value is %s." +
248+
"Data ranges from %s to %s.",
249+
entryCount, entries, minVal, maxVal, minRange, maxRange
250+
)
251+
}
252+
return ""
248253
}
249254
}

MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.List;
4949

5050
import androidx.annotation.NonNull;
51+
import androidx.annotation.Nullable;
5152

5253
/**
5354
* Baseclass of all Chart-Views.
@@ -68,6 +69,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
6869
* object that holds all data that was originally set for the chart, before
6970
* it was modified or any filtering algorithms had been applied
7071
*/
72+
@Nullable
7173
protected T mData = null;
7274

7375
/**

MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import kotlin.math.min
2828
* BarChart with horizontal bar orientation. In this implementation, x- and y-axis are switched, meaning the YAxis class
2929
* represents the horizontal values and the XAxis class represents the vertical values.
3030
*/
31-
class HorizontalBarChart : BarChart {
31+
open class HorizontalBarChart : BarChart {
3232
constructor(context: Context?) : super(context)
3333

3434
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
@@ -201,22 +201,23 @@ class HorizontalBarChart : BarChart {
201201
}
202202

203203
override fun getBarBounds(barEntry: BarEntry, outputRect: RectF) {
204-
val bounds = outputRect
205-
val set = mData.getDataSetForEntry(barEntry)
204+
mData?.let { data ->
205+
val set = data.getDataSetForEntry(barEntry)
206206

207-
val y = barEntry.y
208-
val x = barEntry.x
207+
val y = barEntry.y
208+
val x = barEntry.x
209209

210-
val barWidth = mData.barWidth
210+
val barWidth = data.barWidth
211211

212-
val top = x - barWidth / 2f
213-
val bottom = x + barWidth / 2f
214-
val left = if (y >= 0) y else 0f
215-
val right = if (y <= 0) y else 0f
212+
val top = x - barWidth / 2f
213+
val bottom = x + barWidth / 2f
214+
val left = if (y >= 0) y else 0f
215+
val right = if (y <= 0) y else 0f
216216

217-
bounds.set(left, top, right, bottom)
217+
outputRect.set(left, top, right, bottom)
218218

219-
getTransformer(set!!.axisDependency)!!.rectValueToPixel(bounds)
219+
getTransformer(set!!.axisDependency)!!.rectValueToPixel(outputRect)
220+
}
220221
}
221222

222223
protected var mGetPositionBuffer: FloatArray = FloatArray(2)

0 commit comments

Comments
 (0)