I understand you. I’m also importing the individual classes from gojs, but not the extension (the extension is in the method).
This is the simplified component, I think you will gett a better idea:
import {
Panel, Binding, Spot, Diagram, GraphObject, TextBlock, Placeholder,
Shape, Adornment, Point, Margin, Link, GraphLinksModel, Size, Node, RowColumnDefinition
} from 'gojs'
@Component({
selector: 'dashboard-creation-relations',
templateUrl: './creation-relations.component.html',
styleUrls: ['./creation-relations.component.scss']
})
export class DashboardCreationRelationsComponent implements OnInit, OnDestroy {
diagram: any;
constructor() {
}
ngOnInit() {
this.dashboardCreationService.setSelectedStep(this.stepId);
this.visualOrigins = [];
// this.origins = this.dashboardCreationService.dashboardCreation.origins;
this.visualOrigins = this.dashboardCreationService.dashboardCreation.originsVisual;
const $ = GraphObject.make; // for conciseness in defining templates
this.loadScrollingTable();
const $ = GraphObject.make; // for conciseness in defining templates
// This is the function with the ScrollingTable.js code
this.loadScrollingTable();
this.diagram =
$(Diagram, 'relationsDiagram',
{
initialDocumentSpot: Spot.Center,
initialViewportSpot: Spot.Center,
initialAutoScale: Diagram.Uniform,
validCycle: Diagram.CycleNotDirected, // don't allow loops
'undoManager.isEnabled': true
});
// this.diagram.toolManager.mouseDownTools.add(new ColumnResizingTool());
const fieldTemplate =
$(Panel, 'TableRow', // this Panel is a row in the containing Table
new Binding('portId', 'name'), // this Panel is a "port"
{
background: 'transparent', // so this port's background can be picked by the mouse
// allow drawing links from or to this port:
fromLinkable: true, toLinkable: true
},
$(TextBlock,
{
margin: new Margin(0, 2), column: 0, font: 'bold 14px Roboto',
overflow: TextBlock.OverflowEllipsis,
wrap: TextBlock.None,
stretch: GraphObject.Horizontal,
// and disallow drawing links from or to this text:
fromLinkable: true, toLinkable: false
},
new Binding('text', 'name')),
$(TextBlock,
{
margin: new Margin(0, 2),
column: 1,
overflow: TextBlock.OverflowEllipsis,
stretch: GraphObject.Horizontal,
font: 'bold 14px Roboto'
},
new Binding('text', 'columnType')),
);
this.diagram.nodeTemplate =
$(Node, "Vertical",
{
selectionObjectName: "SCROLLER",
resizable: true, resizeObjectName: "SCROLLER",
portSpreading: Node.SpreadingNone
},
new Binding("location").makeTwoWay(),
$(TextBlock,
{ font: "bold 14px sans-serif" },
new Binding("text", "key")),
$(Panel, "Auto",
$(Shape, { fill: "white" }),
$("ScrollingTable",
{
name: "SCROLLER",
desiredSize: new Size(NaN, 60), // fixed width
stretch: GraphObject.Fill // but stretches vertically
},
this.makeSubBinding('TABLE.itemArray', 'columnDefinitions'),
new Binding("TABLE.column", "left", function (left) { return left ? 2 : 0; }),
new Binding("desiredSize", "size").makeTwoWay(),
{
"TABLE.itemTemplate":
$(Panel, "TableRow",
{
defaultStretch: GraphObject.Horizontal,
fromSpot: Spot.LeftRightSides, toSpot: Spot.LeftRightSides,
fromLinkable: true, toLinkable: true
},
new Binding("portId", "name"),
$(TextBlock, { column: 0 }, new Binding("text", "name")),
$(TextBlock, { column: 1 }, new Binding("text", "columnType"))
),
"TABLE.defaultColumnSeparatorStroke": "grey",
"TABLE.defaultColumnSeparatorStrokeWidth": 0.5,
"TABLE.defaultRowSeparatorStroke": "grey",
"TABLE.defaultRowSeparatorStrokeWidth": 0.5,
"TABLE.defaultSeparatorPadding": new Margin(1, 3, 0, 3)
}
)
)
);
this.diagram.linkTemplate =
$(Link,
{
reshapable: false, resegmentable: false,
relinkableFrom: true, relinkableTo: true,
adjusting: Link.Stretch,
fromSpot: Spot.LeftRightSides,
toSpot: Spot.LeftRightSides
},
{
selectionAdornmentTemplate:
$(Adornment,
$(Shape,
{ isPanelMain: true, stroke: '#009fe3', strokeWidth: 2 }),
$(Shape,
{ toArrow: 'Standard', fill: '#009fe3', stroke: null, scale: 2.5 })
) // end Adornment
},
$(Shape, { stroke: '#646363', strokeWidth: 1.5 }),
$(Shape, { toArrow: 'Standard', stroke: null },
)
);
this.diagram.model =
$(GraphLinksModel,
{
archetypeNodeData: {},
linkFromPortIdProperty: 'sourceColumn',
linkFromKeyProperty: 'source',
linkToPortIdProperty: 'destinationColumn',
linkToKeyProperty: 'destination',
nodeDataArray: this.visualOrigins,
linkDataArray: this.relations
});
const tempfromnode =
$(Node,
{ layerName: 'Tool' },
$(Shape, 'Rectangle',
{
stroke: '#009fe3', strokeWidth: 3, fill: null,
portId: '', width: 1, height: 1
})
);
const temptonode =
$(Node,
{ layerName: 'Tool' },
$(Shape, 'Rectangle',
{
stroke: '#009fe3', strokeWidth: 3, fill: null,
portId: '', width: 1, height: 1
})
);
this.diagram.toolManager.linkingTool.temporaryFromNode = tempfromnode;
this.diagram.toolManager.linkingTool.temporaryFromPort = tempfromnode.port;
this.diagram.toolManager.linkingTool.temporaryToNode = temptonode;
this.diagram.toolManager.linkingTool.temporaryToPort = temptonode.port;
this.diagram.toolManager.relinkingTool.temporaryFromNode = tempfromnode;
this.diagram.toolManager.relinkingTool.temporaryFromPort = tempfromnode.port;
this.diagram.toolManager.relinkingTool.temporaryToNode = temptonode;
this.diagram.toolManager.relinkingTool.temporaryToPort = temptonode.port;
this.diagram.toolManager.linkingTool.temporaryLink =
$(Link,
{ layerName: 'Tool' },
$(Shape,
{ stroke: '#646363', strokeWidth: 2 })
);
}
makeSubBinding(targetname, sourcename) {
const bind = new Binding(targetname, 'origin');
bind.converter = function (details, target) {
const value = details[sourcename];
if (value !== undefined) {
return value;
}
};
return bind;
}
loadScrollingTable() {
GraphObject.defineBuilder("AutoRepeatButton", function (args) {
var $ = GraphObject.make;
// some internal helper functions for auto-repeating
function delayClicking(e, obj) {
endClicking(e, obj);
if (obj.click) {
obj._timer =
setTimeout(function () { repeatClicking(e, obj); },
500); // wait 0.5 seconds before starting clicks
}
}
function repeatClicking(e, obj) {
if (obj._timer) clearTimeout(obj._timer);
if (obj.click) {
obj._timer =
setTimeout(function () {
if (obj.click) {
(obj.click)(e, obj);
repeatClicking(e, obj);
}
},
100); // 0.1 seconds between clicks
}
}
function endClicking(e, obj) {
if (obj._timer) {
clearTimeout(obj._timer);
obj._timer = undefined;
}
}
return $("Button",
{ actionDown: delayClicking, actionUp: endClicking });
});
// Create a scrolling Table Panel, whose name is given as the optional first argument.
// If not given the name defaults to "TABLE".
// Example use:
// $("ScrollingTable", "TABLE",
// new Binding("TABLE.itemArray", "someArrayProperty"),
// ...)
// Note that if you have more than one of these in a Part,
// you'll want to make sure each one has a unique name.
GraphObject.defineBuilder("ScrollingTable", function (args) {
var $ = GraphObject.make;
var tablename = GraphObject.takeBuilderArgument(args, "TABLE");
// an internal helper function for actually performing a scrolling operation
function incrTableIndex(obj, i) {
var diagram = obj.diagram;
var table = obj.panel.panel.panel.findObject(tablename);
if (i === +Infinity || i === -Infinity) { // page up or down
var tabh = table.actualBounds.height;
var rowh = table.elt(table.topIndex).actualBounds.height; // assume each row has same height?
if (i === +Infinity) {
i = Math.max(1, Math.ceil(tabh / rowh) - 1);
} else {
i = -Math.max(1, Math.ceil(tabh / rowh) - 1);
}
}
var idx = table.topIndex + i;
if (idx < 0) idx = 0;
else if (idx >= table.rowCount - 1) idx = table.rowCount - 1;
if (table.topIndex !== idx) {
if (diagram !== null) diagram.startTransaction("scroll");
table.topIndex = idx;
var node = table.part; // may need to reroute links if the table contains any ports
if (node instanceof Node) node.invalidateConnectedLinks();
updateScrollBar(table);
if (diagram !== null) diagram.commitTransaction("scroll");
}
}
function updateScrollBar(table) {
var bar = table.panel.elt(1); // the scrollbar is a sibling of the table
if (!bar) return;
var idx = table.topIndex;
var up = bar.findObject("UP");
if (up) up.opacity = (idx > 0) ? 1.0 : 0.3;
var down = bar.findObject("DOWN");
if (down) down.opacity = (idx < table.rowCount - 1) ? 1.0 : 0.3;
var tabh = bar.actualBounds.height;
var rowh = table.elt(idx).actualBounds.height; //?? assume each row has same height?
if (rowh === 0 && idx < table.rowCount - 2) rowh = table.elt(idx + 1).actualBounds.height;
var numVisibleRows = Math.max(1, Math.ceil(tabh / rowh) - 1);
var needed = idx > 0 || idx + numVisibleRows <= table.rowCount;
bar.opacity = needed ? 1.0 : 0.0;
}
return $(Panel, "Table",
{
_updateScrollBar: updateScrollBar
},
// this actually holds the item elements
$(Panel, "Table",
{
name: tablename,
column: 0,
stretch: GraphObject.Fill,
background: "whitesmoke",
rowSizing: RowColumnDefinition.None,
defaultAlignment: Spot.Top
}),
// this is the scrollbar
$(RowColumnDefinition,
{ column: 1, sizing: RowColumnDefinition.None }),
$(Panel, "Table",
{ column: 1, stretch: GraphObject.Vertical, background: "#DDDDDD" },
// the scroll up button
$("AutoRepeatButton",
{
name: "UP",
row: 0,
alignment: Spot.Top,
"ButtonBorder.figure": "Rectangle",
"ButtonBorder.fill": "lightblue",
click: function (e, obj) { incrTableIndex(obj, -1); }
},
$(Shape, "TriangleUp",
{ stroke: null, desiredSize: new Size(6, 6) })),
// (someday implement a thumb here and support dragging to scroll)
// the scroll down button
$("AutoRepeatButton",
{
name: "DOWN",
row: 2,
alignment: Spot.Bottom,
"ButtonBorder.figure": "Rectangle",
"ButtonBorder.fill": "lightgray",
click: function (e, obj) { incrTableIndex(obj, +1); }
},
$(Shape, "TriangleDown",
{ stroke: null, desiredSize: new Size(6, 6) }))
)
);
});
}
}
Thanks again, i really appreciate your dedication.