فهرست منبع

可以暂停图标,还有play

skyffire 1 سال پیش
والد
کامیت
e05dae903c
2فایلهای تغییر یافته به همراه16 افزوده شده و 2 حذف شده
  1. 4 0
      example/src/App.js
  2. 12 2
      src/index.js

+ 4 - 0
example/src/App.js

@@ -153,6 +153,10 @@ export default () => {
           if (heatmapRef.current !== null) heatmapRef.current.setZoomLevel(60 * 60)
         }}>zoom 60 minutes
         </button>
+        <button onClick={() => {
+          if (heatmapRef.current !== null) heatmapRef.current.autoScroll = true
+        }}> play
+        </button>
         {/* <button onClick={() => { */}
         {/*   const HHmmss = window.prompt('Enter HH:mm:ss', '00:00:00'); */}
         {/*   let split = HHmmss.split(':'); */}

+ 12 - 2
src/index.js

@@ -148,6 +148,8 @@ export default class StockHeatmap extends React.Component {
       // const moveDataPointDirection = dragLength >= 0 ? 'right' : 'left';
       // console.log('drag x=', dragLength, moveDataPointsCount, this.windowPosition);
       this.moveDataWindow(this.windowPosition + moveDataPointsCount * (dragLength >= 0 ? -1 : 1));
+
+      this.autoScroll = false
     } else {
       // const canvas = this.canvasRef.current;
       // if (!canvas) return;
@@ -620,7 +622,6 @@ export default class StockHeatmap extends React.Component {
    * @param {any} data
    */
   addData = (data) => {
-
     if (typeof (data) === 'object') {
       this.data.push(data);
       this.updateWindowedData();
@@ -632,7 +633,9 @@ export default class StockHeatmap extends React.Component {
    */
   updateWindowedData = () => {
     // console.log('window data updated');
-    this.moveDataWindow(this.data.length - this.windowLength - 1);
+    if (this.autoScroll) {
+      this.moveDataWindow(this.data.length - this.windowLength - 1);
+    }
   }
 
   /**
@@ -643,6 +646,13 @@ export default class StockHeatmap extends React.Component {
     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 + 1);
+
+      // 延迟日志
+      if (this.windowedData.length > 1) {
+        let last = this.windowedData[this.windowedData.length - 1]
+        console.log(new Date().getTime() - last.time, last)
+      }
+
       this.windowPosition = position;
       if (this.windowPosition === this.data.length - this.windowLength - 1) {
         // enable auto scroll