diff --git a/install/ui/src/freeipa/topology_graph.js b/install/ui/src/freeipa/topology_graph.js index 23c7f6221..3ca00f6f6 100644 --- a/install/ui/src/freeipa/topology_graph.js +++ b/install/ui/src/freeipa/topology_graph.js @@ -74,20 +74,44 @@ topology_graph.TopoGraph = declare([Evented], { * @param {Array} suffixes array of suffixes */ update: function(nodes, links, suffixes) { + var curr_trasform = this._get_stored_transformation(); + + var zoomed = function() { + var translate = d3.event.translate; + var scale = d3.event.scale; + var transform = "translate(" + translate + ")scale(" + scale + ")"; + + this._svg.selectAll('g.shapes') + .attr("transform", transform); + this._store_current_transformation(); + }.bind(this); + + // adds zoom behavior to the svg + var zoom = d3.behavior.zoom() + .translate(curr_trasform.translate) + .scale(curr_trasform.scale) + .scaleExtent([0.2, 1]) + .on("zoom", zoomed); + // delete all from svg this._svg.selectAll("*").remove(); this._svg.attr('width', this.width) - .attr('height', this.height); + .attr('height', this.height) + .call(zoom); this.links = links; this.nodes = nodes; this.suffixes = suffixes; // load saved coordinates + // node.fixed uses integer + // this is useful when you need to store the original value and set + // the node temporarily fixed for (var i=0,l=nodes.length; i> 1; + self._layout.resume(); + } + // add new nodes var g = this._circle.enter() .append('svg:g') .on("dblclick", function(d) { - d.fixed = !d.fixed; + // Stops propagation dblclick event to the zoom behavior. + d3.event.preventDefault(); + d3.event.stopPropagation(); + //xor operation switch value of fixed from 1 to 0 and vice versa + d.fixed = d.fixed ^ 1; }) - .call(self._layout.drag); + .call(drag); g.append('svg:circle') .attr('class', 'node') @@ -369,6 +461,15 @@ topology_graph.TopoGraph = declare([Evented], { // remove old nodes self._circle.exit().remove(); + + // get previously set position and scale of the graph and move current + // graph to the proper position + var curr_transform = this._get_stored_transformation(); + var transform = "translate(" + curr_transform.translate + + ")scale(" + curr_transform.scale + ")"; + + this._svg.selectAll('g.shapes') + .attr("transform", transform); }, constructor: function(spec) {