
/*
* 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.
 */
/* global Float32Array */
import createRenderPlanner from '../helper/createRenderPlanner.js';
import { calculateCandleWidth } from '../volPath/volPathLayout.js';
import { DynamicTypedArray } from '../../util/DynamicTypedArray.js';
import { error } from '../../util/log.js';
import { map } from 'tvrender/lib/core/util.js';
var VolPathRectLayout = {
  seriesType: 'volPathRect',
  plan: createRenderPlanner(),
  reset: function (seriesModel, ecModel, api) {
    var coordSys = seriesModel.coordinateSystem;
    if (!coordSys) {
      if (process.env.NODE_ENV !== 'production') {
        error('The lines series must have a coordinate system.');
      }
      return;
    }
    var data = seriesModel.getData();
    var cDimIdx = 0;
    var vDimIdx = 1;
    var coordDims = ['x', 'y'];
    var cDimsI = map(data.mapDimensionsAll(coordDims[cDimIdx]), data.getDimensionIndex, data);
    var vDimsI = map(data.mapDimensionsAll(coordDims[vDimIdx]), data.getDimensionIndex, data);
    var x1DimI = cDimsI[1];
    var x2DimI = cDimsI[2];
    var y1DimI = vDimsI[0];
    var y2DimI = vDimsI[1];
    var _a = calculateCandleWidth(seriesModel, data),
      candleWidth = _a.candleWidth,
      bandWidth = _a.bandWidth,
      textRectWidth = _a.textRectWidth,
      gapWidth = _a.gapWidth,
      totalWidth = _a.totalWidth;
    if (cDimsI.length < 2 || vDimsI.length < 2) {
      return;
    }
    var width = api.getWidth();
    var extendLeft = -50;
    var extendRight = width + 50;
    var _b = seriesModel.get("itemStyle"),
      buyUnfinishedBg = _b.buyUnfinishedBg,
      buyFvgColor = _b.buyFvgColor,
      sellFvgColor = _b.sellFvgColor,
      sellUnfinishedBg = _b.sellUnfinishedBg;
    function getHExtend(left, right, extend) {
      switch (extend) {
        case 'left':
          return [extendLeft, right];
        case 'right':
          return [left, extendRight];
        case 'both':
          return [extendLeft, extendRight];
      }
      return [left, right];
    }
    function getBgColor(type, isStack) {
      if (isStack) {
        return type === 'buy' ? buyFvgColor : sellFvgColor;
      }
      return type === 'buy' ? buyUnfinishedBg : sellUnfinishedBg;
    }
    var infoType = seriesModel.get("infoType");
    var isBuyAndSell = infoType === 'buyAndSell';
    var isDelta = infoType === 'delta';
    var isTotal = infoType === 'total';
    var isLadder = infoType === 'ladder';
    var isBuyAndSellLadder = isBuyAndSell || isLadder;
    return {
      progress: function (params, volPathRectData) {
        var store = volPathRectData.getStore();
        // const linesPointById: Record<string, number[]> = {};
        // const linesPoints: { points: number[], key: string }[]  = [];
        var rectPointsByColor = new Map();
        for (var i = params.start; i < params.end; i++) {
          var x1Val = store.get(x1DimI, i);
          var x2Val = store.get(x2DimI, i);
          var y1Val = store.get(y1DimI, i);
          var y2Val = store.get(y2DimI, i);
          var startPoint = coordSys.dataToPoint([x1Val, y1Val]);
          var endPoint = coordSys.dataToPoint([x2Val, y2Val]);
          var itemModel = data.getItemModel(i);
          var _a = itemModel.option.itemStyle,
            extend = _a.extend,
            type = _a.type,
            isStack = _a.isStack;
          var key = getBgColor(type, isStack);
          // const points = [];
          // optimizePoint(startPoint, endPoint, border_width);
          var x1 = startPoint[0];
          var x2 = endPoint[0];
          if (!isBuyAndSellLadder) {
            x1 = x1 + gapWidth;
            x2 = x2 + gapWidth;
          } else {
            var isBuy = type === 'buy';
            x1 = isBuy ? x1 - gapWidth - textRectWidth : x1 + gapWidth;
            x2 = x2 - gapWidth - textRectWidth;
          }
          var _b = getHExtend(x1, x2, extend),
            left = _b[0],
            right = _b[1];
          // const sellX = isOverview ? ocLowX - gapWidth : ocLowX - gapWidth - textRectWidth;
          // const buyX = ocLowX + gapWidth + 1;
          var rectPoints = rectPointsByColor.get(key) || new DynamicTypedArray(1000);
          var y1 = Math.floor(startPoint[1]) + 1;
          var y2 = Math.floor(endPoint[1]);
          rectPoints.push(left);
          rectPoints.push(y1);
          rectPoints.push(right - left);
          rectPoints.push(y2 - y1);
          if (!rectPointsByColor.get(key)) {
            rectPointsByColor.set(key, rectPoints);
          }
        }
        volPathRectData.setLayout({
          rectPointsByColor: rectPointsByColor
        });
      }
    };
  }
};
export default VolPathRectLayout;