1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: MIT |
3 | |
4 | import { Theme } from "../theme.slint" ; |
5 | |
6 | export component AxisLabel inherits Text { |
7 | font-size: Theme.typo.label.size; |
8 | font-weight: Theme.typo.label.weight; |
9 | color: Theme.palette.white; |
10 | horizontal-alignment: center; |
11 | } |
12 | |
13 | export struct AxisValue { |
14 | value: int, |
15 | unit: string |
16 | } |
17 | |
18 | export component ChartAxis { |
19 | in property <[string]> x-model; |
20 | in property <[int]> y-model; |
21 | in property <int> y-min; |
22 | in property <int> y-max; |
23 | in property <string> y-unit; |
24 | |
25 | private property <length> y-zero: root.height * (1 - (0 - y-min) / (y-max - y-min)); |
26 | |
27 | VerticalLayout { |
28 | horizontal-stretch: 1; |
29 | alignment: end; |
30 | |
31 | HorizontalLayout { |
32 | spacing: 1px; |
33 | |
34 | for text in x-model : Rectangle { |
35 | if(text != "" ) : AxisLabel { |
36 | text: text; |
37 | y: parent.height - self.height - 3px; |
38 | } |
39 | } |
40 | } |
41 | } |
42 | |
43 | HorizontalLayout { |
44 | alignment: end; |
45 | |
46 | Rectangle { |
47 | background: green; |
48 | |
49 | for value in y-model : AxisLabel { |
50 | y: (value >= 0 ? parent.height * (1 - (value - y-min) / (y-max - y-min)) : |
51 | y-zero + parent.height * (-1 * value / (y-max - y-min))) - self.height / 2; |
52 | text: "\{value}\{y-unit}" ; |
53 | } |
54 | } |
55 | } |
56 | } |