function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } var Shape = require('../shape'); var Smooth = require('../util/smooth'); var bbox = require('../util/bbox'); var Polyline = /*#__PURE__*/ function (_Shape) { _inheritsLoose(Polyline, _Shape); function Polyline() { return _Shape.apply(this, arguments) || this; } var _proto = Polyline.prototype; _proto._initProperties = function _initProperties() { _Shape.prototype._initProperties.call(this); this._attrs.canFill = true; this._attrs.canStroke = true; this._attrs.type = 'polyline'; }; _proto.getDefaultAttrs = function getDefaultAttrs() { return { points: null, lineWidth: 1, smooth: false }; }; _proto.createPath = function createPath(context) { var self = this; var attrs = self.get('attrs'); var points = attrs.points, smooth = attrs.smooth; var filteredPoints = []; // filter the point which x or y is NaN for (var i = 0, len = points.length; i < len; i++) { var point = points[i]; if (!isNaN(point.x) && !isNaN(point.y)) { filteredPoints.push(point); } } context.beginPath(); if (filteredPoints.length) { context.moveTo(filteredPoints[0].x, filteredPoints[0].y); if (smooth) { var constaint = [[0, 0], [1, 1]]; var sps = Smooth.smooth(filteredPoints, false, constaint); for (var _i = 0, n = sps.length; _i < n; _i++) { var sp = sps[_i]; context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]); } } else { var _i2; var l; for (_i2 = 1, l = filteredPoints.length - 1; _i2 < l; _i2++) { context.lineTo(filteredPoints[_i2].x, filteredPoints[_i2].y); } context.lineTo(filteredPoints[l].x, filteredPoints[l].y); } } }; _proto.calculateBox = function calculateBox() { var attrs = this.get('attrs'); var points = attrs.points, smooth = attrs.smooth, lineWidth = attrs.lineWidth; if (smooth) { var newPoints = []; var constaint = [[0, 0], [1, 1]]; var sps = Smooth.smooth(points, false, constaint); for (var i = 0, n = sps.length; i < n; i++) { var sp = sps[i]; if (i === 0) { newPoints.push([points[0].x, points[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]); } else { var lastPoint = sps[i - 1]; newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]); } } return bbox.getBBoxFromBezierGroup(newPoints, lineWidth); } return bbox.getBBoxFromPoints(points, lineWidth); }; return Polyline; }(Shape); Shape.Polyline = Polyline; module.exports = Polyline;