diff --git a/.gitignore b/.gitignore index c580c3e2..bc5d855a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ typings/* !typings/created/ # File types +*.DS_Store *.log *.tgz .#* diff --git a/package.json b/package.json index 3313d606..52d4806f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "build-docs": "typedoc --mode file --target ES5 --module commonjs --theme default --excludeExternals --name MapillaryJS --out docs/", "build-min": "browserify src/Mapillary.ts --plugin tsify --transform brfs --standalone Mapillary | uglifyjs > dist/mapillary-js.min.js", "clean": "rm -rf dist && mkdir dist", + "clean-typings": "rm -rf typings/modules && rm -rf typings/globals && rm typings/index.d.ts", "copy-assets": "cp -a styles/*.svg dist", "lint": "npm run lint-spec && npm run lint-src", "lint-spec": "tslint -c tslint.json ./spec/**/*.ts ./spec/**/**/*.ts", diff --git a/src/graph/Graph.ts b/src/graph/Graph.ts index 33a24bbc..de5c7e61 100644 --- a/src/graph/Graph.ts +++ b/src/graph/Graph.ts @@ -36,7 +36,7 @@ export class Graph { private _sequences: SequenceHash; private _sequenceHashes: {[skey: string]: SequenceHash}; - private _graph: any; + private _graph: graphlib.Graph; private _nodeIndex: rbush.RBush; private _unWorthyNodes: {[key: string]: boolean}; @@ -55,7 +55,7 @@ export class Graph { this._sequences = {}; this._sequenceHashes = {}; this._nodeIndex = rbush(16, [".lon", ".lat", ".lon", ".lat"]); - this._graph = new graphlib.Graph({multigraph: true}); + this._graph = new graphlib.Graph({ multigraph: true }); this._unWorthyNodes = {}; this._edgeCalculator = new EdgeCalculator(); this._spatial = new Spatial(); @@ -159,13 +159,13 @@ export class Graph { * @return {IEdge} */ public getEdges(node: Node): IEdge[] { - let outEdges: any[] = this._graph.outEdges(node.key); + let outEdges: graphlib.Edge[] = this._graph.outEdges(node.key); - return _.map(outEdges, (outEdge: any) => { - let edge: any = this._graph.edge(outEdge); + return _.map(outEdges, (outEdge: graphlib.Edge) => { + let data: IEdgeData = this._graph.edge(outEdge); return { - data: edge, + data: data, from: outEdge.v, to: outEdge.w, }; @@ -195,7 +195,7 @@ export class Graph { } public nextKey(node: Node, dir: EdgeDirection): string { - let outEdges: any[] = this._graph.outEdges(node.key); + let outEdges: graphlib.Edge[] = this._graph.outEdges(node.key); for (let outEdge of outEdges) { let edgeData: IEdgeData = this._graph.edge(outEdge); @@ -214,14 +214,9 @@ export class Graph { * @param {IEdge[]} edges */ private _addEdgesToNode(node: Node, edges: IEdge[]): void { - let outEdges: any[] = this._graph.outEdges(node.key); + let outEdges: graphlib.Edge[] = this._graph.outEdges(node.key); - for (let outEdgeKey in outEdges) { - if (!outEdges.hasOwnProperty(outEdgeKey)) { - continue; - } - - let outEdge: any = outEdges[outEdgeKey]; + for (let outEdge of outEdges) { this._graph.removeEdge(outEdge); } diff --git a/typings.json b/typings.json index 3d9a1dd8..6f441a10 100644 --- a/typings.json +++ b/typings.json @@ -7,7 +7,6 @@ "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504", "falcor": "file:typings/created/falcor/falcor.d.ts", "falcor-http-datasource": "file:typings/created/falcor-http-datasource/falcor-http-datasource.d.ts", - "graphlib": "file:typings/created/graphlib/graphlib.d.ts", "lib": "file:typings/created/lib/lib.d.ts", "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#aed176536a202b9a2475ce1989ea6d2d0226a185", "rest": "github:DefinitelyTyped/DefinitelyTyped/rest/rest.d.ts#001ca36ba58cef903c4c063555afb07bbc36bb58", @@ -18,6 +17,7 @@ }, "dependencies": { "earcut": "file:typings/created/earcut/earcut.d.ts", + "graphlib": "file:typings/created/graphlib/graphlib.d.ts", "latlon-geohash": "file:typings/created/latlon-geohash/latlon-geohash.d.ts", "pbf": "file:typings/created/pbf/pbf.d.ts", "rbush": "file:typings/created/rbush/rbush.d.ts", diff --git a/typings/created/graphlib/graphlib.d.ts b/typings/created/graphlib/graphlib.d.ts index 913cfa72..296ba45d 100644 --- a/typings/created/graphlib/graphlib.d.ts +++ b/typings/created/graphlib/graphlib.d.ts @@ -1,13 +1,28 @@ -declare module "graphlib" { - export = graphlib; +declare module graphlib { + interface Options { + compound?: boolean; + directed?: boolean; + multigraph?: boolean; + } - module graphlib { - export class Graph { - constructor(); - constructor(params: any); - hasNode(key: string): any; - node(key: string): any; - setNode(key: string, node: any): any; - } + interface Edge { + v: string; + w: string; + name?: string; + } + + class Graph { + constructor(options: Options); + + setNode(v: string, label?: TNodeLabel): void; + hasNode(v: string): boolean; + node(v: string): TNodeLabel; + + setEdge(v: string, w: string, label?: TEdgeLabel, name?: string): void; + outEdges(v: string, w?: string): Edge[]; + edge(edge: Edge): TEdgeLabel; + removeEdge(edge: Edge): void; } } + +export = graphlib;