JSFiddle - React, Tailwind, and code Playground
by dshilkret
HTML
<!DOCTYPE html>
<html lang="en">
<body>
<script src="https://unpkg.com/[email protected]/release/go.js"></script>
<p>
This is a minimalist HTML and JavaScript skeleton of the GoJS Sample
<a href="https://gojs.net/latest/samples/gantt.html">gantt.html</a>. It was automatically generated from a button on the sample page,
and does not contain the full HTML. It is intended as a starting point to adapt for your own usage.
For many samples, you may need to inspect the
<a href="https://github.com/NorthwoodsSoftware/GoJS/blob/master/samples/gantt.html">full source on Github</a>
and copy other files or scripts.
</p>
<div id="allSampleContent" class="p-4 w-full">
<div id="sample">
<div style="width: 100%; display: flex; justify-content: space-between; border: solid 1px black">
<div id="myTasksDiv" style="width: 150px; margin-right: 2px; border-right: 1px solid black; position: relative; -webkit-tap-highlight-color: rgba(255, 255, 255, 0);"><canvas tabindex="0" width="149" height="400" style="position: absolute; top: 0px; left: 0px; z-index: 2; user-select: none; touch-action: none; width: 149px; height: 400px;">This text is displayed if your browser does not support the Canvas HTML element.</canvas><div style="position: absolute; overflow: auto; width: 149px; height: 400px; z-index: 1;"><div style="position: absolute; width: 1px; height: 1px;"></div></div></div>
<div id="myGanttDiv" style="flex-grow: 1; height: 400px; position: relative; -webkit-tap-highlight-color: rgba(255, 255, 255, 0);"><canvas tabindex="0" width="885" height="383" style="position: absolute; top: 0px; left: 0px; z-index: 2; user-select: none; touch-action: none; width: 885px; height: 383px;">This text is displayed if your browser does not support the Canvas HTML element.</canvas><div style="position: absolute; overflow: auto; width: 902px; height: 400px; z-index: 1;"><div style="position: absolute; width: 1188px; height: 508px;"></div></div></div>
</div>
<div...
JavaScript
// Custom Layout for myGantt Diagram
class GanttLayout extends go.Layout {
constructor() {
super();
this.cellHeight = GridCellHeight;
}
doLayout(coll) {
coll = this.collectParts(coll);
const diagram = this.diagram;
diagram.startTransaction("Gantt Layout");
const bars = [];
this.assignTimes(diagram, bars);
this.arrangementOrigin = this.initialOrigin(this.arrangementOrigin);
let y = this.arrangementOrigin.y;
bars.forEach(node => {
const tasknode = myTasks.findNodeForData(node.data);
node.visible = tasknode.isVisible();
node.moveTo(convertStartToX(node.data.start), y);
if (node.visible) y += this.cellHeight;
});
diagram.commitTransaction("Gantt Layout");
}
// Update node data, to make sure each node has a start and a duration
assignTimes(diagram, bars) {
const roots = diagram.findTreeRoots();
roots.each(root => this.walkTree(root, 0, bars));
}
walkTree(node, start, bars) {
bars.push(node);
const model = node.diagram.model;
if (node.isTreeLeaf) {
let dur = node.data.duration;
if (dur === undefined || isNaN(dur)) {
dur = convertDaysToUnits(1); // default task length?
model.set(node.data, "duration", dur);
}
let st = node.data.start;
if (st === undefined || isNaN(st)) {
st = start; // use given START
model.set(node.data, "start", st);
}
return st + dur;
} else {
// first recurse to fill in any missing data
node.findTreeChildrenNodes().each(n => {
start = this.walkTree(n, start, bars);
});
// now can calculate this non-leaf node's data
let min = Infinity;
let max = -Infinity;
const colors = new go.Set();
node.findTreeChildrenNodes().each(n => {
min = Math.min(min, n.data.start);
max = Math.max(max, n.data.start + n.data.duration);
if (n.data.color) colors.add(n.data.color);
});
...