How to use the jointjs.g function in jointjs

To help you get started, we’ve selected a few jointjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metaphacts / ontodia / src / ontodia / diagram / defaultLinkRouter.ts View on Github external
return false;
            }
            const _sourceId = link.get('source').id;
            const _targetId = link.get('target').id;

            return _sourceId !== _targetId && (
                  (_sourceId === sourceId && _targetId === targetId) ||
                  (_sourceId === targetId && _targetId === sourceId)
            );
        });

        // There is more than one siblings. We need to create vertices.
        // First of all we'll find the middle point of the link.
        const srcCenter = diagramModel.graph.getCell(sourceId).getBBox().center();
        const trgCenter = diagramModel.graph.getCell(targetId).getBBox().center();
        const midPoint = joint.g.line(srcCenter, trgCenter).midpoint();

        // Then find the angle it forms.
        const theta = srcCenter.theta(trgCenter);

        const currentLinkIndex = siblings.indexOf(currentLink);
        if (currentLinkIndex !== -1) {
            const v = getVertexForLink(
                theta,
                midPoint,
                siblings.length,
                currentLinkIndex,
                diagramModel,
            );
            updateLinkLabel(
                currentLink,
                currentLinkIndex,
github metaphacts / ontodia / src / ontodia / diagram / defaultLinkRouter.ts View on Github external
// We want the offset values to be calculated as follows 0, 50, 50, 100, 100, 150, 150 ..
    const offset = GAP * Math.ceil(index / 2) - (indexModifyer ? GAP / 2 : 0);
    // Now we need the vertices to be placed at points which are 'offset' pixels distant
    // from the first link and forms a perpendicular angle to it. And as index goes up
    // alternate left and right.
    //
    //  ^  odd indexes
    //  |
    //  |---->  index 0 line (straight line between a source center and a target center.
    //  |
    //  v  even indexes
    const sign = index % 2 ? 1 : -1;
    const angle = joint.g.toRad(theta + sign * 90);

    // We found the vertex.
    const vertex = joint.g.point.fromPolar(offset, angle, midPoint);

    return vertex;
}