Skip to content
Huston Hedinger edited this page Nov 20, 2013 · 1 revision

node keys

Fairly obviously, a well formatted GraphJSON object must posses a top level key called nodes. nodes is a list of dictionaries with declarative data about the individual nodes.

Each node is capable of holding the following top level keys:

  • id
  • properties
  • labels
  • caption
  • nodeMeta

example:

{
    nodes: [
        {
            id: 1234,
            properties: {...},
            labels: [...],
            caption: "something to display!",
            nodeMeta: {...}
        }
    ],
...
}

usage

id (int or str, required) can be a string or integer which must be unique within the GraphJSON object. Additionally, id must be identical to the value passed to source and target in edges.

example:

...
id: 61016,
...
-or-
...
id: "some_unique_string",
...

(dict, optional) Each node can contain an arbitrary number of properties as a dictionary of keys that store values or lists of values. The keys and values of properties can be shared in common with other nodes or can be unique to the node holding them - for instance, "firstName", "app_id", "genre", "title", or "category". Properties can be used in the application layer for analytics, filtering of the data, and several other ways.

example:

...
properties: {
    firstName: "Kevin",
    lastName: "Bacon",
    is_current: true,
    properties_can_be_any_primitives: true,
    age: 52,
    children: ["Steven", "Jerry", "Kiera"]
    ...
}
...

(list, optional) recently Neo4j introduced the "label" feature to the property graph model. Loosely, labels are used as way to categorize nodes for a number of different data modelling and querying benefits. Read more about labels here. There are many cases where supplying labels from the database or between two applications could be useful.

example:

...
labels: ["actor", "director", "male", "award_winner", ...]
...

(str, optional) represents a universal parameter to describe what will display upon interacting with a node (for instance onClick or hover). Caption may seem a less intuitive option than say "name", however there are a number of graph domains where "name" may be irrelevant. Additionally, it is important to disambiguate "caption" from "label". The caption need not be unique for each node, and can be the same as values supplied by properties or labels.

example:

...
caption: "Kevin Bacon",
...

(dict, optional) is a dictionary of values related to rendering graph visualization. Settings assigned to a node via the nodeMeta will override settings defined in the top level GraphJSON meta key. nodeMeta can include the keys coordinates, nodeStyle, and locked.

  • coordinates: (int, optional) includes two parameters that will initially position the nodes at a given x and y coordinate effecting the rest of the layout, or fixing the node in one position (depending on the locked parameter)

    • x: the horizontal coordinate of the node, where 0 is in the middle of the SVG and position depends on its width
    • y: the vertical coordinate of the node, where 0 is in the middle of the SVG and position depends on its height
  • nodeStyle is a dictionary that can include any of the following:

    • fill: an RGB or hex value value that will represent the fill color for a given node
    • size: an integer pixel value for the radius of the node
    • stroke: an RGB or hex value for the color of the outline of a node
    • strokeWidth: a css value that will represent the thickness of the outline for a given node ".75px", or ".5em")

example:

...
nodeStyle: {...},
...
  • locked: (bool, optional) determines if the node will be draggable by the user or if it will move in case of a layout like force. Note: Even if locked is set to true for all nodes in the toplevel GraphJSON meta object, individual nodes that are flagged "locked: true" will be draggable and will be repulsed on force layout.

example:

...
nodeStyle: {...},
...

full examples

Clone this wiki locally