data class SelectionHighlightPopUp(val backgroundColor: Color = Color.White, val backgroundAlpha: Float = 0.7f, val backgroundCornerRadius: CornerRadius = CornerRadius(5f), val backgroundColorFilter: ColorFilter? = null, val backgroundBlendMode: BlendMode = DrawScope.DefaultBlendMode, val backgroundStyle: DrawStyle = Fill, val paddingBetweenPopUpAndPoint: Dp = 20.dp, val labelSize: TextUnit = 14.sp, val labelColor: Color = Color.Black, val labelAlignment: Paint.Align = Paint.Align.CENTER, val labelTypeface: Typeface = Typeface.DEFAULT, val popUpLabel: (Float, Float) -> String = { x, y ->
val xLabel = "x : ${x.toInt()} "
val yLabel = "y : ${String.format("%.2f", y)}"
"$xLabel $yLabel"
}, val draw: DrawScope.(Offset, Point) -> Unit = { selectedOffset, identifiedPoint ->
val highlightTextPaint = TextPaint().apply {
textSize = labelSize.toPx()
color = labelColor.toArgb()
textAlign = labelAlignment
typeface = labelTypeface
}
val label = popUpLabel(identifiedPoint.x, identifiedPoint.y)
drawContext.canvas.nativeCanvas.apply {
val background = getTextBackgroundRect(
selectedOffset.x,
selectedOffset.y,
label,
highlightTextPaint
)
drawRoundRect(
color = backgroundColor,
topLeft = Offset(
background.left.toFloat(),
background.top.toFloat() - paddingBetweenPopUpAndPoint.toPx()
),
size = Size(background.width().toFloat(), background.height().toFloat()),
alpha = backgroundAlpha,
cornerRadius = backgroundCornerRadius,
colorFilter = backgroundColorFilter,
blendMode = backgroundBlendMode,
style = backgroundStyle
)
drawText(
label,
selectedOffset.x,
selectedOffset.y - paddingBetweenPopUpAndPoint.toPx(),
highlightTextPaint
)
}
}) SelectionHighlightPopUp is a data class used to draw the pop on the given selected point on a line to identify the dimensions of the selected point.All the styling related params are included here
Parameters
: Defines the background color of the popup.
: Defines the alpha of the background color.
: Defines the corner radius of the background.
: ColorFilter to apply to the color when drawn into the destination.
:Blending algorithm to be applied to the path when it is drawn.
: Whether or not the path is stroked or filled in.
: The size of the popUp label in TextUnit.
: The color of the label text.
: The alignment of the label text.
: The style of the label text.
paddingBetweenPopUpAndPoint
: The padding between the anchor position/ popup start position and the selected point on the line.
: The text that can be shown on the popup given 2 input params x and y values
: Draw the popUp marker on the selected point with 2 inputs Offset i.e selectedPoint and Point i.e the input data w.r.t selected point