Skip to content

Commit 603a33c

Browse files
committed
Clean up setters
1 parent 7db6086 commit 603a33c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+376
-526
lines changed

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

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,53 +143,34 @@ open class BarChart : BarLineChartBase<BarEntry, IBarDataSet, BarData>, BarDataP
143143
getTransformer(set.axisDependency).rectValueToPixel(outputRect)
144144
}
145145

146-
/**
147-
* If set to true, all values are drawn above their bars, instead of below their top.
148-
*
149-
*/
150-
fun setDrawValueAboveBar(enabled: Boolean) {
151-
mDrawValueAboveBar = enabled
152-
}
153-
154146
/**
155147
* returns true if drawing values above bars is enabled, false if not
156148
*
157149
*/
158-
override val isDrawValueAboveBarEnabled: Boolean
150+
override var isDrawValueAboveBarEnabled: Boolean
159151
get() = mDrawValueAboveBar
160-
161-
/**
162-
* If set to true, a grey area is drawn behind each bar that indicates the maximum value. Enabling his will reduce
163-
* performance by about 50%.
164-
*
165-
*/
166-
fun setDrawBarShadow(enabled: Boolean) {
167-
mDrawBarShadow = enabled
168-
}
152+
set(value) {
153+
mDrawValueAboveBar = value
154+
}
169155

170156
/**
171157
* returns true if drawing shadows (maxvalue) for each bar is enabled, false if not
172158
*
173159
*/
174-
override val isDrawBarShadowEnabled: Boolean
160+
override var isDrawBarShadowEnabled: Boolean
175161
get() = mDrawBarShadow
176-
177-
/**
178-
* Set this to true to make the highlight operation full-bar oriented, false to make it highlight single values (relevant
179-
* only for stacked). If enabled, highlighting operations will highlight the whole bar, even if only a single stack entry
180-
* was tapped.
181-
* Default: false
182-
*
183-
*/
184-
fun setHighlightFullBarEnabled(enabled: Boolean) {
185-
mHighlightFullBarEnabled = enabled
186-
}
162+
set(value) {
163+
mDrawBarShadow = value
164+
}
187165

188166
/**
189167
* @return true the highlight operation is be full-bar oriented, false if single-value
190168
*/
191-
override val isHighlightFullBarEnabled: Boolean
169+
override var isHighlightFullBarEnabled: Boolean
192170
get() = mHighlightFullBarEnabled
171+
set(value) {
172+
mHighlightFullBarEnabled = value
173+
}
193174

194175
/**
195176
* Highlights the value at the given x-value in the given DataSet. Provide
@@ -203,8 +184,11 @@ open class BarChart : BarLineChartBase<BarEntry, IBarDataSet, BarData>, BarDataP
203184
super.highlightValue(Highlight(x, dataSetIndex, dataIndex), false)
204185
}
205186

206-
override val barData: BarData?
187+
override var barData: BarData?
207188
get() = mData
189+
set(value) {
190+
mData = value
191+
}
208192

209193
/**
210194
* Adds half of the bar width to each side of the x-axis range in order to allow the bars of the barchart to be

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

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
163163
/**
164164
* flag indicating if the grid background should be drawn or not
165165
*/
166-
protected var mDrawGridBackground: Boolean = false
166+
var drawGridBackground: Boolean = false
167167

168168
/**
169169
* When enabled, the borders rectangle will be rendered.
@@ -172,7 +172,6 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
172172
* @return
173173
*/
174174
var isDrawBordersEnabled: Boolean = false
175-
protected set
176175

177176
/**
178177
* When enabled, the values will be clipped to contentRect,
@@ -181,7 +180,6 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
181180
* @return
182181
*/
183182
var isClipValuesToContentEnabled: Boolean = false
184-
protected set
185183

186184
/**
187185
* When disabled, the data and/or highlights will not be clipped to contentRect. Disabling this option can
@@ -191,7 +189,6 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
191189
* @return
192190
*/
193191
var isClipDataToContentEnabled: Boolean = true
194-
protected set
195192

196193
/**
197194
* Gets the minimum offset (padding) around the chart, defaults to 15.f
@@ -585,7 +582,7 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
585582
* draws the grid background
586583
*/
587584
protected fun drawGridBackground(c: Canvas) {
588-
if (mDrawGridBackground) {
585+
if (drawGridBackground) {
589586
// draw the grid background
590587

591588
c.drawRect(viewPortHandler.contentRect, mGridBackgroundPaint)
@@ -1120,46 +1117,6 @@ abstract class BarLineChartBase<E: Entry, D : IBarLineScatterCandleBubbleDataSet
11201117
this.isScaleYEnabled = enabled
11211118
}
11221119

1123-
/**
1124-
* set this to true to draw the grid background, false if not
1125-
*
1126-
* @param enabled
1127-
*/
1128-
fun setDrawGridBackground(enabled: Boolean) {
1129-
mDrawGridBackground = enabled
1130-
}
1131-
1132-
/**
1133-
* When enabled, the borders rectangle will be rendered.
1134-
* If this is enabled, there is no point drawing the axis-lines of x- and y-axis.
1135-
*
1136-
* @param enabled
1137-
*/
1138-
fun setDrawBorders(enabled: Boolean) {
1139-
this.isDrawBordersEnabled = enabled
1140-
}
1141-
1142-
/**
1143-
* When enabled, the values will be clipped to contentRect,
1144-
* otherwise they can bleed outside the content rect.
1145-
*
1146-
* @param enabled
1147-
*/
1148-
fun setClipValuesToContent(enabled: Boolean) {
1149-
this.isClipValuesToContentEnabled = enabled
1150-
}
1151-
1152-
/**
1153-
* When disabled, the data and/or highlights will not be clipped to contentRect. Disabling this option can
1154-
* be useful, when the data lies fully within the content rect, but is drawn in such a way (such as thick lines)
1155-
* that there is unwanted clipping.
1156-
*
1157-
* @param enabled
1158-
*/
1159-
fun setClipDataToContent(enabled: Boolean) {
1160-
this.isClipDataToContentEnabled = enabled
1161-
}
1162-
11631120
/**
11641121
* Sets the width of the border lines in dp.
11651122
*

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ class BubbleChart : BarLineChartBase<BubbleEntry, IBubbleDataSet, BubbleData>, B
2727
mRenderer = BubbleChartRenderer(this, mAnimator, viewPortHandler)
2828
}
2929

30-
override val bubbleData: BubbleData?
30+
override var bubbleData: BubbleData?
3131
get() = mData
32+
set(value) {
33+
mData = value
34+
}
3235

3336
override val accessibilityDescription: String?
3437
get() = "This is bubble chart"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ class CandleStickChart : BarLineChartBase<CandleEntry, ICandleDataSet, CandleDat
2727
xAxis.spaceMax = 0.5f
2828
}
2929

30-
override val candleData: CandleData?
30+
override var candleData: CandleData?
3131
get() = mData
32+
set(value) {
33+
mData = value
34+
}
3235

3336
override val accessibilityDescription: String?
3437
get() = "This is a candlestick chart"

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ open class CombinedChart : BarLineChartBase<Entry, IBarLineScatterCandleBubbleDa
6565
setHighlighter(CombinedHighlighter(this, this))
6666

6767
// Old default behaviour
68-
setHighlightFullBarEnabled(true)
68+
mHighlightFullBarEnabled = true
6969

7070
mRenderer = CombinedChartRenderer(this, mAnimator, viewPortHandler)
7171
}
@@ -104,57 +104,56 @@ open class CombinedChart : BarLineChartBase<Entry, IBarLineScatterCandleBubbleDa
104104
}
105105
}
106106

107-
override val lineData: LineData?
107+
override var lineData: LineData?
108108
get() = mData?.lineData
109+
set(value) {
110+
mData?.setData(value)
111+
}
109112

110-
override val barData: BarData?
113+
override var barData: BarData?
111114
get() = mData?.barData
115+
set(value) {
116+
mData?.setData(value)
117+
}
112118

113-
override val scatterData: ScatterData?
119+
override var scatterData: ScatterData?
114120
get() = mData?.scatterData
121+
set(value) {
122+
mData?.setData(value)
123+
}
115124

116-
override val candleData: CandleData?
125+
override var candleData: CandleData?
117126
get() = mData?.candleData
127+
set(value) {
128+
mData?.setData(value)
129+
}
118130

119-
override val bubbleData: BubbleData?
131+
override var bubbleData: BubbleData?
120132
get() = mData?.bubbleData
133+
set(value) {
134+
mData?.setData(value)
135+
}
121136

122-
override val isDrawBarShadowEnabled: Boolean
137+
override var isDrawBarShadowEnabled: Boolean
123138
get() = mDrawBarShadow
139+
set(value) {
140+
mDrawBarShadow = value
141+
}
124142

125-
override val isDrawValueAboveBarEnabled: Boolean
143+
override var isDrawValueAboveBarEnabled: Boolean
126144
get() = mDrawValueAboveBar
127-
128-
/**
129-
* If set to true, all values are drawn above their bars, instead of below
130-
* their top.
131-
*/
132-
fun setDrawValueAboveBar(enabled: Boolean) {
133-
mDrawValueAboveBar = enabled
134-
}
135-
136-
137-
/**
138-
* If set to true, a grey area is drawn behind each bar that indicates the
139-
* maximum value. Enabling his will reduce performance by about 50%.
140-
*/
141-
fun setDrawBarShadow(enabled: Boolean) {
142-
mDrawBarShadow = enabled
143-
}
144-
145-
/**
146-
* Set this to true to make the highlight operation full-bar oriented,
147-
* false to make it highlight single values (relevant only for stacked).
148-
*/
149-
fun setHighlightFullBarEnabled(enabled: Boolean) {
150-
mHighlightFullBarEnabled = enabled
151-
}
145+
set(value) {
146+
mDrawValueAboveBar = value
147+
}
152148

153149
/**
154150
* @return true the highlight operation is be full-bar oriented, false if single-value
155151
*/
156-
override val isHighlightFullBarEnabled: Boolean
152+
override var isHighlightFullBarEnabled: Boolean
157153
get() = mHighlightFullBarEnabled
154+
set(value) {
155+
mHighlightFullBarEnabled = value
156+
}
158157

159158
var drawOrder: Array<DrawOrder>
160159
/**

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ open class LineChart : BarLineChartBase<Entry, ILineDataSet, LineData>, LineData
1818
mRenderer = LineChartRenderer(this, mAnimator, viewPortHandler)
1919
}
2020

21-
override val lineData: LineData
22-
get() = mData ?: LineData()
21+
override var lineData: LineData?
22+
get() = mData
23+
set(value) {
24+
mData = value
25+
}
2326

2427
public override fun onDetachedFromWindow() {
2528
// releases the bitmap in the renderer to avoid oom error
@@ -32,7 +35,7 @@ open class LineChart : BarLineChartBase<Entry, ILineDataSet, LineData>, LineData
3235
override val accessibilityDescription: String?
3336
get() {
3437
val lineData = lineData
35-
val numberOfPoints = lineData.entryCount
38+
val numberOfPoints = lineData?.entryCount ?: return null
3639

3740
// Min and max values...
3841
val yAxisValueFormatter = axisLeft.valueFormatter

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ class ScatterChart : BarLineChartBase<Entry, IScatterDataSet, ScatterData>, Scat
3030
xAxis.spaceMax = 0.5f
3131
}
3232

33-
override val scatterData: ScatterData?
33+
override var scatterData: ScatterData?
3434
get() = mData
35+
set(value) {
36+
mData = scatterData
37+
}
3538

3639
/**
3740
* Predefined ScatterShapes that allow the specification of a shape a ScatterDataSet should be drawn with.

0 commit comments

Comments
 (0)