Hi team,
I take the code from table layout example,
I’ve some problem in positioning cells within the column or row group, here’s my diagram
and here what I’m trying to achieve:
My questions are:
- why cells’ border are not filled when there’s no adjacent cell on the right? (probably I’ve forget some settings)
- why there’s an empty cell after column/row title in both cases?
Here my code:
myDiagram =
$(go.Diagram, "myDiagramRep",
{
layout: $(TableLayout,
$(go.RowColumnDefinition, { row: 1, height: 22 }), // fixed size column headers
$(go.RowColumnDefinition, { column: 1, width: 22 }) // fixed size row headers
),
"InitialLayoutCompleted": function(e) {
// if not all Nodes have real locations, force a layout to happen
if (!e.diagram.nodes.all(function(n) { return n.location.isReal(); })) {
e.diagram.layoutDiagram(true);
}},
"SelectionMoved": function(e) { e.diagram.layoutDiagram(true); },
"resizingTool": new LaneResizingTool(),
// feedback that dropping in the background is not allowed
mouseDragOver: function(e) { e.diagram.currentCursor = "not-allowed"; },
// when dropped in the background, not on a Node or a Group, cancel the drop
mouseDrop: function(e) { e.diagram.currentTool.doCancel(); },
"animationManager.isInitial": false,
"undoManager.isEnabled": true
});
myDiagram.nodeTemplateMap.add("Header", // an overall table header, at the top
$(go.Part, "Auto",
{
row: 0, column: 1, columnSpan: 2,
stretch: go.GraphObject.Horizontal,
selectable: false, pickable: false
},
$(go.Shape, { fill: "transparent", strokeWidth: 0 }),
$(go.TextBlock, { alignment: go.Spot.Center, font: "bold 12pt sans-serif" },
new go.Binding("text"))
));
myDiagram.nodeTemplateMap.add("Sider", // an overall table header, on the left side
$(go.Part, "Auto",
{
row: 1, rowSpan: 2, column: 0,
stretch: go.GraphObject.Vertical,
selectable: false, pickable: false
},
$(go.Shape, { fill: "transparent", strokeWidth: 0 }),
$(go.TextBlock, { alignment: go.Spot.Center, font: "bold 12pt sans-serif", angle: 270 },
new go.Binding("text"))
));
myDiagram.nodeTemplateMap.add("Column Header", // for each column header
$(go.Part, "Spot",
{
row: 2, rowSpan: 2, column: 2,
minSize: new go.Size(500, NaN),
stretch: go.GraphObject.Fill,
movable: false,
resizable: true,
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // for changing the length of a lane
{
alignment: go.Spot.Right,
desiredSize: new go.Size(25, 7),
fill: "lightblue", stroke: "dodgerblue",
cursor: "col-resize"
})
)
},
new go.Binding("column", "col"),
$(go.Shape, { fill: null },
new go.Binding("fill", "color")),
$(go.Panel, "Auto",
{ // this is positioned above the Shape, in row 1
alignment: go.Spot.Top, alignmentFocus: go.Spot.Bottom,
stretch: go.GraphObject.Horizontal,
height: myDiagram.layout.getRowDefinition(1).height
},
$(go.Shape, { fill: "transparent", strokeWidth: 0 }),
$(go.TextBlock,
{
font: "bold 10pt sans-serif", isMultiline: false,
wrap: go.TextBlock.None, overflow: go.TextBlock.OverflowEllipsis
},
new go.Binding("text"))
)
));
myDiagram.nodeTemplateMap.add("Row Sider", // for each row header with single cell
$(go.Part, "Spot",
{
row: 2, column: 1, columnSpan: 2,
minSize: new go.Size(NaN, 100),
stretch: go.GraphObject.Fill,
movable: false,
resizable: true,
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // for changing the breadth of a lane
{
alignment: go.Spot.Bottom,
desiredSize: new go.Size(25, 25),
fill: "lightblue", stroke: "dodgerblue",
cursor: "row-resize"
})
)
},
new go.Binding("row"),
$(go.Shape, { fill: null },
new go.Binding("fill", "color")),
$(go.Panel, "Auto",
{ // this is positioned to the left of the Shape, in column 1
alignment: go.Spot.Left, alignmentFocus: go.Spot.Right,
stretch: go.GraphObject.Vertical, angle: 270,
height: myDiagram.layout.getColumnDefinition(1).width
},
$(go.Shape, { fill: "transparent", strokeWidth: 0 }),
$(go.TextBlock,
{
font: "bold 10pt sans-serif", isMultiline: false,
wrap: go.TextBlock.None, overflow: go.TextBlock.OverflowEllipsis
},
new go.Binding("text"))
)
));
myDiagram.nodeTemplateMap.add("Row Sider2", // for each row header
$(go.Part, "Spot",
{
row: 2, column: 2, columnSpan: 2,
minSize: new go.Size(NaN, 100),
stretch: go.GraphObject.Fill,
movable: false,
resizable: true,
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // for changing the breadth of a lane
{
alignment: go.Spot.Bottom,
desiredSize: new go.Size(7, 25),
fill: "lightblue", stroke: "dodgerblue",
cursor: "row-resize"
})
)
},
new go.Binding("row"),
$(go.Shape, { fill: null },
new go.Binding("fill", "color")),
$(go.Panel, "Auto",
{ // this is positioned to the left of the Shape, in column 1
alignment: go.Spot.Left, alignmentFocus: go.Spot.Right,
stretch: go.GraphObject.Vertical, angle: 270,
height: myDiagram.layout.getColumnDefinition(1).width
},
$(go.Shape, { fill: "transparent", strokeWidth: 0 }),
$(go.TextBlock,
{
font: "bold 10pt sans-serif", isMultiline: false,
wrap: go.TextBlock.None, overflow: go.TextBlock.OverflowEllipsis
},
new go.Binding("text"))
)
));
myDiagram.nodeTemplate = // for regular nodes within cells (groups); you'll want to extend this
$(go.Node, "Auto",
{ width: 100, height: 25, margin: 4 }, // assume uniform Margin, all around
new go.Binding("row"),
new go.Binding("column", "col"),
$(go.Shape, { fill: "white" },
new go.Binding("fill", "color")),
$(go.TextBlock,
new go.Binding("text", "key"))
);
myDiagram.groupTemplate = // for cells
$(go.Group, "Auto",
{
layerName: "Background",
stretch: go.GraphObject.Fill,
selectable: false,
computesBoundsAfterDrag: true,
computesBoundsIncludingLocation: true,
handlesDragDropForMembers: true, // don't need to define handlers on member Nodes and Links
mouseDragEnter: function(e, group, prev) { group.isHighlighted = true; },
mouseDragLeave: function(e, group, next) { group.isHighlighted = false; },
mouseDrop: function(e, group) {
// if any dropped part wasn't already a member of this group, we'll want to let the group's row
// column allow themselves to be resized automatically, in case the row height or column width
// had been set manually by the LaneResizingTool
var anynew = e.diagram.selection.any(function(p) { return p.containingGroup !== group; });
// Don't allow headers/siders to be dropped
var anyHeadersSiders = e.diagram.selection.any(function(p) {
return p.category === "Column Header" || p.category === "Row Sider";
});
if (!anyHeadersSiders && group.addMembers(e.diagram.selection, true)) {
if (anynew) {
e.diagram.layout.getRowDefinition(group.row).height = NaN;
e.diagram.layout.getColumnDefinition(group.column).width = NaN;
}
} else { // failure upon trying to add parts to this group
e.diagram.currentTool.doCancel();
}
}
},
new go.Binding("row"),
new go.Binding("column", "col"),
// the group is normally unseen -- it is completely transparent except when given a color or when highlighted
$(go.Shape,
{
fill: "transparent", stroke: "transparent",
strokeWidth: myDiagram.nodeTemplate.margin.left,
stretch: go.GraphObject.Fill
},
new go.Binding("fill", "color"),
new go.Binding("stroke", "isHighlighted", function(h) { return h ? "red" : "transparent"; }).ofObject()),
$(go.Placeholder,
{ // leave a margin around the member nodes of the group which is the same as the member node margin
alignment: (function(m) { return new go.Spot(0, 0, m.top, m.left); })(myDiagram.nodeTemplate.margin),
padding: (function(m) { return new go.Margin(0, m.right, m.bottom, 0); })(myDiagram.nodeTemplate.margin)
})
);
//[...]
myDiagram.model = new go.GraphLinksModel([
// headers
{ key: "Header", text: "Report Pivot Content", category: "Header" },
// column and row headers
{ key: "Header", text: "Header", row: 2, category: "Row Sider" },
{ key: "Info", text: "Info", row: 3, category: "Row Sider" },
{ key: "Content", text: "Columns", col: 3, category: "Column Header" },
{ key: "Total", text: "Total", row: 4, category: "Row Sider2" },
// cells, each a group assigned to a row and column
{ key: "HeaReq", row: 2, col: 2, isGroup: true, color: "lightyellow" },
{ key: "InfReq", row: 3, col: 2, isGroup: true, color: "lightyellow" },
{ key: "ConApp", row: 3, col: 3, isGroup: true, color: "lightyellow" },
{ key: "TotApp", row: 4, col: 3, isGroup: true, color: "lightblue" },
{ key: "TotApp", row: 4, col: 4, isGroup: true, color: "lightblue" },
// nodes, each assigned to a group/cell
{ key: "Delta", color: "orange", size: "100 100", group: "HeaReq" },
{ key: "Info", color: "orange", size: "100 100", group: "InfReq" },
{ key: "Theta", color: "tomato", size: "100 50", group: "ConApp" },
{ key: "Theta", color: "tomato", size: "100 50", group: "TotApp" }
]);
Thank you for your help
Fulvio