Merge lp:~makyo/juju-gui/adding-subordinates into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 255
Proposed branch: lp:~makyo/juju-gui/adding-subordinates
Merge into: lp:juju-gui/experimental
Diff against target: 72 lines (+50/-1)
2 files modified
app/views/environment.js (+3/-1)
test/test_environment_view.js (+47/-0)
To merge this branch: bzr merge lp:~makyo/juju-gui/adding-subordinates
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+135022@code.launchpad.net

Description of the change

Fix initial creation of subordinates.

When creating a subordinate service initially, it was not being laid out properly by the pack layout, nor was it seeming to have drag events attached. Pack layout was expecting a value accessor function to return some number greater than zero when constructing its radius, which informs the x/y coordinates. Returning zero results in NaN for all three values, thus positioning the service at (0,0) and causing drag events to fail when updating the service's coordinates with dx/dy + NaN. This branch fixes this by ensuring that zero is never returned as the node's value. This fix is quick and intended to make the UI function with the current layout algorithm. Future layout algorithms, if they're designed by hand, will need to keep this in mind as well.

https://codereview.appspot.com/6856067/

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

Reviewers: mp+135022_code.launchpad.net,

Message:
Please take a look.

Description:
Fix initial creation of subordinates.

When creating a subordinate service initially, it was not being laid out
properly by the pack layout, nor was it seeming to have drag events
attached. Pack layout was expecting a value accessor function to return
some number greater than zero when constructing its radius, which
informs the x/y coordinates. Returning zero results in NaN for all
three values, thus positioning the service at (0,0) and causing drag
events to fail when updating the service's coordinates with dx/dy + NaN.
  This branch fixes this by ensuring that zero is never returned as the
node's value. This fix is quick and intended to make the UI function
with the current layout algorithm. Future layout algorithms, if they're
designed by hand, will need to keep this in mind as well.

https://code.launchpad.net/~makyo/juju-gui/adding-subordinates/+merge/135022

(do not edit description out of merge proposal)

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

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-11-19 19:52:43 +0000
+++ app/views/environment.js 2012-11-20 00:06:25 +0000
@@ -318,7 +318,9 @@
            this.vis = vis;
            this.tree = d3.layout.pack()
                  .size([width, height])
- .value(function(d) {return d.unit_count;})
+ .value(function(d) {
+ return d.unit_count === 0 ? 1 : d.unit_count;
+ })
                  .padding(300);

            this.updateCanvas();

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

The diff looks fine, but there is behavior we expect on subordinates
that isn't be tested, I think we can at minimum check to see if subs get
x/y position assignment? What do you think?

https://codereview.appspot.com/6856067/

Revision history for this message
Brad Crittenden (bac) wrote :

Looks good Matt. Thanks.

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

https://codereview.appspot.com/6856067/diff/1/app/views/environment.js#newcode323
app/views/environment.js:323: })
maybe this would be more readable:

min(1, d.unit_count)

https://codereview.appspot.com/6856067/

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

A test was added as well, but rather than just testing whether or not
subordinates had been placed properly, it tests that all services have
been placed properly.

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

https://codereview.appspot.com/6856067/diff/1/app/views/environment.js#newcode323
app/views/environment.js:323: })
On 2012/11/20 14:50:48, bac wrote:
> maybe this would be more readable:

> min(1, d.unit_count)

Thanks! Did Math.max(d.unit_count, 1); (since we want 1 or higher)

https://codereview.appspot.com/6856067/

254. By Madison Scott-Clary

Fixing initial creation of subordinate services

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

The new test makes sense to me Matt.

https://codereview.appspot.com/6856067/

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

*** Submitted:

Fix initial creation of subordinates.

When creating a subordinate service initially, it was not being laid out
properly by the pack layout, nor was it seeming to have drag events
attached. Pack layout was expecting a value accessor function to return
some number greater than zero when constructing its radius, which
informs the x/y coordinates. Returning zero results in NaN for all
three values, thus positioning the service at (0,0) and causing drag
events to fail when updating the service's coordinates with dx/dy + NaN.
  This branch fixes this by ensuring that zero is never returned as the
node's value. This fix is quick and intended to make the UI function
with the current layout algorithm. Future layout algorithms, if they're
designed by hand, will need to keep this in mind as well.

R=benjamin.saller, bac
CC=
https://codereview.appspot.com/6856067

https://codereview.appspot.com/6856067/

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-11-19 19:52:43 +0000
3+++ app/views/environment.js 2012-11-20 16:28:23 +0000
4@@ -318,7 +318,9 @@
5 this.vis = vis;
6 this.tree = d3.layout.pack()
7 .size([width, height])
8- .value(function(d) {return d.unit_count;})
9+ .value(function(d) {
10+ return Math.max(d.unit_count, 1);
11+ })
12 .padding(300);
13
14 this.updateCanvas();
15
16=== modified file 'test/test_environment_view.js'
17--- test/test_environment_view.js 2012-11-15 20:48:30 +0000
18+++ test/test_environment_view.js 2012-11-20 16:28:23 +0000
19@@ -166,6 +166,53 @@
20 }
21 );
22
23+ it('must be able to place new services properly', function() {
24+ var view = new views.environment({
25+ container: container,
26+ db: db,
27+ env: env
28+ }),
29+ tmp_data = {
30+ result: [
31+ ['service', 'add', {
32+ 'subordinate': true,
33+ 'charm': 'cs:precise/puppet-2',
34+ 'id': 'puppet2'
35+ }],
36+ ['service', 'add', {
37+ 'charm': 'cs:precise/mysql-6',
38+ 'id': 'mysql2'
39+ }],
40+ ['unit', 'add', {
41+ 'machine': 0,
42+ 'agent-state': 'started',
43+ 'public-address': '192.168.122.222',
44+ 'id': 'mysql2/0'
45+ }]
46+ ],
47+ op: 'delta'
48+ },
49+ properTransform = /translate\(\d+\.?\d*,\d+\.?\d*\)/;
50+ view.render();
51+
52+ container.all('.service').each(function(serviceNode) {
53+ // Ensure that all initial service nodes' transform attributes are
54+ // properly formated (i.e.: no NaN values).
55+ properTransform.test(serviceNode.getAttribute('transform'))
56+ .should.equal(true);
57+ });
58+
59+ db.on_delta({ data: tmp_data });
60+ view.render();
61+
62+ container.all('.service').each(function(serviceNode) {
63+ // Ensure that all new service nodes' transform attributes are properly
64+ // formated as well (i.e.: no NaN values).
65+ properTransform.test(serviceNode.getAttribute('transform'))
66+ .should.equal(true);
67+ });
68+ });
69+
70 it('must be able to render subordinate relation indicators',
71 function() {
72 var view = new views.environment({

Subscribers

People subscribed via source and target branches