NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@antv/component/lib/axis/polyline.js

99 lines
3.6 KiB
JavaScript
Raw Normal View History

2023-09-14 14:47:11 +08:00
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var Util = require('../util');
var Base = require('./base');
var MatrixUtil = Util.MatrixUtil,
PathUtil = Util.PathUtil;
var vec2 = MatrixUtil.vec2;
var Polyline = /*#__PURE__*/function (_Base) {
_inheritsLoose(Polyline, _Base);
var _super = _createSuper(Polyline);
function Polyline() {
return _Base.apply(this, arguments) || this;
}
var _proto = Polyline.prototype;
_proto.getDefaultCfg = function getDefaultCfg() {
var cfg = _Base.prototype.getDefaultCfg.call(this);
return Util.mix({}, cfg, {
type: 'polyline'
});
};
_proto.getLinePath = function getLinePath() {
var self = this;
var tickPoints = self.get('tickPoints');
var start = self.get('start');
var end = self.get('end');
var points = [];
points.push(start.x);
points.push(start.y);
Util.each(tickPoints, function (tick) {
points.push(tick.x);
points.push(tick.y);
});
points.push(end.x);
points.push(end.y);
var path = PathUtil.catmullRomToBezier(points);
path.unshift(['M', start.x, start.y]);
return path;
};
_proto.getTickPoint = function getTickPoint(value, index) {
var tickPoints = this.get('tickPoints');
return tickPoints[index];
};
_proto.getTickEnd = function getTickEnd(start, value, index) {
var self = this;
var lineAttrs = self.get('tickLine');
var tickLength = value ? value : lineAttrs.length;
var offsetVector = self.getSideVector(tickLength, start, index);
return {
x: start.x + offsetVector[0],
y: start.y + offsetVector[1]
};
};
_proto.getSideVector = function getSideVector(offset, point, index) {
var self = this;
var preTickPoint;
if (index === 0) {
preTickPoint = self.get('start');
if (preTickPoint.x === point.x && preTickPoint.y === point.y) {
return [0, 0];
}
} else {
var tickPoints = self.get('tickPoints');
preTickPoint = tickPoints[index - 1];
}
var vector = [point.x - preTickPoint.x, point.y - preTickPoint.y];
var normal = vec2.normalize([], vector);
var verticalVector = vec2.vertical([], normal, false);
return vec2.scale([], verticalVector, offset);
};
return Polyline;
}(Base);
module.exports = Polyline;