nope/resources/ui/graph/interfaces/IGraphTool.ts

209 lines
6.0 KiB
TypeScript
Raw Normal View History

2020-10-25 20:14:51 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-03-12 12:43:07
* @modify date 2020-07-22 21:53:48
* @desc [description]
*/
import { IBaseNodeOptions } from '../../../@zema/ZISS-Network/type/IBaseNodeOptions';
import { IBaseEdgeOptions } from '../../../@zema/ZISS-Network/type/IBaseEdgeOptions';
import { IUndoRedoGraph } from './IGraph';
import { ITemplate, IMustacheTemplate } from './ITemplate';
import { IVisjsOptions } from './IVisjsOptions';
import { IEditPage } from '../edit-pages/edit-pages.interface';
import { IBasicLayoutComponent, IMinProvidedDataSet, IToolbarConfig, ISelectionConfig, ISelectionTemplate } from '../../gui-components-basic-layout/types/interfaces';
import { ZemaServiceProvider } from '../../../@zema/zema-service-provider.service';
import { Type } from '@angular/core';
/**
* Custom Callback Object.
*
* @export
* @interface ICallbackData
* @extends {IMinProvidedDataSet}
* @template N
* @template E
*/
export interface ICallbackData<N extends IBaseNodeOptions, E extends IBaseEdgeOptions> extends IMinProvidedDataSet {
network: IUndoRedoGraph<N, E>,
options: IVisjsOptions,
selectedNodes: Array<string>,
selectedEdges: Array<string>,
component: IGraphToolComponent<N, E, ICallbackData<N,E>>,
zemaService: ZemaServiceProvider,
selectedTemplate: ITemplate<N,E> | IMustacheTemplate
}
export interface IGraphToolComponent<N extends IBaseNodeOptions, E extends IBaseEdgeOptions, D extends IMinProvidedDataSet> {
options: {
addEdgeCallback?: (edgeData: E, callback: (edgeData: E) => void) => void;
editOnSelect?: boolean;
editOnChange?: boolean;
parseFunctions?: boolean;
enableContextMenu?: boolean;
enableEditing?: boolean;
hidePanelOnDeselect?: boolean;
hideToolbar?: boolean;
hideRightPanel?: boolean;
}
/**
* Element Containing the Layout
*
* @type {IBasicLayoutComponent<ISelectionConfig<N,E>,ICallbackData<N,E>>}
* @memberof IGraphToolComponent
*/
layout: IBasicLayoutComponent<ITemplate<N | IBaseNodeOptions, E | IBaseEdgeOptions> | IMustacheTemplate, D>
/**
* Flag, which will be used to Controll, whether JSON should contain functions or not.
*
* @type {boolean}
* @memberof IGraphToolComponent
*/
parseFunctions: boolean;
/**
* The Options of the VISJS-Graph (Unterlying Graph to Render the Network)
* Will be used as Input.
*
* @type {IVisjsOptions}
* @memberof IGraphToolComponent
*/
visjsOptions: IVisjsOptions;
/**
* Array containing the Rendered Nodes. Will be used as Input.
*
* @type {(Array<N | IBaseNodeOptions>)}
* @memberof IGraphToolComponent
*/
nodes: Array<N | IBaseNodeOptions>;
/**
* Array containing the Rendered Edges. Will be used as Input.
*
* @type {(Array<E | IBaseEdgeOptions>)}
* @memberof IGraphToolComponent
*/
edges: Array<E | IBaseEdgeOptions>;
/**
* The Toolbar. Will be used as Input.
*
* @type {IToolbarConfig<ICallbackData<N,E>>}
* @memberof IGraphToolComponent
*/
toolbar: IToolbarConfig<ICallbackData<N, E>>
/**
* The Underlying Network.
*
* @type {IUndoRedoGraph<N, E>}
* @memberof IGraphToolComponent
*/
network: IUndoRedoGraph<N, E>;
/**
* Element containing the Mouse Position.
*/
readonly mousePos: {
x: number,
y: number
};
/**
* Function to Load the Graph based on a JSON string
* @param data The parsed Graph
* @param overwrite Option to overwrite or add the content
*/
loadJSON(data: string, overwrite?: boolean): void;
/**
* A Function to open Up an Edit-Window,
* Rendering the content of the Component.
*/
openEditInterface<C extends IEditPage<N | IBaseNodeOptions, E | IBaseEdgeOptions>>(
/*** The Angular Component */
component: Type<C>,
/** The Stettings, of the Component */
settings: {
inputTemplate?: ITemplate<N, E>,
[index: string]: any,
},
title: string,
/** callback, if the Sucess-Button is pressed */
sucessCallback: (data: {
template : ITemplate<N | IBaseNodeOptions, E | IBaseEdgeOptions>,
callback?: (template: ITemplate<N | IBaseNodeOptions, E | IBaseEdgeOptions>) => ITemplate<N | IBaseNodeOptions, E | IBaseEdgeOptions>
}) => void,
mode?: 'sidebar' | 'popup'): void;
addNode(pos: { x: number, y: number }): void;
/**
* Function to Update the Data of a Node.
* @param selection The Selected Node.
*/
updateNode(selection: Array<N>): void;
/**
* Function, which is used to Update an Edge
* @param edge The Corresponding Edge, which will be updated.
*/
updateEdges(edge: E): void;
/**
* Function, which will be used to update the Templates
*/
updateTemplates?: (templates: ISelectionConfig<ITemplate<N, E>>) => void;
/**
* Enable Hotkeys
*/
enableHotkeys(): void;
/**
* Disable Hotkeys
*/
disableHotkeys(): void;
/**
* Read Data from the Clipboard
*/
pasteFromClipboard(): void;
/**
* Function will copy Data to the Clipboard.
*
* @memberof IGraphToolComponent
*/
generateTemplateData(): ISelectionTemplate<IMustacheTemplate> ;
/**
* Function to paste the copied Element
* @param template The Template
* @param position The Position, where the Elements should be added
* @param useExistingNodesForEdges Flag to toggle using already existings nodes for connections
*/
paste(
template: {
nodes: N[],
edges: E[],
},
position: {
x: number,
y: number
},
useExistingNodesForEdges: boolean): void;
/**
* Function to copy the selected Elements.
*/
copySelectionToClipboard(): void;
readDataFromClipboard(): Promise<string>;
}