50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @create date 2021-08-24 18:41:28
|
|
* @modify date 2021-08-24 18:41:28
|
|
* @desc [description]
|
|
*/
|
|
|
|
import * as go from "gojs";
|
|
|
|
/**
|
|
* Helper Function to change the visibility of the given node
|
|
*
|
|
* @author M.Karkowski
|
|
* @export
|
|
* @param {go.Part} node The node to adapt
|
|
* @param {string} [property="visible"] the property, on which we should adapt the visbility
|
|
* @param {*} [value=null] if not provided, the visibility is toggled
|
|
*/
|
|
export function hideNode(node: go.Part, property = "visible", value = null): void {
|
|
|
|
if (node) {
|
|
let visiblity = value;
|
|
|
|
if (value == null) {
|
|
visiblity = typeof node.data[property] === "boolean" ? !node.data[property] : false;
|
|
}
|
|
|
|
const diagram = node.diagram;
|
|
diagram.startTransaction("changeVisibility");
|
|
diagram.model.setDataProperty(node.data, property, visiblity);
|
|
diagram.commitTransaction("changeVisibility");
|
|
}
|
|
}
|
|
|
|
export function makeHideButton(alignment = go.Spot.TopRight, toolTip = "Hides the Node.", property = "visible"): go.Node {
|
|
const make = go.GraphObject.make;
|
|
|
|
return make("Button",
|
|
{
|
|
alignment,
|
|
click: (e, obj) => {
|
|
const node = obj.part;
|
|
hideNode(node, property);
|
|
},
|
|
toolTip: make("ToolTip", make(go.TextBlock, toolTip, { margin: 5 })),
|
|
},
|
|
make(go.Shape, "MinusLine", { width: 6, height: 6 })
|
|
);
|
|
} |