Skip to content

Commit 096b8f0

Browse files
authored
home-automation: Fix graph bar alignment and scaling (#9603)
Make bar positioning and sizing responsive to graph dimensions by using relative values instead of fixed pixels. Bars now align correctly with grid lines and scale proportionally with the graph size.
1 parent d80438c commit 096b8f0

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

demos/home-automation/ui/components/graph.slint

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,18 @@ export component Graph {
6666
}
6767

6868
property <[int]> days: [ 58, 60, 22, 90, 40, 30, 50, 40, 20];
69+
property <length> grid-spacing: tile.width * 0.1;
70+
property <length> bar-width: grid-spacing * 0.4;
6971

70-
HorizontalLayout {
71-
x: 25px;
72-
y: parent.height - self.height - 25px;
73-
alignment: start;
74-
spacing: 10px;
75-
for i in days: Rectangle {
76-
y: parent.height - self.height;
77-
border-top-left-radius: 5px;
78-
border-top-right-radius: 5px;
79-
width: 10px;
80-
height: i * 1px;
81-
background: Palette.graph-alternate-foreground;
82-
opacity: 90%;
83-
}
72+
for index in 8: Rectangle {
73+
x: tile.width * 0.1 + (grid-spacing * index) + (grid-spacing - bar-width) / 2;
74+
y: tile.height * 0.9 - self.height;
75+
border-top-left-radius: self.width / 3;
76+
border-top-right-radius: self.border-top-left-radius;
77+
width: bar-width;
78+
height: (tile.height * 0.6) * days[index] / 100.0;
79+
background: Palette.graph-alternate-foreground;
80+
opacity: 90%;
8481
}
8582
}
8683
}

0 commit comments

Comments
 (0)