diff --git a/.gitignore b/.gitignore index 35a538d5..d4cf2d2a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ npm-debug.log bower_components rel tmp -.idea \ No newline at end of file +.idea +/.vs \ No newline at end of file diff --git a/package.json b/package.json index 1e800bcd..e04516fc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 00000000..1700fb09 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,132 @@ +/// + +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, + 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, opts?: DataMapGeographyConfigOptions): void; + labels(options?: DataMapLabelOptions): void; + resize(): void; + arc(data: ReadonlyArray, 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; +} \ No newline at end of file diff --git a/src/js/data/nul.topo.json b/src/js/data/nul.topo.json index c58ff796..70bec3b5 100644 --- a/src/js/data/nul.topo.json +++ b/src/js/data/nul.topo.json @@ -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]}} \ No newline at end of file +{"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]}} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..350b71bf --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "typeRoots": [ "./node_modules/@types" ], + "types": [ "d3" ] + } +} \ No newline at end of file