Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-zoom

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-zoom - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

src/constant.js

308

build/d3-zoom.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3_zoom = global.d3_zoom || {})));
}(this, function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-dispatch'), require('d3-interpolate'), require('d3-selection'), require('d3-transition')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-dispatch', 'd3-interpolate', 'd3-selection', 'd3-transition'], factory) :
(factory((global.d3_zoom = global.d3_zoom || {}),global.d3_dispatch,global.d3_interpolate,global.d3_selection,global.d3_transition));
}(this, function (exports,d3Dispatch,d3Interpolate,d3Selection,d3Transition) { 'use strict';
var version = "0.0.1";
var version = "0.0.2";
exports.version = version;
function constant(x) {
return function() {
return x;
};
}
function ZoomEvent(type, view) {
this.type = type;
this.scale = view.k;
this.translate = [view.x, view.y];
}
function Transform(k, x, y) {
this.k = k;
this.x = x;
this.y = y;
}
Transform.prototype = {
constructor: Transform,
apply: function(point) {
return [point[0] * this.k + this.x, point[1] * this.k + this.y];
},
invert: function(location) {
return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
},
scale: function(k) {
return new Transform(this.k * k, this.x, this.y);
},
translate: function(x, y) {
return new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
},
toString: function() {
return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
}
};
var identity = new Transform(1, 0, 0);
transform.prototype = Transform.prototype;
function transform(node) {
return node == null ? identity : node.__zoom;
}
// Ignore horizontal scrolling.
// Ignore right-click, since that should open the context menu.
function defaultFilter() {
return d3Selection.event.type === "wheel" ? d3Selection.event.deltaY : !d3Selection.event.button;
}
function defaultSize() {
var node = this.ownerSVGElement || this;
return [node.clientWidth, node.clientHeight];
}
function defaultTransform() {
return this.__zoom || identity;
}
function zoom(started) {
var filter = defaultFilter,
size = defaultSize,
scaleMin = 0,
scaleMax = Infinity,
duration = 250,
zooming = 0,
wheelTimer,
wheelDelay = 150,
centerPoint = null,
centerLocation,
mousePoint,
mouseLocation;
// TODO Prevent default.
// TODO Stop propagation.
var listeners = d3Dispatch.dispatch("start", "zoom", "end")
.on("start", started);
function zoom(selection) {
selection
.on("wheel.zoom", wheeled)
.on("mousedown.zoom", mousedowned)
.on("dblclick.zoom", dblclicked)
.on("touchstart.zoom", touchstarted)
.on("touchmove.zoom", touchmoved)
.on("touchend.zoom touchcancel.zoom", touchended)
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
.property("__zoom", defaultTransform);
}
zoom.transform = function(collection, transform) {
var selection = collection.selection ? collection.selection() : collection;
transform = clamp(transform);
selection.property("__zoom", defaultTransform);
if (collection instanceof d3Transition.transition) schedule(collection, transform, centerPoint);
else collection.interrupt().each(emitStart).property("__zoom", transform).each(emitZoom).each(emitEnd);
};
zoom.scaleBy = function(selection, k) {
zoom.scaleTo(selection, function() {
var k0 = this.__zoom.k,
k1 = typeof k === "function" ? k.apply(this, arguments) : k;
return k0 * k1;
});
};
zoom.scaleTo = function(selection, k) {
zoom.transform(selection, function() {
var p0 = centerPoint || (p0 = size.apply(this, arguments), [p0[0] / 2, p0[1] / 2]),
p1 = this.__zoom.invert(p0),
k1 = typeof k === "function" ? k.apply(this, arguments) : k;
return translate(scale(this.__zoom, k1), p0, p1);
});
};
function clamp(transform) {
return function() {
var t = typeof transform === "function" ? transform.apply(this, arguments) : transform;
if (scaleMin > t.k || t.k > scaleMax) {
var p0 = centerPoint || (p0 = size.apply(this, arguments), [p0[0] / 2, p0[1] / 2]),
p1 = t.invert(p0);
t = translate(scale(t, t.k), p0, p1);
}
return t;
};
}
function scale(transform, k) {
return new Transform(Math.max(scaleMin, Math.min(scaleMax, k)), transform.x, transform.y);
}
function translate(transform, p0, p1) {
return p1 = transform.apply(p1), new Transform(transform.k, transform.x + p0[0] - p1[0], transform.y + p0[1] - p1[1]);
}
function schedule(transition, transform, center) {
transition
.on("start.zoom", emitStart)
.on("interrupt.zoom end.zoom", emitEnd)
.tween("zoom:zoom", function() {
var that = this,
args = arguments,
s = size.apply(that, args),
p = center || [s[0] / 2, s[1] / 2],
w = Math.max(s[0], s[1]),
a = that.__zoom,
b = typeof transform === "function" ? transform.apply(that, args) : transform,
i = d3Interpolate.interpolateZoom(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
return function(t) {
if (t === 1) that.__zoom = b; // Avoid rounding error on end.
else { var l = i(t), k = w / l[2]; that.__zoom = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
emitZoom.apply(that, args);
};
});
}
function emitStart() {
if (++zooming === 1) emit("start", this, arguments);
}
function emitZoom() {
emit("zoom", this, arguments);
}
function emitEnd() {
if (--zooming === 0) emit("end", this, arguments);
}
function emit(type, that, args) {
d3Selection.customEvent(new ZoomEvent(type, that.__zoom), listeners.apply, listeners, [type, that, args]);
}
// TODO Clean this up.
function wheeled() {
if (!filter.apply(this, arguments)) return;
var that = this,
args = arguments,
transform = that.__zoom;
if (wheelTimer) clearTimeout(wheelTimer);
// If this is the first wheel event since the wheel was idle, then capture
// the mouse location and the center location to avoid loss of precision
// over the duration of the gesture: if you zoom in a lot and then zoom out,
// we want you to return to the original location exactly.
else {
if (centerPoint) centerLocation = transform.invert(centerPoint);
mouseLocation = transform.invert(mousePoint = d3Selection.mouse(that));
d3Transition.interrupt(that), emitStart.apply(that, args);
}
transform = scale(transform, transform.k * Math.pow(2, -d3Selection.event.deltaY * (d3Selection.event.deltaMode ? 120 : 1) / 500));
// There may be a concurrent mousedown-mouseup gesture! Scaling around an
// explicit center changes the mouse location, so must update the mouse
// location that was captured on mousedown.
if (centerPoint) {
transform = translate(transform, centerPoint, centerLocation);
mouseLocation = transform.invert(mousePoint);
} else {
transform = translate(transform, mousePoint, mouseLocation);
}
that.__zoom = transform;
d3Selection.event.preventDefault();
wheelTimer = setTimeout(wheelidled, wheelDelay);
emitZoom.apply(that, args);
function wheelidled() {
wheelTimer = null;
emitEnd.apply(that, args);
}
}
// TODO Clean this up.
function mousedowned() {
if (!filter.apply(this, arguments)) return;
var that = this,
args = arguments;
// We shouldn’t capture that.__zoom on mousedown because you can wheel after
// mousedown and before mouseup. If that happens AND an explicit center is
// defined, the center location also needs to be updated.
mouseLocation = that.__zoom.invert(mousePoint = d3Selection.mouse(that));
d3Selection.select(d3Selection.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true);
d3Transition.interrupt(that), emitStart.apply(that, args);
function mousemoved() {
that.__zoom = translate(that.__zoom, mousePoint = d3Selection.mouse(that), mouseLocation);
if (centerPoint) centerLocation = that.__zoom.invert(centerPoint);
emitZoom.apply(that, args);
}
function mouseupped() {
d3Selection.select(d3Selection.event.view).on("mousemove.zoom mouseup.zoom", null);
emitEnd.apply(that, args);
}
}
function dblclicked() {
if (!filter.apply(this, arguments)) return;
var t0 = this.__zoom,
p0 = centerPoint || d3Selection.mouse(this),
p1 = t0.invert(p0),
k1 = t0.k * (d3Selection.event.shiftKey ? 0.5 : 2),
t1 = translate(scale(t0, k1), p0, p1);
if (duration > 0) d3Selection.select(this).transition().duration(duration).call(schedule, t1, p0);
else this.__zoom = t1;
}
function touchstarted() {
// TODO
}
function touchmoved() {
// TODO
}
function touchended() {
// TODO
}
zoom.filter = function(_) {
return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
};
zoom.size = function(_) {
return arguments.length ? (size = typeof _ === "function" ? _ : constant([+_[0], +_[1]]), zoom) : size;
};
zoom.scaleExtent = function(_) {
return arguments.length ? (scaleMin = +_[0], scaleMax = +_[1], zoom) : [scaleMin, scaleMax];
};
zoom.center = function(_) {
return arguments.length ? (centerPoint = _ == null ? null : [+_[0], +_[1]], zoom) : centerPoint;
};
zoom.duration = function(_) {
return arguments.length ? (duration = +_, zoom) : duration;
};
zoom.on = function() {
var value = listeners.on.apply(listeners, arguments);
return value === listeners ? zoom : value;
};
return zoom;
}
exports.version = version;
exports.zoom = zoom;
exports.zoomTransform = transform;
}));

2

build/d3-zoom.min.js

@@ -1,1 +0,1 @@

!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o(e.d3_zoom=e.d3_zoom||{})}(this,function(e){"use strict";var o="0.0.1";e.version=o});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-dispatch"),require("d3-interpolate"),require("d3-selection"),require("d3-transition")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-interpolate","d3-selection","d3-transition"],n):n(t.d3_zoom=t.d3_zoom||{},t.d3_dispatch,t.d3_interpolate,t.d3_selection,t.d3_transition)}(this,function(t,n,o,e,i){"use strict";function r(t){return function(){return t}}function u(t,n){this.type=t,this.scale=n.k,this.translate=[n.x,n.y]}function s(t,n,o){this.k=t,this.x=n,this.y=o}function c(t){return null==t?m:t.__zoom}function a(){return"wheel"===e.event.type?e.event.deltaY:!e.event.button}function p(){var t=this.ownerSVGElement||this;return[t.clientWidth,t.clientHeight]}function l(){return this.__zoom||m}function f(t){function c(t){t.on("wheel.zoom",k).on("mousedown.zoom",w).on("dblclick.zoom",x).on("touchstart.zoom",g).on("touchmove.zoom",b).on("touchend.zoom touchcancel.zoom",M).style("-webkit-tap-highlight-color","rgba(0,0,0,0)").property("__zoom",l)}function f(t){return function(){var n="function"==typeof t?t.apply(this,arguments):t;if(B>n.k||n.k>D){var o=V||(o=j.apply(this,arguments),[o[0]/2,o[1]/2]),e=n.invert(o);n=m(h(n,n.k),o,e)}return n}}function h(t,n){return new s(Math.max(B,Math.min(D,n)),t.x,t.y)}function m(t,n,o){return o=t.apply(o),new s(t.k,t.x+n[0]-o[0],t.y+n[1]-o[1])}function y(t,n,e){t.on("start.zoom",_).on("interrupt.zoom end.zoom",z).tween("zoom:zoom",function(){var t=this,i=arguments,r=j.apply(t,i),u=e||[r[0]/2,r[1]/2],c=Math.max(r[0],r[1]),a=t.__zoom,p="function"==typeof n?n.apply(t,i):n,l=o.interpolateZoom(a.invert(u).concat(c/a.k),p.invert(u).concat(c/p.k));return function(n){if(1===n)t.__zoom=p;else{var o=l(n),e=c/o[2];t.__zoom=new s(e,u[0]-o[0]*e,u[1]-o[1]*e)}v.apply(t,i)}})}function _(){1===++H&&d("start",this,arguments)}function v(){d("zoom",this,arguments)}function z(){0===--H&&d("end",this,arguments)}function d(t,n,o){e.customEvent(new u(t,n.__zoom),W.apply,W,[t,n,o])}function k(){function t(){T=null,z.apply(n,o)}if(Y.apply(this,arguments)){var n=this,o=arguments,r=n.__zoom;T?clearTimeout(T):(V&&(q=r.invert(V)),S=r.invert(E=e.mouse(n)),i.interrupt(n),_.apply(n,o)),r=h(r,r.k*Math.pow(2,-e.event.deltaY*(e.event.deltaMode?120:1)/500)),V?(r=m(r,V,q),S=r.invert(E)):r=m(r,E,S),n.__zoom=r,e.event.preventDefault(),T=setTimeout(t,K),v.apply(n,o)}}function w(){function t(){o.__zoom=m(o.__zoom,E=e.mouse(o),S),V&&(q=o.__zoom.invert(V)),v.apply(o,r)}function n(){e.select(e.event.view).on("mousemove.zoom mouseup.zoom",null),z.apply(o,r)}if(Y.apply(this,arguments)){var o=this,r=arguments;S=o.__zoom.invert(E=e.mouse(o)),e.select(e.event.view).on("mousemove.zoom",t,!0).on("mouseup.zoom",n,!0),i.interrupt(o),_.apply(o,r)}}function x(){if(Y.apply(this,arguments)){var t=this.__zoom,n=V||e.mouse(this),o=t.invert(n),i=t.k*(e.event.shiftKey?.5:2),r=m(h(t,i),n,o);G>0?e.select(this).transition().duration(G).call(y,r,n):this.__zoom=r}}function g(){}function b(){}function M(){}var T,q,E,S,Y=a,j=p,B=0,D=1/0,G=250,H=0,K=150,V=null,W=n.dispatch("start","zoom","end").on("start",t);return c.transform=function(t,n){var o=t.selection?t.selection():t;n=f(n),o.property("__zoom",l),t instanceof i.transition?y(t,n,V):t.interrupt().each(_).property("__zoom",n).each(v).each(z)},c.scaleBy=function(t,n){c.scaleTo(t,function(){var t=this.__zoom.k,o="function"==typeof n?n.apply(this,arguments):n;return t*o})},c.scaleTo=function(t,n){c.transform(t,function(){var t=V||(t=j.apply(this,arguments),[t[0]/2,t[1]/2]),o=this.__zoom.invert(t),e="function"==typeof n?n.apply(this,arguments):n;return m(h(this.__zoom,e),t,o)})},c.filter=function(t){return arguments.length?(Y="function"==typeof t?t:r(!!t),c):Y},c.size=function(t){return arguments.length?(j="function"==typeof t?t:r([+t[0],+t[1]]),c):j},c.scaleExtent=function(t){return arguments.length?(B=+t[0],D=+t[1],c):[B,D]},c.center=function(t){return arguments.length?(V=null==t?null:[+t[0],+t[1]],c):V},c.duration=function(t){return arguments.length?(G=+t,c):G},c.on=function(){var t=W.on.apply(W,arguments);return t===W?c:t},c}var h="0.0.2";s.prototype={constructor:s,apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},scale:function(t){return new s(this.k*t,this.x,this.y)},translate:function(t,n){return new s(this.k,this.x+this.k*t,this.y+this.k*n)},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var m=new s(1,0,0);c.prototype=s.prototype,t.version=h,t.zoom=f,t.zoomTransform=c});
export var name = "d3-zoom";
export var version = "0.0.1";
export var version = "0.0.2";
export var description = "";

@@ -10,3 +10,4 @@ export var keywords = ["d3","zoom","behavior","interaction"];

export var repository = {"type":"git","url":"https://github.com/d3/d3-zoom.git"};
export var scripts = {"pretest":"rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -f umd -n d3_zoom -o build/d3-zoom.js -- index.js","test":"tape 'test/**/*-test.js' && eslint index.js src","prepublish":"npm run test && uglifyjs build/d3-zoom.js -c -m -o build/d3-zoom.min.js","postpublish":"VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-zoom.js ../d3.github.com/d3-zoom.v0.0.js && cp build/d3-zoom.min.js ../d3.github.com/d3-zoom.v0.0.min.js && cd ../d3.github.com && git add d3-zoom.v0.0.js d3-zoom.v0.0.min.js && git commit -m \"d3-zoom ${VERSION}\" && git push && cd - && zip -j build/d3-zoom.zip -- LICENSE README.md build/d3-zoom.js build/d3-zoom.min.js"};
export var devDependencies = {"json2module":"0.0","rollup":"0.26","tape":"4","uglify-js":"2"};
export var scripts = {"pretest":"rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -g d3-dispatch:d3_dispatch,d3-interpolate:d3_interpolate,d3-selection:d3_selection,d3-transition:d3_transition -f umd -n d3_zoom -o build/d3-zoom.js -- index.js","test":"tape 'test/**/*-test.js' && eslint index.js src","prepublish":"npm run test && uglifyjs build/d3-zoom.js -c -m -o build/d3-zoom.min.js","postpublish":"VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-zoom.js ../d3.github.com/d3-zoom.v0.0.js && cp build/d3-zoom.min.js ../d3.github.com/d3-zoom.v0.0.min.js && cd ../d3.github.com && git add d3-zoom.v0.0.js d3-zoom.v0.0.min.js && git commit -m \"d3-zoom ${VERSION}\" && git push && cd - && zip -j build/d3-zoom.zip -- LICENSE README.md build/d3-zoom.js build/d3-zoom.min.js"};
export var dependencies = {"d3-dispatch":"~0.4.3","d3-interpolate":"~0.7.0","d3-selection":"~0.7.2","d3-transition":"~0.2.8"};
export var devDependencies = {"eslint":"2","json2module":"0.0","rollup":"0.26","tape":"4","uglify-js":"2"};
export {version} from "./build/package";
export {default as zoom} from "./src/zoom";
export {default as zoomTransform} from "./src/transform";
{
"name": "d3-zoom",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

@@ -24,3 +24,3 @@ "keywords": [

"scripts": {
"pretest": "rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -f umd -n d3_zoom -o build/d3-zoom.js -- index.js",
"pretest": "rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -g d3-dispatch:d3_dispatch,d3-interpolate:d3_interpolate,d3-selection:d3_selection,d3-transition:d3_transition -f umd -n d3_zoom -o build/d3-zoom.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src",

@@ -30,3 +30,10 @@ "prepublish": "npm run test && uglifyjs build/d3-zoom.js -c -m -o build/d3-zoom.min.js",

},
"dependencies": {
"d3-dispatch": "~0.4.3",
"d3-interpolate": "~0.7.0",
"d3-selection": "~0.7.2",
"d3-transition": "~0.2.8"
},
"devDependencies": {
"eslint": "2",
"json2module": "0.0",

@@ -33,0 +40,0 @@ "rollup": "0.26",

@@ -7,5 +7,12 @@ # d3-zoom

If you use NPM, `npm install d3-zoom`. Otherwise, download the [latest release](https://github.com/d3/d3-zoom/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-zoom.v0.0.min.js) or as part of [D3 4.0 alpha](https://github.com/mbostock/d3/tree/4). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_zoom` global is exported:
If you use NPM, `npm install d3-zoom`. Otherwise, download the [latest release](https://github.com/d3/d3-zoom/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-zoom.v0.0.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_zoom` global is exported:
```html
<script src="https://d3js.org/d3-color.v0.4.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v0.4.min.js"></script>
<script src="https://d3js.org/d3-ease.v0.7.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v0.7.min.js"></script>
<script src="https://d3js.org/d3-selection.v0.7.min.js"></script>
<script src="https://d3js.org/d3-timer.v0.4.min.js"></script>
<script src="https://d3js.org/d3-transition.v0.2.min.js"></script>
<script src="https://d3js.org/d3-zoom.v0.0.min.js"></script>

@@ -12,0 +19,0 @@ <script>

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc