score:5
Accepted answer
So you wish to change
xAxisScale = new_xScale;
yAxisScale = new_yScale;
inside the zoom function for some reason.
If you do it the rescale will not work as expected.
var new_xScale = d3.event.transform.rescaleX(xAxisScale)
var new_yScale = d3.event.transform.rescaleY(yAxisScale)
Reason: xAxisScale andyAxisScale should be the original, because the rescale is calculated based/relative to the original scale value.
One way to get around this would be to make a copy of the original x and y scale.
// create scale objects
var xAxisScale =d3.scaleLinear()
.domain([-200,-100])
.range([0,width]);
var yAxisScale = d3.scaleLinear()
.domain([-10,-20])
.range([height,0]);
//make a copy of the scales
var copyX = xAxisScale.copy();
var copyY = yAxisScale.copy();
// create axis objects
Next in your zoomFunction do :
function zoomFunction(){
// create new scale ojects based on event
var new_xScale = d3.event.transform.rescaleX(copyX)
var new_yScale = d3.event.transform.rescaleY(copyY)
//changing scale due to some reason.
xAxisScale = new_xScale;
yAxisScale = new_yScale;
// update axes
gX.call(xAxis.scale(xAxisScale));
gY.call(yAxis.scale(yAxisScale));
// update circle
circles.attr("transform", d3.event.transform)
};
working code here
Source: stackoverflow.com
Related Query
- d3 update old scale when pan and zoom
- D3 - How to get correct scale and translate origin after manual zoom and pan to country path
- d3.js pan and zoom jumps when using mouse after programatic zoom
- Map zoom and pan in d3 js v4 + scale limit
- Update zoom state in d3 v4 after manually setting translation and scale
- How to keep current zoom scale and translate level when re-rendering graph
- In d3.js v4 zoom functionality I am having an issue where when i zoom out and then pan the chart goes out of the viewport instantly
- D3.js V4 image not shown on safari, when trying to implement pan and zoom feature
- d3 zoom and pan upgrade to version 4
- 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.js click and apply zoom and pan to distribute points located inside a targeted division to the triggered subdivisions
- D3 click coordinates after pan and zoom
- D3 Zoom with Scrollbars used as panning, Scrollbar width and height adjusts to zoom scale
- Constrain zoom and pan in d3
- Accurate pan and zoom to svg node
- D3 Map Pan and Zoom Performance on Chrome
- D3 disable pan & zoom when scrolling
- D3 change zoom and pan gestures
- D3.js Zoom and Pan to element on Click
- D3 forced layout zoom and pan not working
- d3 click event is stopped with zoom and pan layer
- How to link D3 zoom and pan controls
- Changing time scale from days to weeks, how do I update and sum data values?
- What Transformation values to calculate for scale and translate if you want to zoom
- Apply zoom pan and axis rescale in d3
- How to make SVG:A elements clickable when using D3.js Pan & Zoom behaviour?
- D3.js - force diagram. How to add zoom and pan
- d3 v4: Clip path not updating after pan and zoom
- Javascript / D3.js - draw large data set - improve the speed of zoom and pan in svg chart ploted by d3.js
- Using the zoom and pan functionality of d3
More Query from same tag
- Overriding d3 funnel chart's default
- Update D3 Line Graph from List Options
- D3 Line Chart not having proper X & Y axis plotting with Labels
- Why d3 line generator fails when to and from 0 or both
- Removing old text labels when bar chart is updated
- D3 CSV Import Sort Function Display
- Use a jquery type slider to iterate through a csv and display one bar at a time in a d3.js bar chart
- Filter JavaScript object according to one attribute
- Width limit on D3 force layout centers
- User input to Project on JSON map
- d3.rebind in D3 v4
- replace tag with with a different dom element using d3.js
- Access to svg from D3 library
- radio button in conjunction with c3 does not show text
- d3 js highlight nodes containing given string
- Unexpected brush filtering behaviour
- How can I determine if a point is hidden on a projection?
- Bar Chart with Counts in dc.js
- Using d3, how can I create a histogram or bar plot where the last bar is the count of all values greater than some number?
- Loading in multiple CSVs and storing them each in an individual array
- tickSubdivide not always working?
- what scale to use for representing years only on x axis in d3 js
- D3.zoom jumps when using mouse wheel after programmatically zoom
- D3 How to filter menu based on nested data
- Compilation errors when drawing a piechart using d3.js and TypeScript
- Limit zoom to a 'maximum' in d3 geo tiles
- How to make React Recharts tooltip modal over all charts?
- Display original (conditional) brushed unbrushed crossfilter bars with dc.js with different colors
- The d3 force layout central node positioning
- Bootstrap modal doesn't pop up when a node is clicked