UNPKG

@turbox3d/graphic-component-pixi

Version:

Graphic component library based on pixi

56 lines 2.92 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import { Mesh2D } from '@turbox3d/renderer-pixi'; import * as PIXI from 'pixi.js'; import { drawText } from '../_utils/utils'; /** * @description: 半径尺寸线 */ var AngleDimension = /*#__PURE__*/function (_Mesh2D) { function AngleDimension() { var _this; _classCallCheck(this, AngleDimension); _this = _callSuper(this, AngleDimension, arguments); _this.view = new PIXI.Graphics(); return _this; } _inherits(AngleDimension, _Mesh2D); return _createClass(AngleDimension, [{ key: "draw", value: function draw() { var _a, _b, _c, _d, _e; var graphics = this.view; graphics.clear(); graphics.lineStyle(1, 0x131313); graphics.line["native"] = true; graphics.arc(this.props.center.x, this.props.center.y, this.props.radius, this.props.startAngle, this.props.endAngle, !this.props.anticlockwise); // calculate number text var k = -1; if (this.props.anticlockwise) k *= -1; if (this.props.endAngle % (Math.PI * 2) < this.props.startAngle % (Math.PI * 2)) k *= -1; var text = Math.abs(this.props.endAngle - this.props.startAngle) % (Math.PI * 2) * 180 / Math.PI; if (k < 0) text = 360 - text; var bisectorAngle = (this.props.startAngle + this.props.endAngle) / 2; var bisectorDir = { x: Math.cos(bisectorAngle), y: Math.sin(bisectorAngle) }; drawText(graphics, text.toFixed(0), { offset: { x: this.props.center.x + 1.3 * k * this.props.radius * bisectorDir.x, y: this.props.center.y + 1.2 * k * this.props.radius * bisectorDir.y }, size: this.props.radius / 2, rotation: Math.PI / 2 + bisectorAngle }); this.view.rotation = (_a = this.props.rotation) !== null && _a !== void 0 ? _a : 0; this.view.scale.set((_c = (_b = this.props.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1, (_e = (_d = this.props.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1); } }]); }(Mesh2D); export { AngleDimension as default };