
/*
* 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';
import { each } from 'tvrender/lib/core/util.js';
// const straightLineProto = graphic.Line.prototype;
// const bezierCurveProto = graphic.BezierCurve.prototype;
var GradientLineShape = /** @class */function () {
  function GradientLineShape() {
    this.points = [];
  }
  return GradientLineShape;
}();
// function isPointNull(point: number[] | number) {
//     if (point instanceof Array) {
//         return isNaN(point[0]) || isNaN(point[1]);
//     }
//     return false;
// }
var GradientLinePath = /** @class */function (_super) {
  __extends(GradientLinePath, _super);
  function GradientLinePath(opts) {
    var _this = _super.call(this, opts) || this;
    _this.type = 'GradientLine';
    return _this;
  }
  GradientLinePath.prototype.getDefaultStyle = function () {
    return {
      stroke: 'transparent',
      fill: '#000'
    };
  };
  GradientLinePath.prototype.getDefaultShape = function () {
    return new GradientLineShape();
  };
  GradientLinePath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points;
    var lastColor = '';
    var shouldMovePoint = true;
    var lastPoint;
    each(points, function (item) {
      var point = item.point,
        color = item.color;
      if (isNaN(point[1]) || !color) {
        shouldMovePoint = true;
        return;
      }
      if (lastColor && lastColor !== color) {
        ctx.strokeStyle(color);
        if (!shouldMovePoint) {
          ctx.beginPathFill();
          lastPoint && ctx.moveTo(lastPoint[0], lastPoint[1]);
        }
      }
      if (shouldMovePoint) {
        ctx.beginPathFill();
        ctx.moveTo(point[0], point[1]);
        shouldMovePoint = false;
      } else {
        ctx.lineTo(point[0], point[1]);
        lastPoint = point;
      }
      if (lastColor !== color) {
        lastColor = color;
      }
    });
    if (lastColor) {
      ctx.strokeStyle(lastColor);
    }
  };
  return GradientLinePath;
}(graphic.Path);
export default GradientLinePath;