Skip to content

Commit

Permalink
Add Typescript definition file (#409)
Browse files Browse the repository at this point in the history
* Create initial type definition file

* Improve types

* Restore nul.json

Can't download or create this file on Windows

* Restore nul.topo.json

Can't download or create this file on Windows
  • Loading branch information
JasonKaz authored and markmarkoh committed Aug 21, 2017
1 parent 1f3ba44 commit db5d023
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ npm-debug.log
bower_components
rel
tmp
.idea
.idea
/.vs
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"dependencies": {
"d3": "^3.5.6",
"topojson": "^1.6.19"
"topojson": "^1.6.19",
"@types/d3": "3.5.38"
},
"devDependencies": {
"grunt": "~0.4.1",
Expand All @@ -32,5 +33,6 @@
"grunt-replace": "~0.4.4",
"grunt-sync-pkg": "^0.1.2",
"grunt-text-replace": "~0.3.6"
}
},
"types": "./src/index.d.ts"
}
132 changes: 132 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/// <reference types="d3" />

declare interface DataMapOptions {
element: HTMLElement;
scope?: string;
geographyConfig?: DataMapGeographyConfigOptions;
bubblesConfig?: DataMapBubblesConfigOptions;
arcConfig?: DataMapArcConfigOptions;
setProjection?: (element: HTMLElement, options: DataMapOptions) => DataMapProjection;
fills?: { defaultFill?: string, [key: string]: string };
done?: (datamap: {
svg: d3.Selection<any>,
options: DataMapOptions,
path: d3.geo.Path;
projection: d3.geo.Projection;
}) => void;
responsive?: boolean;
projection?: string;
height?: null | number;
width?: null | number;
dataType?: "json" | "csv";
dataUrl?: null | string;
data?: any;
filters?: any;
aspectRatio?: number;
projectionConfig?: { rotation: any[] };
}

declare interface DataMapGeographyConfigOptions {
dataUrl?: null | string;
hideAntarctica?: boolean;
hideHawaiiAndAlaska?: boolean;
borderWidth?: number;
borderOpacity?: number;
borderColor?: string;
popupTemplate?: (geography: DataMapGeographyData, data: any) => string;
popupOnHover?: boolean;
highlightOnHover?: boolean;
highlightFillColor?: string;
highlightBorderColor?: string;
highlightBorderWidth?: number;
highlightBorderOpacity?: number;
}

declare interface DataMapBubblesConfigOptions {
borderWidth?: number;
borderOpacity?: number;
borderColor?: string;
popupOnHover?: boolean;
radius?: null | number,
popupTemplate?: (geography: DataMapGeographyData, data: DataMapBubbleDatum) => string;
fillOpacity?: number;
animate?: boolean,
highlightOnHover?: boolean;
highlightFillColor?: string;
highlightBorderColor?: string;
highlightBorderWidth?: number;
highlightBorderOpacity?: number;
highlightFillOpacity?: number;
exitDelay?: number;
key?: any; //JSON.stringify
}

declare interface DataMapArcConfigOptions {
strokeColor?: string;
strokeWidth?: number;
arcSharpness?: number;
animationSpeed?: number;
popupOnHover?: boolean;
popupTemplate?: (geography: DataMapGeographyData, data: any) => string;
}

declare interface DataMapGeographyData {
properties: { name: string };
}

declare interface DataMapProjection {
path: d3.geo.Path;
projection: d3.geo.Projection;
}

declare interface DataMapBubbleDatum {
latitude: number;
longitude: number;
radius: number;
fillKey?: string;
borderColor?: string;
borderWidth?: number;
borderOpacity?: number;
fillOpacity?: number;
[key: string]: any;
}

declare interface DataMapLabelOptions {
labelColor?: string;
lineWidth?: number;
fontSize?: number;
fontFamily?: string;
customLabelText: any;
}

declare interface DataMapArcDatum {
origin: string | {
latitude: number, longitude: number
};
destination: string | {
latitude: number, longitude: number
};
options?: {
strokeWidth?: number;
strokeColor?: string;
greatArc?: boolean;
};
}

declare class DataMap {
constructor(options: DataMapOptions);
legend(): void;
updateChoropleth(data: string | any | null, options?: { reset: boolean, data: any }): void;
bubbles(data: ReadonlyArray<DataMapBubbleDatum>, opts?: DataMapGeographyConfigOptions): void;
labels(options?: DataMapLabelOptions): void;
resize(): void;
arc(data: ReadonlyArray<DataMapArcDatum>, options?: DataMapArcConfigOptions): void;
latLngToXY(lat: number, lng: number): any;
addLayer(className: string, id: string, first: boolean): SVGElement;
updatePopup(element: HTMLElement, d: DataMapGeographyData, options: DataMapGeographyConfigOptions): string;
addPlugin(name: string, pluginFn: Function): void;
}

interface JQuery {
datamaps(options: DataMapOptions): void;
}
2 changes: 1 addition & 1 deletion src/js/data/nul.topo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"Topology","objects":{"nul":{"type":"GeometryCollection","geometries":[{"type":"Polygon","properties":{"name":null},"id":"-99","arcs":[[0]]}]}},"arcs":[[[0,9999],[9999,0],[0,-9999],[-9999,0],[0,9999]]],"transform":{"scale":[9.053905432543252e-10,9.053905432543252e-10],"translate":[-0.000004544999911,-0.000004496999935]}}
{"type":"Topology","objects":{"nul":{"type":"GeometryCollection","geometries":[{"type":"Polygon","properties":{"name":null},"id":"-99","arcs":[[0]]}]}},"arcs":[[[0,9999],[9999,0],[0,-9999],[-9999,0],[0,9999]]],"transform":{"scale":[9.053905432543252e-10,9.053905432543252e-10],"translate":[-0.000004544999911,-0.000004496999935]}}
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"typeRoots": [ "./node_modules/@types" ],
"types": [ "d3" ]
}
}

0 comments on commit db5d023

Please sign in to comment.