Loader.js

Summary
Loader.js
LoaderProvides methods for loading and serving JSON data.
Functions
loadJSONLoads a JSON structure to the visualization.
toJSONReturns a JSON tree/graph structure from the visualization’s Graph.

Loader

Provides methods for loading and serving JSON data.

Summary
Functions
loadJSONLoads a JSON structure to the visualization.
toJSONReturns a JSON tree/graph structure from the visualization’s Graph.

Functions

loadJSON

loadJSON: function(json,
i)

Loads a JSON structure to the visualization.  The JSON structure can be a JSON tree or graph structure.

A JSON tree or graph structure consists of nodes, each having as properties

id(string) A unique identifier for the node
name(string) A node’s name
data(object) The data optional property contains a hash (i.e {}) where you can store all the information you want about this node.

For JSON Tree structures, there’s an extra optional property children of type Array which contains the node’s children.

Example

var json = {
  "id": "aUniqueIdentifier",
  "name": "usually a nodes name",
  "data": {
    "some key": "some value",
    "some other key": "some other value"
   },
  "children": [ *other nodes or empty* ]
};

JSON Graph structures consist of an array of nodes, each specifying the nodes to which the current node is connected.  For JSON Graph structures, the children property is replaced by the adjacencies property.

There are two types of Graph structures, simple and extended graph structures.

For simple Graph structures, the adjacencies property contains an array of strings, each specifying the id of the node connected to the main node.

Example

var json = [
  {
    "id": "aUniqueIdentifier",
    "name": "usually a nodes name",
    "data": {
      "some key": "some value",
      "some other key": "some other value"
     },
    "adjacencies": ["anotherUniqueIdentifier", "yetAnotherUniqueIdentifier", 'etc']
  },

  'other nodes go here...'
];

For extended Graph structures, the adjacencies property contains an array of Adjacency objects that have as properties

nodeTo(string) The other node connected by this adjacency.
data(object) A data property, where we can store custom key/value information.

Example

var json = [
  {
    "id": "aUniqueIdentifier",
    "name": "usually a nodes name",
    "data": {
      "some key": "some value",
      "some other key": "some other value"
     },
    "adjacencies": [
    {
      nodeTo:"aNodeId",
      data: {} //put whatever you want here
    },
    'other adjacencies go here...'
  },

  'other nodes go here...'
];

About the data property

As described before, you can store custom data in the data property of JSON nodes and adjacencies.  You can use almost any string as key for the data object.  Some keys though are reserved by the toolkit, and have special meanings.  This is the case for keys starting with a dollar sign, for example, $width.

For JSON node objects, adding dollar prefixed properties that match the names of the options defined in Options.Node will override the general value for that option with that particular value.  For this to work however, you do have to set overridable = true in Options.Node.

The same thing is true for JSON adjacencies.  Dollar prefixed data properties will alter values set in Options.Edge if Options.Edge has overridable = true.

When loading JSON data into TreeMaps, the data property must contain a value for the $area key, since this is the value which will be taken into account when creating the layout.  The same thing goes for the $color parameter.

In JSON Nodes you can use also $label- prefixed properties to refer to Options.Label properties.  For example, $label-size will refer to Options.Label size property.  Also, in JSON nodes and adjacencies you can set canvas specific properties individually by using the $canvas- prefix.  For example, $canvas-shadowBlur will refer to the shadowBlur property.

These properties can also be accessed after loading the JSON data from Graph.Nodes and Graph.Adjacences by using Accessors.  For more information take a look at the Graph and Accessors documentation.

Finally, these properties can also be used to create advanced animations like with Options.NodeStyles.  For more information about creating animations please take a look at the Graph.Plot and Graph.Plot.animate documentation.

loadJSON Parameters

jsonA JSON Tree or Graph structure.
iFor Graph structures only.  Sets the indexed node as root for the visualization.

toJSON

toJSON: function(type)

Returns a JSON tree/graph structure from the visualization’s Graph.  See Loader.loadJSON for the graph formats available.

See also

Loader.loadJSON

Parameters

type(string) Default’s “tree”.  The type of the JSON structure to be returned.  Possible options are “tree” or “graph”.
loadJSON: function(json,
i)
Loads a JSON structure to the visualization.
toJSON: function(type)
Returns a JSON tree/graph structure from the visualization’s Graph.
A Graph Class that provides useful manipulation functions.
Provides Node rendering options for Tree and Graph based visualizations.
Provides Edge rendering options for Tree and Graph based visualizations.
Provides styling for Labels such as font size, family, etc.
A Graph node.
A Graph adjacence (or edge) connecting two Graph.Nodes.
Defines a set of methods for data, canvas and label styles manipulation implemented by Graph.Node and Graph.Adjacence instances.
Apply different styles when a node is hovered or selected.
Graph rendering and animation methods.
animate: function(opt,
versor)
Animates a Graph by interpolating some Graph.Node, Graph.Adjacence or Graph.Label properties.
Close