
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
 * AUTO-GENERATED FILE. DO NOT MODIFY.
 */

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import * as globalListener from './globalListener.js';
import ComponentView from '../../view/Component.js';
var makeDispatchAction = globalListener.makeDispatchAction;
var AxisPointerView = /** @class */function (_super) {
  __extends(AxisPointerView, _super);
  function AxisPointerView() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.type = AxisPointerView.type;
    _this.xLock = false;
    return _this;
  }
  AxisPointerView.prototype.render = function (globalAxisPointerModel, ecModel, api) {
    var _this = this;
    var _a, _b;
    var xAxisModel = ecModel.getComponent('xAxis');
    var yAxisModel = ecModel.getComponent('yAxis');
    var globalTooltipModel = ecModel.getComponent('tooltip');
    var triggerOn = globalAxisPointerModel.get('triggerOn') || globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click|mousewheel';
    var playbackSelectModel = ecModel.getComponent('playbackSelect');
    // const magnet = globalTooltipModel?.get('magnet');
    // const updatePointDisable = globalTooltipModel?.get('updatePointDisable');
    var payload = ecModel.getUpdatePayload();
    var isDataZoom = (payload === null || payload === void 0 ? void 0 : payload.type) === 'dataZoom';
    // Register global listener in AxisPointerView to enable
    // AxisPointerView to be independent to Tooltip.
    var handleAxisPointer = function (currTrigger, e, dispatchAction) {
      var _a;
      if (currTrigger === 'mousedown') {
        _this.xLock = true;
      }
      if (currTrigger === 'mouseup') {
        _this.xLock = false;
      }
      var updatePointDisable = globalTooltipModel && globalTooltipModel.option.updatePointDisable;
      if (((_a = e) === null || _a === void 0 ? void 0 : _a.preventAxisPointer) || updatePointDisable || (playbackSelectModel === null || playbackSelectModel === void 0 ? void 0 : playbackSelectModel.option.show) || globalAxisPointerModel.option.updatePointDisable) {
        return;
      }
      if (triggerOn !== 'none' && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)) {
        var x = e && e.offsetX;
        var y = e && e.offsetY;
        var lastXIndex = xAxisModel === null || xAxisModel === void 0 ? void 0 : xAxisModel.get('axisPointer').value;
        // todo 拖拽的时候不想这个线动 先这样处理
        if (e && _this.xLock && typeof lastXIndex === 'number') {
          var dataZoomModal = ecModel.getComponent('dataZoom');
          var zoomDisabled = dataZoomModal ? dataZoomModal.get('disabled') || dataZoomModal.get('moveOnMouseMove') === false : true;
          if (!zoomDisabled) {
            x = xAxisModel.axis.toGlobalCoord(xAxisModel.axis.dataToCoord(lastXIndex));
          }
        }
        dispatchAction({
          type: 'updateAxisPointer',
          currTrigger: currTrigger,
          x: x,
          y: y
        });
      }
    };
    // this.lock = false;
    // todo 当进行dataZoom的时候也需要更新axisPointer
    if (isDataZoom) {
      var dispatch = makeDispatchAction(api);
      var event_1 = (_b = (_a = payload.batch) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.event;
      if ((event_1 === null || event_1 === void 0 ? void 0 : event_1.originX) || (event_1 === null || event_1 === void 0 ? void 0 : event_1.originY)) {
        handleAxisPointer('mousemove', {
          offsetX: event_1.originX,
          offsetY: event_1.originY
        }, dispatch.dispatchAction);
      }
    }
    globalListener.register('axisPointer', api, handleAxisPointer);
  };
  AxisPointerView.prototype.remove = function (ecModel, api) {
    globalListener.unregister('axisPointer', api);
  };
  AxisPointerView.prototype.dispose = function (ecModel, api) {
    globalListener.unregister('axisPointer', api);
  };
  AxisPointerView.type = 'axisPointer';
  return AxisPointerView;
}(ComponentView);
export default AxisPointerView;