Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Side by Side Diff: app/views/environment.js

Issue 6720048: Preserve zoom settings in the environment view.
Patch Set: Preserve zoom settings in the environment view. Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 YUI.add('juju-view-environment', function(Y) { 3 YUI.add('juju-view-environment', function(Y) {
4 4
5 var views = Y.namespace('juju.views'), 5 var views = Y.namespace('juju.views'),
6 Templates = views.Templates, 6 Templates = views.Templates,
7 models = Y.namespace('juju.models'); 7 models = Y.namespace('juju.models');
8 8
9 /* 9 /*
10 * Utility function to get a number from a computed style. 10 * Utility function to get a number from a computed style.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 this.yscale = d3.scale.linear() 230 this.yscale = d3.scale.linear()
231 .domain([-height / 2, height / 2]) 231 .domain([-height / 2, height / 2])
232 .range([height, 0]); 232 .range([height, 0]);
233 233
234 // Create a pan/zoom behavior manager. 234 // Create a pan/zoom behavior manager.
235 var zoom = d3.behavior.zoom() 235 var zoom = d3.behavior.zoom()
236 .x(this.xscale) 236 .x(this.xscale)
237 .y(this.yscale) 237 .y(this.yscale)
238 .scaleExtent([0.25, 2.0]) 238 .scaleExtent([0.25, 2.0])
239 .on('zoom', function() { 239 .on('zoom', function() {
240 var sourceEvent = d3.event.sourceEvent;
241 // Avoid spurious zooming if the event is a double click inside
242 // a service box.
243 if (sourceEvent.type === 'dblclick' &&
benjamin.saller 2012/10/17 14:35:11 .on("dblclick.zoom", null) during the bind will re
frankban 2012/10/17 14:56:54 Done.
244 Y.one(sourceEvent.target).ancestor('.service')) {
245 return;
246 }
240 // Keep the slider up to date with the scale on other sorts 247 // Keep the slider up to date with the scale on other sorts
241 // of zoom interactions 248 // of zoom interactions
242 var s = self.slider; 249 var s = self.slider;
243 s.set('value', Math.floor(d3.event.scale * 100)); 250 s.set('value', Math.floor(d3.event.scale * 100));
244 self.rescale(vis, d3.event); 251 self.rescale(vis, d3.event);
245 }); 252 });
246 self.zoom = zoom; 253 self.zoom = zoom;
247 254
248 // Set up the visualization with a pack layout. 255 // Set up the visualization with a pack layout.
249 var vis = d3.select(container.getDOMNode()) 256 var vis = d3.select(container.getDOMNode())
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Just show the service on double-click. 386 // Just show the service on double-click.
380 var service = self.serviceForBox(d); 387 var service = self.serviceForBox(d);
381 (self.service_click_actions.show_service)(service, self); 388 (self.service_click_actions.show_service)(service, self);
382 }, 389 },
383 390
384 relationClick: function(d, self) { 391 relationClick: function(d, self) {
385 self.removeRelationConfirm(d, this, self); 392 self.removeRelationConfirm(d, this, self);
386 }, 393 },
387 394
388 /* 395 /*
389 * Sync view models with curent db.models. 396 * Sync view models with current db.models.
390 */ 397 */
391 updateData: function() { 398 updateData: function() {
392 //model data 399 //model data
393 var vis = this.vis, 400 var vis = this.vis,
394 app = this.get('app'), 401 app = this.get('app'),
395 db = this.get('db'), 402 db = this.get('db'),
396 relations = db.relations.toArray(), 403 relations = db.relations.toArray(),
397 services = db.services.map(views.toBoundingBox); 404 services = db.services.map(views.toBoundingBox);
398 405
399 this.services = services; 406 this.services = services;
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 /* 872 /*
866 * Utility function to get subordinate relations for a service. 873 * Utility function to get subordinate relations for a service.
867 */ 874 */
868 subordinateRelationsForService: function(service) { 875 subordinateRelationsForService: function(service) {
869 return this.rel_pairs.filter(function(p) { 876 return this.rel_pairs.filter(function(p) {
870 return p.modelIds().indexOf(service.modelId()) !== -1 && 877 return p.modelIds().indexOf(service.modelId()) !== -1 &&
871 p.scope === 'container'; 878 p.scope === 'container';
872 }); 879 });
873 }, 880 },
874 renderSlider: function() { 881 renderSlider: function() {
875 var self = this; 882 var self = this,
883 value = 100,
884 currentScale = this.get('scale');
876 // Build a slider to control zoom level 885 // Build a slider to control zoom level
877 // TODO once we have a stored value in view models, use that 886 if (currentScale) {
878 // for the value property, but for now, zoom to 100% 887 value = currentScale * 100;
888 }
879 var slider = new Y.Slider({ 889 var slider = new Y.Slider({
880 min: 25, 890 min: 25,
881 max: 200, 891 max: 200,
882 value: 100 892 value: value
883 }); 893 });
884 slider.render('#slider-parent'); 894 slider.render('#slider-parent');
885 slider.after('valueChange', function(evt) { 895 slider.after('valueChange', function(evt) {
886 // Don't fire a zoom if there's a zoom event already in progress; 896 // Don't fire a zoom if there's a zoom event already in progress;
887 // that will run rescale for us. 897 // that will run rescale for us.
888 if (d3.event && d3.event.scale && d3.event.translate) { 898 if (d3.event && d3.event.scale && d3.event.translate) {
889 return; 899 return;
890 } 900 }
891 self._fire_zoom((evt.newVal - evt.prevVal) / 100); 901 self._fire_zoom((evt.newVal - evt.prevVal) / 100);
892 }); 902 });
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 // Set the sizes from the viewport. 952 // Set the sizes from the viewport.
943 this.setSizesFromViewport(); 953 this.setSizesFromViewport();
944 954
945 // Ensure relation labels are sized properly. 955 // Ensure relation labels are sized properly.
946 container.all('.rel-label').each(function(label) { 956 container.all('.rel-label').each(function(label) {
947 var width = label.one('text').getClientRect().width + 10; 957 var width = label.one('text').getClientRect().width + 10;
948 label.one('rect').setAttribute('width', width) 958 label.one('rect').setAttribute('width', width)
949 .setAttribute('x', -width / 2); 959 .setAttribute('x', -width / 2);
950 }); 960 });
951 961
962 // Preserve zoom when the scene is updated.
963 var changed = false,
964 currentScale = this.get('scale'),
965 currentTranslate = this.get('translate');
966 if (currentTranslate && currentTranslate !== this.zoom.translate()) {
967 this.zoom.translate(currentTranslate);
968 changed = true;
969 }
970 if (currentScale && currentScale !== this.zoom.scale()) {
971 this.zoom.scale(currentScale);
972 changed = true;
973 }
974 if (changed) {
975 this._fire_zoom(0);
976 }
977
952 // Render the slider after the view is attached. 978 // Render the slider after the view is attached.
953 // Although there is a .syncUI() method on sliders, it does not 979 // Although there is a .syncUI() method on sliders, it does not
954 // seem to play well with the app framework: the slider will render 980 // seem to play well with the app framework: the slider will render
955 // the first time, but on navigation away and back, will not 981 // the first time, but on navigation away and back, will not
956 // re-render within the view. 982 // re-render within the view.
957 this.renderSlider(); 983 this.renderSlider();
958 984
959 // Chainable method. 985 // Chainable method.
960 return this; 986 return this;
961 }, 987 },
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 */ 1152 */
1127 rescale: function(vis, evt) { 1153 rescale: function(vis, evt) {
1128 // Make sure we don't scale outside of our bounds. 1154 // Make sure we don't scale outside of our bounds.
1129 // This check is needed because we're messing with d3's zoom 1155 // This check is needed because we're messing with d3's zoom
1130 // behavior outside of mouse events (e.g.: with the slider), 1156 // behavior outside of mouse events (e.g.: with the slider),
1131 // and can't trust that zoomExtent will play well. 1157 // and can't trust that zoomExtent will play well.
1132 var new_scale = Math.floor(evt.scale * 100); 1158 var new_scale = Math.floor(evt.scale * 100);
1133 if (new_scale < 25 || new_scale > 200) { 1159 if (new_scale < 25 || new_scale > 200) {
1134 evt.scale = this.get('scale'); 1160 evt.scale = this.get('scale');
1135 } 1161 }
1162 // Store the current value of scale so that it can be restored later.
1136 this.set('scale', evt.scale); 1163 this.set('scale', evt.scale);
1164 // Store the current value of translate as well, by copying the event
1165 // array in order to avoid reference sharing.
1166 this.set('translate', evt.translate.slice(0));
1137 vis.attr('transform', 'translate(' + evt.translate + ')' + 1167 vis.attr('transform', 'translate(' + evt.translate + ')' +
1138 ' scale(' + evt.scale + ')'); 1168 ' scale(' + evt.scale + ')');
1139 this.updateServiceMenuLocation(); 1169 this.updateServiceMenuLocation();
1140 }, 1170 },
1141 1171
1142 /* 1172 /*
1143 * Event handler to show the graph-list picker 1173 * Event handler to show the graph-list picker
1144 */ 1174 */
1145 showGraphListPicker: function(evt) { 1175 showGraphListPicker: function(evt) {
1146 var container = this.get('container'), 1176 var container = this.get('container'),
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 'juju-models', 1494 'juju-models',
1465 'd3', 1495 'd3',
1466 'base-build', 1496 'base-build',
1467 'handlebars-base', 1497 'handlebars-base',
1468 'node', 1498 'node',
1469 'svg-layouts', 1499 'svg-layouts',
1470 'event-resize', 1500 'event-resize',
1471 'slider', 1501 'slider',
1472 'view'] 1502 'view']
1473 }); 1503 });
OLDNEW
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b