The Logic Circuit sample allows the user to make circuits using gates and wires, which are updated whenever a Link is modified and at intervals by a looped setTimeout function.

The updateStates function calls a function to update each node according to type, which uses the color of the links into the node to determine the color of those exiting it. Red means zero or false; green means one or true. Double-clicking an input node will toggle true/false.

Mouse over a node to see its category, displayed using a shared Adornment set as the tooltip. A Palette to the left of the main diagram allows the user to drag and drop new nodes. These nodes can then be linked using ports which are defined on the various node templates. Each input port can only have one input link, while output ports can have many output links. This is controlled by the GraphObject.toMaxLinks property.

Diagram Model saved in JSON format:
{ "class": "go.GraphLinksModel", "linkFromPortIdProperty": "fromPort", "linkToPortIdProperty": "toPort", "nodeDataArray": [ {"category":"input", "key":"input1", "loc":"-150 -80" }, {"category":"or", "key":"or1", "loc":"-70 0" }, {"category":"not", "key":"not1", "loc":"10 0" }, {"category":"xor", "key":"xor1", "loc":"100 0" }, {"category":"or", "key":"or2", "loc":"200 0" }, {"category":"output", "key":"output1", "loc":"200 -100" } ], "linkDataArray": [ {"from":"input1", "fromPort":"out", "to":"or1", "toPort":"in1"}, {"from":"or1", "fromPort":"out", "to":"not1", "toPort":"in"}, {"from":"not1", "fromPort":"out", "to":"or1", "toPort":"in2"}, {"from":"not1", "fromPort":"out", "to":"xor1", "toPort":"in1"}, {"from":"xor1", "fromPort":"out", "to":"or2", "toPort":"in1"}, {"from":"or2", "fromPort":"out", "to":"xor1", "toPort":"in2"}, {"from":"xor1", "fromPort":"out", "to":"output1", "toPort":""} ]}

### GoJS Features in this sample

#### ToolTips

A tooltip is an Adornment that is shown when the mouse hovers over an object that has its GraphObject.toolTip set. The tooltip part is bound to the same data as the part itself.

It is typical to implement a tooltip as a "ToolTip" Panel holding a TextBlock or a Panel of TextBlocks and other objects. Each "ToolTip" is just an "Auto" Panel Adornment that is shadowed, and where the border is a rectangular Shape with a light gray fill. However you can implement the tooltip as any arbitrarily complicated Adornment.

More information can be found in the GoJS Intro.

Related samples

#### Palette

A Palette is a subclass of Diagram that is used to display a number of Parts that can be dragged into the diagram that is being modified by the user. The initialization of a Palette is just like the initialization of any Diagram. Like Diagrams, you can have more than one Palette on the page at the same time.

More information can be found in the GoJS Intro.

Related samples

#### Grid Patterns

GoJS provides functionality to display a grid of lines drawn at regular intervals. Grid Panels can also force dragged parts to be aligned on grid points, and resize parts to be multiples of the grid cell size.

Grids are implemented using a type of Panel, Panel.Grid. Grid Panels, like most other types of Panels, can be used within Nodes or any other kind of Part. However when they are used as the Diagram.grid, they are effectively infinite in extent.

More information can be found in the GoJS Intro.

Related samples