@@ -32,25 +32,26 @@ open class BarChartRenderer(
3232
3333 @JvmField
3434 protected var shadowPaint: Paint
35+
3536 @JvmField
3637 protected var barBorderPaint: Paint
3738
3839 /* *
3940 * if set to true, the bar chart's bars would be round on all corners instead of rectangular
4041 */
41- private var mDrawRoundedBars = false
42+ private var drawRoundedBars = false
4243
4344 /* *
4445 * the radius of the rounded bar chart bars
4546 */
46- private var mRoundedBarRadius = 0f
47+ private var roundedBarRadius = 0f
4748
4849 constructor (
4950 chart: BarDataProvider , animator: ChartAnimator ? ,
5051 viewPortHandler: ViewPortHandler ? , mDrawRoundedBars: Boolean , mRoundedBarRadius: Float
5152 ) : this (chart, animator, viewPortHandler) {
52- this .mDrawRoundedBars = mDrawRoundedBars
53- this .mRoundedBarRadius = mRoundedBarRadius
53+ this .drawRoundedBars = mDrawRoundedBars
54+ this .roundedBarRadius = mRoundedBarRadius
5455 }
5556
5657 override fun initBuffers () {
@@ -82,14 +83,14 @@ open class BarChartRenderer(
8283 }
8384 }
8485
85- private val mBarShadowRectBuffer = RectF ()
86+ private val barShadowRectBuffer = RectF ()
8687
8788 init {
88- mHighlightPaint = Paint (Paint .ANTI_ALIAS_FLAG )
89- mHighlightPaint .style = Paint .Style .FILL
90- mHighlightPaint .color = Color .rgb(0 , 0 , 0 )
89+ highlightPaint = Paint (Paint .ANTI_ALIAS_FLAG )
90+ highlightPaint .style = Paint .Style .FILL
91+ highlightPaint .color = Color .rgb(0 , 0 , 0 )
9192 // set alpha after color
92- mHighlightPaint .alpha = 120
93+ highlightPaint .alpha = 120
9394
9495 shadowPaint = Paint (Paint .ANTI_ALIAS_FLAG )
9596 shadowPaint.style = Paint .Style .FILL
@@ -106,8 +107,8 @@ open class BarChartRenderer(
106107
107108 val drawBorder = dataSet.barBorderWidth > 0f
108109
109- val phaseX = mAnimator .phaseX
110- val phaseY = mAnimator .phaseY
110+ val phaseX = animator .phaseX
111+ val phaseY = animator .phaseY
111112
112113 // draw the bar shadow before the values
113114 if (chart.isDrawBarShadowEnabled) {
@@ -121,110 +122,108 @@ open class BarChartRenderer(
121122
122123 var i = 0
123124 val count = min((ceil(((dataSet.entryCount).toFloat() * phaseX).toDouble())).toInt().toDouble(), dataSet.entryCount.toDouble()).toInt()
124- while (i < count
125- ) {
125+ while (i < count) {
126126 val e = dataSet.getEntryForIndex(i)
127127
128128 x = e.x
129129
130- mBarShadowRectBuffer .left = x - barWidthHalf
131- mBarShadowRectBuffer .right = x + barWidthHalf
130+ barShadowRectBuffer .left = x - barWidthHalf
131+ barShadowRectBuffer .right = x + barWidthHalf
132132
133- trans!! .rectValueToPixel(mBarShadowRectBuffer )
133+ trans!! .rectValueToPixel(barShadowRectBuffer )
134134
135- if (! mViewPortHandler .isInBoundsLeft(mBarShadowRectBuffer .right)) {
135+ if (! viewPortHandler .isInBoundsLeft(barShadowRectBuffer .right)) {
136136 i++
137137 continue
138138 }
139139
140- if (! mViewPortHandler .isInBoundsRight(mBarShadowRectBuffer .left)) {
140+ if (! viewPortHandler .isInBoundsRight(barShadowRectBuffer .left)) {
141141 break
142142 }
143143
144- mBarShadowRectBuffer .top = mViewPortHandler .contentTop()
145- mBarShadowRectBuffer .bottom = mViewPortHandler .contentBottom()
144+ barShadowRectBuffer .top = viewPortHandler .contentTop()
145+ barShadowRectBuffer .bottom = viewPortHandler .contentBottom()
146146
147- if (mDrawRoundedBars ) {
148- c.drawRoundRect(mBarShadowRectBuffer, mRoundedBarRadius, mRoundedBarRadius , shadowPaint)
147+ if (drawRoundedBars ) {
148+ c.drawRoundRect(barShadowRectBuffer, roundedBarRadius, roundedBarRadius , shadowPaint)
149149 } else {
150- c.drawRect(mBarShadowRectBuffer , shadowPaint)
150+ c.drawRect(barShadowRectBuffer , shadowPaint)
151151 }
152152 i++
153153 }
154154 }
155155
156156 // initialize the buffer
157- val buffer = barBuffers!! [index]
158- buffer!! .setPhases(phaseX, phaseY)
159- buffer.setDataSet(index)
160- buffer.setInverted(chart.isInverted(dataSet.axisDependency))
161- buffer.setBarWidth(chart.barData.barWidth)
162-
163- buffer.feed(dataSet)
164-
157+ val buffer = barBuffers!! [index]!! .apply {
158+ setPhases(phaseX, phaseY)
159+ setDataSet(index)
160+ setInverted(chart.isInverted(dataSet.axisDependency))
161+ setBarWidth(chart.barData.barWidth)
162+ feed(dataSet)
163+ }
165164 trans!! .pointValuesToPixel(buffer.buffer)
166165
167166 val isCustomFill = dataSet.fills != null && dataSet.fills.isNotEmpty()
168167 val isSingleColor = dataSet.colors.size == 1
169168 val isInverted = chart.isInverted(dataSet.axisDependency)
170169
171170 if (isSingleColor) {
172- mRenderPaint .color = dataSet.color
171+ renderPaint .color = dataSet.color
173172 }
174173
175174 var j = 0
176175 var pos = 0
177176 while (j < buffer.size()) {
178- if (! mViewPortHandler .isInBoundsLeft(buffer.buffer[j + 2 ])) {
177+ if (! viewPortHandler .isInBoundsLeft(buffer.buffer[j + 2 ])) {
179178 j + = 4
180179 pos++
181180 continue
182181 }
183182
184- if (! mViewPortHandler .isInBoundsRight(buffer.buffer[j])) {
183+ if (! viewPortHandler .isInBoundsRight(buffer.buffer[j])) {
185184 break
186185 }
187186
188187 if (! isSingleColor) {
189188 // Set the color for the currently drawn value. If the index
190189 // is out of bounds, reuse colors.
191- mRenderPaint .color = dataSet.getColor(pos)
190+ renderPaint .color = dataSet.getColor(pos)
192191 }
193192
194193 if (isCustomFill) {
195194 dataSet.getFill(pos)
196195 .fillRect(
197- c, mRenderPaint ,
196+ c, renderPaint ,
198197 buffer.buffer[j],
199198 buffer.buffer[j + 1 ],
200199 buffer.buffer[j + 2 ],
201200 buffer.buffer[j + 3 ],
202201 if (isInverted) Fill .Direction .DOWN else Fill .Direction .UP ,
203- mRoundedBarRadius
202+ roundedBarRadius
204203 )
205204 } else {
206- if (mDrawRoundedBars ) {
205+ if (drawRoundedBars ) {
207206 c.drawRoundRect(
208207 RectF (
209208 buffer.buffer[j], buffer.buffer[j + 1 ], buffer.buffer[j + 2 ],
210209 buffer.buffer[j + 3 ]
211- ), mRoundedBarRadius, mRoundedBarRadius, mRenderPaint
210+ ), roundedBarRadius, roundedBarRadius, renderPaint
212211 )
213212 } else {
214213 c.drawRect(
215214 buffer.buffer[j], buffer.buffer[j + 1 ], buffer.buffer[j + 2 ],
216- buffer.buffer[j + 3 ], mRenderPaint
215+ buffer.buffer[j + 3 ], renderPaint
217216 )
218217 }
219218 }
220219
221220 if (drawBorder) {
222- if (mDrawRoundedBars ) {
221+ if (drawRoundedBars ) {
223222 c.drawRoundRect(
224223 RectF (
225224 buffer.buffer[j], buffer.buffer[j + 1 ], buffer.buffer[j + 2 ],
226225 buffer.buffer[j + 3 ]
227- ), mRoundedBarRadius, mRoundedBarRadius , barBorderPaint
226+ ), roundedBarRadius, roundedBarRadius , barBorderPaint
228227 )
229228 } else {
230229 c.drawRect(
@@ -246,7 +245,7 @@ open class BarChartRenderer(
246245
247246 barRect[left, top, right] = bottom
248247
249- trans.rectToPixelPhase(barRect, mAnimator .phaseY)
248+ trans.rectToPixelPhase(barRect, animator .phaseY)
250249 }
251250
252251 override fun drawValues (c : Canvas ) {
@@ -288,7 +287,7 @@ open class BarChartRenderer(
288287 // get the buffer
289288 val buffer = barBuffers!! [i]
290289
291- val phaseY = mAnimator .phaseY
290+ val phaseY = animator .phaseY
292291
293292 val iconsOffset = MPPointF .getInstance(dataSet.iconsOffset)
294293 iconsOffset.x = Utils .convertDpToPixel(iconsOffset.x)
@@ -297,15 +296,15 @@ open class BarChartRenderer(
297296 // if only single values are drawn (sum)
298297 if (! dataSet.isStacked) {
299298 var j = 0
300- while (j < buffer!! .buffer.size * mAnimator .phaseX) {
299+ while (j < buffer!! .buffer.size * animator .phaseX) {
301300 val x = (buffer.buffer[j] + buffer.buffer[j + 2 ]) / 2f
302301
303- if (! mViewPortHandler .isInBoundsRight(x)) {
302+ if (! viewPortHandler .isInBoundsRight(x)) {
304303 break
305304 }
306305
307- if (! mViewPortHandler .isInBoundsY(buffer.buffer[j + 1 ])
308- || ! mViewPortHandler .isInBoundsLeft(x)
306+ if (! viewPortHandler .isInBoundsY(buffer.buffer[j + 1 ])
307+ || ! viewPortHandler .isInBoundsLeft(x)
309308 ) {
310309 j + = 4
311310 continue
@@ -350,7 +349,7 @@ open class BarChartRenderer(
350349 var bufferIndex = 0
351350 var index = 0
352351
353- while (index < dataSet.entryCount * mAnimator .phaseX) {
352+ while (index < dataSet.entryCount * animator .phaseX) {
354353 val entry = dataSet.getEntryForIndex(index)
355354
356355 val vals = entry.yVals
@@ -362,12 +361,12 @@ open class BarChartRenderer(
362361 // non-stacked
363362 // in between
364363 if (vals == null ) {
365- if (! mViewPortHandler .isInBoundsRight(x)) {
364+ if (! viewPortHandler .isInBoundsRight(x)) {
366365 break
367366 }
368367
369- if (! mViewPortHandler .isInBoundsY(buffer.buffer[bufferIndex + 1 ])
370- || ! mViewPortHandler .isInBoundsLeft(x)
368+ if (! viewPortHandler .isInBoundsY(buffer.buffer[bufferIndex + 1 ])
369+ || ! viewPortHandler .isInBoundsLeft(x)
371370 ) {
372371 continue
373372 }
@@ -443,12 +442,12 @@ open class BarChartRenderer(
443442 val y = (transformed[k + 1 ]
444443 + (if (drawBelow) negOffset else posOffset))
445444
446- if (! mViewPortHandler .isInBoundsRight(x)) {
445+ if (! viewPortHandler .isInBoundsRight(x)) {
447446 break
448447 }
449448
450- if (! mViewPortHandler .isInBoundsY(y)
451- || ! mViewPortHandler .isInBoundsLeft(x)
449+ if (! viewPortHandler .isInBoundsY(y)
450+ || ! viewPortHandler .isInBoundsLeft(x)
452451 ) {
453452 k + = 2
454453 continue
@@ -511,8 +510,8 @@ open class BarChartRenderer(
511510
512511 val trans = chart.getTransformer(set.axisDependency)
513512
514- mHighlightPaint .color = set.highLightColor
515- mHighlightPaint .alpha = set.highLightAlpha
513+ highlightPaint .color = set.highLightColor
514+ highlightPaint .alpha = set.highLightAlpha
516515
517516 val isStack = if (high.stackIndex >= 0 && e.isStacked) true else false
518517
@@ -538,10 +537,10 @@ open class BarChartRenderer(
538537
539538 setHighlightDrawPos(high, barRect)
540539
541- if (mDrawRoundedBars ) {
542- c.drawRoundRect(RectF (barRect), mRoundedBarRadius, mRoundedBarRadius, mHighlightPaint )
540+ if (drawRoundedBars ) {
541+ c.drawRoundRect(RectF (barRect), roundedBarRadius, roundedBarRadius, highlightPaint )
543542 } else {
544- c.drawRect(barRect, mHighlightPaint )
543+ c.drawRect(barRect, highlightPaint )
545544 }
546545 }
547546 }
0 commit comments