MCPcopy Index your code
hub / github.com/plotly/plotly.js / zoomClipped

Function zoomClipped

src/plots/geo/zoom.js:201–300  ·  view source on GitHub ↗
(geo, projection)

Source from the content-addressed store, hash-verified

199// zoom for clipped projections
200// inspired by https://www.jasondavies.com/maps/d3.geo.zoom.js
201function zoomClipped(geo, projection) {
202 var view = {r: projection.rotate(), k: projection.scale()};
203 var zoom = initZoom(geo, projection);
204 var event = d3eventDispatch(zoom, 'zoomstart', 'zoom', 'zoomend');
205 var zooming = 0;
206 var zoomOn = zoom.on;
207
208 var zoomPoint;
209
210 zoom.on('zoomstart', function() {
211 d3.select(this).style(zoomstartStyle);
212
213 var mouse0 = d3.mouse(this);
214 var rotate0 = projection.rotate();
215 var lastRotate = rotate0;
216 var translate0 = projection.translate();
217 var q = quaternionFromEuler(rotate0);
218
219 zoomPoint = position(projection, mouse0);
220
221 zoomOn.call(zoom, 'zoom', function() {
222 var mouse1 = d3.mouse(this);
223
224 projection.scale(view.k = d3.event.scale);
225
226 if(!zoomPoint) {
227 // if no zoomPoint, the mouse wasn't over the actual geography yet
228 // maybe this point is the start... we'll find out next time!
229 mouse0 = mouse1;
230 zoomPoint = position(projection, mouse0);
231 } else if(position(projection, mouse1)) {
232 // check if the point is on the map
233 // if not, don't do anything new but scale
234 // if it is, then we can assume between will exist below
235 // so we don't need the 'bank' function, whatever that is.
236
237 // go back to original projection temporarily
238 // except for scale... that's kind of independent?
239 projection
240 .rotate(rotate0)
241 .translate(translate0);
242
243 // calculate the new params
244 var point1 = position(projection, mouse1);
245 var between = rotateBetween(zoomPoint, point1);
246 var newEuler = eulerFromQuaternion(multiply(q, between));
247 var rotateAngles = view.r = unRoll(newEuler, zoomPoint, lastRotate);
248
249 if(!isFinite(rotateAngles[0]) || !isFinite(rotateAngles[1]) ||
250 !isFinite(rotateAngles[2])) {
251 rotateAngles = lastRotate;
252 }
253
254 // update the projection
255 projection.rotate(rotateAngles);
256 lastRotate = rotateAngles;
257 }
258

Callers

nothing calls this directly

Calls 12

initZoomFunction · 0.85
d3eventDispatchFunction · 0.85
quaternionFromEulerFunction · 0.85
positionFunction · 0.85
rotateBetweenFunction · 0.85
eulerFromQuaternionFunction · 0.85
unRollFunction · 0.85
zoomedFunction · 0.85
zoomstartedFunction · 0.85
zoomendedFunction · 0.85
syncFunction · 0.85
multiplyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…