
/*
* 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 LinePlotShape = /** @class */function () {
  function LinePlotShape() {
    this.points = [];
  }
  return LinePlotShape;
}();
function isPointNull(point) {
  if (point instanceof Array) {
    return isNaN(point[0]) || isNaN(point[1]);
  }
  return false;
}
var LinePlotPath = /** @class */function (_super) {
  __extends(LinePlotPath, _super);
  function LinePlotPath(opts) {
    var _this = _super.call(this, opts) || this;
    _this.type = 'linePlot';
    return _this;
  }
  LinePlotPath.prototype.getDefaultStyle = function () {
    return {
      stroke: '#000',
      fill: null
    };
  };
  LinePlotPath.prototype.getDefaultShape = function () {
    return new LinePlotShape();
  };
  LinePlotPath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points,
      connectSelf = shape.connectSelf,
      barWidth = shape.barWidth,
      isWebviewRender = shape.isWebviewRender,
      stroke = shape.stroke;
    if (connectSelf) {
      var offset = barWidth / 2;
      var isMove = false;
      for (var index = 0; index < points.length; index++) {
        var point = points[index];
        if (point === 0 || isPointNull(point)) {
          isMove = true;
          continue;
        }
        if (isMove) {
          var nextPoint = points[index + 1];
          var _a = point,
            x = _a[0],
            y = _a[1];
          if (!nextPoint || isPointNull(nextPoint)) {
            ctx.moveTo(x - offset, y);
            ctx.lineTo(x + offset, y);
            if (isWebviewRender && stroke && index % 10 === 0) {
              ctx.strokeStyle(stroke);
              ctx.beginPathFill();
              ctx.moveTo(x, y);
            }
            continue;
          }
          ctx.moveTo(x, y);
          isMove = false;
        } else {
          var _b = point,
            x = _b[0],
            y = _b[1];
          ctx.lineTo(x, y);
          if (isWebviewRender && stroke && index % 10 === 0) {
            ctx.strokeStyle(stroke);
            ctx.beginPathFill();
            ctx.moveTo(x, y);
          }
        }
      }
    } else {
      for (var index = 0; index < points.length; index++) {
        var point = points[index];
        if (point === 0 || isPointNull(point)) {
          var nextPoint = points[++index];
          while ((nextPoint === 0 || isPointNull(nextPoint)) && index < points.length) {
            nextPoint = points[++index];
          }
          if (!nextPoint) {
            continue;
          }
          var _c = nextPoint,
            x_1 = _c[0],
            y_1 = _c[1];
          ctx.moveTo(x_1, y_1);
          continue;
        }
        var _d = point,
          x = _d[0],
          y = _d[1];
        ctx.lineTo(x, y);
        if (isWebviewRender && stroke && index % 10 === 0) {
          ctx.strokeStyle(stroke);
          ctx.beginPathFill();
          ctx.moveTo(x, y);
        }
      }
    }
  };
  return LinePlotPath;
}(graphic.Path);
export default LinePlotPath;