score:0
I have created one fiddle for you. fiddle
Please check the function refreshGraph
var refreshGraph =function(){
window.resetGraph = !window.resetGraph;
console.log(window.resetGraph);
if(window.resetGraph){
window.scale = window.zoom.scale();
window.translate = window.zoom.translate();
window.zoom.scale(1).translate([0,0]);
}else{
window.zoom.scale(window.scale)
.translate(window.translate);
}
console.log(window.zoom.scale());
console.log(translate);
draw();
}
I have used window.zoom (used window to let you know that this is shared)
Button reset toggles the zoom level to 0 scale and toggles back to where it was if clicked again.
Hope it helps.
score:1
I just solved it by keeping track of the current scale and translation values:
zoom.on("zoom", function() {
svgGroup.attr("transform", "translate(" + (<any>d3.event).translate + ")" + "scale(" + (<any>d3.event).scale + ")");
// keep track of the currentZoomScale and currentPosition at all times
currentZoomScale = (<any>d3.event).scale;
currentPosition = (<any>d3.event).translate;
});
Then when re-rendering the graph in my scaleGraph function above I just checked to see if the graph was re-rendered because of the subGraph being toggled, if it has then I use the current scale and translation values:
if (ctrl.autoResizeGraph !== "original" && togglingSubGraph) {
zoomScale = currentZoomScale; // render the graph at its current scale
translate = currentPosition; // render the graph at its current position
}
Source: stackoverflow.com
Related Query
- How to keep current zoom scale and translate level when re-rendering graph
- How to change speed of translate and scale when zooming in and out in D3 (using zoom.on & d3.event.translate, d3.event.zoom)?
- D3 - How to get correct scale and translate origin after manual zoom and pan to country path
- How to zoom and translate to center of force directed graph in D3
- how to know the current Zoom level in D3.js
- how do i add a zoom in and zoom out button in a graph on d3
- d3 update old scale when pan and zoom
- How do you translate HTML elements along with SVG elements when zooming and panning with D3
- When a d3.behavior.zoom event is triggered programatically, how do you set inital values for translate and scale?
- How to keep the circle, stroke and font size when zooming in d3.js V4 layout?
- D3 v6: How to zoom stacked bar by selected segment to stretch only selected segment and shrink rest segments (and keep initial chart width)?
- What Transformation values to calculate for scale and translate if you want to zoom
- D3.js: How to keep marker and text on same position when zooming in and out
- How to scale and translate together?
- D3 How to keep element same size while transform scale / translate
- d3 time scale setting initial zoom level and domain
- How do I change the colour of my d3.js Bar Graph bars individually and make a Scale for them?
- How to remove unwanted lines in Axis scale of a graph when using D3.js?
- How to move D3 graph to initial zoom and at 0,0 position - RESET Graph?
- How to keep mouse over object when using drag and snap to with d3.js
- How do I prevent graph elements from reaching the axis of my graph in D3 and scale properly?
- d3 change scale domain and keep the zoom working as expected
- How do you query your dataset when you zoom into and out of a d3 map?
- how to implement zoom in d3 graph of force directed layout and position the nodes
- how to zoom svg semantic graph when the mouse is under svg instead of node
- D3 transform scale and translate
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- How to show full text when zoom in & truncate it when zoom out
- how to set the domain and scale on an axis on a nvd3.js multiBarChart
- How do I specify the initial zoom level in D3?
More Query from same tag
- Transitioning innerRadius of svg.arc - D3.js
- Property getBBox does not exist on type SVGElement
- Replace object in array with two objects
- Why doesn't the same group render a correct line chart and corresponding range chart?
- in D3.js is there any way bind the scroll event in both the x and y directions to panning the svg?
- unable to show text over the node in d3 force layout
- d3.js axis labels not displaying in responsive bar chart
- Add labels to D3 line
- D3.js: display limited number of ticks
- D3 force layout - linking nodes by name instead of index
- D3JS: Multi-Nested JSON data
- Calculating an average from a javascript array
- Fix tooltips on horizontal bar chart d3.js
- Draw polygon inside of the SVG defined viewport
- Style fill for d3.js topojson map not completely filling
- How do I modify csv data after upload in vue?
- My D3js treemap chart is ou of my div when i zoom on it
- D3 Transform Rescale X jumps to right
- Rect in in d3js svg disappears after routing to another page in AngularJS
- topoJSON on D3: map doesn't show (but it works on www.mapshaper.org)
- D3 NGX Line Chart appearing to have a height when it shouldn't
- d3.js - graph is broken after adding new nodes
- Draw rect according to json array?
- D3 Choropleth Map: Colors are not appearing
- Colour of points repeat after 10 data sets on D3.js scatter plot
- D3.JS: Multi-series line chart, show tooltip for all lines at date?
- Adding mouseover popups to d3 tree leaves
- jquery and d3: why does my page reload when I use $("svg").remove()?
- Enter/exit not properly cleaning up popped nodes/links in force layout
- D3js single horizontal bar with three colors