2020-10-25 20:14:51 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-03-12 11:56:55
|
2020-10-29 18:20:42 +00:00
|
|
|
* @modify date 2020-10-29 12:07:07
|
2020-10-25 20:14:51 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { IBaseEdgeOptions } from '../interfaces/IBaseEdgeOptions';
|
2020-10-29 18:20:42 +00:00
|
|
|
import { IBaseNodeOptions } from '../interfaces/IBaseNodeOptions';
|
|
|
|
import { IUndoRedoGraph } from '../interfaces/IGraph';
|
2020-10-25 20:14:51 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-10-29 18:20:42 +00:00
|
|
|
export function clusterSelected(network: IUndoRedoGraph<any,any>, selectFirstForTemplate = true, clusterEdgeProperties = {
|
2020-10-25 20:14:51 +00:00
|
|
|
color: 'red',
|
|
|
|
dashes: true,
|
|
|
|
label: 'cluster',
|
|
|
|
arrows: {
|
|
|
|
to: {enabled: false},
|
|
|
|
middle: {enabled: false},
|
|
|
|
from: {enabled: false}
|
|
|
|
},
|
|
|
|
}){
|
|
|
|
|
2020-10-29 18:20:42 +00:00
|
|
|
const nodes = network.network.getSelectedNodes();
|
2020-10-25 20:14:51 +00:00
|
|
|
let added = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to Clusterize the Elements
|
|
|
|
* @param clusterNodeProperties Cluster Properties for the Node
|
|
|
|
*/
|
|
|
|
const cluster = (template: ITemplate<IBaseNodeOptions,IBaseEdgeOptions> = undefined) => {
|
2020-10-29 18:20:42 +00:00
|
|
|
network.network.cluster({
|
2020-10-25 20:14:51 +00:00
|
|
|
joinCondition(nodeOptions) {
|
|
|
|
return nodes.includes(nodeOptions.id);
|
|
|
|
},
|
|
|
|
clusterNodeProperties: template.nodes[0],
|
|
|
|
clusterEdgeProperties
|
|
|
|
});
|
|
|
|
|
|
|
|
/** Save the Network */
|
2020-10-29 18:20:42 +00:00
|
|
|
network.save();
|
2020-10-25 20:14:51 +00:00
|
|
|
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Based on the Selection, try to */
|
|
|
|
if (selectFirstForTemplate && nodes.length > 0){
|
|
|
|
|
|
|
|
/** Extract the Node */
|
2020-10-29 18:20:42 +00:00
|
|
|
const node = network.data.nodes.get(nodes[0]);
|
2020-10-25 20:14:51 +00:00
|
|
|
|
|
|
|
/** 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){
|
2020-10-29 18:20:42 +00:00
|
|
|
// openEditInterface<ClusterEditorComponent<IBaseNodeOptions,IBaseEdgeOptions>>(
|
|
|
|
// ClusterEditorComponent as any,
|
|
|
|
// {},
|
|
|
|
// 'Change Cluster-Settings',
|
|
|
|
// (data) => {
|
|
|
|
// cluster(data.template);
|
|
|
|
// },
|
|
|
|
// );
|
2020-10-25 20:14:51 +00:00
|
|
|
}
|
|
|
|
}
|