
/*
* 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.
 */
import { __extends } from "tslib";
// FIXME step not support polar
// import LineDraw from '../helper/LineDraw.js';
import ChartView from '../../view/Chart.js';
import * as graphic from '../../util/graphic.js';
// import type SeriesData from '../../data/SeriesData.js';
import { createClipPath } from '../helper/createClipPathFromCoordSys.js';
import FillPolyPath from './FillPolyPath.js';
// import LargeFillPolyPath from './LargeFillPolyPath.js';
import { getFormatColor } from '../../util/format.js';
import { each } from 'tvrender/lib/core/util.js';
var FillsView = /** @class */function (_super) {
  __extends(FillsView, _super);
  function FillsView() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.type = FillsView.type;
    return _this;
  }
  FillsView.prototype.init = function (ecModel, api) {
    // this._lineDraw = new LineDraw(Line);
    // this.group.add(this._lineDraw.group)
  };
  FillsView.prototype.render = function (seriesModel, ecModel, api) {
    var data = seriesModel.getData();
    var pointsByColor = data.getLayout('pointsByColor');
    var isMobile = seriesModel.get('isMobile');
    if (!this._polygonGroup) {
      this._polygonGroup = new graphic.Group();
      this.group.add(this._polygonGroup);
    } else {
      this._polygonGroup.removeAll();
    }
    var z2 = seriesModel.get('z2');
    var polygonGroup = this._polygonGroup;
    var coordSys = seriesModel.coordinateSystem;
    // const emphasisState = seriesModel.get('emphasis').emphasisState;
    // const groupId = seriesModel.get('groupId');
    each(pointsByColor, function (points, key) {
      var colors = key.split(':');
      var fill = key;
      var isDefaultFill = false;
      if (colors.length > 1) {
        var topColor = colors[0],
          topValue = colors[1],
          bottomColor = colors[2],
          bottomValue = colors[3];
        var tValue = coordSys.dataToPoint([0, topValue])[1];
        var bValue = coordSys.dataToPoint([0, bottomValue])[1];
        fill = new graphic.LinearGradient(0, tValue, 0, bValue, [{
          offset: 0,
          color: topColor
        }, {
          offset: 1,
          color: bottomColor
        }], true);
      } else {
        var _a = getFormatColor(fill),
          color = _a.color,
          isDefaultColor = _a.isDefaultColor;
        fill = color;
        isDefaultFill = isDefaultColor;
      }
      var el = new FillPolyPath({
        shape: {
          points: points,
          isWebviewRender: isMobile,
          fill: fill
        },
        style: {
          // fill: key,
          fill: fill,
          lineJoin: 'round'
        },
        z2: isDefaultFill ? -1 : z2
      });
      // el.states.emphasis = emphasisState;
      polygonGroup.add(el);
    });
    var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
    if (clipPath) {
      this.group.setClipPath(clipPath);
    } else {
      this.group.removeClipPath();
    }
    // toggleHoverEmphasis(this.group, null, null, false);
    // getECData(this.group).groupId = groupId;
    // this._lastZlevel = zlevel;
    // this._finished = true;
  };

  FillsView.prototype.eachRendered = function (cb) {
    // this._lineDraw && this._lineDraw.eachRendered(cb);
    graphic.traverseElements(this._polygonGroup, cb);
  };
  FillsView.prototype.remove = function (ecModel, api) {
    // this._lineDraw && this._lineDraw.remove();
    // this._lineDraw = null;
    // Clear motion when lineDraw is removed;
    this._polygonGroup && this._polygonGroup.removeAll();
    this._polygonGroup = null;
  };
  FillsView.prototype.dispose = function (ecModel, api) {
    this.remove(ecModel, api);
  };
  FillsView.type = 'fills';
  return FillsView;
}(ChartView);
export default FillsView;