Vis Tutorial Lesson 3: Node Properties
In this lab we learn how to change the properties of each node including:
- The shape
- The background color
- The size
- The font color
Prompt
1 2 3 4 5 6 7 8 | |
ChatGPT o4 Response
To refactor the lab-02 files to add color and shape to each vertex, we will modify the lab-02.json to include the color and shape properties for each node. Here's how we can adjust the structure:
Updated lab-03.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Updated lab-03.js:
You don't need to change much in the JavaScript file, but here it is for completeness.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Changes explained:
- Each node now has a
colorandshapeproperty. These properties allow you to customize the appearance of each node. - For node 4, a larger size is specified with the
sizeproperty to make it a "big box." - The edges are unchanged but include a new edge between nodes 3 and 6 to reflect the inclusion of Node 6.
When you run this, each node will now have the specified color and shape, creating a visually distinct network.
Using White Text On Dark Colors
Prompt
1 | |
ChatGPT said:
ChatGPT
To change the text color for nodes with darker background colors like blue and purple, you can use the font property within each node's configuration to specify the text color. Here's how you can update your lab-03.json file to set the text color to white for the green and purple nodes:
Updated lab-02.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Explanation:
- For
Node 5(blue) andNode 6(purple), I added the"font": {"color": "white"}property, which changes the text color to white for better readability against the darker backgrounds.
Now, when you display the graph, the text on the blue and purple nodes will appear in white, making it much easier to read.
More Things to Try
You can also change the border width:
- borderWidth
- color.border
- opacity
- icon
- image
The size is used to determine the size of node shapes that do not have the label inside of them. These shapes are: image, circularImage, diamond, dot, star, triangle, triangleDown, hexagon, square and icon
Custom Canvas Shapes
You can make the shape "custom" and then supply a Canvas drawing function: