Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt type=module #208

Merged
merged 10 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"es6": true
},
"rules": {
"no-cond-assign": 0,
"no-constant-condition": 0,
"no-floating-decimal": 2
"no-constant-condition": 0
}
}
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.sublime-workspace
.DS_Store
dist/
test/output/
node_modules
npm-debug.log
43 changes: 13 additions & 30 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
Copyright 2013-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 2013-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.

MIT License for https://github.com/scijs/integrate-adaptive-simpson

The MIT License (MIT)

Copyright (c) 2015 Ricky Reusser
Copyright 2015 Ricky Reusser

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -51,4 +34,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ Extended geographic projections for [d3-geo](https://github.com/d3/d3-geo). See

## Installing

If you use NPM, `npm install d3-geo-projection`. Otherwise, download the [latest release](https://github.com/d3/d3-geo-projection/releases/latest). You can also load directly from [d3js.org](https://d3js.org) as a [standalone library](https://d3js.org/d3-geo-projection.v2.min.js). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
If you use npm, `npm install d3-geo-projection`. You can also download the [latest release on GitHub](https://github.com/d3/d3-geo-projection/releases/latest). For vanilla HTML in modern browsers, import d3-geo-projection from Skypack:

```html
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="https://d3js.org/d3-geo.v2.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v3.min.js"></script>
<script type="module">

import {geoAitoff} from "https://cdn.skypack.dev/d3-geo-projection@4";

const projection = geoAitoff();

</script>
```

For legacy environments, you can load d3-geo-projection’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-array@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-geo@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-geo-projection@4"></script>
<script>

var aitoff = d3.geoAitoff();
const projection = d3.geoAitoff();

</script>
```
Expand Down
65 changes: 36 additions & 29 deletions bin/geo2svg → bin/geo2svg.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env node

var os = require("os"),
commander = require("commander"),
d3 = Object.assign({}, require("d3-geo"), require("../")),
read = require("./read"),
write = require("./write");
import {EOL} from "os";
import {program} from "commander";
import {geoPath} from "d3-geo";
import {readFileSync} from "fs";
import {dirname, resolve} from "path";
import {fileURLToPath} from "url";
import {geoQuantize} from "../src/index.js";
import read from "./read.js";
import write from "./write.js";

commander
.version(require("../package.json").version)
const version = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version;

const options = program
.version(version)
.usage("[options] [file]")
.description("Convert GeoJSON to SVG.")
.option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
Expand All @@ -18,31 +24,36 @@ commander
.option("--fill <value>", "default fill", "none")
.option("--stroke <value>", "default stroke", "black")
.option("-r, --radius <value>", "default point radius", 4.5)
.parse(process.argv);
.parse(process.argv)
.opts();

if (commander.args.length === 0) commander.args[0] = "-";
else if (commander.args.length !== 1) {
if (program.args.length === 0) program.args[0] = "-";
else if (program.args.length !== 1) {
console.error();
console.error(" error: multiple input files");
console.error();
process.exit(1);
}

var reader = read(commander.args[0], commander.newlineDelimited, transform).then(end).catch(abort),
writer = write(commander.out),
path = d3.geoPath().pointRadius(function(d) { var p = d.properties, v; return p && (v = p["point-radius"] || p.pointRadius) != null ? v : commander.radius; }),
render = commander.precision == null ? path : function(d) { return path(d3.geoQuantize(d, commander.precision)); };
var reader = read(program.args[0], options.newlineDelimited, transform).then(end),
writer = write(options.out),
path = geoPath().pointRadius(function(d) { var p = d.properties, v; return p && (v = p["point-radius"] || p.pointRadius) != null ? v : options.radius; }),
render = options.precision == null ? path : function(d) { return path(geoQuantize(d, options.precision)); };

reader.catch(error => {
console.error(error.stack);
});

writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + os.EOL
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" + os.EOL
+ "<!-- Generated by geo2svg " + require("../package.json").version + ". https://d3js.org/d3-geo-projection/ -->" + os.EOL
writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + EOL
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" + EOL
+ "<!-- Generated by geo2svg " + version + ". https://d3js.org/d3-geo-projection/ -->" + EOL
+ "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\""
+ " width=\"" + +commander.width + "\""
+ " height=\"" + +commander.height + "\""
+ " viewBox=\"0 0 " + +commander.width + " " + +commander.height + "\""
+ (commander.fill != "black" ? " fill=\"" + attr(commander.fill) + "\"" : "")
+ (commander.stroke != "none" ? " stroke=\"" + attr(commander.stroke) + "\"" : "")
+ ">" + os.EOL);
+ " width=\"" + +options.width + "\""
+ " height=\"" + +options.height + "\""
+ " viewBox=\"0 0 " + +options.width + " " + +options.height + "\""
+ (options.fill != "black" ? " fill=\"" + attr(options.fill) + "\"" : "")
+ (options.stroke != "none" ? " stroke=\"" + attr(options.stroke) + "\"" : "")
+ ">" + EOL);

function transform(d) {
var p = d.properties, v;
Expand All @@ -63,15 +74,11 @@ function transform(d) {
+ (v = render(d), v ? " d=\"" + v + "\"" : "")
+ ">"
+ ((v = p && p["title"]) != null ? "<title>" + text(v + "") + "</title>" : "")
+ "</path>" + os.EOL);
+ "</path>" + EOL);
}

function end() {
return writer.write("</svg>" + os.EOL);
}

function abort(error) {
console.error(error.stack);
return writer.write("</svg>" + EOL);
}

function text(string) {
Expand Down
44 changes: 26 additions & 18 deletions bin/geograticule → bin/geograticule.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env node

var commander = require("commander"),
graticule = require("d3-geo").geoGraticule(),
write = require("./write");
import {program} from "commander";
import {geoGraticule} from "d3-geo";
import {readFileSync} from "fs";
import {dirname, resolve} from "path";
import {fileURLToPath} from "url";
import write from "./write.js";

commander
.version(require("../package.json").version)
const version = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version;

const graticule = geoGraticule();

const options = program
.version(version)
.usage("[options]")
.description("Generate a GeoJSON graticule.")
.option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
Expand All @@ -16,29 +23,30 @@ commander
.option("--step-minor <value>", "the minor step; defaults to " + graticule.stepMinor(), parseStep)
.option("--step-major <value>", "the major step; defaults to " + graticule.stepMajor(), parseStep)
.option("--precision <value>", "the precision; defaults to " + graticule.precision(), graticule.precision)
.parse(process.argv);
.parse(process.argv)
.opts();

if (commander.args.length !== 0) {
if (program.args.length !== 0) {
console.error();
console.error(" error: unexpected arguments");
console.error();
process.exit(1);
}

if (commander.extent != null) {
if (commander.extentMinor == null) commander.extentMinor = commander.extent;
if (commander.extentMajor == null) commander.extentMajor = commander.extent;
if (options.extent != null) {
if (options.extentMinor == null) options.extentMinor = options.extent;
if (options.extentMajor == null) options.extentMajor = options.extent;
}
if (commander.step != null) {
if (commander.stepMinor == null) commander.stepMinor = commander.step;
if (commander.stepMajor == null) commander.stepMajor = commander.step;
if (options.step != null) {
if (options.stepMinor == null) options.stepMinor = options.step;
if (options.stepMajor == null) options.stepMajor = options.step;
}
if (commander.extentMinor != null) graticule.extentMinor(commander.extentMinor);
if (commander.extentMajor != null) graticule.extentMajor(commander.extentMajor);
if (commander.stepMinor != null) graticule.stepMinor(commander.stepMinor);
if (commander.stepMajor != null) graticule.stepMajor(commander.stepMajor);
if (options.extentMinor != null) graticule.extentMinor(options.extentMinor);
if (options.extentMajor != null) graticule.extentMajor(options.extentMajor);
if (options.stepMinor != null) graticule.stepMinor(options.stepMinor);
if (options.stepMajor != null) graticule.stepMajor(options.stepMajor);

var writer = write(commander.out);
var writer = write(options.out);
writer.write(JSON.stringify(graticule()) + "\n");
writer.end().catch(abort);

Expand Down
53 changes: 0 additions & 53 deletions bin/geoproject

This file was deleted.

Loading