You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the code below, I almost had nice tooltips per bar, something like this:
That is, till I realized the x and y aren't the actual values, just scaled values etc. Can we pass tooltips the x,y values or pair of the point being drawn?
@ExperimentalFeature
class TextToolTip(
val textSize: Float = 16f,
@ColorRes val textColor: Int? = null,
val typeface: Int = Typeface.NORMAL,
val pixelsAboveBar: Float = 8f,
val labelsFormatter: ((Float) -> String)?) : Tooltip {
private lateinit var tooltipView: TextView
override fun onCreateTooltip(parentView: ViewGroup) {
tooltipView = TextView(parentView.context)
tooltipView.layoutParams = ViewGroup.LayoutParams(wrapContent, wrapContent)
tooltipView.visibility = View.INVISIBLE
tooltipView.textSize = textSize
textColor?.let { tooltipView.textColor = ContextCompat.getColor(parentView.context, it) }
tooltipView.setTypeface(tooltipView.typeface, typeface)
parentView.addView(tooltipView)
}
override fun onDataPointTouch(x: Float, y: Float) {
tooltipView.visibility = View.VISIBLE
tooltipView.x = x - tooltipView.width / 2
tooltipView.y = y - tooltipView.context.dips(pixelsAboveBar)
tooltipView.text = labelsFormatter?.let { it(y) } ?: y.toString()
}
override fun onDataPointClick(x: Float, y: Float) {}
}
fun Context.dips(dipValue: Float) =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, resources.displayMetrics)
The text was updated successfully, but these errors were encountered:
That is, till I realized the x and y aren't the actual values, just scaled values etc.
x and y are the chart view coordinates of a given point.
Can we pass tooltips the x,y values or pair of the point being drawn?
Passing the index of the pair might be enough to fulfill this use-case. With that I was able to reach something close to what you need I believe. I will consider it for the next release.
Using the code below, I almost had nice tooltips per bar, something like this:
That is, till I realized the x and y aren't the actual values, just scaled values etc. Can we pass tooltips the x,y values or pair of the point being drawn?
The text was updated successfully, but these errors were encountered: