Skip to content

Commit

Permalink
Restructure as bundle.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 12, 2016
1 parent f16850b commit 98243ff
Show file tree
Hide file tree
Showing 62 changed files with 128 additions and 5,310 deletions.
13 changes: 0 additions & 13 deletions .eslintrc

This file was deleted.

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
build/
dist/
node_modules
npm-debug.log
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.sublime-*
build/
dist/*.zip
test/
91 changes: 30 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ To further reduce file size, TopoJSON can use quantized delta-encoding for integ

As a result, TopoJSON is substantially more compact than GeoJSON, frequently offering a reduction of 80% or more even without simplification. Yet encoding topology also has numerous useful applications for maps and visualization above! It allows [topology-preserving shape simplification](https://github.com/topojson/topojson-simplify), which ensures that adjacent features remain connected after simplification; this applies even across feature collections, such as simultaneous consistent simplification of state and county boundaries. Topology can also be used for [Dorling](http://www.ncgia.ucsb.edu/projects/Cartogram_Central/types.html) or [hexagonal cartograms](http://pitchinteractive.com/latest/tilegrams-more-human-maps/), as well as other techniques that need shared boundary information such as [automatic map coloring](https://bl.ocks.org/4188334).

See also:

* [topojson-client](https://github.com/topojson/topojson-client)
* [topojson-simplify](https://github.com/topojson/topojson-simplify)
* [topojson-specification](https://github.com/topojson/topojson-specification)

## Installing

If you use NPM, `npm install topojson`. Otherwise, download the [latest release](https://github.com/topojson/topojson/releases/latest). You can also load directly from [unpkg](https://unpkg.com). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `topojson` global is exported:
Expand All @@ -32,65 +26,40 @@ var topology = topojson.topology({foo: geojson});

## API Reference

<a name="topology" href="#topology">#</a> topojson.<b>topology</b>(<i>objects</i>[, <i>quantization</i>])

Converts the specified [GeoJSON *objects*](http://geojson.org/geojson-spec.html#geojson-objects) to TopoJSON. The input *objects* are modified **in-place** and should not be referenced after calling this method; this is a destructive operation!

If a *quantization* parameter is specified, the input geometry is quantized prior to computing the topology, and the returned topology is quantized, and its arcs are [delta-encoded](https://github.com/topojson/topojson-specification/blob/master/README.md#213-arcs). Quantization is recommended to improve the quality of the topology if the input geometry is messy (*i.e.*, small floating point error means that adjacent boundaries do not have identical values); typical values are powers of ten, such as 1e4, 1e5 or 1e6. See also [topojson.quantize](https://github.com/topojson/topojson-client/blob/master/README.md#quantize) to quantize a topology after it has been constructed, without altering the topological relationships.

## Command-Line Reference

### geo2topo

<a name="geo2topo" href="#geo2topo">#</a> <b>geo2topo</b> [<i>options…</i>] &lt;<i>name</i>=<i>file</i>&gt;[<>](https://github.com/topojson/topojson/blob/master/bin/geo2topo "Source")

Converts one or more GeoJSON objects to an output topology. For example, to convert the us-states.json GeoJSON FeatureCollection to a TopologyJSON topology with the “states” object in us.json:

```
geo2topo states=us-states.json > us.json
```

For convenience, you can omit the object name and specify only the file *name*; the object name will be the basename of the file, with the directory and extension removed. For example, to convert the states.json GeoJSON FeatureCollection to a TopologyJSON topology with the “states” object in us.json:

```
geo2topo states.json > us.json
```

See also [topo2geo](https://github.com/topojson/topojson-client/blob/master/README.md#topo2geo).

<a name="geo2topo_help" href="#geo2topo_help">#</a> geo2topo <b>-h</b>
<br><a href="#geo2topo_help">#</a> geo2topo <b>--help</b>

Output usage information.

<a name="geo2topo_version" href="#geo2topo_version">#</a> geo2topo <b>-V</b>
<br><a href="#geo2topo_version">#</a> geo2topo <b>--version</b>

Output the version number.
### Generation (topojson-server)

<a name="geo2topo_newline_delimited" href="#geo2topo_newline_delimited">#</a> geo2topo <b>-n</b>
<br><a href="#geo2topo_newline_delimited">#</a> geo2topo <b>--newline-delimited</b>
* [topojson.topology](https://github.com/topojson/topojson-server/blob/master/README.md#topology) - convert GeoJSON to TopoJSON.

Output [newline-delimited JSON](http://ndjson.org/), with one feature per line.
### Simplification (topojson-simplify)

<a name="geo2topo_in" href="#geo2topo_in">#</a> geo2topo <b>-i</b> <i>file</i>
<br><a href="#geo2topo_in">#</a> geo2topo <b>--in</b> <i>file</i>
* [topojson.presimplify](https://github.com/topojson/topojson-simplify/blob/master/README.md#presimplify) - prepare TopoJSON for simplification.
* [topojson.simplify](https://github.com/topojson/topojson-simplify/blob/master/README.md#simplify) - simplify geometry by removing coordinates.
* [topojson.quantile](https://github.com/topojson/topojson-simplify/blob/master/README.md#quantile) - compute a simplification threshold.
* [topojson.filter](https://github.com/topojson/topojson-simplify/blob/master/README.md#filter) - remove rings from a topology.
* [topojson.filterAttached](https://github.com/topojson/topojson-simplify/blob/master/README.md#filterAttached) - remove detached rings.
* [topojson.filterWeight](https://github.com/topojson/topojson-simplify/blob/master/README.md#filterWeight) - remove small rings.
* [topojson.planarRingArea](https://github.com/topojson/topojson-simplify/blob/master/README.md#planarRingArea) - compute the planar area of a ring.
* [topojson.planarTriangleArea](https://github.com/topojson/topojson-simplify/blob/master/README.md#planarTriangleArea) - compute the planar area of a triangle.
* [topojson.sphericalRingArea](https://github.com/topojson/topojson-simplify/blob/master/README.md#sphericalRingArea) - compute the spherical area of a ring.
* [topojson.sphericalTriangleArea](https://github.com/topojson/topojson-simplify/blob/master/README.md#sphericalTriangleArea) - compute the spherical area of a triangle.

Specify the input TopoJSON file name. Defaults to “-” for stdin.
### Manipulation (topojson-client)

<a name="geo2topo_list" href="#geo2topo_list">#</a> geo2topo <b>-l</b>
<br><a href="#geo2topo_list">#</a> geo2topo <b>--list</b>
* [topojson.feature](https://github.com/topojson/topojson-client/blob/master/README.md#feature) - convert TopoJSON to GeoJSON.
* [topojson.merge](https://github.com/topojson/topojson-client/blob/master/README.md#merge) - merge TopoJSON geometry and convert to GeoJSON polygons.
* [topojson.mergeArcs](https://github.com/topojson/topojson-client/blob/master/README.md#mergeArcs) - merge TopoJSON geometry to form polygons.
* [topojson.mesh](https://github.com/topojson/topojson-client/blob/master/README.md#mesh) - mesh TopoJSON geometry and convert to GeoJSON lines.
* [topojson.meshArcs](https://github.com/topojson/topojson-client/blob/master/README.md#meshArcs) - mesh TopoJSON geometry to form lines.
* [topojson.neighbors](https://github.com/topojson/topojson-client/blob/master/README.md#neighbors) - compute adjacent features.
* [topojson.bbox](https://github.com/topojson/topojson-client/blob/master/README.md#bbox) - compute the bounding box of a topology.
* [topojson.quantize](https://github.com/topojson/topojson-client/blob/master/README.md#quantize) - round coordinates, reducing precision.
* [topojson.transform](https://github.com/topojson/topojson-client/blob/master/README.md#transform) - remove delta-encoding and apply a transform.
* [topojson.untransform](https://github.com/topojson/topojson-client/blob/master/README.md#untransform) - apply delta-encoding and remove a transform.

List the names of the objects in the input topology, and then exit. For example, this:

```
geo2topo -l < us.json
```

Will output this:
## Command-Line Reference

```
counties
states
nation
```
* [geo2topo](https://github.com/topojson/topojson-server/blob/master/README.md#geo2topo) - convert GeoJSON to TopoJSON.
* [toposimplify](https://github.com/topojson/topojson-simplify/blob/master/README.md#toposimplify) - simplify TopoJSON, removing coordinates.
* [topo2geo](https://github.com/topojson/topojson-client/blob/master/README.md#topo2geo) - convert TopoJSON to GeoJSON.
* [topomerge](https://github.com/topojson/topojson-client/blob/master/README.md#topomerge) - merge TopoJSON geometry, and optionally filter.
* [topoquantize](https://github.com/topojson/topojson-client/blob/master/README.md#topoquantize) - round TopoJSON, reducing precision.
125 changes: 0 additions & 125 deletions bin/geo2topo

This file was deleted.

30 changes: 29 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
export {default as topology} from "./src/topology";
export {
topology
} from "topojson-server";

export {
filter,
filterAttached,
filterWeight,
planarRingArea,
planarTriangleArea,
presimplify,
quantile,
simplify,
sphericalRingArea,
sphericalTriangleArea
} from "topojson-simplify";

export {
bbox,
feature,
merge,
mergeArcs,
mesh,
meshArcs,
neighbors,
quantize,
transform,
untransform
} from "topojson-client";
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "topojson",
"version": "2.0.0",
"description": "Convert GeoJSON to TopoJSON for smaller files and the power of topology!",
"version": "2.1.0",
"description": "An extension to GeoJSON that encodes topology.",
"keywords": [
"topojson",
"geojson"
Expand All @@ -12,30 +12,38 @@
"name": "Mike Bostock",
"url": "https://bost.ocks.org/mike"
},
"main": "dist/topojson.js",
"main": "dist/topojson.node.js",
"browser": "dist/topojson.js",
"module": "index",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": "https://github.com/topojson/topojson.git"
},
"bin": {
"geo2topo": "bin/geo2topo"
"geo2topo": "node_modules/topojson-server/bin/geo2topo",
"toposimplify": "node_modules/topojson-simplify/bin/toposimplify",
"topo2geo": "node_modules/topojson-client/bin/topo2geo",
"topomerge": "node_modules/topojson-client/bin/topomerge",
"topoquantize": "node_modules/topojson-client/bin/topoquantize"
},
"scripts": {
"pretest": "rm -rf dist && mkdir dist && rollup --banner \"$(preamble)\" -f umd -n topojson -o dist/topojson.js -- index.js && rollup -f cjs -o build/topojson-internals.js -- test/internals.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" -cm -o dist/topojson.min.js -- dist/topojson.js",
"postpublish": "git push && git push --tags && zip -j dist/topojson.zip -- LICENSE.md README.md dist/topojson.js dist/topojson.min.js"
},
"dependencies": {
"commander": "2"
"pretest": "rm -rf dist && mkdir dist && node rollup.node",
"test": "tape 'test/**/*-test.js'",
"prepublish": "npm run test && rollup -c --banner \"$(preamble)\" -f umd -n topojson -o dist/topojson.js -- index.js && uglifyjs --preamble \"$(preamble)\" dist/topojson.js -c negate_iife=false -m -o dist/topojson.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp -v README.md LICENSE.md dist/topojson.js dist/topojson.min.js ../topojson-bower && cd ../topojson-bower && git add README.md LICENSE.md topojson.js topojson.min.js && git commit -m \"Release $VERSION.\" && git tag -am \"Release $VERSION.\" v${VERSION} && git push && git push --tags && cd - && cp dist/topojson.js ../d3.github.com/topojson.v2.js && cp dist/topojson.min.js ../d3.github.com/topojson.v2.min.js && cd ../d3.github.com && git add topojson.v2.js topojson.v2.min.js && git commit -m \"topojson ${VERSION}\" && git push && cd - && zip -j dist/topojson.zip -- LICENSE.md README.md dist/topojson.js dist/topojson.min.js"
},
"devDependencies": {
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.36",
"rollup-plugin-ascii": "0.0",
"rollup-plugin-node-resolve": "2",
"tape": "4",
"topojson-client": "2",
"uglify-js": "2"
},
"dependencies": {
"topojson-client": "2.1.0",
"topojson-server": "2.0.0",
"topojson-simplify": "2.0.0"
}
}
6 changes: 6 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ascii from "rollup-plugin-ascii";
import node from "rollup-plugin-node-resolve";

export default {
plugins: [node(), ascii()]
};
22 changes: 22 additions & 0 deletions rollup.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var fs = require("fs"),
rollup = require("rollup"),
dependencies = require("./package.json").dependencies;

rollup.rollup({
entry: "index.js",
external: Object.keys(dependencies)
}).then(function(bundle) {
var code = bundle.generate({
format: "cjs"
}).code;
return new Promise(function(resolve, reject) {
fs.writeFile("dist/topojson.node.js", code, "utf8", function(error) {
if (error) return reject(error);
else resolve();
});
});
}).catch(abort);

function abort(error) {
console.error(error.stack);
}
Loading

0 comments on commit 98243ff

Please sign in to comment.