Prefer ChartyColor over raw Color in public APIs
Charty's colors are expressed with com.himanshoe.charty.color.ChartyColor — a sealed type with
Solid(color) and Gradient(colors). Every color a caller can set for a drawn chart element goes
through it, so any element can be a solid or a gradient, and the API stays consistent.
Rule
A public val/parameter that colors a chart element must be ChartyColor, not Color. This
covers fills, strokes, series/segment/arc/band/needle/point/zone colors — anything painted.
// Do
val fillColor: ChartyColor = ChartyColor.Solid(Color(0xFF1E88E5))
val zones: List<GaugeZone> // where GaugeZone.color: ChartyColor
// Don't
val fillColor: Color = Color(0xFF1E88E5)
Resolve to a Brush at draw time (private helper, at the drawing site):
private fun ChartyColor.toBrush(): Brush =
when (this) {
is ChartyColor.Solid -> SolidColor(color)
is ChartyColor.Gradient -> Brush.verticalGradient(colors)
}
A default ARGB literal lives in a private const val ...ARGB = 0xFF…… (avoids detekt MagicNumber),
wrapped as ChartyColor.Solid(Color(THE_ARGB)).
Not covered (raw Color is fine here)
TextStyle— it already carries its ownColor; keep usingTextStyle.- Internal / private drawing functions — may take a resolved
ColororBrushparameter; the rule is about the public surface callers configure. - Pre-existing raw-
Colorproperties (ChartScaffoldConfig.axisColor/gridColor,ReferenceLineConfig.color/borderColor,PersistentMarker.guideLineColor, crosshair line colors): legacy. Don't sweep them just to change types, but when you add a new color property next to them, make the new oneChartyColor.
Applying it
- New config/data/composable color property → type it
ChartyColor, default aSolid(...). - Add a private
toBrush()(or reuse an existing one in that drawer) and paint withbrush = .... - Commit gate: a staged diff that adds a public
Color-typed color property (outside the exemptions above) is not ready — switch it toChartyColor.commit-with-statschecks for it.
Quick self-check on a staged diff:
git diff --cached -U0 -- '*/config/*.kt' '*/data/*.kt' | grep -E '^\+' | grep -E 'val [A-Za-z]*[Cc]olor[A-Za-z]*: Color'
Every hit should be justified by an exemption above; otherwise make it ChartyColor.