Browse Source

Removed DataTable support from Graph (will be back when vis.DataSet is supported)

css_transitions
josdejong 11 years ago
parent
commit
ab6e07a180
5 changed files with 163 additions and 442 deletions
  1. +34
    -52
      examples/graph/05_social_network.html
  2. +43
    -28
      examples/graph/06_groups.html
  3. +40
    -178
      src/graph/graph.js
  4. +40
    -178
      vis.js
  5. +6
    -6
      vis.min.js

+ 34
- 52
examples/graph/05_social_network.html View File

@ -4,68 +4,50 @@
<title>Graph | Social Network</title>
<style>
body {font: 10pt arial;}
body {
font: 10pt arial;
}
</style>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="../../vis.js"></script>
<script type="text/javascript">
var DIR = 'img/soft-scraps-icons/';
var nodes = null;
var edges = null;
var graph = null;
var DIR = 'img/soft-scraps-icons/';
google.load('visualization', '1');
// Set callback to run when API is loaded
google.setOnLoadCallback(drawVisualization);
// Called when the Visualization API is loaded.
function drawVisualization() {
// Create a data table with nodes.
nodes = new google.visualization.DataTable();
nodes.addColumn('number', 'id');
nodes.addColumn('string', 'text'); // optional
nodes.addColumn('string', 'image'); // optional
nodes.addColumn('string', 'style'); // optional
// Create a data table with links.
edges = new google.visualization.DataTable();
edges.addColumn('number', 'from');
edges.addColumn('number', 'to');
edges.addColumn('number', 'value'); // optional
edges.addColumn('string', 'color'); // optional
edges.addColumn('number', 'length'); // optional
function draw() {
// create people
nodes.addRow([1, 'Algie', DIR + 'Smiley-Angry-icon.png', 'image']);
nodes.addRow([2, 'Alston', DIR + 'Smiley-Grin-icon.png', 'image']);
nodes.addRow([3, 'Barney', DIR + 'User-Administrator-Blue-icon.png', 'image']);
nodes.addRow([4, 'Coley', DIR + 'User-Administrator-Green-icon.png', 'image']);
nodes.addRow([5, 'Grant', DIR + 'User-Coat-Blue-icon.png', 'image']);
nodes.addRow([6, 'Langdon', DIR + 'User-Coat-Green-icon.png', 'image']);
nodes.addRow([7, 'Lee', DIR + 'User-Coat-Red-icon.png', 'image']);
nodes.addRow([8, 'Merlin', DIR + 'User-Executive-Green-icon.png', 'image']);
nodes.addRow([9, 'Mick', DIR + 'User-Preppy-Blue-icon.png', 'image']);
nodes.addRow([10, 'Tod', DIR + 'User-Preppy-Red-icon.png', 'image']);
nodes = [
{id: 1, text: 'Algie', image: DIR + 'Smiley-Angry-icon.png', style: 'image'},
{id: 2, text: 'Alston', image: DIR + 'Smiley-Grin-icon.png', style: 'image'},
{id: 3, text: 'Barney', image: DIR + 'User-Administrator-Blue-icon.png', style: 'image'},
{id: 4, text: 'Coley', image: DIR + 'User-Administrator-Green-icon.png', style: 'image'},
{id: 5, text: 'Grant', image: DIR + 'User-Coat-Blue-icon.png', style: 'image'},
{id: 6, text: 'Langdon', image: DIR + 'User-Coat-Green-icon.png', style: 'image'},
{id: 7, text: 'Lee', image: DIR + 'User-Coat-Red-icon.png', style: 'image'},
{id: 8, text: 'Merlin', image: DIR + 'User-Executive-Green-icon.png', style: 'image'},
{id: 9, text: 'Mick', image: DIR + 'User-Preppy-Blue-icon.png', style: 'image'},
{id: 10, text: 'Tod', image: DIR + 'User-Preppy-Red-icon.png', style: 'image'}
];
// create connections
var color = '#BFBFBF';
var len = 100; // pixels
var len = undefined;
edges.addRow([2, 8, 3, color, len]);
edges.addRow([2, 9, 5, color, len]);
edges.addRow([2, 10, 1, color, len]);
edges.addRow([4, 6, 8, color, len]);
edges.addRow([5, 7, 2, color, len]);
edges.addRow([4, 5, 1, color, len]);
edges.addRow([9, 10, 2, color, len]);
edges.addRow([2, 3, 6, color, len]);
edges.addRow([3, 9, 4, color, len]);
edges.addRow([5, 3, 1, color, len]);
edges.addRow([2, 7, 4, color, len]);
edges = [
{from: 2, to: 8, value: 3, color: color},
{from: 2, to: 9, value: 5, color: color},
{from: 2, to: 10, value: 1, color: color},
{from: 4, to: 6, value: 8, color: color},
{from: 5, to: 7, value: 2, color: color},
{from: 4, to: 5, value: 1, color: color},
{from: 9, to: 10, value: 2, color: color},
{from: 2, to: 3, value: 6, color: color},
{from: 3, to: 9, value: 4, color: color},
{from: 5, to: 3, value: 1, color: color},
{from: 2, to: 7, value: 4, color: color}
];
// specify options
var options = {
@ -76,16 +58,16 @@
}
};
// Instantiate our graph object.
// create graph
graph = new vis.Graph(document.getElementById('mygraph'));
// Draw our graph with the created data and options
// draw data
graph.draw(nodes, edges, options);
}
</script>
</head>
<body>
<body onload="draw()">
<div id="mygraph"></div>
<p>
Icons: <a href="http://www.deleket.com/" target="_blank">Scrap Icons by Deleket</a>

+ 43
- 28
examples/graph/06_groups.html View File

@ -22,17 +22,11 @@
// Called when the Visualization API is loaded.
function draw() {
// Create and populate a data table.
nodes = new google.visualization.DataTable();
nodes.addColumn('number', 'id');
nodes.addColumn('string', 'text');
nodes.addColumn('number', 'group');
edges = new google.visualization.DataTable();
edges.addColumn('number', 'from');
edges.addColumn('number', 'to');
edges.addColumn('number', 'length');
edges.addColumn('string', 'color');
var from, to;
nodes = [];
edges = [];
var color = 'gray';
var len = undefined;
@ -42,21 +36,30 @@
var groupMin = 0;
var groupMax = parseInt(document.getElementById('groupCount').value);
var group = groupMin;
var groupLeader = new Array(); // will contain the node id with the most links of each group
var groupLeader = []; // will contain the node id with the most links of each group
while (group < groupMax) {
// randomly create some nodes
var i = 0;
var cols = parseInt(Math.sqrt(nodeCount));
var connectionCount = new Array();
var connectionCount = [];
while (i < nodeCount) {
nodes.addRow([i + nodeOffset, i + nodeOffset + '', group]);
nodes.push({
id: i + nodeOffset,
text: String(i + nodeOffset),
group: group
});
connectionCount[i] = 0;
// create links in a scale-free-graph way
if (i == 1) {
var from = i;
var to = 0;
edges.addRow([from + nodeOffset, to + nodeOffset, len, color]);
from = i;
to = 0;
edges.push({
from: from + nodeOffset,
to: to + nodeOffset,
length: len,
color: color
});
connectionCount[from]++;
connectionCount[to]++;
}
@ -70,9 +73,14 @@
j++;
}
var from = i;
var to = j;
edges.addRow([from + nodeOffset, to + nodeOffset, len, color]);
from = i;
to = j;
edges.push({
from: from + nodeOffset,
to: to + nodeOffset,
length: len,
color: color
});
connectionCount[from]++;
connectionCount[to]++;
}
@ -82,16 +90,24 @@
// calculate the node with the most number of connections
var leader = 0;
for (c in connectionCount) {
if (connectionCount[c] > connectionCount[leader])
leader = parseInt(c);
for (var c in connectionCount) {
if (connectionCount.hasOwnProperty(c)) {
if (connectionCount[c] > connectionCount[leader]) {
leader = parseInt(c);
}
}
}
if (group > groupMin) {
// connect to the leader of this group to the leader of a random other group
var from = leader + nodeOffset;
var to = groupLeader[groupMin + parseInt(Math.random() * (group - groupMin))];
edges.addRow([from, to, len, color]);
from = leader + nodeOffset;
to = groupLeader[groupMin + parseInt(Math.random() * (group - groupMin))];
edges.push({
from: from,
to: to,
length: len,
color: color
});
}
// add this leader to the list
@ -123,7 +139,7 @@
</script>
</head>
<body>
<body onload="draw()">
<form onsubmit= "javascript: draw(); return false;">
Number of groups:
<input type="text" value="6" id="groupCount" style="width: 50px;">
@ -135,6 +151,5 @@
<div id="mygraph"></div>
<div id="info"></div>
</body>
</html>

+ 40
- 178
src/graph/graph.js View File

@ -84,12 +84,11 @@ function Graph (container) {
/**
* Main drawing logic. This is the function that needs to be called
* in the html page, to draw the Network.
* Note that Object DataTable is defined in google.visualization.DataTable
*
* A data table with the events must be provided, and an options table.
* @param {google.visualization.DataTable | Array} [nodes] The data containing the nodes.
* @param {google.visualization.DataTable | Array} [edges] The data containing the edges.
* @param {google.visualization.DataTable | Array} [packages] The data containing the packages
* @param {Array} [nodes] The data containing the nodes.
* @param {Array} [edges] The data containing the edges.
* @param {Array} [packages] The data containing the packages
* @param {Object} options A name/value map containing settings
*/
Graph.prototype.draw = function(nodes, edges, packages, options) {
@ -1069,64 +1068,17 @@ Graph.prototype._setSize = function(width, height) {
}
};
/**
* Convert a Google DataTable to a Javascript Array
* @param {google.visualization.DataTable} table
* @return {Array} array
*/
Graph.tableToArray = function(table) {
var array = [];
var col;
// read the column names
var colCount = table.getNumberOfColumns();
var cols = {};
for (col = 0; col < colCount; col++) {
var label = table.getColumnLabel(col);
cols[label] = col;
}
var rowCount = table.getNumberOfRows();
for (var i = 0; i < rowCount; i++) {
// copy all properties from the table columns to an object
var properties = {};
for (col in cols) {
if (cols.hasOwnProperty(col)) {
properties[col] = table.getValue(i, cols[col]);
}
}
array.push(properties);
}
return array;
};
/**
* Append nodes
* Nodes with a duplicate id will be replaced
* @param {google.visualization.DataTable | Array} nodesTable The data containing the nodes.
* @param {Array} nodes The data containing the nodes.
*/
Graph.prototype.addNodes = function(nodesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
nodesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(nodesTable);
}
else if (Graph.isArray(nodesTable)){
// Javascript Array
table = nodesTable;
}
else {
return;
}
Graph.prototype.addNodes = function(nodes) {
var hasValues = false;
var rowCount = table.length;
var rowCount = nodes.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = nodes[i];
if (properties.value != undefined) {
hasValues = true;
@ -1148,34 +1100,21 @@ Graph.prototype.addNodes = function(nodesTable) {
/**
* Load all nodes by reading the data table nodesTable
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} nodesTable The data containing the nodes.
* @param {Array} nodes The data containing the nodes.
*/
Graph.prototype.setNodes = function(nodesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
nodesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(nodesTable);
}
else if (Graph.isArray(nodesTable)){
// Javascript Array
table = nodesTable;
}
else {
Graph.prototype.setNodes = function(nodes) {
this.selection = [];
this.nodes = [];
this.hasMovingNodes = false;
if (!nodes) {
return;
}
this.hasMovingNodes = false;
this.nodesTable = table;
this.nodes = [];
this.selection = [];
this.nodesTable = nodes;
var hasValues = false;
var rowCount = table.length;
var rowCount = nodes.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = nodes[i];
if (properties.value != undefined) {
hasValues = true;
@ -1393,33 +1332,20 @@ Graph.prototype._findNodeByRow = function (row) {
/**
* Load edges by reading the data table
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} edgesTable The data containing the edges.
* @param {Array} edges The data containing the edges.
*/
Graph.prototype.setEdges = function(edgesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
edgesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(edgesTable);
}
else if (Graph.isArray(edgesTable)){
// Javascript Array
table = edgesTable;
}
else {
return;
}
this.edgesTable = table;
Graph.prototype.setEdges = function(edges) {
this.edges = [];
this.hasMovingEdges = false;
if (!edges) {
return;
}
this.edgesTable = edges;
var hasValues = false;
var rowCount = table.length;
var rowCount = edges.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = edges[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with edges (row " + i + ")";
@ -1446,30 +1372,14 @@ Graph.prototype.setEdges = function(edgesTable) {
/**
* Load edges by reading the data table
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} edgesTable The data containing the edges.
* @param {Array} edges The data containing the edges.
*/
Graph.prototype.addEdges = function(edgesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
edgesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(edgesTable);
}
else if (Graph.isArray(edgesTable)){
// Javascript Array
table = edgesTable;
}
else {
return;
}
Graph.prototype.addEdges = function(edges) {
var hasValues = false;
var rowCount = table.length;
var rowCount = edges.length;
for (var i = 0; i < rowCount; i++) {
// copy all properties
var properties = table[i];
var properties = edges[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with edges (row " + i + ")";
@ -1688,28 +1598,12 @@ Graph.prototype._findEdgeByRow = function (row) {
/**
* Append packages
* Packages with a duplicate id will be replaced
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} packagesTable The data containing the packages.
* @param {Array} packages The data containing the packages.
*/
Graph.prototype.addPackages = function(packagesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
packagesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(packagesTable);
}
else if (Graph.isArray(packagesTable)){
// Javascript Array
table = packagesTable;
}
else {
return;
}
var rowCount = table.length;
Graph.prototype.addPackages = function(packages) {
var rowCount = packages.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = packages[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with packages (row " + i + ")";
@ -1730,31 +1624,18 @@ Graph.prototype.addPackages = function(packagesTable) {
/**
* Set a new packages table
* Packages with a duplicate id will be replaced
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} packagesTable The data containing the packages.
* @param {Array} packages The data containing the packages.
*/
Graph.prototype.setPackages = function(packagesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
packagesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(packagesTable);
}
else if (Graph.isArray(packagesTable)){
// Javascript Array
table = packagesTable;
}
else {
Graph.prototype.setPackages = function(packages) {
this.packages = [];
if (!packages) {
return;
}
this.packagesTable = packages;
this.packagesTable = table;
this.packages = [];
var rowCount = table.length;
var rowCount = packages.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = packages[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with packages (row " + i + ")";
@ -1963,25 +1844,6 @@ Graph.prototype._findPackageByRow = function (row) {
return this.packages[row];
};
/**
* Retrieve an object which maps the column ids by their names
* For example a table with columns [id, name, value] will return an
* object {"id": 0, "name": 1, "value": 2}
* @param {google.visualization.DataTable} table A google datatable
* @return {Object} columnIds An object
*/
// TODO: cleanup this unused method
Graph.prototype._getColumnNames = function (table) {
var colCount = table.getNumberOfColumns();
var cols = {};
for (var col = 0; col < colCount; col++) {
var label = table.getColumnLabel(col);
cols[label] = col;
}
return cols;
};
/**
* Update the values of all object in the given array according to the current
* value range of the objects in the array.
@ -4319,7 +4181,7 @@ Graph.Package.prototype.setProperties = function(properties, constants) {
return;
}
// note that the provided properties can also be null, when they come from the Google DataTable
// note that the provided properties can also be null
if (properties.from != undefined) {this.from = this.graph._getNode(properties.from);}
if (properties.to != undefined) {this.to = this.graph._getNode(properties.to);}

+ 40
- 178
vis.js View File

@ -6891,12 +6891,11 @@ function Graph (container) {
/**
* Main drawing logic. This is the function that needs to be called
* in the html page, to draw the Network.
* Note that Object DataTable is defined in google.visualization.DataTable
*
* A data table with the events must be provided, and an options table.
* @param {google.visualization.DataTable | Array} [nodes] The data containing the nodes.
* @param {google.visualization.DataTable | Array} [edges] The data containing the edges.
* @param {google.visualization.DataTable | Array} [packages] The data containing the packages
* @param {Array} [nodes] The data containing the nodes.
* @param {Array} [edges] The data containing the edges.
* @param {Array} [packages] The data containing the packages
* @param {Object} options A name/value map containing settings
*/
Graph.prototype.draw = function(nodes, edges, packages, options) {
@ -7876,64 +7875,17 @@ Graph.prototype._setSize = function(width, height) {
}
};
/**
* Convert a Google DataTable to a Javascript Array
* @param {google.visualization.DataTable} table
* @return {Array} array
*/
Graph.tableToArray = function(table) {
var array = [];
var col;
// read the column names
var colCount = table.getNumberOfColumns();
var cols = {};
for (col = 0; col < colCount; col++) {
var label = table.getColumnLabel(col);
cols[label] = col;
}
var rowCount = table.getNumberOfRows();
for (var i = 0; i < rowCount; i++) {
// copy all properties from the table columns to an object
var properties = {};
for (col in cols) {
if (cols.hasOwnProperty(col)) {
properties[col] = table.getValue(i, cols[col]);
}
}
array.push(properties);
}
return array;
};
/**
* Append nodes
* Nodes with a duplicate id will be replaced
* @param {google.visualization.DataTable | Array} nodesTable The data containing the nodes.
* @param {Array} nodes The data containing the nodes.
*/
Graph.prototype.addNodes = function(nodesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
nodesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(nodesTable);
}
else if (Graph.isArray(nodesTable)){
// Javascript Array
table = nodesTable;
}
else {
return;
}
Graph.prototype.addNodes = function(nodes) {
var hasValues = false;
var rowCount = table.length;
var rowCount = nodes.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = nodes[i];
if (properties.value != undefined) {
hasValues = true;
@ -7955,34 +7907,21 @@ Graph.prototype.addNodes = function(nodesTable) {
/**
* Load all nodes by reading the data table nodesTable
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} nodesTable The data containing the nodes.
* @param {Array} nodes The data containing the nodes.
*/
Graph.prototype.setNodes = function(nodesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
nodesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(nodesTable);
}
else if (Graph.isArray(nodesTable)){
// Javascript Array
table = nodesTable;
}
else {
Graph.prototype.setNodes = function(nodes) {
this.selection = [];
this.nodes = [];
this.hasMovingNodes = false;
if (!nodes) {
return;
}
this.hasMovingNodes = false;
this.nodesTable = table;
this.nodes = [];
this.selection = [];
this.nodesTable = nodes;
var hasValues = false;
var rowCount = table.length;
var rowCount = nodes.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = nodes[i];
if (properties.value != undefined) {
hasValues = true;
@ -8200,33 +8139,20 @@ Graph.prototype._findNodeByRow = function (row) {
/**
* Load edges by reading the data table
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} edgesTable The data containing the edges.
* @param {Array} edges The data containing the edges.
*/
Graph.prototype.setEdges = function(edgesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
edgesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(edgesTable);
}
else if (Graph.isArray(edgesTable)){
// Javascript Array
table = edgesTable;
}
else {
return;
}
this.edgesTable = table;
Graph.prototype.setEdges = function(edges) {
this.edges = [];
this.hasMovingEdges = false;
if (!edges) {
return;
}
this.edgesTable = edges;
var hasValues = false;
var rowCount = table.length;
var rowCount = edges.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = edges[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with edges (row " + i + ")";
@ -8253,30 +8179,14 @@ Graph.prototype.setEdges = function(edgesTable) {
/**
* Load edges by reading the data table
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} edgesTable The data containing the edges.
* @param {Array} edges The data containing the edges.
*/
Graph.prototype.addEdges = function(edgesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
edgesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(edgesTable);
}
else if (Graph.isArray(edgesTable)){
// Javascript Array
table = edgesTable;
}
else {
return;
}
Graph.prototype.addEdges = function(edges) {
var hasValues = false;
var rowCount = table.length;
var rowCount = edges.length;
for (var i = 0; i < rowCount; i++) {
// copy all properties
var properties = table[i];
var properties = edges[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with edges (row " + i + ")";
@ -8495,28 +8405,12 @@ Graph.prototype._findEdgeByRow = function (row) {
/**
* Append packages
* Packages with a duplicate id will be replaced
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} packagesTable The data containing the packages.
* @param {Array} packages The data containing the packages.
*/
Graph.prototype.addPackages = function(packagesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
packagesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(packagesTable);
}
else if (Graph.isArray(packagesTable)){
// Javascript Array
table = packagesTable;
}
else {
return;
}
var rowCount = table.length;
Graph.prototype.addPackages = function(packages) {
var rowCount = packages.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = packages[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with packages (row " + i + ")";
@ -8537,31 +8431,18 @@ Graph.prototype.addPackages = function(packagesTable) {
/**
* Set a new packages table
* Packages with a duplicate id will be replaced
* Note that Object DataTable is defined in google.visualization.DataTable
* @param {google.visualization.DataTable | Array} packagesTable The data containing the packages.
* @param {Array} packages The data containing the packages.
*/
Graph.prototype.setPackages = function(packagesTable) {
var table;
if (typeof google !== 'undefined' && google.visualization && google.visualization.DataTable &&
packagesTable instanceof google.visualization.DataTable) {
// Google DataTable.
// Convert to a Javascript Array
table = Graph.tableToArray(packagesTable);
}
else if (Graph.isArray(packagesTable)){
// Javascript Array
table = packagesTable;
}
else {
Graph.prototype.setPackages = function(packages) {
this.packages = [];
if (!packages) {
return;
}
this.packagesTable = packages;
this.packagesTable = table;
this.packages = [];
var rowCount = table.length;
var rowCount = packages.length;
for (var i = 0; i < rowCount; i++) {
var properties = table[i];
var properties = packages[i];
if (properties.from === undefined) {
throw "Column 'from' missing in table with packages (row " + i + ")";
@ -8770,25 +8651,6 @@ Graph.prototype._findPackageByRow = function (row) {
return this.packages[row];
};
/**
* Retrieve an object which maps the column ids by their names
* For example a table with columns [id, name, value] will return an
* object {"id": 0, "name": 1, "value": 2}
* @param {google.visualization.DataTable} table A google datatable
* @return {Object} columnIds An object
*/
// TODO: cleanup this unused method
Graph.prototype._getColumnNames = function (table) {
var colCount = table.getNumberOfColumns();
var cols = {};
for (var col = 0; col < colCount; col++) {
var label = table.getColumnLabel(col);
cols[label] = col;
}
return cols;
};
/**
* Update the values of all object in the given array according to the current
* value range of the objects in the array.
@ -11126,7 +10988,7 @@ Graph.Package.prototype.setProperties = function(properties, constants) {
return;
}
// note that the provided properties can also be null, when they come from the Google DataTable
// note that the provided properties can also be null
if (properties.from != undefined) {this.from = this.graph._getNode(properties.from);}
if (properties.to != undefined) {this.to = this.graph._getNode(properties.to);}

+ 6
- 6
vis.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save