
/*
* 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 PolyPlotShape = /** @class */function () {
  function PolyPlotShape() {
    this.points = [];
    this.baseY = 0;
  }
  return PolyPlotShape;
}();
function isPointNull(point) {
  if (point instanceof Array) {
    return isNaN(point[0]) || isNaN(point[1]);
  }
  return false;
}
var PolyPlotPath = /** @class */function (_super) {
  __extends(PolyPlotPath, _super);
  function PolyPlotPath(opts) {
    var _this = _super.call(this, opts) || this;
    _this.type = 'polyPlot';
    return _this;
  }
  PolyPlotPath.prototype.getDefaultStyle = function () {
    return {
      stroke: 'transparent'
    };
  };
  PolyPlotPath.prototype.getDefaultShape = function () {
    return new PolyPlotShape();
  };
  PolyPlotPath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points,
      baseY = shape.baseY,
      connectSelf = shape.connectSelf,
      barWidth = shape.barWidth;
    if (connectSelf) {
      var offset = barWidth / 2;
      var isMove = false;
      var lastExistIndex = -1;
      for (var index = 0; index < points.length; index++) {
        var point = points[index];
        if (point === 0 || isPointNull(point)) {
          isMove = true;
          continue;
        }
        var _a = point,
          x = _a[0],
          y = _a[1];
        var nextPoint = points[index + 1];
        var nextIsNull = !nextPoint || nextPoint === 0 || isPointNull(nextPoint);
        if (lastExistIndex < 0 || isMove) {
          ctx.moveTo(x - offset, y);
          if (nextIsNull) {
            ctx.lineTo(x + offset, y);
            ctx.lineTo(x + offset, baseY);
            ctx.lineTo(x - offset, baseY);
            ctx.lineTo(x - offset, y);
          }
          isMove = false;
        } else {
          ctx.lineTo(x + offset, y);
          if (nextIsNull) {
            ctx.lineTo(x + offset, baseY);
            var startPoint = points[lastExistIndex];
            ctx.lineTo(startPoint[0] - x, baseY);
            ctx.lineTo(startPoint[0] - x, startPoint[1]);
          }
        }
        lastExistIndex = index;
      }
      return;
    }
    var startIndex = 0;
    for (var index = 0; index < points.length; index++) {
      var point = points[index];
      if (point === 0 || isPointNull(point)) {
        if (startIndex) {
          ctx.lineTo(points[index - 1][0], baseY);
          var startPoint = points[startIndex];
          ctx.lineTo(startPoint[0], baseY);
          ctx.lineTo(startPoint[0], startPoint[1]);
        }
        var nextPoint = points[++index];
        while ((nextPoint === 0 || isPointNull(nextPoint)) && index < points.length) {
          nextPoint = points[++index];
        }
        if (!nextPoint) {
          continue;
        }
        var _b = nextPoint,
          x_1 = _b[0],
          y_1 = _b[1];
        ctx.moveTo(x_1, y_1);
        startIndex = index;
        continue;
      }
      var _c = point,
        x = _c[0],
        y = _c[1];
      ctx.lineTo(x, y);
      if (index === points.length - 1) {
        ctx.lineTo(points[index][0], baseY);
        var startPoint = points[startIndex];
        ctx.lineTo(startPoint[0], baseY);
        ctx.lineTo(startPoint[0], startPoint[1]);
      }
    }
  };
  return PolyPlotPath;
}(graphic.Path);
export default PolyPlotPath;