Merge lp:~frankban/juju-gui/preserve-zoom into lp:juju-gui/experimental

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 189
Proposed branch: lp:~frankban/juju-gui/preserve-zoom
Merge into: lp:juju-gui/experimental
Diff against target: 78 lines (+30/-5)
1 file modified
app/views/environment.js (+30/-5)
To merge this branch: bzr merge lp:~frankban/juju-gui/preserve-zoom
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+130087@code.launchpad.net

Description of the change

Preserve zoom settings in the environment view.

The zoom scale and translate are preserved after a scene redraw
(e.g. when adding/removing relations, destroying services,
navigating to the service view and back to the front page).

https://codereview.appspot.com/6720048/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (4.0 KiB)

Reviewers: mp+130087_code.launchpad.net,

Message:
Please take a look.

Description:
Preserve zoom settings in the environment view.

The zoom scale and translate are preserved after a scene redraw
(e.g. when adding/removing relations, destroying services,
navigating to the service view and back to the front page).

https://code.launchpad.net/~frankban/juju-gui/preserve-zoom/+merge/130087

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6720048/

Affected files:
   A [revision details]
   M app/views/environment.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision:
<email address hidden>

Index: app/views/environment.js
=== modified file 'app/views/environment.js'
--- app/views/environment.js 2012-10-15 19:22:40 +0000
+++ app/views/environment.js 2012-10-17 10:43:51 +0000
@@ -237,6 +237,13 @@
          .y(this.yscale)
          .scaleExtent([0.25, 2.0])
          .on('zoom', function() {
+ var sourceEvent = d3.event.sourceEvent;
+ // Avoid spurious zooming if the event is a double click
inside
+ // a service box.
+ if (sourceEvent.type === 'dblclick' &&
+ Y.one(sourceEvent.target).ancestor('.service')) {
+ return;
+ }
                  // Keep the slider up to date with the scale on other sorts
                  // of zoom interactions
                  var s = self.slider;
@@ -386,7 +393,7 @@
          },

          /*
- * Sync view models with curent db.models.
+ * Sync view models with current db.models.
           */
          updateData: function() {
            //model data
@@ -872,14 +879,17 @@
            });
          },
          renderSlider: function() {
- var self = this;
+ var self = this,
+ value = 100,
+ currentScale = this.get('scale');
            // Build a slider to control zoom level
- // TODO once we have a stored value in view models, use that
- // for the value property, but for now, zoom to 100%
+ if (currentScale) {
+ value = currentScale * 100;
+ }
            var slider = new Y.Slider({
              min: 25,
              max: 200,
- value: 100
+ value: value
            });
            slider.render('#slider-parent');
            slider.after('valueChange', function(evt) {
@@ -949,6 +959,22 @@
                .setAttribute('x', -width / 2);
            });

+ // Preserve zoom when the scene is updated.
+ var changed = false,
+ currentScale = this.get('scale'),
+ currentTranslate = this.get('translate');
+ if (currentTranslate && currentTranslate !==
this.zoom.translate()) {
+ this.zoom.translate(currentTranslate);
+ changed = true;
+ }
+ if (currentScale && currentScale !== this.z...

Read more...

Revision history for this message
Madison Scott-Clary (makyo) wrote :

Trainee review by Matthew. Looks good to me and works well. Thanks for
the catch on double-clicking a service causing a zoom! One minor about
a comment below, and as always, wait for the blessed review.

https://codereview.appspot.com/6720048/diff/1/app/views/environment.js
File app/views/environment.js (right):

https://codereview.appspot.com/6720048/diff/1/app/views/environment.js#newcode1163
app/views/environment.js:1163: // Store the current value of translate
by copying the event array
Minor: I know the above line was there before, but maybe it deserves a
comment as well, possibly just merged with this comment.

https://codereview.appspot.com/6720048/

lp:~frankban/juju-gui/preserve-zoom updated
191. By Francesco Banconi

Added comment where we store the value of scale.

Revision history for this message
Francesco Banconi (frankban) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

Thanks for the review Matthew.

https://codereview.appspot.com/6720048/diff/1/app/views/environment.js
File app/views/environment.js (right):

https://codereview.appspot.com/6720048/diff/1/app/views/environment.js#newcode1163
app/views/environment.js:1163: // Store the current value of translate
by copying the event array
On 2012/10/17 14:11:34, matthew.scott wrote:
> Minor: I know the above line was there before, but maybe it deserves a
comment
> as well, possibly just merged with this comment.

Done.

https://codereview.appspot.com/6720048/

Revision history for this message
Benjamin Saller (bcsaller) wrote :

LGTM with the minor noted.

Thanks

https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js
File app/views/environment.js (right):

https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js#newcode243
app/views/environment.js:243: if (sourceEvent.type === 'dblclick' &&
.on("dblclick.zoom", null) during the bind will remove the dblclick
behavior.

https://codereview.appspot.com/6720048/

lp:~frankban/juju-gui/preserve-zoom updated
192. By Francesco Banconi

Disable zoom everywhere on dblclick.

193. By Francesco Banconi

Lint.

Revision history for this message
Francesco Banconi (frankban) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

Thanks Ben.

https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js
File app/views/environment.js (right):

https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js#newcode243
app/views/environment.js:243: if (sourceEvent.type === 'dblclick' &&
On 2012/10/17 14:35:11, benjamin.saller wrote:
> .on("dblclick.zoom", null) during the bind will remove the dblclick
behavior.

Done.

https://codereview.appspot.com/6720048/

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Preserve zoom settings in the environment view.

The zoom scale and translate are preserved after a scene redraw
(e.g. when adding/removing relations, destroying services,
navigating to the service view and back to the front page).

R=matthew.scott, benjamin.saller
CC=
https://codereview.appspot.com/6720048

https://codereview.appspot.com/6720048/

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

The dbl click causing zoom, is actually a nice effect that would be nice to
preserve as a transition .. Transient though without perm zoom changes.
Part of the feel of going into a svc details is meant to be zoom into focus
on this service.

On Wednesday, October 17, 2012, Francesco Banconi wrote:

> Thanks Ben.
>
>
> https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js
> File app/views/environment.js (right):
>
>
> https://codereview.appspot.com/6720048/diff/4001/app/views/environment.js#newcode243
> app/views/environment.js:243: if (sourceEvent.type === 'dblclick' &&
> On 2012/10/17 14:35:11, benjamin.saller wrote:
> > .on("dblclick.zoom", null) during the bind will remove the dblclick
> behavior.
>
> Done.
>
> https://codereview.appspot.com/6720048/
>
> --
> https://code.launchpad.net/~frankban/juju-gui/preserve-zoom/+merge/130087
> Your team Juju GUI Hackers is requested to review the proposed merge of
> lp:~frankban/juju-gui/preserve-zoom into lp:juju-gui.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/views/environment.js'
2--- app/views/environment.js 2012-10-15 19:22:40 +0000
3+++ app/views/environment.js 2012-10-17 14:57:22 +0000
4@@ -254,6 +254,8 @@
5 .attr('height', height)
6 .append('svg:g')
7 .call(zoom)
8+ // Disable zoom on double click.
9+ .on('dblclick.zoom', null)
10 .append('g');
11
12 vis.append('svg:rect')
13@@ -386,7 +388,7 @@
14 },
15
16 /*
17- * Sync view models with curent db.models.
18+ * Sync view models with current db.models.
19 */
20 updateData: function() {
21 //model data
22@@ -872,14 +874,17 @@
23 });
24 },
25 renderSlider: function() {
26- var self = this;
27+ var self = this,
28+ value = 100,
29+ currentScale = this.get('scale');
30 // Build a slider to control zoom level
31- // TODO once we have a stored value in view models, use that
32- // for the value property, but for now, zoom to 100%
33+ if (currentScale) {
34+ value = currentScale * 100;
35+ }
36 var slider = new Y.Slider({
37 min: 25,
38 max: 200,
39- value: 100
40+ value: value
41 });
42 slider.render('#slider-parent');
43 slider.after('valueChange', function(evt) {
44@@ -949,6 +954,22 @@
45 .setAttribute('x', -width / 2);
46 });
47
48+ // Preserve zoom when the scene is updated.
49+ var changed = false,
50+ currentScale = this.get('scale'),
51+ currentTranslate = this.get('translate');
52+ if (currentTranslate && currentTranslate !== this.zoom.translate()) {
53+ this.zoom.translate(currentTranslate);
54+ changed = true;
55+ }
56+ if (currentScale && currentScale !== this.zoom.scale()) {
57+ this.zoom.scale(currentScale);
58+ changed = true;
59+ }
60+ if (changed) {
61+ this._fire_zoom(0);
62+ }
63+
64 // Render the slider after the view is attached.
65 // Although there is a .syncUI() method on sliders, it does not
66 // seem to play well with the app framework: the slider will render
67@@ -1133,7 +1154,11 @@
68 if (new_scale < 25 || new_scale > 200) {
69 evt.scale = this.get('scale');
70 }
71+ // Store the current value of scale so that it can be restored later.
72 this.set('scale', evt.scale);
73+ // Store the current value of translate as well, by copying the event
74+ // array in order to avoid reference sharing.
75+ this.set('translate', evt.translate.slice(0));
76 vis.attr('transform', 'translate(' + evt.translate + ')' +
77 ' scale(' + evt.scale + ')');
78 this.updateServiceMenuLocation();

Subscribers

People subscribed via source and target branches