Skip to content

Commit

Permalink
Merge branch 'main' into zoom-center-211
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil authored May 30, 2023
2 parents f76063d + 95cd670 commit c4eb45a
Show file tree
Hide file tree
Showing 18 changed files with 1,340 additions and 1,501 deletions.
8 changes: 2 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"no-cond-assign": 0
"browser": true,
"node": true
}
}
18 changes: 18 additions & 0 deletions .github/eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "eslint-compact",
"pattern": [
{
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}
30 changes: 30 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn --frozen-lockfile
- run: |
echo ::add-matcher::.github/eslint.json
yarn run eslint src test --format=compact
- run: yarn test
40 changes: 13 additions & 27 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
Copyright 2010-2016 Mike Bostock
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright 2010-2021 Mike Bostock

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
143 changes: 72 additions & 71 deletions README.md

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions d3-zoom.sublime-project

This file was deleted.

61 changes: 34 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
{
"name": "d3-zoom",
"version": "1.8.3",
"version": "3.0.0",
"description": "Pan and zoom SVG, HTML or Canvas using mouse or touch input.",
"homepage": "https://d3js.org/d3-zoom/",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-zoom.git"
},
"keywords": [
"d3",
"d3-module",
"zoom",
"behavior",
"interaction"
],
"homepage": "https://d3js.org/d3-zoom/",
"license": "BSD-3-Clause",
"license": "ISC",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "dist/d3-zoom.js",
"unpkg": "dist/d3-zoom.min.js",
"jsdelivr": "dist/d3-zoom.min.js",
"module": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-zoom.git"
"url": "https://bost.ocks.org/mike"
},
"type": "module",
"files": [
"dist/**/*.js",
"src/**/*.js"
],
"scripts": {
"pretest": "rollup -c",
"test": "tape 'test/**/*-test.js' && eslint src",
"prepublishOnly": "rm -rf dist && yarn test",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
"module": "src/index.js",
"main": "src/index.js",
"jsdelivr": "dist/d3-zoom.min.js",
"unpkg": "dist/d3-zoom.min.js",
"exports": {
"umd": "./dist/d3-zoom.min.js",
"default": "./src/index.js"
},
"dependencies": {
"d3-dispatch": "1 - 2",
"d3-drag": "2",
"d3-interpolate": "1 - 2",
"d3-selection": "2",
"d3-transition": "2"
"d3-dispatch": "1 - 3",
"d3-drag": "2 - 3",
"d3-interpolate": "1 - 3",
"d3-selection": "2 - 3",
"d3-transition": "2 - 3"
},
"devDependencies": {
"eslint": "6",
"jsdom": "^16.2.2",
"rollup": "1",
"rollup-plugin-terser": "5",
"tape": "4"
"eslint": "7",
"jsdom": "16",
"mocha": "9",
"rollup": "2",
"rollup-plugin-terser": "7"
},
"scripts": {
"test": "mocha 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && yarn test && rollup -c && git push",
"postpublish": "git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
},
"engines": {
"node": ">=12"
}
}
10 changes: 9 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {readFileSync} from "fs";
import {terser} from "rollup-plugin-terser";
import * as meta from "./package.json";

// Extract copyrights from the LICENSE.
const copyright = readFileSync("./LICENSE", "utf-8")
.split(/\n/g)
.filter(line => /^Copyright\s+/.test(line))
.map(line => line.replace(/^Copyright\s+/, ""))
.join(", ");

const config = {
input: "src/index.js",
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
Expand All @@ -10,7 +18,7 @@ const config = {
format: "umd",
indent: false,
extend: true,
banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`,
banner: `// ${meta.homepage} v${meta.version} Copyright ${copyright}`,
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
},
plugins: []
Expand Down
5 changes: 0 additions & 5 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ export default function ZoomEvent(type, {
_: {value: dispatch}
});
}

ZoomEvent.prototype.on = function() {
var value = this._.on.apply(this._, arguments);
return value === this._ ? this : value;
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as zoom} from "./zoom.js";
export {default as zoomTransform, identity as zoomIdentity} from "./transform.js";
export {default as zoomTransform, identity as zoomIdentity, Transform as ZoomTransform} from "./transform.js";
40 changes: 23 additions & 17 deletions src/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {Transform, identity} from "./transform.js";
import noevent, {nopropagation} from "./noevent.js";

// Ignore right-click, since that should open the context menu.
// except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
function defaultFilter(event) {
return !event.ctrlKey && !event.button;
return (!event.ctrlKey || event.type === 'wheel') && !event.button;
}

function defaultCenter(event) {
Expand All @@ -35,7 +36,7 @@ function defaultTransform() {
}

function defaultWheelDelta(event) {
return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002);
return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
}

function defaultTouchable() {
Expand Down Expand Up @@ -66,22 +67,23 @@ export default function() {
interpolate = interpolateZoom,
listeners = dispatch("start", "zoom", "end"),
touchstarting,
touchfirst,
touchending,
touchDelay = 500,
wheelDelay = 150,
clickDistance2 = 0;
clickDistance2 = 0,
tapDistance = 10;

function zoom(selection) {
selection
.property("__zoom", defaultTransform)
.on("wheel.zoom", wheeled)
.on("wheel.zoom", wheeled, {passive: false})
.on("mousedown.zoom", mousedowned)
.on("dblclick.zoom", dblclicked)
.filter(touchable)
.on("touchstart.zoom", touchstarted)
.on("touchmove.zoom", touchmoved)
.on("touchend.zoom touchcancel.zoom", touchended)
.style("touch-action", "none")
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
}

Expand Down Expand Up @@ -198,7 +200,6 @@ export default function() {
start: function() {
if (++this.active === 1) {
this.that.__zooming = this;
this.dispatch = listeners.copy();
this.emit("start");
}
return this;
Expand All @@ -219,17 +220,16 @@ export default function() {
return this;
},
emit: function(type) {
var dispatch = this.dispatch,
d = select(this.that).datum();
dispatch.call(
var d = select(this.that).datum();
listeners.call(
type,
this.that,
new ZoomEvent(type, {
sourceEvent: this.sourceEvent,
target: zoom,
type,
transform: this.that.__zoom,
dispatch
dispatch: listeners
}),
d
);
Expand Down Expand Up @@ -275,10 +275,10 @@ export default function() {

function mousedowned(event, ...args) {
if (touchending || !filter.apply(this, arguments)) return;
var g = gesture(this, args, true).event(event),
var currentTarget = event.currentTarget,
g = gesture(this, args, true).event(event),
v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
p = pointer(event, currentTarget),
currentTarget = event.currentTarget,
x0 = event.clientX,
y0 = event.clientY;

Expand Down Expand Up @@ -339,7 +339,7 @@ export default function() {
if (touchstarting) touchstarting = clearTimeout(touchstarting);

if (started) {
if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
interrupt(this);
g.start();
}
Expand All @@ -352,8 +352,6 @@ export default function() {
n = touches.length, i, t, p, l;

noevent(event);
if (touchstarting) touchstarting = clearTimeout(touchstarting);
g.taps = 0;
for (i = 0; i < n; ++i) {
t = touches[i], p = pointer(t, this);
if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
Expand All @@ -371,6 +369,7 @@ export default function() {
}
else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
else return;

g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
}

Expand All @@ -394,8 +393,11 @@ export default function() {
g.end();
// If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
if (g.taps === 2) {
var p = select(this).on("dblclick.zoom");
if (p) p.apply(this, arguments);
t = pointer(t, this);
if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
var p = select(this).on("dblclick.zoom");
if (p) p.apply(this, arguments);
}
}
}
}
Expand Down Expand Up @@ -449,5 +451,9 @@ export default function() {
return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
};

zoom.tapDistance = function(_) {
return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
};

return zoom;
}
12 changes: 12 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"browser": true,
"node": true,
"mocha": true
}
}
Loading

0 comments on commit c4eb45a

Please sign in to comment.