Modifying the visual attributes of a graph

A Tulip graph contains a lot of visual attributes that can be freely modified from Python. These attributes are used by the Tulip software when rendering the graph. Below is an exhaustive list of these attributes :

  • nodes and edges layout
  • nodes rotations
  • nodes and edges selection
  • nodes and edges colors
  • nodes and edges sizes
  • nodes and edges shapes
  • nodes and edges border colors
  • nodes and edges border widths
  • nodes and edges labels
  • nodes and edges labels colors
  • nodes and edges labels fonts
  • nodes and edges textures
  • edge extremities shapes
  • edge extremities sizes

Graph layout

The layout of the graph can be modified through the use of the “viewLayout” graph property (of type tlp.LayoutProperty). The position of a node is defined by a 3d point (of type tlp.Coord). Bends (or curve control points) can also be set on the edges through a list of 3d points.

The sample code below shows how to set a random layout from Python:

import random

size = 100
viewLayout = graph.getLayoutProperty("viewLayout")

for n in graph.getNodes():
  x = random.random() * size
  y = random.random() * size
  viewLayout[n] = tlp.Coord(x, y, 0)

Rotations of the nodes

Rotations can be applied on graph nodes when rendering them. The rotation angles in degrees must be stored in the “viewRotation” graph property (of type tlp.DoubleProperty).

The sample code below rotates of 90 degrees the nodes whose degree is greater than 10:

viewRotation = graph.getDoubleProperty("viewRotation")

for n in graph.getNodes():
  if graph.deg(n) > 10:
    viewRotation[n] = 90

Selection

Elements of the graph can be marked in a selected state. These elements will be highlighted in the Tulip viusalizations. The current selection is stored in the “viewSelection” graph property (of type tlp.BooleanProperty).

The sample code below select nodes whose degree is greater than 3 and the edges between the selected nodes:

viewSelection = graph.getBooleanProperty("viewSelection")

viewSelection.setAllNodeValue(False)
viewSelection.setAllEdgeValue(False)

for n in graph.getNodes():
  if graph.deg(n) > 3:
    viewSelection[n] = True

for e in graph.getEdges():
  if viewSelection[graph.source(e)] and viewSelection[graph.target(e)]:
    viewSelection[e] = True

Colors of graph elements and labels

The colors of nodes and edges can be modified through the “viewColor” and “viewBorderColor” graph properties (of type tlp.ColorProperty). The colors of nodes and edges labels can be modified through the “viewLabelColor” and “viewLabelBorderColor” graph property. The colors must be given in RGBA format through an instance of the tlp.Color class.

The sample code below colors nodes whose degree is greater than 3 in blue and the others in green:

blue = tlp.Color(0,0,255)
green = tlp.Color(0,255,0)

viewColor = graph.getColorProperty("viewColor")

for n in graph.getNodes():
  if graph.deg(n) > 3:
    viewColor[n] = blue
  else:
    viewColor[n] = green

Some predefined colors constants are also available in the tlp.Color. Below is the exhaustive list of these constants:

  • tlp.Color.Amaranth
  • tlp.Color.Amber
  • tlp.Color.Apricot
  • tlp.Color.Aquamarine
  • tlp.Color.Azure
  • tlp.Color.BabyBlue
  • tlp.Color.Beige
  • tlp.Color.Black
  • tlp.Color.Blue
  • tlp.Color.BlueGreen
  • tlp.Color.BlueViolet
  • tlp.Color.Blush
  • tlp.Color.Bronze
  • tlp.Color.Brown
  • tlp.Color.Burgundy
  • tlp.Color.Byzantium
  • tlp.Color.Carmine
  • tlp.Color.Cerise
  • tlp.Color.Cerulean
  • tlp.Color.Champagne
  • tlp.Color.ChartreuseGreen
  • tlp.Color.Chocolate
  • tlp.Color.Coffee
  • tlp.Color.Copper
  • tlp.Color.Coral
  • tlp.Color.Crimson
  • tlp.Color.Cyan
  • tlp.Color.DesertSand
  • tlp.Color.ElectricBlue
  • tlp.Color.Erin
  • tlp.Color.Gold
  • tlp.Color.Gray
  • tlp.Color.Green
  • tlp.Color.Harlequin
  • tlp.Color.Indigo
  • tlp.Color.Ivory
  • tlp.Color.Jade
  • tlp.Color.JungleGreen
  • tlp.Color.Lavender
  • tlp.Color.Lemon
  • tlp.Color.Lilac
  • tlp.Color.Lime
  • tlp.Color.Magenta
  • tlp.Color.MagentaRose
  • tlp.Color.Maroon
  • tlp.Color.Mauve
  • tlp.Color.NavyBlue
  • tlp.Color.Olive
  • tlp.Color.Orange
  • tlp.Color.OrangeRed
  • tlp.Color.Orchid
  • tlp.Color.Peach
  • tlp.Color.Pear
  • tlp.Color.Periwinkle
  • tlp.Color.PersianBlue
  • tlp.Color.Pink
  • tlp.Color.Plum
  • tlp.Color.PrussianBlue
  • tlp.Color.Puce
  • tlp.Color.Purple
  • tlp.Color.Raspberry
  • tlp.Color.Red
  • tlp.Color.RedViolet
  • tlp.Color.Rose
  • tlp.Color.Salmon
  • tlp.Color.Sapphire
  • tlp.Color.Scarlet
  • tlp.Color.Silver
  • tlp.Color.SlateGray
  • tlp.Color.SpringBud
  • tlp.Color.SpringGreen
  • tlp.Color.Tan
  • tlp.Color.Taupe
  • tlp.Color.Teal
  • tlp.Color.Turquoise
  • tlp.Color.Violet
  • tlp.Color.Viridian
  • tlp.Color.White
  • tlp.Color.Yellow

Sizes of graph elements

The display sizes of the graph elements can be modified through the use of the “viewSize” graph property (of type tlp.SizeProperty). The display sizes of the edge extremities can also be modified through the “viewSrcAnchorSize” and “viewTgtAnchorSize” graph properties. The width, height and depth of an element must be given through an instance of the tlp.Size class.

The sample code below set nodes sizes proportional to their degree:

viewSize = graph.getSizeProperty("viewSize")

baseSize = tlp.Size(1,1,1)

for n in graph.getNodes():
    viewSize[n] = baseSize * (graph.deg(n) + 1)

Shapes of graph elements

The shape of nodes and edges can be modified through the use of the “viewShape” graph property (of type tlp.IntegerProperty). Some predefined constants are available for code readability (shapes are defined by integers in Tulip).

Below is the exhaustive list of the constants for nodes shapes:

  • tlp.NodeShape.Billboard
  • tlp.NodeShape.ChristmasTree
  • tlp.NodeShape.Circle
  • tlp.NodeShape.Cone
  • tlp.NodeShape.Cross
  • tlp.NodeShape.Cube
  • tlp.NodeShape.CubeOutlined
  • tlp.NodeShape.CubeOutlinedTransparent
  • tlp.NodeShape.Cylinder
  • tlp.NodeShape.Diamond
  • tlp.NodeShape.GlowSphere
  • tlp.NodeShape.HalfCylinder
  • tlp.NodeShape.Hexagon
  • tlp.NodeShape.Pentagon
  • tlp.NodeShape.Ring
  • tlp.NodeShape.RoundedBox
  • tlp.NodeShape.Sphere
  • tlp.NodeShape.Square
  • tlp.NodeShape.Star
  • tlp.NodeShape.Triangle
  • tlp.NodeShape.Window
  • tlp.NodeShape.Icon (see tlp.TulipFontAwesome and tlp.TulipMaterialDesignIcons)

Below is the exhaustive list of the constants for edges shapes:

  • tlp.EdgeShape.Polyline
  • tlp.EdgeShape.BezierCurve
  • tlp.EdgeShape.CatmullRomCurve
  • tlp.EdgeShape.CubicBSplineCurve

The shape of the edge extremities can also be modified through the “viewSrcAnchorShape” and “viewTgtAnchorShape” graph properties. Constants are also available for code readability, here is the exhaustive list :

  • tlp.EdgeExtremityShape.None
  • tlp.EdgeExtremityShape.Arrow
  • tlp.EdgeExtremityShape.Circle
  • tlp.EdgeExtremityShape.Cone
  • tlp.EdgeExtremityShape.Cross
  • tlp.EdgeExtremityShape.Cube
  • tlp.EdgeExtremityShape.CubeOutlinedTransparent
  • tlp.EdgeExtremityShape.Cylinder
  • tlp.EdgeExtremityShape.Diamond
  • tlp.EdgeExtremityShape.GlowSphere
  • tlp.EdgeExtremityShape.HalfCylinder
  • tlp.EdgeExtremityShape.Hexagon
  • tlp.EdgeExtremityShape.Pentagon
  • tlp.EdgeExtremityShape.Ring
  • tlp.EdgeExtremityShape.Sphere
  • tlp.EdgeExtremityShape.Square
  • tlp.EdgeExtremityShape.Star
  • tlp.EdgeExtremityShape.FontAwesomeIcon (see tlp.TulipFontAwesome)

The sample code below set the shape of the selected nodes to a circle:

viewShape = graph.getIntegerProperty("viewShape")
viewSelection = graph.getBooleanProperty("viewSelection")

for n in graph.getNodes():
  if viewSelection[n]:
    viewShape[n] = tlp.NodeShape.Circle

Labels of graph elements

The labels associated to graph elements can modified through the “viewLabel” graph property (of type tlp.StringProperty). The font used to render the labels can be modified through the “viewFont” graph property (of type tlp.StringProperty). A font is described by a path to a TrueType font file (.ttf).

The sample code below labels nodes according to their id:

viewLabel = graph.getStringProperty("viewLabel")

for n in graph.getNodes():
  viewLabel[n] = "Node " + str(n.id)

The position of the label relative to the associated elements can also be modified through the “viewLabelPosition” graph property (of type tlp.IntegerProperty). Constants are defined for code readability, below is the exhaustive list:

  • tlp.LabelPosition.Center
  • tlp.LabelPosition.Top
  • tlp.LabelPosition.Bottom
  • tlp.LabelPosition.Left
  • tlp.LabelPosition.Right

Border width of graph elements and labels

The border width of graph elements can be modified through the “viewBorderWidth” graph property (of type tlp.DoubleProperty). The border width of graph elements labels can be modified through the “viewLabelBorderWidth” graph property (of type tlp.DoubleProperty). The width is defined by a floating point value.

Applying a texture to nodes or edges

A texture can be applied when Tulip renders the graph elements. Setting a texture to graph elements can be done through the “viewTexture” graph property (of type tlp.StringProperty). A texture is described by a path to an image file. Note that the image must have the same width and height for correct texture loading.