
/*
* 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 ComponentView from "../../view/Component.js";
import TradeDayLine from "./TradeDayLine.js";
// const getRectFill = (color: ZRColor) => {
//     if (typeof color !== 'string') {
//         return '#000'
//     }
//     return getIsLightColor(color) ? '#fff' : '#000';
// }
// const r = 15;
var optimizeX = function (x, lineWidth) {
  return lineWidth % 2 === 0 ? x : Math.floor(x) + 0.5;
};
var TradeDayView = /** @class */function (_super) {
  __extends(TradeDayView, _super);
  function TradeDayView() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.type = TradeDayView.type;
    return _this;
  }
  TradeDayView.prototype.init = function (ecModel, api) {
    this._api = api;
  };
  TradeDayView.prototype.render = function (tradeDayModel, ecModel, api) {
    this.group.removeAll();
    if (!tradeDayModel.get("show")) {
      return;
    }
    var group = this.group;
    var xAxisModal = ecModel.getComponent("xAxis", 0);
    if (!xAxisModal) {
      return;
    }
    var scale = xAxisModal.axis.scale;
    var ordinalMeta = scale.getOrdinalMeta();
    var rect;
    // const offset = scale.barSpace / 2;
    var gird = ecModel.getComponent("grid", 0);
    if (gird && gird.coordinateSystem) {
      rect = gird.coordinateSystem.getRect();
    }
    if (!rect) {
      return;
    }
    var marksByWeight = ordinalMeta.getMarksByWeight();
    var marks = marksByWeight.get(50 /* Day */);
    var offset = Math.round(scale.barSpace / 2);
    var _a = scale.getExtent(),
      startIndex = _a[0],
      endIndex = _a[1];
    var points = [];
    var lineStyle = tradeDayModel.get('lineStyle');
    var z = tradeDayModel.get('z');
    for (var idx = 0; idx < marks.length; idx++) {
      var mark = marks[idx];
      if (startIndex > mark.index) {
        continue;
      }
      if (endIndex < mark.index) {
        break;
      }
      var x = xAxisModal.axis.toGlobalCoord(xAxisModal.axis.dataToCoord(mark.index));
      points.push(optimizeX(x - offset, lineStyle.width));
    }
    var height = rect.height + rect.y;
    var tradeDayLineEl = new TradeDayLine({
      shape: {
        points: points,
        height: height
      },
      style: {
        lineDash: lineStyle.type,
        lineWidth: lineStyle.width,
        stroke: lineStyle.color
      },
      z: z
    });
    group.add(tradeDayLineEl);
    // const width = api.getWidth();
    // const height = api.getHeight();
  };

  TradeDayView.prototype.dispose = function () {
    // this._api && this._api.getZr()?.off('mousemove', this._eventClick);
  };
  TradeDayView.type = "tradeDay";
  return TradeDayView;
}(ComponentView);
export { TradeDayView };