Committed by
Gerrit Code Review
GUI -- Cleaning up pan/zoom functions.
Change-Id: I5f1a69d018bac7c9be9f225bbbd197e0c97102b4
Showing
1 changed file
with
21 additions
and
44 deletions
... | @@ -150,7 +150,7 @@ | ... | @@ -150,7 +150,7 @@ |
150 | L: [cycleLabels, 'Cycle device labels'], | 150 | L: [cycleLabels, 'Cycle device labels'], |
151 | P: togglePorts, | 151 | P: togglePorts, |
152 | U: [unpin, 'Unpin node (hover mouse over)'], | 152 | U: [unpin, 'Unpin node (hover mouse over)'], |
153 | - R: [resetZoomPan, 'Reset zoom / pan'], | 153 | + R: [resetPanZoom, 'Reset pan / zoom'], |
154 | V: [showTrafficAction, 'Show related traffic'], | 154 | V: [showTrafficAction, 'Show related traffic'], |
155 | A: [showAllTrafficAction, 'Show all traffic'], | 155 | A: [showAllTrafficAction, 'Show all traffic'], |
156 | F: [showDeviceLinkFlowsAction, 'Show device link flows'], | 156 | F: [showDeviceLinkFlowsAction, 'Show device link flows'], |
... | @@ -218,7 +218,7 @@ | ... | @@ -218,7 +218,7 @@ |
218 | 218 | ||
219 | // D3 selections | 219 | // D3 selections |
220 | var svg, | 220 | var svg, |
221 | - zoomPanContainer, | 221 | + panZoomContainer, |
222 | bgImg, | 222 | bgImg, |
223 | topoG, | 223 | topoG, |
224 | nodeG, | 224 | nodeG, |
... | @@ -2298,7 +2298,8 @@ | ... | @@ -2298,7 +2298,8 @@ |
2298 | meta = srcEv.metaKey, | 2298 | meta = srcEv.metaKey, |
2299 | shift = srcEv.shiftKey; | 2299 | shift = srcEv.shiftKey; |
2300 | 2300 | ||
2301 | - if ((panZoom() && !meta) || (!panZoom() && meta)) { | 2301 | + // if the meta key is pressed, we are panning/zooming, so ignore |
2302 | + if (meta) { | ||
2302 | return; | 2303 | return; |
2303 | } | 2304 | } |
2304 | 2305 | ||
... | @@ -2516,21 +2517,25 @@ | ... | @@ -2516,21 +2517,25 @@ |
2516 | } | 2517 | } |
2517 | 2518 | ||
2518 | 2519 | ||
2519 | - function zoomPan(scale, translate) { | 2520 | + // === Pan and Zoom behaviors... |
2520 | - zoomPanContainer.attr("transform", "translate(" + translate + ")scale(" + scale + ")"); | 2521 | + |
2522 | + function panZoom(translate, scale) { | ||
2523 | + panZoomContainer.attr('transform', | ||
2524 | + 'translate(' + translate + ')scale(' + scale + ')'); | ||
2521 | // keep the map lines constant width while zooming | 2525 | // keep the map lines constant width while zooming |
2522 | - bgImg.style("stroke-width", 2.0 / scale + "px"); | 2526 | + bgImg.style('stroke-width', 2.0 / scale + 'px'); |
2523 | } | 2527 | } |
2524 | 2528 | ||
2525 | - function resetZoomPan() { | 2529 | + function resetPanZoom() { |
2526 | - zoomPan(1, [0,0]); | 2530 | + panZoom([0,0], 1); |
2527 | - zoom.scale(1).translate([0,0]); | 2531 | + zoom.translate([0,0]).scale(1); |
2528 | } | 2532 | } |
2529 | 2533 | ||
2530 | - function setupZoomPan() { | 2534 | + function setupPanZoom() { |
2531 | function zoomed() { | 2535 | function zoomed() { |
2532 | - if (!panZoom() ^ !d3.event.sourceEvent.metaKey) { | 2536 | + // pan zoom active when meta key is pressed... |
2533 | - zoomPan(d3.event.scale, d3.event.translate); | 2537 | + if (d3.event.sourceEvent.metaKey) { |
2538 | + panZoom(d3.event.translate, d3.event.scale); | ||
2534 | } | 2539 | } |
2535 | } | 2540 | } |
2536 | 2541 | ||
... | @@ -2578,34 +2583,6 @@ | ... | @@ -2578,34 +2583,6 @@ |
2578 | 2583 | ||
2579 | } | 2584 | } |
2580 | 2585 | ||
2581 | - // ============================== | ||
2582 | - // Toggle Buttons in masthead | ||
2583 | - | ||
2584 | - // TODO: toggle button (and other widgets in the masthead) should be provided | ||
2585 | - // by the framework; not generated by the view. | ||
2586 | - | ||
2587 | - //var showInstances; | ||
2588 | - | ||
2589 | -/* | ||
2590 | - function addButtonBar(view) { | ||
2591 | - var bb = d3.select('#mast') | ||
2592 | - .append('span').classed('right', true).attr('id', 'bb'); | ||
2593 | - | ||
2594 | - function mkTogBtn(text, cb) { | ||
2595 | - return bb.append('span') | ||
2596 | - .classed('btn', true) | ||
2597 | - .text(text) | ||
2598 | - .on('click', cb); | ||
2599 | - } | ||
2600 | - | ||
2601 | - //showInstances = mkTogBtn('Show Instances', toggleInst); | ||
2602 | - } | ||
2603 | -*/ | ||
2604 | - | ||
2605 | - function panZoom() { | ||
2606 | - return false; | ||
2607 | - } | ||
2608 | - | ||
2609 | function loadGlyphs(svg) { | 2586 | function loadGlyphs(svg) { |
2610 | var defs = svg.append('defs'); | 2587 | var defs = svg.append('defs'); |
2611 | gly.defBird(defs); | 2588 | gly.defBird(defs); |
... | @@ -2653,11 +2630,11 @@ | ... | @@ -2653,11 +2630,11 @@ |
2653 | loadGlyphs(svg); | 2630 | loadGlyphs(svg); |
2654 | d3u.appendGlow(svg); | 2631 | d3u.appendGlow(svg); |
2655 | 2632 | ||
2656 | - zoomPanContainer = svg.append('g').attr('id', 'zoomPanContainer'); | 2633 | + panZoomContainer = svg.append('g').attr('id', 'panZoomContainer'); |
2657 | - setupZoomPan(); | 2634 | + setupPanZoom(); |
2658 | 2635 | ||
2659 | // group for the topology | 2636 | // group for the topology |
2660 | - topoG = zoomPanContainer.append('g') | 2637 | + topoG = panZoomContainer.append('g') |
2661 | .attr('id', 'topo-G') | 2638 | .attr('id', 'topo-G') |
2662 | .attr('transform', fcfg.translate()); | 2639 | .attr('transform', fcfg.translate()); |
2663 | 2640 | ||
... | @@ -2867,7 +2844,7 @@ | ... | @@ -2867,7 +2844,7 @@ |
2867 | .scale(s) | 2844 | .scale(s) |
2868 | .translate(t); | 2845 | .translate(t); |
2869 | 2846 | ||
2870 | - bgImg = zoomPanContainer.insert("g", '#topo-G'); | 2847 | + bgImg = panZoomContainer.insert("g", '#topo-G'); |
2871 | bgImg.attr('id', 'map').selectAll('path') | 2848 | bgImg.attr('id', 'map').selectAll('path') |
2872 | .data(topoData.features) | 2849 | .data(topoData.features) |
2873 | .enter() | 2850 | .enter() | ... | ... |
-
Please register or login to post a comment