86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @create date 2020-03-12 11:56:55
|
|
* @modify date 2020-03-12 13:00:04
|
|
* @desc [description]
|
|
*/
|
|
|
|
import { ClusterEditorComponent } from '../edit-pages/cluster.edit-page';
|
|
import { IGraphToolComponent, ICallbackData } from '../interfaces/IGraphTool';
|
|
import { IBaseNodeOptions } from '../interfaces/IBaseNodeOptions';
|
|
import { IBaseEdgeOptions } from '../interfaces/IBaseEdgeOptions';
|
|
import { ITemplate } from '../interfaces/ITemplate';
|
|
|
|
/**
|
|
*
|
|
* @param component Component, which will be used
|
|
* @param selectFirstForTemplate
|
|
*/
|
|
/**
|
|
*
|
|
* @param component Component containing the Network and the openPromt Function
|
|
* @param selectFirstForTemplate Flag, which will enabling, to look for Node
|
|
* @param clusterEdgeProperties Properties for the Edges, that will be added
|
|
*/
|
|
export function clusterSelected(component: IGraphToolComponent<IBaseNodeOptions,IBaseEdgeOptions, ICallbackData<IBaseNodeOptions,IBaseEdgeOptions>>, selectFirstForTemplate = true, clusterEdgeProperties = {
|
|
color: 'red',
|
|
dashes: true,
|
|
label: 'cluster',
|
|
arrows: {
|
|
to: {enabled: false},
|
|
middle: {enabled: false},
|
|
from: {enabled: false}
|
|
},
|
|
}){
|
|
|
|
const nodes = component.network.network.getSelectedNodes();
|
|
let added = false;
|
|
|
|
/**
|
|
* Function to Clusterize the Elements
|
|
* @param clusterNodeProperties Cluster Properties for the Node
|
|
*/
|
|
const cluster = (template: ITemplate<IBaseNodeOptions,IBaseEdgeOptions> = undefined) => {
|
|
component.network.network.cluster({
|
|
joinCondition(nodeOptions) {
|
|
return nodes.includes(nodeOptions.id);
|
|
},
|
|
clusterNodeProperties: template.nodes[0],
|
|
clusterEdgeProperties
|
|
});
|
|
|
|
/** Save the Network */
|
|
component.network.save();
|
|
|
|
added = true;
|
|
}
|
|
|
|
/** Based on the Selection, try to */
|
|
if (selectFirstForTemplate && nodes.length > 0){
|
|
|
|
/** Extract the Node */
|
|
const node = component.network.data.nodes.get(nodes[0]);
|
|
|
|
/** Only if a Template is proveded, generate the node */
|
|
if (node.clusterTemplate && typeof node.clusterTemplate === 'function'){
|
|
cluster(node.clusterTemplate(node));
|
|
} else if (node.clusterTemplate && typeof node.clusterTemplate === 'object'){
|
|
cluster(node.clusterTemplate);
|
|
}
|
|
|
|
added = selectFirstForTemplate ? true: added;
|
|
}
|
|
|
|
/** Only if the Element hasnt been added, open up the Prompt */
|
|
if (!added){
|
|
component.openEditInterface<ClusterEditorComponent<IBaseNodeOptions,IBaseEdgeOptions>>(
|
|
ClusterEditorComponent as any,
|
|
{},
|
|
'Change Cluster-Settings',
|
|
(data) => {
|
|
cluster(data.template);
|
|
},
|
|
);
|
|
}
|
|
} |