Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {

dataRenderer = BarChartRenderer(this, mAnimator, viewPortHandler, mDrawRoundedBars, mRoundedBarRadius)

highlighter = BarHighlighter(this)
setHighlighter(BarHighlighter(this))

xAxis.spaceMin = 0.5f
xAxis.spaceMax = 0.5f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<IBarLineScatt

xAxisRenderer = XAxisRenderer(viewPortHandler, mXAxis, mLeftAxisTransformer)

if (highlighter == null) // otherwise it overwrites highlighter from successors
highlighter = ChartHighlighter(this)
setHighlighter(ChartHighlighter(this))

chartTouchListener = BarLineChartTouchListener(this, viewPortHandler.matrixTouch, 3f)

Expand Down
6 changes: 6 additions & 0 deletions chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import info.appdev.charting.data.ChartData
import info.appdev.charting.data.Entry
import info.appdev.charting.formatter.DefaultValueFormatter
import info.appdev.charting.formatter.IValueFormatter
import info.appdev.charting.highlight.ChartHighlighter
import info.appdev.charting.highlight.Highlight
import info.appdev.charting.highlight.IHighlighter
import info.appdev.charting.interfaces.dataprovider.base.IBaseProvider
Expand Down Expand Up @@ -151,6 +152,7 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
protected var dataRenderer: DataRenderer? = null

var highlighter: IHighlighter? = null
protected set

/**
* Returns the ViewPortHandler of the chart that is responsible for the
Expand Down Expand Up @@ -1044,6 +1046,10 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
/**
* Returns a recyclable PointF instance.
*/
fun setHighlighter(highlighter: ChartHighlighter<*>?) {
this.highlighter = highlighter
}

override val centerOfView: PointF
get() = this.center

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ open class CombinedChart : BarLineChartBase<CombinedData>, CombinedDataProvider
get() = this@CombinedChart.candleData
}

highlighter = CombinedHighlighter(this, barDataProvider)
setHighlighter(CombinedHighlighter(this, barDataProvider))

// Old default behaviour
this@CombinedChart.isHighlightFullBar = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class HorizontalBarChart : BarChart {
mRightAxisTransformer = TransformerHorizontalBarChart(viewPortHandler)

dataRenderer = HorizontalBarChartRenderer(this, mAnimator, viewPortHandler)
highlighter = HorizontalBarHighlighter(this)
setHighlighter(HorizontalBarHighlighter(this))

axisRendererLeft = YAxisRendererHorizontalBarChart(viewPortHandler, mAxisLeft, mLeftAxisTransformer)
axisRendererRight = YAxisRendererHorizontalBarChart(viewPortHandler, mAxisRight, mRightAxisTransformer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import info.appdev.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataS
/**
* Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart.
*/
abstract class BarLineScatterCandleBubbleDataSet<T : BaseEntry<Float>>(yVals: MutableList<T>, label: String) :
abstract class BarLineScatterCandleBubbleDataSet<T : Entry>(yVals: MutableList<T>, label: String) :
DataSet<T>(yVals, label), IBarLineScatterCandleBubbleDataSet<T> {
/**
* Sets the color that is used for drawing the highlight indicators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import info.appdev.charting.utils.convertDpToPixel
* This is the base dataset of all DataSets. It's purpose is to implement critical methods
* provided by the IDataSet interface.
*/
abstract class BaseDataSet<T : BaseEntry<Float>>() : IDataSet<T> {
abstract class BaseDataSet<T : Entry>() : IDataSet<T> {
/**
* List representing all colors that are used for this DataSet
*/
Expand Down
76 changes: 8 additions & 68 deletions chartLib/src/main/kotlin/info/appdev/charting/data/BaseEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,34 @@ package info.appdev.charting.data

import android.graphics.drawable.Drawable

abstract class BaseEntry<T> where T : Number, T : Comparable<T> {
abstract class BaseEntry {

protected var yBase: T? = null
protected var xBase: T? = null

open var y: T
get() = yBase ?: throw IllegalStateException("y not initialized")
protected var yBase: Float = 0f
open var y: Float
get() = yBase
set(value) {
yBase = value
}

open var x: T
get() = xBase ?: throw IllegalStateException("x not initialized")
set(value) {
xBase = value
}

var data: Any? = null

var icon: Drawable? = null

constructor()

constructor(y: T) {
this.yBase = y
}

constructor(y: T, data: Any?) : this(y) {
this.data = data
}

constructor(y: T, icon: Drawable?) : this(y) {
this.icon = icon
}

constructor(y: T, icon: Drawable?, data: Any?) : this(y) {
this.icon = icon
this.data = data
}

/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
*/
constructor(x: T, y: T) {
this.xBase = x
constructor(y: Float) {
this.yBase = y
}

/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param data Spot for additional data this Entry represents.
*/
constructor(x: T, y: T, data: Any?) {
this.xBase = x
this.yBase = y
constructor(y: Float, data: Any?) : this(y) {
this.data = data
}

/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
*/
constructor(x: T, y: T, icon: Drawable?) {
this.xBase = x
this.yBase = y
constructor(y: Float, icon: Drawable?) : this(y) {
this.icon = icon
}

/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
* @param data Spot for additional data this Entry represents.
*/
constructor(x: T, y: T, icon: Drawable?, data: Any?) {
this.xBase = x
this.yBase = y
constructor(y: Float, icon: Drawable?, data: Any?) : this(y) {
this.icon = icon
this.data = data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ abstract class ChartData<T : IDataSet<out Entry>> : Serializable {
}

val dataSet: IDataSet<*> = dataSets[dataSetIndex]
val entry = dataSet.getEntryForXValue(xValue, Float.NaN) as? Entry ?: return false
val entry: Entry = dataSet.getEntryForXValue(xValue, Float.NaN) ?: return false

return removeEntry(entry, dataSetIndex)
}
Expand Down
8 changes: 4 additions & 4 deletions chartLib/src/main/kotlin/info/appdev/charting/data/DataSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.math.abs
* groups of values inside the Chart (e.g. the values for a specific line in the
* LineChart, or the values of a specific group of bars in the BarChart).
*/
abstract class DataSet<T : BaseEntry<Float>>(
abstract class DataSet<T : Entry>(
protected var mEntries: MutableList<T>,
label: String = ""
) : BaseDataSet<T>(label), Serializable {
Expand Down Expand Up @@ -219,9 +219,9 @@ abstract class DataSet<T : BaseEntry<Float>>(
while (low < high) {
val m = low + (high - low) / 2

val currentEntry: T = mEntries[m]
val currentEntry: Entry = mEntries[m]

val nextEntry: T = mEntries[m + 1]
val nextEntry: Entry = mEntries[m + 1]

val d1 = currentEntry.x - xValue
val d2 = nextEntry.x - xValue
Expand Down Expand Up @@ -251,7 +251,7 @@ abstract class DataSet<T : BaseEntry<Float>>(
closest = high
}

val closestEntry: T = mEntries[closest]
val closestEntry: Entry = mEntries[closest]
val closestXValue = closestEntry.x
if (rounding == Rounding.UP) {
// If rounding up, and found x-value is lower than specified x, and we can go upper...
Expand Down
63 changes: 49 additions & 14 deletions chartLib/src/main/kotlin/info/appdev/charting/data/Entry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,60 @@ import kotlin.math.abs
* Class representing one entry in the chart. Might contain multiple values.
* Might only contain a single value depending on the used constructor.
*/
open class Entry : BaseEntry<Float>, Parcelable, Serializable {
open class Entry : BaseEntry, Parcelable, Serializable {

constructor() : super()

constructor(y: Float) : super(y)

constructor(y: Float, data: Any?) : super(y, data)

constructor(y: Float, icon: Drawable?) : super(y, icon)
private var _x: Float = 0f
open var x: Float
get() = _x
set(value) {
_x = value
}

constructor(y: Float, icon: Drawable?, data: Any?) : super(y, icon, data)
constructor()

constructor(x: Float, y: Float) : super(x, y)
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
*/
constructor(x: Float, y: Float) : super(y) {
this._x = x
}

constructor(x: Float, y: Float, data: Any?) : super(x, y, data)
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param data Spot for additional data this Entry represents.
*/
constructor(x: Float, y: Float, data: Any?) : super(y, data) {
this._x = x
}

constructor(x: Float, y: Float, icon: Drawable?) : super(x, y, icon)
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
*/
constructor(x: Float, y: Float, icon: Drawable?) : super(y, icon) {
this._x = x
}

constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(x, y, icon, data)
/**
* A Entry represents one single entry in the chart.
*
* @param x the x value
* @param y the y value (the actual value of the entry)
* @param icon icon image
* @param data Spot for additional data this Entry represents.
*/
constructor(x: Float, y: Float, icon: Drawable?, data: Any?) : super(y, icon, data) {
this._x = x
}

/**
* returns an exact copy of the entry
Expand Down Expand Up @@ -88,7 +123,7 @@ open class Entry : BaseEntry<Float>, Parcelable, Serializable {
}

protected constructor(`in`: Parcel) {
this.xBase = `in`.readFloat()
this._x = `in`.readFloat()
this.yBase = `in`.readFloat()
if (`in`.readInt() == 1) {
this.data = `in`.readParcelable(Any::class.java.classLoader)
Expand Down
Loading
Loading