
/*
* 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 } from 'tvrender/lib/core/util.js';
function getHeight(seriesModel) {
  var coordSys = seriesModel.coordinateSystem;
  var yAxis = coordSys.getAxis('y');
  var _a = yAxis.getExtent(),
    start = _a[0],
    end = _a[1];
  return {
    height: end - start,
    startY: yAxis.toGlobalCoord(end)
  };
}
var bgColorLayout = {
  seriesType: 'bgcolor',
  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]);
    var xOffset = seriesModel.get('offset') || 0;
    var showLast = seriesModel.get('showLast');
    return {
      progress: function (params, bgColorData) {
        var rectsByColor = {};
        var barWidth = Math.ceil(coordSys.getBaseAxis().scale.barSpace) || 5;
        var leftOffset = barWidth / 2;
        var _a = getHeight(seriesModel),
          height = _a.height,
          startY = _a.startY;
        var lastIndex = bgColorData.count(true) - 1;
        for (var i = params.start; i < params.end; i++) {
          if (showLast && lastIndex - bgColorData.getRawIndex(i) >= showLast) {
            continue;
          }
          var itemModel = bgColorData.getItemModel(i);
          var color = itemModel.get('itemStyle').color;
          if (!color) {
            continue;
          }
          var x = store.get(dimIdx0, i);
          var xPx = coordSys.dataToPoint([x + xOffset, 0])[0];
          var width = barWidth;
          if (i + 1 < params.end) {
            var x1 = store.get(dimIdx0, i + 1);
            var x1Px = coordSys.dataToPoint([x1 + xOffset, 0])[0];
            width = x1Px - xPx;
          }
          // const key = `${color}:${width}`;
          var rects = rectsByColor[color] || [];
          rects.push({
            x: xPx - leftOffset,
            y: startY,
            width: width
          });
          rectsByColor[color] = rects;
        }
        bgColorData.setLayout({
          rectsByColor: rectsByColor,
          height: height
        });
      }
    };
  }
};
export default bgColorLayout;