source: imaps-frontend/node_modules/konva/lib/shapes/Arrow.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Arrow = void 0;
4const Factory_1 = require("../Factory");
5const Line_1 = require("./Line");
6const Validators_1 = require("../Validators");
7const Global_1 = require("../Global");
8const Path_1 = require("./Path");
9class Arrow extends Line_1.Line {
10 _sceneFunc(ctx) {
11 super._sceneFunc(ctx);
12 var PI2 = Math.PI * 2;
13 var points = this.points();
14 var tp = points;
15 var fromTension = this.tension() !== 0 && points.length > 4;
16 if (fromTension) {
17 tp = this.getTensionPoints();
18 }
19 var length = this.pointerLength();
20 var n = points.length;
21 var dx, dy;
22 if (fromTension) {
23 const lp = [
24 tp[tp.length - 4],
25 tp[tp.length - 3],
26 tp[tp.length - 2],
27 tp[tp.length - 1],
28 points[n - 2],
29 points[n - 1],
30 ];
31 const lastLength = Path_1.Path.calcLength(tp[tp.length - 4], tp[tp.length - 3], 'C', lp);
32 const previous = Path_1.Path.getPointOnQuadraticBezier(Math.min(1, 1 - length / lastLength), lp[0], lp[1], lp[2], lp[3], lp[4], lp[5]);
33 dx = points[n - 2] - previous.x;
34 dy = points[n - 1] - previous.y;
35 }
36 else {
37 dx = points[n - 2] - points[n - 4];
38 dy = points[n - 1] - points[n - 3];
39 }
40 var radians = (Math.atan2(dy, dx) + PI2) % PI2;
41 var width = this.pointerWidth();
42 if (this.pointerAtEnding()) {
43 ctx.save();
44 ctx.beginPath();
45 ctx.translate(points[n - 2], points[n - 1]);
46 ctx.rotate(radians);
47 ctx.moveTo(0, 0);
48 ctx.lineTo(-length, width / 2);
49 ctx.lineTo(-length, -width / 2);
50 ctx.closePath();
51 ctx.restore();
52 this.__fillStroke(ctx);
53 }
54 if (this.pointerAtBeginning()) {
55 ctx.save();
56 ctx.beginPath();
57 ctx.translate(points[0], points[1]);
58 if (fromTension) {
59 dx = (tp[0] + tp[2]) / 2 - points[0];
60 dy = (tp[1] + tp[3]) / 2 - points[1];
61 }
62 else {
63 dx = points[2] - points[0];
64 dy = points[3] - points[1];
65 }
66 ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2);
67 ctx.moveTo(0, 0);
68 ctx.lineTo(-length, width / 2);
69 ctx.lineTo(-length, -width / 2);
70 ctx.closePath();
71 ctx.restore();
72 this.__fillStroke(ctx);
73 }
74 }
75 __fillStroke(ctx) {
76 var isDashEnabled = this.dashEnabled();
77 if (isDashEnabled) {
78 this.attrs.dashEnabled = false;
79 ctx.setLineDash([]);
80 }
81 ctx.fillStrokeShape(this);
82 if (isDashEnabled) {
83 this.attrs.dashEnabled = true;
84 }
85 }
86 getSelfRect() {
87 const lineRect = super.getSelfRect();
88 const offset = this.pointerWidth() / 2;
89 return {
90 x: lineRect.x - offset,
91 y: lineRect.y - offset,
92 width: lineRect.width + offset * 2,
93 height: lineRect.height + offset * 2,
94 };
95 }
96}
97exports.Arrow = Arrow;
98Arrow.prototype.className = 'Arrow';
99(0, Global_1._registerNode)(Arrow);
100Factory_1.Factory.addGetterSetter(Arrow, 'pointerLength', 10, (0, Validators_1.getNumberValidator)());
101Factory_1.Factory.addGetterSetter(Arrow, 'pointerWidth', 10, (0, Validators_1.getNumberValidator)());
102Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
103Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
Note: See TracBrowser for help on using the repository browser.