
/*
* 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 { error } from '../../util/log.js';
import { map, each } from 'tvrender/lib/core/util.js';
import { ArrowSize } from './constants.js';
var arrowHeight = ArrowSize[1];
var closeArrowHeight = ArrowSize[1] + 3;
var arrowMargin = 10;
var textMargin = 6;
var textHeight = 26;
var StrategyLayout = {
  seriesType: 'strategy',
  plan: createRenderPlanner(),
  reset: function (seriesModel) {
    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();
    // const pipelineContext = seriesModel.pipelineContext;
    var dims = map(coordSys.dimensions, function (dim) {
      return data.mapDimension(dim);
    }).slice(0, 2);
    var store = data.getStore();
    var dimIdx0 = data.getDimensionIndex(dims[0]);
    // const dimIdx1 = data.getDimensionIndex(dims[1]);
    // const signVisible = !seriesModel.get('strategySignInvisible');
    // const countVisible = !seriesModel.get('strategyCountInvisible');
    // const allVisible = signVisible && countVisible;
    // const allInVisible = !signVisible && !countVisible;
    // const visibleTextHeight = (+signVisible + +countVisible) * textHeight / 2;
    // const visibleTextMargin = allInVisible ? 0 : textMargin;
    // const split = allVisible ? '\n' : '';
    // const globalSymbol = seriesModel.get('symbol')
    return {
      progress: function (params, strategyData) {
        var upTriangle = [];
        var downTriangle = [];
        var upArrow = [];
        var downArrow = [];
        var closeDownArrow = [];
        var closeUpArrow = [];
        var closeUpTriangle = [];
        var closeDownTriangle = [];
        var isLarge = params.count > 150;
        var signVisible = !seriesModel.get('strategySignInvisible') && !isLarge;
        var countVisible = !seriesModel.get('strategyCountInvisible') && !isLarge;
        var allVisible = signVisible && countVisible;
        var allInVisible = !signVisible && !countVisible;
        var visibleTextHeight = (+signVisible + +countVisible) * textHeight / 2;
        var visibleTextMargin = allInVisible ? 0 : textMargin;
        var split = allVisible ? '\n' : '';
        var texts = [];
        var _loop_1 = function (i) {
          var x = store.get(dimIdx0, i);
          var dataModal = strategyData.getItemModel(i);
          var upOrders = dataModal.get('upOrders');
          var downOrders = dataModal.get('downOrders');
          var baseDown = dataModal.get('baseDown');
          var baseUp = dataModal.get('baseUp');
          var baseUpPoint = coordSys.dataToPoint([x, baseUp]);
          var baseDownPoint = coordSys.dataToPoint([x, baseDown]);
          var optimizeX = baseUpPoint[0] + 0.5;
          each(upOrders, function (item) {
            (item.isClose ? closeUpTriangle : upTriangle).push(coordSys.dataToPoint([x, item.price]));
            var visibleArrowHeight = item.isClose ? closeArrowHeight : arrowHeight;
            var arrowY = baseUpPoint[1] + arrowMargin + visibleArrowHeight / 2;
            (item.isClose ? closeUpArrow : upArrow).push([optimizeX, arrowY]);
            if (!allInVisible) {
              var count = countVisible ? '+' + item.count : '';
              var comment = signVisible ? item.comment : '';
              texts.push({
                text: "" + comment + split + count,
                point: [baseUpPoint[0], baseUpPoint[1] + arrowMargin + visibleArrowHeight + visibleTextMargin]
              });
            }
            baseUpPoint[1] = baseUpPoint[1] + arrowMargin + visibleArrowHeight + visibleTextMargin + visibleTextHeight;
          });
          each(downOrders, function (item) {
            (item.isClose ? closeDownTriangle : downTriangle).push(coordSys.dataToPoint([x, item.price]));
            var visibleArrowHeight = item.isClose ? closeArrowHeight : arrowHeight;
            var arrowY = baseDownPoint[1] - arrowMargin - visibleArrowHeight / 2;
            (item.isClose ? closeDownArrow : downArrow).push([optimizeX, arrowY]);
            if (!allInVisible) {
              var count = countVisible ? '-' + item.count : '';
              var comment = signVisible ? item.comment : '';
              texts.push({
                text: "" + count + split + comment,
                point: [baseDownPoint[0], baseDownPoint[1] - arrowMargin - visibleArrowHeight - visibleTextMargin - visibleTextHeight]
              });
            }
            baseDownPoint[1] = baseDownPoint[1] - arrowMargin - visibleArrowHeight - visibleTextMargin - visibleTextHeight;
          });
        };
        for (var i = params.start; i < params.end; i++) {
          _loop_1(i);
        }
        data.setLayout({
          upTriangle: upTriangle,
          downTriangle: downTriangle,
          upArrow: upArrow,
          downArrow: downArrow,
          texts: texts,
          closeDownArrow: closeDownArrow,
          closeUpArrow: closeUpArrow,
          closeUpTriangle: closeUpTriangle,
          closeDownTriangle: closeDownTriangle
        });
      }
    };
  }
};
export default StrategyLayout;