Merge lp:~makyo/juju-gui/bundle-zoomtofit into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 1152
Proposed branch: lp:~makyo/juju-gui/bundle-zoomtofit
Merge into: lp:juju-gui/experimental
Diff against target: 115 lines (+22/-17)
5 files modified
app/subapps/browser/views/bundle.js (+1/-1)
app/views/topology/bundle.js (+11/-10)
app/views/topology/topology.js (+5/-0)
app/views/topology/utils.js (+3/-4)
test/test_bundle_module.js (+2/-2)
To merge this branch: bzr merge lp:~makyo/juju-gui/bundle-zoomtofit
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+192363@code.launchpad.net

Description of the change

Bundle topo preview fixes

Center bundle topo properly and size SVG to parent container. This incidentally fixes what appeared to be a bug of non-promulgated charms not being displayed (was off the canvas).

https://codereview.appspot.com/14930052/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :
Download full text (4.5 KiB)

Reviewers: mp+192363_code.launchpad.net,

Message:
Please take a look.

Description:
Bundle topo preview fixes

Center bundle topo properly and size SVG to parent container. This
incidentally fixes what appeared to be a bug of non-promulgated charms
not being displayed (was off the canvas).

https://code.launchpad.net/~makyo/juju-gui/bundle-zoomtofit/+merge/192363

(do not edit description out of merge proposal)

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

Affected files (+15, -17 lines):
   A [revision details]
   M app/subapps/browser/views/bundle.js
   M app/views/topology/bundle.js
   M app/views/topology/utils.js
   M test/test_bundle_module.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: test/test_bundle_module.js
=== modified file 'test/test_bundle_module.js'
--- test/test_bundle_module.js 2013-10-10 00:05:02 +0000
+++ test/test_bundle_module.js 2013-10-22 10:52:27 +0000
@@ -113,11 +113,11 @@
            // that we've scaled the canvas as expected. In the model.
            assert.equal(
                parseFloat(bundle.topology.get('scale'), 10).toFixed(2),
- 0.48);
+ 0.44);
            // and on the canvas.
            var scaleAttr = svg.select('g').attr('transform');
            var match = /scale\(([\d\.]+)\)/.exec(scaleAttr);
- assert.equal(parseFloat(match[1]).toFixed(2), 0.48);
+ assert.equal(parseFloat(match[1]).toFixed(2), 0.44);
            done();
          }).then(undefined, done);
    });

Index: app/views/topology/bundle.js
=== modified file 'app/views/topology/bundle.js'
--- app/views/topology/bundle.js 2013-10-18 16:47:34 +0000
+++ app/views/topology/bundle.js 2013-10-22 10:20:48 +0000
@@ -381,6 +381,9 @@
      var topo = this.topology;
      var vertices = topoUtils.serviceBoxesToVertices(topo.service_boxes);
      var centroid = topoUtils.centroid(vertices);
+ var scale = topo.get('scale');
+ centroid[0] += 96 * scale;
+ centroid[1] += 96 * scale;
      this.topology.modules.PanZoomModule.panToPoint({point: centroid});
    };

@@ -394,21 +397,15 @@
    BundleTopology.prototype.zoomToFit = function() {
      var topo = this.topology;
      var vertices = topoUtils.serviceBoxesToVertices(topo.service_boxes);
- var bb = topoUtils.getBoundingBox(vertices);
+ var bb = topoUtils.getBoundingBox(vertices, 96, 96);
      var width = topo.get('width'),
          height = topo.get('height');

      // Zoom to Fit
- // We are really only interested in scale down
- // here when the bundle is too large to
- // render in the space provided.
- var maxScale = 1.0;
- if (bb.w > width || bb.h > height) {
- maxScale = Math.min(bb.w / width, bb.h / height);
- maxScale -= 0.05; // Margin
- }
+ var maxScale = Math.min(width / bb.w, height / bb.h);
+ maxScale -= 0.05; // Margin
      // Clamp Scale
- maxScale = Math.max(0.25 , Math.min(1...

Read more...

Revision history for this message
Gary Poster (gary) wrote :

LGTM with trivials. Would be nice to have a test of the getBoundingBox
changes. Doing QA now. Thank you!

https://codereview.appspot.com/14930052/diff/1/app/subapps/browser/views/bundle.js
File app/subapps/browser/views/bundle.js (right):

https://codereview.appspot.com/14930052/diff/1/app/subapps/browser/views/bundle.js#newcode175
app/subapps/browser/views/bundle.js:175: var options = {size: [720,
360]};
As we discussed, please check with Luca to see if he thinks we can
increase the height a bit.

https://codereview.appspot.com/14930052/diff/1/app/views/topology/bundle.js
File app/views/topology/bundle.js (right):

https://codereview.appspot.com/14930052/diff/1/app/views/topology/bundle.js#newcode386
app/views/topology/bundle.js:386: centroid[1] += 96 * scale;
It would be lovely to deduce 96. Failing that, I think we ought to at
least document what it is supposed to be (perhaps by using a well-named
"constant" variable).

https://codereview.appspot.com/14930052/diff/1/app/views/topology/utils.js
File app/views/topology/utils.js (right):

https://codereview.appspot.com/14930052/diff/1/app/views/topology/utils.js#newcode174
app/views/topology/utils.js:174: translateX: minX - boxWidth,
translateY: minY - boxHeight,
You said we don't use this, but we also agreed that boxHeight and
boxWidth should each be divided by 2. Delete or fix. :-)

https://codereview.appspot.com/14930052/

Revision history for this message
Gary Poster (gary) wrote :

On 2013/10/23 17:10:13, gary.poster wrote:
> LGTM with trivials. Would be nice to have a test of the
getBoundingBox changes.
> Doing QA now. Thank you!

https://codereview.appspot.com/14930052/diff/1/app/subapps/browser/views/bundle.js
> File app/subapps/browser/views/bundle.js (right):

https://codereview.appspot.com/14930052/diff/1/app/subapps/browser/views/bundle.js#newcode175
> app/subapps/browser/views/bundle.js:175: var options = {size: [720,
360]};
> As we discussed, please check with Luca to see if he thinks we can
increase the
> height a bit.

https://codereview.appspot.com/14930052/diff/1/app/views/topology/bundle.js
> File app/views/topology/bundle.js (right):

https://codereview.appspot.com/14930052/diff/1/app/views/topology/bundle.js#newcode386
> app/views/topology/bundle.js:386: centroid[1] += 96 * scale;
> It would be lovely to deduce 96. Failing that, I think we ought to at
least
> document what it is supposed to be (perhaps by using a well-named
"constant"
> variable).

https://codereview.appspot.com/14930052/diff/1/app/views/topology/utils.js
> File app/views/topology/utils.js (right):

https://codereview.appspot.com/14930052/diff/1/app/views/topology/utils.js#newcode174
> app/views/topology/utils.js:174: translateX: minX - boxWidth,
translateY: minY -
> boxHeight,
> You said we don't use this, but we also agreed that boxHeight and
boxWidth
> should each be divided by 2. Delete or fix. :-)

QA good. Thank you! This is a huge improvement, and we could launch
with it if needed, I think. I look forward to proper centering in the
future, if we can.

Gary

https://codereview.appspot.com/14930052/

lp:~makyo/juju-gui/bundle-zoomtofit updated
1150. By Madison Scott-Clary

Better fitting at the cost of better centering; next iteration.

1151. By Madison Scott-Clary

Test change for new math

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

On 2013/10/23 21:31:09, matthew.scott wrote:
> Please take a look.

Looks even better, thank you.

If you could get this landed before tomorrow morning's demo that would
be nice, but if not, no worries. :-)

https://codereview.appspot.com/14930052/

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

*** Submitted:

Bundle topo preview fixes

Center bundle topo properly and size SVG to parent container. This
incidentally fixes what appeared to be a bug of non-promulgated charms
not being displayed (was off the canvas).

R=gary.poster
CC=
https://codereview.appspot.com/14930052

https://codereview.appspot.com/14930052/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/subapps/browser/views/bundle.js'
2--- app/subapps/browser/views/bundle.js 2013-10-17 16:55:19 +0000
3+++ app/subapps/browser/views/bundle.js 2013-10-23 21:28:47 +0000
4@@ -172,7 +172,7 @@
5 var content = this.template(attrs);
6 var node = this.get('container').setHTML(content);
7 var renderTo = this.get('renderTo');
8- var options = {size: [480, 360]};
9+ var options = {size: [720, 500]};
10 this.hideIndicator(renderTo);
11
12 var showTopo = true;
13
14=== modified file 'app/views/topology/bundle.js'
15--- app/views/topology/bundle.js 2013-10-23 16:03:22 +0000
16+++ app/views/topology/bundle.js 2013-10-23 21:28:47 +0000
17@@ -378,6 +378,12 @@
18 var topo = this.topology;
19 var vertices = topoUtils.serviceBoxesToVertices(topo.service_boxes);
20 var centroid = topoUtils.centroid(vertices);
21+ var scale = topo.get('scale'),
22+ width = topo.get('width'),
23+ height = topo.get('height');
24+ var bb = topo.get('bundleBoundingBox');
25+ centroid[0] += Math.abs(width - bb.w) * scale;
26+ centroid[1] += Math.abs(height - bb.h) * scale;
27 this.topology.modules.PanZoomModule.panToPoint({point: centroid});
28 };
29
30@@ -391,21 +397,16 @@
31 BundleTopology.prototype.zoomToFit = function() {
32 var topo = this.topology;
33 var vertices = topoUtils.serviceBoxesToVertices(topo.service_boxes);
34- var bb = topoUtils.getBoundingBox(vertices);
35+ var bb = topoUtils.getBoundingBox(vertices, 96, 96);
36+ topo.set('bundleBoundingBox', bb);
37 var width = topo.get('width'),
38 height = topo.get('height');
39
40 // Zoom to Fit
41- // We are really only interested in scale down
42- // here when the bundle is too large to
43- // render in the space provided.
44- var maxScale = 1.0;
45- if (bb.w > width || bb.h > height) {
46- maxScale = Math.min(bb.w / width, bb.h / height);
47- maxScale -= 0.05; // Margin
48- }
49+ var maxScale = Math.min(width / bb.w, height / bb.h);
50+ maxScale -= 0.1; // Margin
51 // Clamp Scale
52- maxScale = Math.max(0.25 , Math.min(1.0, maxScale));
53+ maxScale = Math.min(1.0, maxScale);
54 this.centerViewport(maxScale);
55 };
56
57
58=== modified file 'app/views/topology/topology.js'
59--- app/views/topology/topology.js 2013-10-18 16:47:34 +0000
60+++ app/views/topology/topology.js 2013-10-23 21:28:47 +0000
61@@ -235,6 +235,11 @@
62 }, {
63 ATTRS: {
64 /**
65+ * @property {Object} boundingBox
66+ * A bounding-box for all of the services
67+ */
68+ boundingBox: {},
69+ /**
70 * @property {models.Database} db
71 */
72 db: {},
73
74=== modified file 'app/views/topology/utils.js'
75--- app/views/topology/utils.js 2013-10-03 04:47:21 +0000
76+++ app/views/topology/utils.js 2013-10-23 21:28:47 +0000
77@@ -160,7 +160,7 @@
78 return centroid;
79 };
80
81- utils.getBoundingBox = function(vertices) {
82+ utils.getBoundingBox = function(vertices, boxWidth, boxHeight) {
83 var minX = Infinity, maxX = -Infinity,
84 minY = Infinity, maxY = -Infinity;
85
86@@ -171,9 +171,8 @@
87 if (v[1] > maxY) { maxY = v[1]; }
88 });
89 return {
90- translateX: minX, translateY: minY,
91- w: maxX - minX, h: maxY - minY};
92-
93+ translateX: minX - boxWidth / 2, translateY: minY - boxHeight / 2,
94+ w: maxX - minX + boxWidth, h: maxY - minY + boxHeight};
95 };
96
97 }, '0.1.0', {
98
99=== modified file 'test/test_bundle_module.js'
100--- test/test_bundle_module.js 2013-10-23 16:03:22 +0000
101+++ test/test_bundle_module.js 2013-10-23 21:28:47 +0000
102@@ -111,11 +111,11 @@
103 // that we've scaled the canvas as expected. In the model.
104 assert.equal(
105 parseFloat(bundle.topology.get('scale'), 10).toFixed(2),
106- 0.48);
107+ 0.39);
108 // and on the canvas.
109 var scaleAttr = svg.select('g').attr('transform');
110 var match = /scale\(([\d\.]+)\)/.exec(scaleAttr);
111- assert.equal(parseFloat(match[1]).toFixed(2), 0.48);
112+ assert.equal(parseFloat(match[1]).toFixed(2), 0.39);
113 done();
114 }).then(undefined, done);
115 });

Subscribers

People subscribed via source and target branches