
/*
* 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';
import { ArrowSize } from './constants.js';
var arrowHeight = ArrowSize[1];
var closeArrowHeight = ArrowSize[1] + 3;
var arrowMargin = 10;
var PlaybackOrderLayout = {
  seriesType: 'playbackOrder',
  plan: createRenderPlanner(),
  reset: function (seriesModel, ecModel) {
    var coordSys = seriesModel.coordinateSystem;
    if (!coordSys) {
      if (process.env.NODE_ENV !== 'production') {
        error('The lines series must have a coordinate system.');
      }
      return;
    }
    var mainSeriesModal = ecModel.getMainSeries();
    if (!mainSeriesModal) {
      return;
    }
    var mainData = mainSeriesModal.getData();
    var dimLow = Math.max(mainData.getDimensionIndex('lowest'), 1);
    var dimHigh = Math.max(mainData.getDimensionIndex('highest'), 1);
    var mainStore = mainData.getStore();
    var data = seriesModel.getData();
    var dims = map(coordSys.dimensions, function (dim) {
      return data.mapDimension(dim);
    }).slice(0, 2);
    var store = data.getStore();
    var dimIdx0 = data.getDimensionIndex(dims[0]);
    return {
      progress: function (params, playbackorderData) {
        var upArrow = [];
        var downArrow = [];
        for (var i = params.start; i < params.end; i++) {
          var x = store.get(dimIdx0, i);
          var baseUp = mainStore.getByRawIndex(dimLow, x);
          var baseDown = mainStore.getByRawIndex(dimHigh, x);
          var dataModal = playbackorderData.getItemModel(i);
          var upOrders = dataModal.get('upOrders');
          var downOrders = dataModal.get('downOrders');
          var baseUpPoint = coordSys.dataToPoint([x, baseUp]);
          var baseDownPoint = coordSys.dataToPoint([x, baseDown]);
          var optimizeX = baseUpPoint[0] + 0.5;
          if (upOrders && upOrders.length) {
            var arrowY = baseUpPoint[1] + arrowMargin + arrowHeight / 2;
            upArrow.push([optimizeX, arrowY, upOrders.length, i]);
          }
          if (downOrders && downOrders.length) {
            var arrowY = baseDownPoint[1] - arrowMargin - arrowHeight / 2;
            downArrow.push([optimizeX, arrowY, downOrders.length, i]);
          }
        }
        data.setLayout({
          upArrow: upArrow,
          downArrow: downArrow
        });
      }
    };
  }
};
export default PlaybackOrderLayout;