SelectionHighlightData

constructor(highlightTextOffset: Dp = 15.dp, highlightTextSize: TextUnit = 12.sp, highlightTextColor: Color = Color.Black, highlightTextBackgroundColor: Color = Color.Yellow, highlightTextBackgroundAlpha: Float = 0.7f, highlightTextTypeface: Typeface = Typeface.DEFAULT, highlightBarCornerRadius: Dp = 2.dp, highlightBarColor: Color = Color.Black, highlightBarStrokeWidth: Dp = 2.dp, highlightPopUpCornerRadius: CornerRadius = CornerRadius(5f), backgroundColorFilter: ColorFilter? = null, backgroundBlendMode: BlendMode = DrawScope.DefaultBlendMode, backgroundStyle: DrawStyle = Fill, highlightLabelAlignment: Paint.Align = Paint.Align.CENTER, isHighlightBarRequired: Boolean = true, isHighlightFullBar: Boolean = false, popUpLabel: (Float, Float) -> String = { x, y -> val xLabel = "x : ${x.toInt()} " val yLabel = "y : ${String.format("%.2f", y)}" "$xLabel $yLabel" }, drawPopUp: DrawScope.(Offset, BarData, Float, Float, BarChartType) -> Unit = { selectedOffset, identifiedPoint, centerPointOfBar, selectedXAxisWidth, barChartType -> val highlightTextPaint = TextPaint().apply { textSize = highlightTextSize.toPx() color = highlightTextColor.toArgb() textAlign = highlightLabelAlignment typeface = highlightTextTypeface } val label = popUpLabel(identifiedPoint.point.x, identifiedPoint.point.y) drawContext.canvas.nativeCanvas.apply { val x = if (barChartType == BarChartType.VERTICAL) centerPointOfBar else selectedXAxisWidth + highlightTextOffset.toPx() val y = if (barChartType == BarChartType.VERTICAL) selectedOffset.y else centerPointOfBar val background = getTextBackgroundRect( x, y, label, highlightTextPaint ) drawRoundRect( color = highlightTextBackgroundColor, topLeft = Offset( background.left.toFloat(), if (barChartType == BarChartType.VERTICAL) background.top.toFloat() - highlightTextOffset.toPx() else (y - background.height() / 2) ), size = Size(background.width().toFloat(), background.height().toFloat()), alpha = highlightTextBackgroundAlpha, cornerRadius = highlightPopUpCornerRadius, colorFilter = backgroundColorFilter, blendMode = backgroundBlendMode, style = backgroundStyle ) val drawTextX = if (barChartType == BarChartType.VERTICAL) centerPointOfBar else selectedXAxisWidth + highlightTextOffset.toPx() val drawTextY = if (barChartType == BarChartType.VERTICAL) selectedOffset.y - highlightTextOffset.toPx() else (y + background.height() / 2) - (highlightTextPaint.fontMetrics.descent) drawText( label, drawTextX, drawTextY, highlightTextPaint ) } }, drawHighlightBar: DrawScope.(Float, Float, Float, Float, BarChartType) -> Unit = { x, y, width, height, barChartType -> val rectWidth = if (barChartType == BarChartType.VERTICAL) width else height val rectHeight = if (barChartType == BarChartType.VERTICAL) height else width drawRoundRect( color = highlightBarColor, topLeft = Offset(x, y), size = Size(rectWidth, rectHeight), cornerRadius = CornerRadius( highlightBarCornerRadius.toPx(), highlightBarCornerRadius.toPx() ), style = Stroke(width = highlightBarStrokeWidth.toPx()) ) }, groupBarPopUpLabel: (String, Float) -> String = { name, value -> val xLabel = "Name : $name " val yLabel = "Value : ${String.format("%.2f", value)}" "$xLabel $yLabel" }, drawGroupBarPopUp: DrawScope.(Offset, BarData, Float) -> Unit = { selectedOffset, identifiedPoint, centerPointOfBar -> val highlightTextPaint = TextPaint().apply { textSize = highlightTextSize.toPx() color = highlightTextColor.toArgb() textAlign = highlightLabelAlignment typeface = highlightTextTypeface } val xLabel = "${identifiedPoint.point.x.toInt()}" val label = groupBarPopUpLabel(xLabel, identifiedPoint.point.y) drawContext.canvas.nativeCanvas.apply { val background = getTextBackgroundRect( centerPointOfBar, selectedOffset.y, label, highlightTextPaint ) drawRoundRect( color = highlightTextBackgroundColor, topLeft = Offset( background.left.toFloat(), background.top.toFloat() - highlightTextOffset.toPx() ), size = Size(background.width().toFloat(), background.height().toFloat()), alpha = highlightTextBackgroundAlpha, cornerRadius = highlightPopUpCornerRadius, colorFilter = backgroundColorFilter, blendMode = backgroundBlendMode, style = backgroundStyle ) drawText( label, centerPointOfBar, selectedOffset.y - highlightTextOffset.toPx(), highlightTextPaint ) } }, barChartType: BarChartType = BarChartType.VERTICAL)

Parameters

highlightTextOffset

: Padding between the highlighted bar and the text

highlightTextSize

: Text size of the highlighted bar text

highlightTextColor

: Text color of the highlighted bar text

highlightTextBackgroundColor

: Background color of the highlight background

highlightTextBackgroundAlpha

: Alpha for the highlighted text background

highlightTextTypeface

: Typeface of the highlighted bar text

highlightBarCornerRadius

: Corner radius of the highlighted bar

highlightBarColor

: Color of the highlighted bar

highlightBarStrokeWidth

: Stroke width of the highlighted bar

highlightPopUpCornerRadius

: Corner radius of the highlighted background

backgroundColorFilter

: ColorFilter to apply to the color when drawn into the destination.

backgroundBlendMode

:Blending algorithm to be applied to the path when it is drawn.

backgroundStyle

: Whether or not the path is stroked or filled in.

isHighlightBarRequired

: Boolean flag to enable disable highlight

popUpLabel

: The text that can be shown on the popup given 2 input params x and y values

drawPopUp

: Override this to change the default background implementation. You are provided with the selected offset, x, y values, center point of bar.

drawHighlightBar

: draw override this to change the default drawRoundRect implementation. You are provided with the actual point x, y, height, width.

groupBarPopUpLabel

: Popup label for selected bar in group bar chart.

drawGroupBarPopUp

: draw override this to change the default popup implementation. You are provided with the actual point x, y, height, width.