Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,5 @@
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"no-cond-assign": 0,
"no-prototype-builtins": 0
}
}
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
39 changes: 13 additions & 26 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
Copyright (c) 2010-2018, Michael 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.

* The name Michael Bostock may not 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 MICHAEL BOSTOCK 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.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,20 @@ For more, see [the d3-selection collection on Observable](https://observablehq.c

## Installing

If you use NPM, `npm install d3-selection`. Otherwise, download the [latest release](https://github.com/d3/d3-selection/releases/latest). You can also load d3-selection as a standalone library or as part of [D3](https://github.com/d3/d3). ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
If you use npm, `npm install d3-selection`. You can also download the [latest release on GitHub](https://github.com/d3/d3-selection/releases/latest). For vanilla HTML in modern browsers, import d3-selection from Skypack:

```html
<script src="https://cdn.jsdelivr.net/npm/d3-selection@2"></script>
<script type="module">
import {selectAll} from "https://cdn.skypack.dev/d3-selection@3";

const div = selectAll("div");
</script>
```

For legacy environments, you can load d3-selection’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:

```html
<script src="https://cdn.jsdelivr.net/npm/d3-selection@3"></script>
<script>

const div = d3.selectAll("div");
Expand Down
45 changes: 26 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,50 @@
"name": "d3-selection",
"version": "2.0.0",
"description": "Data-driven DOM manipulation: select elements and join them to data.",
"homepage": "https://d3js.org/d3-selection/",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-selection.git"
},
"keywords": [
"d3",
"d3-module",
"dom",
"selection",
"data-join"
],
"homepage": "https://d3js.org/d3-selection/",
"license": "BSD-3-Clause",
"license": "ISC",
"author": {
"name": "Mike Bostock",
"url": "https://bost.ocks.org/mike"
},
"main": "dist/d3-selection.js",
"unpkg": "dist/d3-selection.min.js",
"jsdelivr": "dist/d3-selection.min.js",
"module": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-selection.git"
},
"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-selection.min.js",
"unpkg": "dist/d3-selection.min.js",
"exports": {
"umd": "./dist/d3-selection.min.js",
"default": "./src/index.js"
},
"sideEffects": false,
"devDependencies": {
"eslint": "6",
"eslint": "7",
"jsdom": "15",
"rollup": "1",
"rollup-plugin-terser": "5",
"tape": "4"
"mocha": "8",
"rollup": "2",
"rollup-plugin-terser": "5"
},
"scripts": {
"test": "mocha 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
"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 -"
},
"engines": {
"node": ">=12"
}
}
10 changes: 10 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"mocha": true
}
}
32 changes: 15 additions & 17 deletions test/create-test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
var tape = require("tape"),
jsdom = require("./jsdom"),
d3 = require("../");
import assert from "assert";
import * as d3 from "../src/index.js";
import jsdom from "./jsdom.js";

tape("d3.create(name) returns a new HTML element with the given name", function(test) {
it("d3.create(name) returns a new HTML element with the given name", () => {
global.document = jsdom("");
try {
var h1 = d3.create("h1");
test.equal(h1._groups[0][0].namespaceURI, "http://www.w3.org/1999/xhtml");
test.equal(h1._groups[0][0].tagName, "H1");
test.deepEqual(h1._parents, [null]);
test.end();
} finally {
const h1 = d3.create("h1");
assert.strictEqual(h1._groups[0][0].namespaceURI, "http://www.w3.org/1999/xhtml");
assert.strictEqual(h1._groups[0][0].tagName, "H1");
assert.deepStrictEqual(h1._parents, [null]);
} finally {
delete global.document;
}
});

tape("d3.create(name) returns a new SVG element with the given name", function(test) {
it("d3.create(name) returns a new SVG element with the given name", () => {
global.document = jsdom("");
try {
var svg = d3.create("svg");
test.equal(svg._groups[0][0].namespaceURI, "http://www.w3.org/2000/svg");
test.equal(svg._groups[0][0].tagName, "svg");
test.deepEqual(svg._parents, [null]);
test.end();
} finally {
const svg = d3.create("svg");
assert.strictEqual(svg._groups[0][0].namespaceURI, "http://www.w3.org/2000/svg");
assert.strictEqual(svg._groups[0][0].tagName, "svg");
assert.deepStrictEqual(svg._parents, [null]);
} finally {
delete global.document;
}
});
28 changes: 13 additions & 15 deletions test/creator-test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
var tape = require("tape"),
jsdom = require("./jsdom"),
d3 = require("../");
import assert from "assert";
import * as d3 from "../src/index.js";
import jsdom from "./jsdom.js";

tape("d3.creator(name).call(element) returns a new element with the given name", function(test) {
var document = jsdom("<body class='foo'>");
test.deepEqual(type(d3.creator("h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
test.deepEqual(type(d3.creator("xhtml:h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
test.deepEqual(type(d3.creator("svg").call(document.body)), {namespace: "http://www.w3.org/2000/svg", name: "svg"});
test.deepEqual(type(d3.creator("g").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "G"});
test.end();
it("d3.creator(name).call(element) returns a new element with the given name", () => {
const document = jsdom("<body class='foo'>");
assert.deepStrictEqual(type(d3.creator("h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
assert.deepStrictEqual(type(d3.creator("xhtml:h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
assert.deepStrictEqual(type(d3.creator("svg").call(document.body)), {namespace: "http://www.w3.org/2000/svg", name: "svg"});
assert.deepStrictEqual(type(d3.creator("g").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "G"});
});

tape("d3.creator(name).call(element) can inherit the namespace from the given element", function(test) {
var document = jsdom("<body class='foo'><svg></svg>"),
it("d3.creator(name).call(element) can inherit the namespace from the given element", () => {
const document = jsdom("<body class='foo'><svg></svg>"),
svg = document.querySelector("svg");
test.deepEqual(type(d3.creator("g").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "G"});
test.deepEqual(type(d3.creator("g").call(svg)), {namespace: "http://www.w3.org/2000/svg", name: "g"});
test.end();
assert.deepStrictEqual(type(d3.creator("g").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "G"});
assert.deepStrictEqual(type(d3.creator("g").call(svg)), {namespace: "http://www.w3.org/2000/svg", name: "g"});
});

function type(element) {
Expand Down
7 changes: 4 additions & 3 deletions test/jsdom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var jsdom = require("jsdom");
import * as jsdom from "jsdom";

module.exports = function(html) {
export default function(html) {
return (new jsdom.JSDOM(html)).window.document;
};
}

21 changes: 10 additions & 11 deletions test/matcher-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var tape = require("tape"),
jsdom = require("./jsdom"),
d3 = require("../");
import assert from "assert";
import * as d3 from "../src/index.js";
import jsdom from "./jsdom.js";

tape("d3.matcher(selector).call(element) returns true if the element matches the selector", function(test) {
var document = jsdom("<body class='foo'>");
test.equal(d3.matcher("body").call(document.body), true);
test.equal(d3.matcher(".foo").call(document.body), true);
test.equal(d3.matcher("body.foo").call(document.body), true);
test.equal(d3.matcher("h1").call(document.body), false);
test.equal(d3.matcher("body.bar").call(document.body), false);
test.end();
it("d3.matcher(selector).call(element) returns true if the element matches the selector", () => {
const document = jsdom("<body class='foo'>");
assert.strictEqual(d3.matcher("body").call(document.body), true);
assert.strictEqual(d3.matcher(".foo").call(document.body), true);
assert.strictEqual(d3.matcher("body.foo").call(document.body), true);
assert.strictEqual(d3.matcher("h1").call(document.body), false);
assert.strictEqual(d3.matcher("body.bar").call(document.body), false);
});
49 changes: 22 additions & 27 deletions test/namespace-test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
var tape = require("tape"),
d3 = require("../");
import assert from "assert";
import * as d3 from "../src/index.js";

tape("d3.namespace(name) returns name if there is no namespace prefix", function(test) {
test.equal(d3.namespace("foo"), "foo");
test.equal(d3.namespace("foo:bar"), "bar");
test.end();
it("d3.namespace(name) returns name if there is no namespace prefix", () => {
assert.strictEqual(d3.namespace("foo"), "foo");
assert.strictEqual(d3.namespace("foo:bar"), "bar");
});

tape("d3.namespace(name) coerces name to a string", function(test) {
test.equal(d3.namespace({toString: function() { return "foo"; }}), "foo");
test.deepEqual(d3.namespace({toString: function() { return "svg"; }}), {space: "http://www.w3.org/2000/svg", local: "svg"});
test.end();
it("d3.namespace(name) coerces name to a string", () => {
assert.strictEqual(d3.namespace({toString: function() { return "foo"; }}), "foo");
assert.deepStrictEqual(d3.namespace({toString: function() { return "svg"; }}), {space: "http://www.w3.org/2000/svg", local: "svg"});
});

tape("d3.namespace(name) returns the expected values for built-in namespaces", function(test) {
test.deepEqual(d3.namespace("svg"), {space: "http://www.w3.org/2000/svg", local: "svg"});
test.deepEqual(d3.namespace("xhtml"), {space: "http://www.w3.org/1999/xhtml", local: "xhtml"});
test.deepEqual(d3.namespace("xlink"), {space: "http://www.w3.org/1999/xlink", local: "xlink"});
test.deepEqual(d3.namespace("xml"), {space: "http://www.w3.org/XML/1998/namespace", local: "xml"});
test.deepEqual(d3.namespace("svg:g"), {space: "http://www.w3.org/2000/svg", local: "g"});
test.deepEqual(d3.namespace("xhtml:b"), {space: "http://www.w3.org/1999/xhtml", local: "b"});
test.deepEqual(d3.namespace("xlink:href"), {space: "http://www.w3.org/1999/xlink", local: "href"});
test.deepEqual(d3.namespace("xml:lang"), {space: "http://www.w3.org/XML/1998/namespace", local: "lang"});
test.end();
it("d3.namespace(name) returns the expected values for built-in namespaces", () => {
assert.deepStrictEqual(d3.namespace("svg"), {space: "http://www.w3.org/2000/svg", local: "svg"});
assert.deepStrictEqual(d3.namespace("xhtml"), {space: "http://www.w3.org/1999/xhtml", local: "xhtml"});
assert.deepStrictEqual(d3.namespace("xlink"), {space: "http://www.w3.org/1999/xlink", local: "xlink"});
assert.deepStrictEqual(d3.namespace("xml"), {space: "http://www.w3.org/XML/1998/namespace", local: "xml"});
assert.deepStrictEqual(d3.namespace("svg:g"), {space: "http://www.w3.org/2000/svg", local: "g"});
assert.deepStrictEqual(d3.namespace("xhtml:b"), {space: "http://www.w3.org/1999/xhtml", local: "b"});
assert.deepStrictEqual(d3.namespace("xlink:href"), {space: "http://www.w3.org/1999/xlink", local: "href"});
assert.deepStrictEqual(d3.namespace("xml:lang"), {space: "http://www.w3.org/XML/1998/namespace", local: "lang"});
});

tape("d3.namespace(\"xmlns:…\") treats the whole name as the local name", function(test) {
test.deepEqual(d3.namespace("xmlns:xlink"), {space: "http://www.w3.org/2000/xmlns/", local: "xmlns:xlink"});
test.end();
it("d3.namespace(\"xmlns:…\") treats the whole name as the local name", () => {
assert.deepStrictEqual(d3.namespace("xmlns:xlink"), {space: "http://www.w3.org/2000/xmlns/", local: "xmlns:xlink"});
});

tape("d3.namespace(name) observes modifications to d3.namespaces", function(test) {
it("d3.namespace(name) observes modifications to d3.namespaces", () => {
d3.namespaces.d3js = "https://d3js.org/2016/namespace";
test.deepEqual(d3.namespace("d3js:pie"), {space: "https://d3js.org/2016/namespace", local: "pie"});
assert.deepStrictEqual(d3.namespace("d3js:pie"), {space: "https://d3js.org/2016/namespace", local: "pie"});
delete d3.namespaces.d3js;
test.equal(d3.namespace("d3js:pie"), "pie");
test.end();
assert.strictEqual(d3.namespace("d3js:pie"), "pie");
});
9 changes: 4 additions & 5 deletions test/namespaces-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var tape = require("tape"),
d3 = require("../");
import assert from "assert";
import * as d3 from "../src/index.js";

tape("d3.namespaces is the expected map", function(test) {
test.deepEqual(d3.namespaces, {
it("d3.namespaces is the expected map", () => {
assert.deepStrictEqual(d3.namespaces, {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
});
test.end();
});
Loading