Skip to content

Commit

Permalink
Merge pull request #170 from AppDevNext/KotlinConversionLineChart
Browse files Browse the repository at this point in the history
Kotlin conversion LineChart
  • Loading branch information
hannesa2 authored Nov 28, 2023
2 parents e42bf09 + 7a9d178 commit 696f945
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import java.io.OutputStream;
import java.util.ArrayList;

import androidx.annotation.NonNull;

/**
* Baseclass of all Chart-Views.
*
Expand Down Expand Up @@ -1311,6 +1313,7 @@ public void setDrawMarkers(boolean enabled) {
/**
* Returns the ChartData object that has been set for the chart.
*/
@NonNull
public T getData() {
return mData;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.mikephil.charting.charts

import android.content.Context
import android.util.AttributeSet
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider
import com.github.mikephil.charting.renderer.LineChartRenderer
import java.util.Locale

class LineChart : BarLineChartBase<LineData?>, LineDataProvider {

constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

override fun init() {
super.init()
mRenderer = LineChartRenderer(this, mAnimator, mViewPortHandler)
}

override val lineData: LineData
get() {
mData?.let {
return it
} ?: run {
return LineData()
}
}

public override fun onDetachedFromWindow() {
// releases the bitmap in the renderer to avoid oom error
if (mRenderer != null && mRenderer is LineChartRenderer) {
(mRenderer as LineChartRenderer).releaseBitmap()
}
super.onDetachedFromWindow()
}

override fun getAccessibilityDescription(): String {
val lineData = lineData
val numberOfPoints = lineData.entryCount

// Min and max values...
val yAxisValueFormatter = axisLeft.valueFormatter
val minVal = yAxisValueFormatter.getFormattedValue(lineData.yMin, null)
val maxVal = yAxisValueFormatter.getFormattedValue(lineData.yMax, null)

// Data range...
val xAxisValueFormatter = xAxis.valueFormatter
val minRange = xAxisValueFormatter.getFormattedValue(lineData.xMin, null)
val maxRange = xAxisValueFormatter.getFormattedValue(lineData.xMax, null)
val entries = if (numberOfPoints == 1) "entry" else "entries"
return String.format(
Locale.getDefault(), "The line chart has %d %s. " +
"The minimum value is %s and maximum value is %s." +
"Data ranges from %s to %s.",
numberOfPoints, entries, minVal, maxVal, minRange, maxRange
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.mikephil.charting.interfaces.dataprovider

import com.github.mikephil.charting.components.YAxis.AxisDependency
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData
import com.github.mikephil.charting.utils.Transformer

interface BarLineScatterCandleBubbleDataProvider : ChartInterface {
fun getTransformer(axis: AxisDependency?): Transformer?
fun isInverted(axis: AxisDependency?): Boolean
val lowestVisibleX: Float
val highestVisibleX: Float
override fun getData(): BarLineScatterCandleBubbleData<*>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.mikephil.charting.interfaces.dataprovider

import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.components.YAxis.AxisDependency
import com.github.mikephil.charting.data.LineData

interface LineDataProvider : BarLineScatterCandleBubbleDataProvider {
val lineData: LineData
fun getAxis(dependency: AxisDependency): YAxis?
}
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,12 @@ public void drawExtras(Canvas c) {
/**
* cache for the circle bitmaps of all datasets
*/
private HashMap<IDataSet, DataSetImageCache> mImageCaches = new HashMap<>();
private final HashMap<IDataSet, DataSetImageCache> mImageCaches = new HashMap<>();

/**
* buffer for drawing the circles
*/
private float[] mCirclesBuffer = new float[2];
private final float[] mCirclesBuffer = new float[2];

protected void drawCircles(Canvas c) {

Expand Down Expand Up @@ -782,7 +782,7 @@ public void releaseBitmap() {

private class DataSetImageCache {

private Path mCirclePathBuffer = new Path();
private final Path mCirclePathBuffer = new Path();

private Bitmap[] circleBitmaps;

Expand Down

0 comments on commit 696f945

Please sign in to comment.