Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init() {
const $ = go.GraphObject.make; // for conciseness in defining templates
this.myDiagram = $(
go.Diagram,
'myDiagramDiv', // create a Diagram for the DIV HTML element
{
initialContentAlignment: go.Spot.LeftCenter,
layout: $(
go.TreeLayout,
{
angle: 0,
arrangement: go.TreeLayout.ArrangementVertical,
treeStyle: go.TreeLayout.StyleLayered
}),
isReadOnly: true
});
this.myDiagram.allowHorizontalScroll = true;
this.myDiagram.allowVerticalScroll = true;
this.myDiagram.allowZoom = false;
this.myDiagram.allowSelect = true;
this.myDiagram.autoScale = Diagram.Uniform;
this.myDiagram.contentAlignment = go.Spot.LeftCenter;
initDiagram () {
const $ = go.GraphObject.make
this.diagram =
$(go.Diagram, 'erDiagramDiv', // must name or refer to the DIV HTML element
{
initialContentAlignment: go.Spot.Center,
allowDelete: false,
allowCopy: false,
layout: $(go.ForceDirectedLayout),
'undoManager.isEnabled': true
})
// the template for each attribute in a node's array of item data
const itemTempl =
$(go.Panel, 'Horizontal',
$(go.Shape,
{ desiredSize: new go.Size(10, 10),
margin: new go.Margin(0, 5, 0, 0) },
new go.Binding('figure', 'figure'),
new go.Binding('fill', 'color')),
$(go.TextBlock,
{ stroke: '#333333',
new go.Binding("figure"),
new go.Binding("fill")),
$(go.TextBlock,
{
font: "bold 10pt Helvetica, Arial, sans-serif",
margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: false
},
new go.Binding("text").makeTwoWay())
),
// four small named ports, one on each side:
makePort("T", go.Spot.Top, false, true),
makePort("L", go.Spot.Left, true, true),
makePort("R", go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, true, false),
{ // handle mouse enter/leave events to show/hide the ports
mouseEnter: function(e, node) { showSmallPorts(node, true); },
mouseLeave: function(e, node) { showSmallPorts(node, false); }
},
);
function showSmallPorts(node, show) {
node.ports.each(function(port) {
if (port.portId !== "") { // don't change the default port, which is the big shape
port.fill = show ? "rgba(0,0,0,.3)" : null;
}
});
}
var linkSelectionAdornmentTemplate =
{ fill: this.getBrush('lightgrad'), stroke: '#756875', strokeWidth: 3 }),
$(go.Panel, 'Table',
{ margin: 8, stretch: go.GraphObject.Fill },
$(go.RowColumnDefinition, { row: 0, sizing: go.RowColumnDefinition.None }),
// the table header
$(go.TextBlock,
{
row: 0,
alignment: go.Spot.Center,
margin: new go.Margin(0, 14, 0, 2), // leave room for Button
font: 'bold 16px sans-serif'
},
new go.Binding('text', 'key')),
// the collapse/expand button
$('PanelExpanderButton', 'LIST', // the name of the element whose visibility this button toggles
{ row: 0, alignment: go.Spot.TopRight }),
// the list of Panels, each showing an attribute
$(go.Panel, 'Vertical',
{
name: 'LIST',
row: 1,
padding: 3,
alignment: go.Spot.TopLeft,
defaultAlignment: go.Spot.Left,
stretch: go.GraphObject.Horizontal,
itemTemplate: itemTempl
},
new go.Binding('itemArray', 'fields'))
) // end Table Panel
) // end Node
// define the Link template, representing a relationship
let gridlayer = diagram.findLayer('Grid');
let circles = new go.Set(go.Part);
gridlayer.parts.each((circle: any) => {
if (circle.name === 'CIRCLE') { circles.add(circle); }
});
circles.each(function (circle) {
diagram.remove(circle);
});
// add circles centered at the root
// let $ = go.GraphObject.make; // for conciseness in defining templates
for (let lay = 1; lay <= this.maxLayers; lay++) {
let radius = lay * this.layerThickness;
let circle =
$(go.Part,
{ name: 'CIRCLE', layerName: 'Grid' },
{ locationSpot: go.Spot.Center, location: this.root.location },
$(go.Shape, 'Circle',
{ width: radius * 2, height: radius * 2 },
{ fill: 'rgba(200,200,200,0.2)', stroke: null }));
diagram.add(circle);
}
}
});
return s + ")";
})),
// method return type, if any
$(go.TextBlock, "",
new go.Binding("text", "type", function(t) { return (t ? ": " : ""); })),
$(go.TextBlock,
{ isMultiline: false, editable: true },
new go.Binding("text", "type").makeTwoWay())
);
// this simple template does not have any buttons to permit adding or
// removing properties or methods, but it could!
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{
locationSpot: go.Spot.Center,
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides
},
$(go.Shape, { fill: "lightyellow" }),
$(go.Panel, "Table",
{ defaultRowSeparatorStroke: "black" },
// header
$(go.TextBlock,
{
row: 0, columnSpan: 2, margin: 3, alignment: go.Spot.Center,
font: "bold 12pt sans-serif",
isMultiline: false, editable: true
},
new go.Binding("text", "name").makeTwoWay()),
// Attributes
fromLinkable: true,
toLinkable: true,
cursor: "pointer"
}),
$(go.Panel, "Horizontal",
$(go.Picture, {
name: "Picture",
desiredSize: new go.Size(39, 50),
margin: new go.Margin(6, 8, 6, 10),
},
new go.Binding("source", "key", findHeadShot)),
// define the panel where the text will appear
$(go.Panel, "Table", {
maxSize: new go.Size(150, 999),
margin: new go.Margin(6, 10, 0, 3),
defaultAlignment: go.Spot.Left
},
$(go.RowColumnDefinition, {
column: 2,
width: 4
}),
$(go.TextBlock, textStyle(), // the name
{
row: 0,
column: 0,
columnSpan: 5,
font: "12pt Segoe UI,sans-serif",
editable: true,
isMultiline: false,
minSize: new go.Size(10, 16)
},
new go.Binding("text", "name").makeTwoWay()),
private createDiagram(diagramId: string): Diagram {
const $ = go.GraphObject.make;
const myDiagram: Diagram = $(go.Diagram, diagramId, {
initialContentAlignment: go.Spot.LeftCenter,
layout: $(go.TreeLayout, {
angle: 0,
arrangement: go.TreeLayout.ArrangementVertical,
treeStyle: go.TreeLayout.StyleLayered
}),
isReadOnly: false,
allowHorizontalScroll: true,
allowVerticalScroll: true,
allowZoom: false,
allowSelect: true,
autoScale: Diagram.Uniform,
contentAlignment: go.Spot.LeftCenter,
TextEdited: this.onTextEdited
});
myDiagram.toolManager.panningTool.isEnabled = false;
const $ = go.GraphObject.make;
const myDiagram: Diagram = $(go.Diagram, diagramId, {
initialContentAlignment: go.Spot.LeftCenter,
layout: $(go.TreeLayout, {
angle: 0,
arrangement: go.TreeLayout.ArrangementVertical,
treeStyle: go.TreeLayout.StyleLayered
}),
isReadOnly: false,
allowHorizontalScroll: true,
allowVerticalScroll: true,
allowZoom: false,
allowSelect: true,
autoScale: Diagram.Uniform,
contentAlignment: go.Spot.LeftCenter,
TextEdited: this.onTextEdited
});
myDiagram.toolManager.panningTool.isEnabled = false;
myDiagram.toolManager.mouseWheelBehavior = ToolManager.WheelScroll;
myDiagram.nodeTemplate = $(
go.Node,
'Auto',
{
selectionChanged: node => this.props.onNodeSelection(node.key as string, node.isSelected)
},
$(go.Shape, 'RoundedRectangle', { strokeWidth: 0 }, new go.Binding('fill', 'color')),
$(go.TextBlock, { margin: 8, editable: true }, new go.Binding('text', 'label'))
);
row: 1,
column: 0,
margin: new go.Margin(5, 10, 0, 10)
},
new go.Binding('font', 'key', (key: string) => {
const type = serverMapComponent.isBaseApplication(key) ? 'big' : 'normal';
return ServerMapTheme.general.common.font[type];
}),
new go.Binding('stroke', '', () => {
return ServerMapTheme.general.node.normal.text.stroke;
}),
new go.Binding('text', 'applicationName')
),
$(
go.Panel, 'Auto',
{ row: 0, column: 0, alignment: go.Spot.BottomCenter },
$(
go.TextBlock,
{
margin: new go.Margin(0, 0, 10, 0),
},
new go.Binding('visible', 'instanceCount', (v) => {
return v > 1 ? true : false;
}),
new go.Binding('font', '', () => {
return ServerMapTheme.general.common.font.normal;
}),
new go.Binding('stroke', '', () => {
return ServerMapTheme.general.instance.text.stroke;
}),
new go.Binding('text', 'instanceCount')
)