
/*
* 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';
import { getFontSize, getDistance } from './util.js';
// import BoundingRect from 'tvrender/lib/core/BoundingRect.js';
// import { createFloat32Array } from '../../util/vendor.js';
function getYByLocation(seriesModel) {
  var location = seriesModel.get('location');
  if (!['bottom', 'top'].includes(location)) {
    return null;
  }
  var yAxis = seriesModel.coordinateSystem.getAxis('y');
  var scale = yAxis.scale;
  var _a = yAxis.getExtent(),
    end = _a[1];
  var _b = scale.rawExtentInfo.getBoundaryGapInner(),
    boundaryGapX = _b[0],
    boundaryGapY = _b[1];
  return Math.floor(location === 'top' ? end * boundaryGapX : end * (1 - boundaryGapY));
}
var CharPlotLayout = {
  seriesType: 'charPlot',
  plan: createRenderPlanner(),
  reset: function (seriesModel) {
    var data = seriesModel.getData();
    var coordSys = seriesModel.coordinateSystem;
    // const pipelineContext = seriesModel.pipelineContext;
    if (!coordSys) {
      return;
    }
    var bandWidth = coordSys.getAxesByScale('ordinal')[0].scale.barSpace;
    var location = seriesModel.get('location');
    var size = seriesModel.get('size');
    var fontSize = getFontSize(size, bandWidth);
    var distance = getDistance(location, fontSize);
    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 char = seriesModel.get('char');
    var text = seriesModel.get('text');
    var price = getYByLocation(seriesModel);
    var showLast = seriesModel.get('showLast');
    return {
      progress: function (params, charPlotData) {
        var charList = [];
        var textList = [];
        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'),
            color = _a.color,
            textcolor = _a.textcolor;
          var point = coordSys.dataToPoint(tmpIn);
          var x = point[0];
          var y = (price !== null && price !== void 0 ? price : point[1]) + distance;
          if (char && color) {
            charList.push({
              x: x,
              y: y,
              textColor: color
            });
          }
          var textColor = textcolor || color;
          if (text && textColor) {
            textList.push({
              x: x,
              y: y + distance,
              textColor: textColor
            });
          }
        }
        charPlotData.setLayout({
          charList: charList,
          fontSize: fontSize,
          textList: textList
        });
        // console.log('%c [ points ]-83', 'font-size:13px; background:pink; color:#bf2c9f;', points)
      }
    };
  }
};

export default CharPlotLayout;