Sfoglia il codice sorgente

修复数据延迟问题

skyffire 1 anno fa
parent
commit
c8b58364d1
3 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 1 2
      example/src/App.js
  2. 2 1
      src/index.js
  3. 2 0
      types/index.d.ts

+ 1 - 2
example/src/App.js

@@ -66,6 +66,7 @@ function parseStockData(data) {
       side: side
     },
     ts: formatTimestamp(time),
+    time: time,
     tradingsymbol: "XYZ123",
     pendingOrders: []
   };
@@ -89,8 +90,6 @@ export default () => {
     ws.onmessage = function(event) {
       const message = JSON.parse(event.data);
 
-      console.log(message)
-
       let stock = parseStockData(message)
 
       ref.addData(stock)

+ 2 - 1
src/index.js

@@ -620,6 +620,7 @@ export default class StockHeatmap extends React.Component {
    * @param {any} data
    */
   addData = (data) => {
+
     if (typeof (data) === 'object') {
       this.data.push(data);
       this.updateWindowedData();
@@ -641,7 +642,7 @@ export default class StockHeatmap extends React.Component {
   moveDataWindow = (position) => {
     if (position !== this.windowPosition && position > -1 && position < this.data.length - this.windowLength) {
       // move position only if within valid range
-      this.windowedData = this.data.slice(position, position + this.windowLength);
+      this.windowedData = this.data.slice(position, position + this.windowLength + 1);
       this.windowPosition = position;
       if (this.windowPosition === this.data.length - this.windowLength - 1) {
         // enable auto scroll

+ 2 - 0
types/index.d.ts

@@ -79,6 +79,8 @@ export interface StockData {
   },
   /** Timestamp for this data point HH:mm:ss */
   ts: string,
+  /** UpdateTime */
+  time: number,
   /** The Stock symbol */
   tradingsymbol: string,
   /** Currently pending orders for this data point */