UNPKG

sprotty

Version:

A next-gen framework for graphical views

80 lines 3.94 kB
"use strict"; /******************************************************************************** * Copyright (c) 2018 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DecorationPlacer = void 0; const inversify_1 = require("inversify"); const smodel_1 = require("../../base/model/smodel"); const model_1 = require("./model"); const vnode_utils_1 = require("../../base/views/vnode-utils"); const model_2 = require("../bounds/model"); const model_3 = require("../routing/model"); const routing_1 = require("../routing/routing"); const sprotty_protocol_1 = require("sprotty-protocol"); let DecorationPlacer = class DecorationPlacer { decorate(vnode, element) { if ((0, model_1.isDecoration)(element)) { const position = this.getPosition(element); const translate = 'translate(' + position.x + ', ' + position.y + ')'; (0, vnode_utils_1.setAttr)(vnode, 'transform', translate); } return vnode; } getPosition(element) { if (element instanceof smodel_1.SChildElementImpl && element.parent instanceof model_3.SRoutableElementImpl) { const route = this.edgeRouterRegistry.route(element.parent); if (route.length > 1) { const index = Math.floor(0.5 * (route.length - 1)); const offset = (0, model_2.isSizeable)(element) ? { x: -0.5 * element.bounds.width, y: -0.5 * element.bounds.width } : sprotty_protocol_1.Point.ORIGIN; return { x: 0.5 * (route[index].x + route[index + 1].x) + offset.x, y: 0.5 * (route[index].y + route[index + 1].y) + offset.y }; } } if ((0, model_2.isSizeable)(element)) return { x: -0.666 * element.bounds.width, y: -0.666 * element.bounds.height }; return sprotty_protocol_1.Point.ORIGIN; } postUpdate() { } }; exports.DecorationPlacer = DecorationPlacer; __decorate([ (0, inversify_1.inject)(routing_1.EdgeRouterRegistry), __metadata("design:type", routing_1.EdgeRouterRegistry) ], DecorationPlacer.prototype, "edgeRouterRegistry", void 0); exports.DecorationPlacer = DecorationPlacer = __decorate([ (0, inversify_1.injectable)() ], DecorationPlacer); //# sourceMappingURL=decoration-placer.js.map