Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

How to extends GoJS methods in Angular 2+ (ParallelRouteLink extension example)

$
0
0

@JasonLee12345 wrote:

import { Component } from "@angular/core";
import * as go from 'gojs';

@Component({
    selector: 'app-ParallelRouteLink'
})
export class ParallelRouteLink extends go.Link {

    constructor() {
        super();
    }

    protected computePoints(): boolean {
        console.log('The child function is called')
        if (!this.isOrthogonal && this.curve !== go.Link.Bezier && this.hasCurviness()) {
            console.log('Used the compute')
            let curv = this.computeCurviness();
            if (curv !== 0) {
                let num = this.pointsCount;
                let pidx = 0;
                let qidx = num-1;
                if (num >= 4) {
                    pidx++;
                    qidx--;
                }

                let frompt = this.getPoint(pidx);
                let topt = this.getPoint(qidx);
                let dx = topt.x - frompt.x;
                let dy = topt.y - frompt.y;

                let mx = frompt.x + dx * 1 / 8;
                let my = frompt.y + dy * 1 / 8;
                let px = mx;
                let py = my;
                if (-0.01 < dy && dy < 0.01) {
                    if (dx > 0) py -= curv; else py += curv;
                } else {
                    let slope = -dx / dy;
                    let e = Math.sqrt(curv * curv / (slope * slope + 1));
                    if (curv < 0) e = -e;
                    px = (dy < 0 ? -1 : 1) * e + mx;
                    py = slope * (px - mx) + my;
                }

                mx = frompt.x + dx * 7 / 8;
                my = frompt.y + dy * 7 / 8;
                let qx = mx;
                let qy = my;
                if (-0.01 < dy && dy < 0.01) {
                    if (dx > 0) qy -= curv; else qy += curv;
                } else {
                    let slope = -dx / dy;
                    let e = Math.sqrt(curv * curv / (slope * slope + 1));
                    if (curv < 0) e = -e;
                    qx = (dy < 0 ? -1 : 1) * e + mx;
                    qy = slope * (qx - mx) + my;
                }

                this.insertPointAt(pidx+1, px, py);
                this.insertPointAt(qidx+1, qx, qy);
            }
            return true;
        } else {
            return false;
        }
    };
}

This is the way I'm extending go.Link. I'm sure right now the super function is getting called but the computePoints is not. Not sure what is the correct way of doing this.

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles