klighd-core
A diagram view for KGraph models implemented in Sprotty.
Works with the KLighD language server.
Getting started
The klighd-core
package is nearly self-contained and is almost able to display generated KGraph
models. An application that uses this packages has to provide a few platform dependent services that
can not be implemented by the core package before-hand.
Implementing the services
Connection
The connection service is responsible for sending diagram actions to and from the diagram server.
The transport of the actions is platform dependent and has to be chosen according to each platform's
capabilities.
Each service has to implement the Connection
interface exported by the core container. Refer to
the exported interface for more information about the required methods.
Session Storage
The session storage service is used to cache data in a key-value store. The duration of persistence
should be short-lived and no longer than a user session.
Each service has to implement the SessionStorage
interface exported by the core container, which
is compatible with the web Storage
interface. Refer to the exported interface for more information about the required methods.
A good candidate for an implementation might be the sessionStorage
web API if it is available on
the implementing platform.
Persistence Storage
The persistence storage is used to persist data over long periods. The data should still be available
after an application reload.
Each service has to implement the PersistenceStorage
interface exported by the core container.
It is similar to the web Storage
interface, but allows asynchronous data access.
Refer to the exported interface for more information about the required methods.
Using klighd-core
Using the klighd-core
package requires the initialization of a diagram container, implementation
of the required services, and the initialization of a model request to kick of the visualization.
The following code serves as a boilerplate for getting started, assuming that an implementation for
each service exists:
import "klighd-core/styles/main.css";
import {
createKlighdDiagramContainer,
requestModel,
getActionDispatcher,
SetPreferencesAction,
bindServices,
} from "@kieler/klighd-core";
import { ConnectionImpl } from "./services/connection";
import { PersistenceStorageImpl } from "./services/persistence";
async function init() {
const connection = new ConnectionImpl();
const persistenceStorage = new PersistenceStorageImpl();
const diagramContainer = createKlighdDiagramContainer("container-id");
bindServices(diagramContainer, { connection, sessionStorage, persistenceStorage });
const actionDispatcher = getActionDispatcher(diagramContainer);
await requestModel(actionDispatcher, sourceUri);
actionDispatcher.dispatch(
new SetPreferencesAction({
resizeToFit: false,
forceLightBackground: true,
})
);
}