
/*
* 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 { map } from 'tvrender/lib/core/util.js';
var ArrowsPlotLayout = {
  seriesType: 'arrowsPlot',
  plan: createRenderPlanner(),
  reset: function (seriesModel) {
    var data = seriesModel.getData();
    var coordSys = seriesModel.coordinateSystem;
    // const pipelineContext = seriesModel.pipelineContext;
    if (!coordSys) {
      return;
    }
    // const bandWidth = coordSys.getAxesByScale('ordinal')[0].scale.barSpace;
    var dims = map(coordSys.dimensions, function (dim) {
      return data.mapDimension(dim);
    }).slice(0, 2);
    // const dimLen = dims.length;
    var store = data.getStore();
    var dimIdx0 = data.getDimensionIndex(dims[0]);
    var dimIdx1 = data.getDimensionIndex(dims[1]);
    var xOffset = seriesModel.get('offset') || 0;
    var showLast = seriesModel.get('showLast');
    return {
      progress: function (params, arrowsPlotData) {
        var upArrowsByColor = {};
        var downArrowsByColor = {};
        var maxValue = 0;
        var minValue = 0;
        var lastIndex = data.count(true) - 1;
        var tmpIn = [];
        for (var i = params.start; i < params.end; i++) {
          if (showLast && lastIndex - data.getRawIndex(i) >= showLast) {
            continue;
          }
          tmpIn[0] = store.get(dimIdx0, i) + xOffset;
          tmpIn[1] = store.get(dimIdx1, i);
          if (isNaN(tmpIn[1])) {
            continue;
          }
          var itemModel = data.getItemModel(i);
          var _a = itemModel.get('itemStyle'),
            upColor = _a.upColor,
            downColor = _a.downColor,
            value = _a.value;
          var point = coordSys.dataToPoint(tmpIn);
          if (value > 0) {
            var upArrows = upArrowsByColor[upColor] || [];
            upArrows.push({
              x: point[0],
              y: point[1],
              value: value
            });
            upArrowsByColor[upColor] = upArrows;
            maxValue = Math.max(maxValue, value);
          } else {
            var downArrows = downArrowsByColor[downColor] || [];
            downArrows.push({
              x: point[0],
              y: point[1],
              value: value
            });
            downArrowsByColor[downColor] = downArrows;
            minValue = Math.min(minValue, value);
          }
          downArrowsByColor[downColor];
        }
        arrowsPlotData.setLayout({
          upArrowsByColor: upArrowsByColor,
          downArrowsByColor: downArrowsByColor,
          maxValue: maxValue,
          minValue: minValue
        });
        // console.log('%c [ points ]-83', 'font-size:13px; background:pink; color:#bf2c9f;', points)
      }
    };
  }
};

export default ArrowsPlotLayout;