Kaynağa Gözat

修改鼠标拖拽暂停逻辑,让它更灵敏

skyffire 1 yıl önce
ebeveyn
işleme
dfe6bdeb98
1 değiştirilmiş dosya ile 7 ekleme ve 5 silme
  1. 7 5
      src/index.js

+ 7 - 5
src/index.js

@@ -151,18 +151,20 @@ export default class StockHeatmap extends React.Component {
    * @param {MouseEvent} e
    */
   eventMouseMove = (e) => {
+    // 判断鼠标拖拽距离
+    const dragLength = e.x - this.mouseDownX;
+    if (this.isMouseDown && dragLength > 60) {
+      this.props.toggleAutoScroll(false)
+    }
+
+    // 其他事件处理
     if (this.isMouseDown && this.xScale) {
       // Mouse drag, scroll the time series
-      const dragLength = e.x - this.mouseDownX;
       const moveDataPointsCount = Math.floor(Math.abs(dragLength) / this.xScale.bandwidth());
       if (moveDataPointsCount > 0) this.mouseDownX = e.x;
       // const moveDataPointDirection = dragLength >= 0 ? 'right' : 'left';
       // console.log('drag x=', dragLength, moveDataPointsCount, this.windowPosition);
       this.moveDataWindow(this.windowPosition + moveDataPointsCount * (dragLength >= 0 ? -1 : 1));
-
-      if (dragLength > 60) {
-        this.props.toggleAutoScroll(false)
-      }
     } else {
       if (e.clientX < this.defaults.hmWidth() && e.clientY < this.defaults.hmHeight()) {
         this.mouse = {