Selection Highlight Pop Up
constructor(backgroundColor: Color = Color.White, backgroundAlpha: Float = 0.7f, backgroundCornerRadius: CornerRadius = CornerRadius(5f), backgroundColorFilter: ColorFilter? = null, backgroundBlendMode: BlendMode = DrawScope.DefaultBlendMode, backgroundStyle: DrawStyle = Fill, paddingBetweenPopUpAndPoint: Dp = 20.dp, labelSize: TextUnit = 14.sp, labelColor: Color = Color.Black, labelAlignment: Paint.Align = Paint.Align.CENTER, labelTypeface: Typeface = Typeface.DEFAULT, popUpLabel: (Float, Float) -> String = { x, y ->
val xLabel = "x : ${x.toInt()} "
val yLabel = "y : ${String.format("%.2f", y)}"
"$xLabel $yLabel"
}, 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
)
}
})
Parameters
background Color
: Defines the background color of the popup.
background Alpha
: Defines the alpha of the background color.
background Corner Radius
: Defines the corner radius of the background.
background Color Filter
: ColorFilter to apply to the color when drawn into the destination.
background Blend Mode
:Blending algorithm to be applied to the path when it is drawn.
background Style
: Whether or not the path is stroked or filled in.
label Size
: The size of the popUp label in TextUnit.
label Color
: The color of the label text.
label Alignment
: The alignment of the label text.
label Typeface
: The style of the label text.
padding Between Pop Up And Point
: The padding between the anchor position/ popup start position and the selected point on the line.
pop Up Label
: The text that can be shown on the popup given 2 input params x and y values