Scoop API

scoop:scoop.ui.component:0.1.0

src/chart/appearance.scoop

Selected production source · src/chart/appearance.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.graphics.text.*
5import scoop.ui.*
6import scoop.ui.style.*
8internal class ChartAppearance(
9 val theme: Theme,
10 val fonts: FontCollection,
11 val direction: LayoutDirection
12) {
13 val density = theme.tokens.typography.body.fontSize / 14.0
14 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.foreground
19 }
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 foreground
36 else
37 text,
38 paragraph
39 ).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.chart
43 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.five
50 }
51 }