Skip to content

Commit

Permalink
Add colorCode property to DefaultMarkerLabelFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalik committed Sep 13, 2023
1 parent a913f5d commit 4ea8a8e
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import com.patrykandpatrick.vico.core.extension.sumOf
import com.patrykandpatrick.vico.core.extension.transformToSpannable

/**
* The default label formatter used for markers.
* The default label formatter used for markers. [colorCode] specifies whether to color-code the _y_ values in the
* labels.
*
* @see MarkerLabelFormatter
*/
public class DefaultMarkerLabelFormatter : MarkerLabelFormatter {
public class DefaultMarkerLabelFormatter(private val colorCode: Boolean = true) : MarkerLabelFormatter {

override fun getLabel(
markedEntries: List<Marker.EntryModel>,
Expand All @@ -38,11 +39,15 @@ public class DefaultMarkerLabelFormatter : MarkerLabelFormatter {
postfix = if (markedEntries.size > 1) ")" else "",
separator = "; ",
) { model ->
appendCompat(
PATTERN.format(model.entry.y),
ForegroundColorSpan(model.color),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
)
if (colorCode) {
appendCompat(
PATTERN.format(model.entry.y),
ForegroundColorSpan(model.color),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
)
} else {
append(PATTERN.format(model.entry.y))
}
}

private companion object {
Expand Down

0 comments on commit 4ea8a8e

Please sign in to comment.