Merge lp:~seb128/ubuntu-system-settings/battery-draw-x-text-1289460 into lp:ubuntu-system-settings
- battery-draw-x-text-1289460
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Iain Lane | ||||
Approved revision: | 780 | ||||
Merged at revision: | 787 | ||||
Proposed branch: | lp:~seb128/ubuntu-system-settings/battery-draw-x-text-1289460 | ||||
Merge into: | lp:ubuntu-system-settings | ||||
Diff against target: |
130 lines (+59/-15) 1 file modified
plugins/battery/PageComponent.qml (+59/-15) |
||||
To merge this branch: | bzr merge lp:~seb128/ubuntu-system-settings/battery-draw-x-text-1289460 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Needs Fixing | |
Iain Lane | Approve | ||
Review via email: mp+225856@code.launchpad.net |
Commit message
battery, draw the x axis labels
Description of the change
battery, draw the x axis labels
Sebastien Bacher (seb128) wrote : | # |
Iain Lane (laney) wrote : | # |
Thanks.
I think you could have avoided doing so many manipulations involving the margins if you had used a combination of translating and scaling to avoid them. But it's done now so don't bother changing.
- On N4, I made the "Today" label go off the end by setting the time to 01:53 (ish).
- Please wrap long lines.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:775
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 776. By Sebastien Bacher
-
correctly calculate the space for the text
- 777. By Sebastien Bacher
-
Wrap some long lines
- 778. By Sebastien Bacher
-
don't check for 0 value, we start at 1
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:777
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 779. By Sebastien Bacher
-
draw the first mark as well
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:779
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Iain Lane (laney) wrote : | # |
I ran it (possibly with more data this time than last). There's a problem with the x coordinate for the previous day's data.
http://
And do you know if it's possible to smooth the text? If you size that image to 100% you can see that the text is jagged and not very nice looking.
- 780. By Sebastien Bacher
-
revert change that seemed logical but is creating issues
Sebastien Bacher (seb128) wrote : | # |
> I ran it (possibly with more data this time than last). There's a problem with the x coordinate for the previous day's data.
> http://
Ok, I reverted the change that created that. The formular there looks weird but it works, we can fix in another change
> And do you know if it's possible to smooth the text? If you size that image to 100% you can see that the text is jagged and not very nice looking.
I didn't find any while looking in the canvas api, not sure what to do there ...
Iain Lane (laney) wrote : | # |
Alright, looks fine for now.
I think the line drawing code is a bit suspicious but that's pre-existing.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:780
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'plugins/battery/PageComponent.qml' |
2 | --- plugins/battery/PageComponent.qml 2014-01-27 18:12:16 +0000 |
3 | +++ plugins/battery/PageComponent.qml 2014-07-09 15:03:35 +0000 |
4 | @@ -127,43 +127,84 @@ |
5 | id: canvas |
6 | width:parent.width - units.gu(4) |
7 | anchors.horizontalCenter: parent.horizontalCenter |
8 | - height: units.gu(15) |
9 | + height: units.gu(23) |
10 | |
11 | antialiasing: true |
12 | |
13 | - function drawAxes(ctx, axisWidth, axisHeight) { |
14 | + function drawAxes(ctx, axisWidth, axisHeight, bottomMargin, rightMargin) { |
15 | + |
16 | + var currentHour = Qt.formatDateTime(new Date(), "h") |
17 | + var currentMinutes = Qt.formatDateTime(new Date(), "m") |
18 | + var displayHour |
19 | + var labelWidth |
20 | + var zeroMark |
21 | + |
22 | ctx.save() |
23 | ctx.beginPath() |
24 | ctx.strokeStyle = UbuntuColors.lightAubergine |
25 | |
26 | ctx.lineWidth = units.dp(2) |
27 | |
28 | + var fontHeight = FontUtils.sizeToPixels("small") |
29 | + ctx.font="%1px Ubuntu".arg(fontHeight) |
30 | + |
31 | ctx.translate(0, 1) |
32 | |
33 | // 11 ticks with 0, 5, 10 being big |
34 | for (var i = 0; i <= 10; i++) { |
35 | var x = (i % 5 == 0) ? 0 : Math.floor(axisWidth / 2) |
36 | - var y = (i / 10) * (height - axisHeight - ctx.lineWidth) |
37 | + var y = (i / 10) * (height - axisHeight - bottomMargin - ctx.lineWidth) |
38 | ctx.moveTo(x, y) |
39 | ctx.lineTo(axisWidth, y) |
40 | } |
41 | |
42 | ctx.translate(axisWidth + ctx.lineWidth / 2, |
43 | - height - axisHeight - ctx.lineWidth / 2) |
44 | + height - axisHeight - bottomMargin - ctx.lineWidth / 2) |
45 | |
46 | ctx.moveTo(0, 0) |
47 | ctx.lineTo(0, -ctx.lineWidth) |
48 | |
49 | - // 25 ticks with 0, 6, 12, 18, 24 being big |
50 | + // 24 ticks with 6, 12, 18, 24 being big |
51 | for (i = 0; i <= 24; i++) { |
52 | - x = (i / 24) * (width - axisWidth - ctx.lineWidth) |
53 | + /* the marks need to be shifted on the hours */ |
54 | + x = ((i - currentMinutes / 60) / 24) * (width - axisWidth - ctx.lineWidth - rightMargin) |
55 | + if (x < 0) |
56 | + continue |
57 | y = (i % 6 == 0) ? axisHeight : axisHeight - |
58 | Math.floor(axisHeight / 2) |
59 | ctx.moveTo(x, 0) |
60 | ctx.lineTo(x, y) |
61 | + |
62 | + /* Determine the hour to display */ |
63 | + displayHour = (currentHour - (24-i)) |
64 | + if (displayHour < 0) |
65 | + displayHour = displayHour + 24 |
66 | + /* Store the x for the day change line */ |
67 | + if (displayHour === 0) |
68 | + zeroMark = x |
69 | + |
70 | + /* Write the x-axis legend */ |
71 | + if (i % 6 == 0) { |
72 | + labelWidth = context.measureText("%1".arg(displayHour)).width; |
73 | + ctx.fillText("%1".arg(displayHour), |
74 | + x - labelWidth/2, |
75 | + axisHeight + units.dp(1) + fontHeight) |
76 | + } |
77 | } |
78 | |
79 | - ctx.translate(0, 0) |
80 | + labelWidth = context.measureText(i18n.tr("Yesterday")).width; |
81 | + if(labelWidth < zeroMark) |
82 | + ctx.fillText(i18n.tr("Yesterday"), |
83 | + (zeroMark - labelWidth)/2, |
84 | + axisHeight + units.dp(6) + 2*fontHeight) |
85 | + |
86 | + ctx.fillText("|", zeroMark, axisHeight + units.dp(6) + 2*fontHeight) |
87 | + |
88 | + labelWidth = context.measureText(i18n.tr("Today")).width; |
89 | + if(labelWidth < (width - zeroMark - rightMargin - axisWidth - ctx.lineWidth)) |
90 | + ctx.fillText(i18n.tr("Today"), |
91 | + zeroMark + (width - zeroMark - labelWidth)/2, |
92 | + axisHeight + units.dp(6) + 2*fontHeight) |
93 | |
94 | ctx.stroke() |
95 | ctx.restore() |
96 | @@ -174,12 +215,14 @@ |
97 | ctx.save(); |
98 | ctx.clearRect(0, 0, canvas.width, canvas.height) |
99 | |
100 | - var axisWidth = 10 |
101 | - var axisHeight = 10 |
102 | - |
103 | - var graphHeight = height - axisHeight |
104 | - |
105 | - drawAxes(ctx, axisWidth, axisHeight) |
106 | + var axisWidth = units.gu(1) |
107 | + var axisHeight = units.gu(1) |
108 | + |
109 | + /* Space to write the legend */ |
110 | + var bottomMargin = units.gu(6) |
111 | + var rightMargin = units.gu(1) |
112 | + |
113 | + drawAxes(ctx, axisWidth, axisHeight, bottomMargin, rightMargin) |
114 | |
115 | /* Display the charge history */ |
116 | ctx.beginPath(); |
117 | @@ -191,10 +234,11 @@ |
118 | // Invert the y axis so we draw from the bottom left |
119 | ctx.scale(1, -1) |
120 | // Move the origin to just above the axes |
121 | - ctx.translate(axisWidth, axisHeight) |
122 | + ctx.translate(axisWidth, axisHeight + bottomMargin) |
123 | // Scale to avoid the axes so we can draw as if they aren't |
124 | // there |
125 | - ctx.scale(1 - (axisWidth / width), 1 - axisHeight / height) |
126 | + ctx.scale(1 - ((axisWidth + rightMargin) / width), |
127 | + 1 - (axisHeight + bottomMargin) / height) |
128 | |
129 | var gradient = ctx.createLinearGradient(0, 0, 0, height); |
130 | gradient.addColorStop(1, "green"); |
The code might look a bit complex, but turns out it's not trivial to write on a canvas. The results to be decent on desktop and phone configs, from my testing