Skip to content

Commit 3845a28

Browse files
committed
Cosmetic
1 parent 1f40036 commit 3845a28

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ open class LegendRenderer(
327327
if (direction == LegendDirection.RIGHT_TO_LEFT)
328328
posX -= calculatedLabelSizes[i]?.width ?: 0f
329329

330-
if (entry.label != null)
331-
drawLabel(canvas, posX, posY + labelLineHeight, entry.label!!)
330+
drawLabel(canvas, posX, posY + labelLineHeight, entry.label)
332331

333332
if (direction == LegendDirection.LEFT_TO_RIGHT)
334333
posX += calculatedLabelSizes[i]?.width ?: 0f
@@ -369,9 +368,9 @@ open class LegendRenderer(
369368

370369
var i = 0
371370
while (i < entries.size) {
372-
val e = entries[i]
373-
val drawingForm = e.form != LegendForm.NONE
374-
val formSize = if (java.lang.Float.isNaN(e.formSize)) defaultFormSize else e.formSize.convertDpToPixel()
371+
val entry = entries[i]
372+
val drawingForm = entry.form != LegendForm.NONE
373+
val formSize = if (java.lang.Float.isNaN(entry.formSize)) defaultFormSize else entry.formSize.convertDpToPixel()
375374

376375
var posX = originPosX
377376

@@ -381,27 +380,26 @@ open class LegendRenderer(
381380
else
382381
posX -= formSize - stack
383382

384-
drawForm(canvas, posX, posY + formYOffset, e, legend)
383+
drawForm(canvas, posX, posY + formYOffset, entry, legend)
385384

386385
if (direction == LegendDirection.LEFT_TO_RIGHT) posX += formSize
387386
}
388387

389-
if (e.label != null) {
388+
if (entry.label != null) {
390389
if (drawingForm && !wasStacked) posX += if (direction == LegendDirection.LEFT_TO_RIGHT)
391390
formToTextSpace
392391
else
393392
-formToTextSpace
394393
else if (wasStacked) posX = originPosX
395394

396-
if (direction == LegendDirection.RIGHT_TO_LEFT) posX -= Utils.calcTextWidth(labelPaint, e.label).toFloat()
395+
if (direction == LegendDirection.RIGHT_TO_LEFT) posX -= Utils.calcTextWidth(labelPaint, entry.label).toFloat()
397396

398-
if (e.label != null)
399-
if (!wasStacked) {
400-
drawLabel(canvas, posX, posY + labelLineHeight, e.label!!)
401-
} else {
402-
posY += labelLineHeight + labelLineSpacing
403-
drawLabel(canvas, posX, posY + labelLineHeight, e.label!!)
404-
}
397+
if (!wasStacked) {
398+
drawLabel(canvas, posX, posY + labelLineHeight, entry.label)
399+
} else {
400+
posY += labelLineHeight + labelLineSpacing
401+
drawLabel(canvas, posX, posY + labelLineHeight, entry.label)
402+
}
405403

406404
// make a step down
407405
posY += labelLineHeight + labelLineSpacing
@@ -503,11 +501,11 @@ open class LegendRenderer(
503501
* Draws the provided label at the given position.
504502
*
505503
* @param canvas canvas to draw with
506-
* @param x
507-
* @param y
508504
* @param label the label to draw
509505
*/
510-
protected fun drawLabel(canvas: Canvas, x: Float, y: Float, label: String) {
511-
canvas.drawText(label, x, y, labelPaint)
506+
protected fun drawLabel(canvas: Canvas, x: Float, y: Float, label: String?) {
507+
label?.let {
508+
canvas.drawText(it, x, y, labelPaint)
509+
}
512510
}
513511
}

0 commit comments

Comments
 (0)