scoop:scoop.ui.component:0.1.0
src/chart/appearance.scoop
Selected production source · src/chart/appearance.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.ui.*6
import scoop.ui.style.*8
internal class ChartAppearance(9
val theme: Theme,10
val fonts: FontCollection,11
val direction: LayoutDirection12
) {13
val density = theme.tokens.typography.body.fontSize / 14.014
val text =15
theme.tokens.typography.body.copy {16
fontSize = theme.tokens.typography.body.fontSize * 12.0 / 14.0;17
weight = 400;18
color = theme.tokens.palette.muted.foreground19
}20
val foreground = text.copy { color = theme.tokens.palette.background.foreground }21
val paragraph =22
paragraphStyle {23
maxLines = Some(1L);24
ellipsis = "…"25
}26
fun measure(value: String): Size =27
Paragraph(fonts, value, text, paragraph).use {28
p -> p.layoutUnwrapped().use { layout -> layout.size }29
}30
fun draw(canvas: Canvas, value: String, origin: Point, strong: Boolean = false) {31
Paragraph(32
fonts,33
value,34
if (strong)35
foreground36
else37
text,38
paragraph39
).use { p -> p.layoutUnwrapped().use { layout -> canvas.drawText(layout, origin) } }40
}41
fun color(snapshot: ChartSnapshot, index: Long): Color {42
val palette = theme.tokens.palette.chart43
return snapshot.data.series[index].color ?:44
when (snapshot.colors[index]) {45
case 0 -> palette.one;46
case 1 -> palette.two;47
case 2 -> palette.three;48
case 3 -> palette.four;49
else -> palette.five50
}51
}52
}