
/*
* 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";
/**
 * Line path for bezier and straight line draw
 */
import * as graphic from '../../util/graphic.js';
// const straightLineProto = graphic.Line.prototype;
// const bezierCurveProto = graphic.BezierCurve.prototype;
var BarPlotShape = /** @class */function () {
  function BarPlotShape() {
    this.points = [];
    this.baseY = 0;
    this.width = 5;
  }
  return BarPlotShape;
}();
function isPointNull(point) {
  if (point instanceof Array) {
    return isNaN(point[0]) || isNaN(point[1]);
  }
  return false;
}
var BarPlotPath = /** @class */function (_super) {
  __extends(BarPlotPath, _super);
  function BarPlotPath(opts) {
    var _this = _super.call(this, opts) || this;
    _this.type = 'BarPlot';
    return _this;
  }
  BarPlotPath.prototype.getDefaultStyle = function () {
    return {
      stroke: 'none',
      fill: '#000'
    };
  };
  BarPlotPath.prototype.getDefaultShape = function () {
    return new BarPlotShape();
  };
  BarPlotPath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points,
      baseY = shape.baseY,
      width = shape.width,
      isWebviewRender = shape.isWebviewRender,
      fill = shape.fill;
    var offset = width / 2;
    var gap = offset >= 1 ? 1 : 0;
    for (var index = 0; index < points.length; index++) {
      var point = points[index];
      if (point === 0 || isPointNull(point)) {
        continue;
      }
      var _a = point,
        x = _a[0],
        y = _a[1];
      var left = Math.floor(x - offset);
      var leftX = left + gap;
      var rightX = Math.floor(left + width);
      var dataY = Math.floor(y);
      ctx.moveTo(leftX, dataY);
      ctx.lineTo(rightX, dataY);
      ctx.lineTo(rightX, baseY);
      ctx.lineTo(leftX, baseY);
      ctx.lineTo(leftX, dataY);
      if (isWebviewRender && fill && index % 5 === 0) {
        ctx.fillStyle(fill);
        ctx.beginPathFill();
      }
    }
  };
  return BarPlotPath;
}(graphic.Path);
export default BarPlotPath;