Common API Operation class API
API | example | Application scenarios | |
Add a node |
|
|
Add a new node to the canvas with a button click |
Deleting a Selected Node |
|
|
There is a button click on the page to delete the selected node and line |
Gets the JSON of the current canvas |
|
|
Gets json for all elements of the current canvas to save |
Load JSON to refresh the canvas |
|
|
Generally used to refresh and load elements on the canvas |
Obtain a node by using the node key |
|
|
Know the node key and get the details of the node |
Change the value of a node attribute |
|
|
Change the color of the node, or size, etc |
Gets the first element that gets focus, either a node or a line | myDiagram.selection.first() |
|
|
Gets all nodes that get focus | myDiagram.nodes |
|
|
The node information for traversing the entire canvas is written as 1 |
|
||
Add a line to a node |
|
||
The selected node |
|
||
Special case API usage |
|
Var newData ={“text”:”AAAA”,”key”:-33,”loc”:”0 0″}; var node = myDiagram.findNodeForData(newdat2); You can’t get this object unless it happens to be a new node, because when you add a node, Gojs automatically adds a property to the node or line |
Common event definition apis, and usage
Application scenarios | The keyword | example | Case description |
The node selects the change event | SelectionChanged: The function method name of the callback // This property is enclosed in curly braces within $(go.node,), as shown in the example on the right |
Nodes are one color when checked and another color when unchecked |
|
Node double-click event |
|
This example is mainly used in the following scenarios: Double-click a node to obtain detailed information about the node, and modify the node information in a pop-up window. |
|
An event triggered by a drag from the Palette |
|
|
|
The node where the canvas is currently being dragged | Not tested, line saved |
|
The canvas basically defines the class API
Define a concise notation for gojs globally. | var $ = go.GraphObject.make; | |
Define the basic properties of the canvas |
|
The only comment left out is that I forgot to bind the div used by the canvas and save it in myDiagram. The subsequent node Settings use this variable, which means defining nodes and manipulating nodes on the canvas |
The Canvas element attribute defines the class API
api | example | |
Define a single node | MyDiagram. NodeTemplate = $(go) Node, * * *) / / * * * for the definition of a Node |
|
Define multiple nodes (there are multiple nodes on the canvas) | MyDiagram. NodeTemplateMap. Add (” A kind of Node, “$(go) Node, * * *)) |
|
Define the line | myDiagram.linkTemplate=$(go.Link,***); |
Adding listening Events
The listener node generates events |
|
Listener line generates events |
|
Listening for delete events |
|
Go.Shape property (Shape)
The rounded rectangle | RoundedRectangle | |
See the API for more | Gojs.net/latest/intr… |
General properties
stroke | Border color | Null indicates no border and can be filled with “#87CEFA”, “red”, etc |
margin | Frame spacing | |
visible | The setting is whether the element is visible | True for visible, false for invisible, |
textAlign | Text location | “Center” in the middle |
editable | Whether the text is editable | True, false |
font | The font | “bold 8pt Microsoft YaHei, Arial, sans-serif” |
fill | The background color | Fill in “#87CEFA”, “red”, etc |
alignment | Element position setting | Go. Spot. BottomLeft/lower left go. Spot. BottomRight/lower right go Spot. The TopLeft/upper left go Spot. The TopRight/alignment on again: go. Spot. The TopRight |
isMultiline | Whether line breaks are allowed when editing | The default true |
maxLines:1, | Sets the maximum number of lines for text to display | |
minSize: | Minimum size | New go.size (10, 16), after controlling the maximum Size, the text will wrap automatically |
maxSize: | The largest size |
Special case solution
Problems arising | Solution |
Nodes or lines cannot be deleted | Check whether the canvas’s global Settings disable deletion, or whether the node and line Settings disable deletion, keyword isReadOnly, or whether there is a problem with the node binding event |
Repeated calls to the definition canvas failed | The bound div cannot be redefined, and the API for reloading data should be used |
Copyright notice: This article is the blogger’s original article, reprint please indicate the source
(To be updated later………)