This editable organizational chart sample color-codes the Nodes according to the tree level in the hierarchy.
Select a node to edit its data values. This sample uses the Data Inspector extension to display and modify Part data. Because this simple app is part of a static web site, there is no way to upload a photograph for a person.
Double click in the diagram background to add a new boss. That uses the ClickCreatingTool with a custom ClickCreatingTool.insertPart to scroll to the new node and start editing the TextBlock for its name .
Drag a node onto another in order to change relationships, if permitted. Right-click or tap-hold a Node to bring up a context menu that allows you to:
To learn how to build an org chart from scratch with GoJS, see the Getting Started tutorial.
This sample is set to the dark theme by default.
If you want to have some "assistant" nodes on the side, above the regular reports, see the Org Chart Assistants sample, which is a more simply styled version of this sample that uses a custom TreeLayout to position "assistants" that way.
The "Table" Panel, Panel.Table, arranges objects in rows and columns. Each object in a Table Panel is put into the cell indexed by the value of GraphObject.row and GraphObject.column. The panel will look at the rows and columns for all of the objects in the panel to determine how many rows and columns the table should have. More information can be found in the GoJS Intro.
This predefined layout is used for placing Nodes of a tree-structured graph in layers (rows or columns). For discussion and examples of the most commonly used properties of the TreeLayout, see the Trees page in the Introduction. More information can be found in the GoJS Intro.
A GoJS context menu is an Adornment that is shown when the user context-clicks (right mouse click or long touch hold) an object that has its GraphObject.contextMenu set. The context menu is bound to the same data as the part itself.
It is typical to implement a context menu as a "ContextMenu" Panel containing "ContextMenuButton"s,
as you can see in the code below in the assignment of the Node's GraphObject.contextMenu and Diagram.contextMenu properties.
Each "ContextMenu" is just a "Vertical" Panel Adornment that is shadowed.
Each "ContextMenuButton" is a Panel on which you can set the GraphObject.click event handler.
In the event handler obj.part
will be the whole context menu Adornment.
obj.part.adornedPart
will be the adorned Node or Link.
The bound data is obj.part.data
, which will be the same as obj.part.adornedPart.data
.
More information can be found in the GoJS Intro.
GoJS defines several Panels for common uses. These include "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", "ContextMenuButton", and "CheckBoxButton". "ContextMenuButton"s are typically used inside of "ContextMenu" Panels; "CheckBoxButton"s are used in the implementation of "CheckBox" Panels.
These predefined panels can be used as if they were Panel-derived classes in calls to GraphObject.make. They are implemented as simple visual trees of GraphObjects in Panels, with pre-set properties and event handlers.
More information can be found in the GoJS Intro.
Using a premade GoJS extension, you can create an HTML-based inspector that displays and allows editing of data for the selected Part (if any), or for a particular JavaScript object, or for the shared Model.modelData object, which exists even if there are no nodes or links.
The inspector code lies in DataInspector.js and DataInspector.css. This code is meant to be a starting point for making your own model data inspector.
A generic demonstration of this extension can be found in the GoJS Intro.
GoJS allows diagrams to be themed. This is commonly used to provide a light and dark mode for diagrams.
The Diagram.themeManager handles themes within a Diagram. The ThemeManager can by shared by multiple diagrams, and is responsible to managing the current theme and default theme, along with any theme updates. More information can be found in the GoJS Intro.