Explorar o código

Add typescript type information.

rongmz %!s(int64=5) %!d(string=hai) anos
pai
achega
840eb397bf
Modificáronse 4 ficheiros con 47 adicións e 0 borrados
  1. 1 0
      example/src/App.js
  2. 1 0
      package.json
  3. 40 0
      types/index.d.ts
  4. 5 0
      types/utils.d.ts

+ 1 - 0
example/src/App.js

@@ -7,6 +7,7 @@ export default () => {
 
   const [loading, setLoading] = React.useState(true);
   const progressRef = React.useRef(null);
+  /** @type {React.MutableRefObject<StockHeatmap>} */
   const heatmapRef = React.useRef(null);
   const [windowDim, setWindowDim] = React.useState([0, 0]);
 

+ 1 - 0
package.json

@@ -26,6 +26,7 @@
   "engines": {
     "node": ">=10"
   },
+  "types": "./types/index.d.ts",
   "scripts": {
     "build": "microbundle-crl --no-compress --format modern,cjs",
     "start": "microbundle-crl watch --no-compress --format modern,cjs",

+ 40 - 0
types/index.d.ts

@@ -0,0 +1,40 @@
+import React from 'react';
+import * as d3Scale from 'd3-scale';
+import * as d3Array from 'd3-array';
+import * as d3Color from 'd3-color';
+import * as d3Format from 'd3-format';
+import * as d3Interpolate from 'd3-interpolate';
+import * as d3Shape from 'd3-shape';
+import * as d3Zoom from 'd3-zoom';
+import * as d3Timer from 'd3-timer';
+import * as d3Ease from 'd3-ease';
+
+export const d3: typeof d3Scale & typeof d3Array & typeof d3Color & typeof d3Format & typeof d3Interpolate & typeof d3Shape & typeof d3Zoom & typeof d3Ease & typeof d3Timer;
+/**
+ * Stock Heatmap
+ * @author Rounak Saha
+ *
+ * © Copyright 2020, Rounak Saha
+ */
+export default class StockHeatmap extends React.Component<{
+    /** The width of the heatmap */
+    width: number,
+    /** The height of the heatmap */
+    height: number
+}> {
+    /**
+     * Set Data for the Heatmap to generate
+     * @param {any[]} data The data to set
+     */
+    setData: (data: any[]) => void;
+    /**
+     * Add as extra data to existing data array.
+     * @param {any} data
+     */
+    addData: (data: any) => void;
+    /**
+     * This sets the Heatmap Zoom level aka. window.
+     * @param {number} zoom The seconds to zoom into
+     */
+    setZoomLevel: (zoom: number) => void;
+}

+ 5 - 0
types/utils.d.ts

@@ -0,0 +1,5 @@
+export function extractBidPrices(data: any[]): number[];
+export function extractBidVolumes(data: any): number[];
+export function extractMaxVolume(data: any): number;
+export function extractMaxTradedVolume(data: any[]): number;
+export function zoomTimeFormat(seconds: number): string;