@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
125 lines • 8.33 kB
JavaScript
"use strict";
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2019-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
const interactive_module_1 = require("@kieler/klighd-interactive/lib/interactive-module");
const elk_bundled_1 = require("elkjs/lib/elk.bundled");
const inversify_1 = require("inversify");
const sprotty_1 = require("sprotty");
const sprotty_elk_1 = require("sprotty-elk");
const actions_module_1 = require("./actions/actions-module");
// import bookmarkModule from './bookmarks/bookmark-module';
const di_symbols_1 = require("./di.symbols");
const diagram_pieces_module_1 = require("./diagram-pieces/diagram-pieces-module");
const diagram_server_1 = require("./diagram-server");
const hover_1 = require("./hover/hover");
const popup_provider_1 = require("./hover/popup-provider");
const klighd_mouse_tool_1 = require("./klighd-mouse-tool");
const klighd_svg_exporter_1 = require("./klighd-svg-exporter");
const layout_config_1 = require("./layout-config");
const model_viewer_1 = require("./model-viewer");
const actions_1 = require("./options/actions");
const options_module_1 = require("./options/options-module");
const preferences_registry_1 = require("./preferences-registry");
const proxy_view_module_1 = require("./proxy-view/proxy-view-module");
const sidebar_1 = require("./sidebar");
const skgraph_model_renderer_1 = require("./skgraph-model-renderer");
const skgraph_models_1 = require("./skgraph-models");
const actions_2 = require("./syntheses/actions");
const syntheses_registry_1 = require("./syntheses/syntheses-registry");
const update_depthmap_module_1 = require("./update/update-depthmap-module");
const views_1 = require("./views");
/**
* Dependency injection module that adds functionality for diagrams and configures the views for SKGraphElements.
*/
const kGraphDiagramModule = new inversify_1.ContainerModule((bind, unbind, isBound, rebind) => {
bind(sprotty_1.TYPES.ModelSource).to(diagram_server_1.KlighdDiagramServer).inSingletonScope();
rebind(sprotty_1.TYPES.ILogger).to(sprotty_1.ConsoleLogger).inSingletonScope();
rebind(sprotty_1.TYPES.LogLevel).toConstantValue(sprotty_1.LogLevel.warn);
// required binding for elkjs to work
bind(sprotty_1.TYPES.IModelLayoutEngine).toService(sprotty_elk_1.ElkLayoutEngine);
// Our own layout configurator that just copies the element's poperties as the layout options.
bind(layout_config_1.KielerLayoutConfigurator).toSelf().inSingletonScope();
rebind(sprotty_elk_1.ILayoutConfigurator).to(layout_config_1.KielerLayoutConfigurator).inSingletonScope();
const elkFactory = () => new elk_bundled_1.default({ algorithms: ['layered'] }); // See elkjs documentation
bind(sprotty_elk_1.ElkFactory).toConstantValue(elkFactory);
rebind(sprotty_1.TYPES.CommandStackOptions).toConstantValue({
// Override the default animation speed to be 500 ms, as the default value is too quick.
defaultDuration: 500,
undoHistoryLimit: 50,
});
rebind(sprotty_1.MouseTool).to(klighd_mouse_tool_1.KlighdMouseTool);
bind(klighd_mouse_tool_1.KlighdMouseTool).toSelf().inSingletonScope();
bind(sprotty_1.TYPES.MouseListener).to(hover_1.KlighdHoverMouseListener);
bind(sprotty_1.TYPES.IPopupModelProvider).to(popup_provider_1.PopupModelProvider);
rebind(sprotty_1.TYPES.HoverState).toDynamicValue(() => ({
mouseOverTimer: undefined,
mouseOutTimer: undefined,
popupOpen: false,
previousPopupElement: undefined,
}));
rebind(sprotty_1.TYPES.ModelRendererFactory).toFactory((ctx) => (targetKind, processors) => {
const viewRegistry = ctx.container.get(sprotty_1.TYPES.ViewRegistry);
return new skgraph_model_renderer_1.SKGraphModelRenderer(viewRegistry, targetKind, processors);
});
// Notes that this rebinds the Service and not the TYPE.ModelViewer intentionally as the type is bound to a dynamic value in Sprotty
rebind(sprotty_1.ModelViewer).to(model_viewer_1.KlighdModelViewer).inSingletonScope();
const context = { bind, unbind, isBound, rebind };
(0, sprotty_1.configureModelElement)(context, 'html', sprotty_1.HtmlRootImpl, sprotty_1.HtmlRootView);
(0, sprotty_1.configureModelElement)(context, 'pre-rendered', sprotty_1.PreRenderedElementImpl, sprotty_1.PreRenderedView);
(0, sprotty_1.configureModelElement)(context, 'graph', sprotty_1.SGraphImpl, views_1.SKGraphView);
(0, sprotty_1.configureModelElement)(context, skgraph_models_1.NODE_TYPE, skgraph_models_1.SKNode, views_1.KNodeView);
(0, sprotty_1.configureModelElement)(context, skgraph_models_1.EDGE_TYPE, skgraph_models_1.SKEdge, views_1.KEdgeView);
(0, sprotty_1.configureModelElement)(context, skgraph_models_1.PORT_TYPE, skgraph_models_1.SKPort, views_1.KPortView);
(0, sprotty_1.configureModelElement)(context, skgraph_models_1.LABEL_TYPE, skgraph_models_1.SKLabel, views_1.KLabelView);
bind(di_symbols_1.DISymbol.SynthesesRegistry).to(syntheses_registry_1.SynthesesRegistry).inSingletonScope();
(0, sprotty_1.configureActionHandler)(context, actions_2.SetSynthesesAction.KIND, di_symbols_1.DISymbol.SynthesesRegistry);
(0, sprotty_1.configureActionHandler)(context, actions_2.SetSynthesisAction.KIND, di_symbols_1.DISymbol.SynthesesRegistry);
bind(di_symbols_1.DISymbol.PreferencesRegistry).to(preferences_registry_1.PreferencesRegistry).inSingletonScope();
(0, sprotty_1.configureActionHandler)(context, actions_1.SetPreferencesAction.KIND, di_symbols_1.DISymbol.PreferencesRegistry);
(0, sprotty_1.configureActionHandler)(context, actions_1.ResetPreferencesAction.KIND, di_symbols_1.DISymbol.PreferencesRegistry);
rebind(sprotty_1.TYPES.SvgExporter).to(klighd_svg_exporter_1.KlighdSvgExporter).inSingletonScope();
});
/**
* Dependency injection container that bundles all needed sprotty and custom modules to allow SKGraphs to be drawn with sprotty.
*/
function createContainer(widgetId) {
const container = new inversify_1.Container();
container.load(sprotty_1.defaultModule, sprotty_1.boundsModule, sprotty_elk_1.elkLayoutModule, sprotty_1.selectModule, interactive_module_1.interactiveModule, sprotty_1.viewportModule, sprotty_1.exportModule, sprotty_1.modelSourceModule, sprotty_1.updateModule, sprotty_1.hoverModule,
// keep the klighd-specific modules at the last positions because of possible binding overrides.
actions_module_1.default, options_module_1.optionsModule, sidebar_1.sidebarModule, kGraphDiagramModule, update_depthmap_module_1.default,
/* bookmarkModule, */ diagram_pieces_module_1.default, proxy_view_module_1.proxyViewModule);
// FIXME: bookmarkModule is currently broken due to wrong usage of Sprotty commands. action handling needs to be reimplemented for this to work.
(0, sprotty_1.overrideViewerOptions)(container, {
// These are ignored ignored and overwritten by the current needsClientLayout preference during model request.
needsClientLayout: false, // client layout = micro layout (Sprotty/Sprotty+KLighD)
needsServerLayout: true, // server layout = macro layout (ELK/elkjs). false here to not forward it to the Java server (the model source), but keep and handle it directly on the diagram server proxy manually
baseDiv: widgetId,
hiddenDiv: `${widgetId}_hidden`,
// TODO: We should be able to completely deactivate Sprotty's zoom limits to not limit top down layout.
// This is a workaround to allow quite deep zoom to work for most cases already.
zoomLimits: {
min: 0.00000000000001,
max: 1000000000000000,
},
horizontalScrollLimits: { min: -1000000000000000, max: 1000000000000000 },
verticalScrollLimits: { min: -1000000000000000, max: 1000000000000000 },
});
return container;
}
exports.default = createContainer;
//# sourceMappingURL=di.config.js.map