Merge lp:~seb128/ubuntu-system-settings/battery-draw-x-text-1289460 into lp:ubuntu-system-settings

Proposed by Sebastien Bacher
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
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

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

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

Revision history for this message
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.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:775
http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/936/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1640
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1388
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/128
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/128
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/128/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/128
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1913
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2662
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2662/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9403
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1151
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1555
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1555/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/936/rebuild

review: Approve (continuous-integration)
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

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:777
http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/944/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1709
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1447
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/136
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/136
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/136/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/136
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1974
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2752
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2752/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9482
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1205
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1616
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1616/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/944/rebuild

review: Approve (continuous-integration)
779. By Sebastien Bacher

draw the first mark as well

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:779
http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/945/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1716
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1452
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/137
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/137
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/137/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/137
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1979
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2759
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2759/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9488
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1210
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1621
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1621/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/945/rebuild

review: Approve (continuous-integration)
Revision history for this message
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://people.canonical.com/~laney/weird-things/battery.png

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.

review: Needs Fixing
780. By Sebastien Bacher

revert change that seemed logical but is creating issues

Revision history for this message
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://people.canonical.com/~laney/weird-things/battery.png

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 ...

Revision history for this message
Iain Lane (laney) wrote :

Alright, looks fine for now.

I think the line drawing code is a bit suspicious but that's pre-existing.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:780
http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/953/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1760
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1480
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/145
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/145
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/145/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/145
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/2021
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2820
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2820/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9552
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1236
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1662
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1662/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/953/rebuild

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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");

Subscribers

People subscribed via source and target branches