Skip to content

Instantly share code, notes, and snippets.

@jdutta
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdutta/f9d1f9aec700f51d27c5 to your computer and use it in GitHub Desktop.
Save jdutta/f9d1f9aec700f51d27c5 to your computer and use it in GitHub Desktop.
adj-matrix
{
"directed": true,
"graph": [],
"nodes": [
{
"id": "InvalidLogin"
},
{
"id": "Change collaboration role"
},
{
"id": "Create"
},
{
"id": "Add"
},
{
"id": "Role"
},
{
"id": "Trash"
},
{
"id": "Storage expiration"
},
{
"id": "Authorization"
},
{
"id": "Preview"
},
{
"id": "Unsync"
},
{
"id": "Expire collaboration"
},
{
"id": "Logout"
},
{
"id": "Copy"
},
{
"id": "Edit"
},
{
"id": "Unshare"
},
{
"id": "Accept collaboration"
},
{
"id": "Upload"
},
{
"id": "Remove"
},
{
"id": "Remove collaborator"
},
{
"id": "Login"
},
{
"id": "Rename"
},
{
"id": "Expire sharing"
},
{
"id": "Lock"
},
{
"id": "Move"
},
{
"id": "Sync"
},
{
"id": "Unlock"
},
{
"id": "Document Scanning"
},
{
"id": "Invite collaborator"
},
{
"id": "Download"
}
],
"links": [
{
"source": 0,
"target": 19,
"weight": 4
},
{
"source": 0,
"target": 0,
"weight": 1
},
{
"source": 1,
"target": 1,
"weight": 1
},
{
"source": 1,
"target": 9,
"weight": 1
},
{
"source": 1,
"target": 23,
"weight": 1
},
{
"source": 1,
"target": 16,
"weight": 1
},
{
"source": 1,
"target": 18,
"weight": 1
},
{
"source": 1,
"target": 13,
"weight": 1
},
{
"source": 2,
"target": 20,
"weight": 17
},
{
"source": 2,
"target": 5,
"weight": 31
},
{
"source": 2,
"target": 21,
"weight": 3
},
{
"source": 2,
"target": 13,
"weight": 31
},
{
"source": 2,
"target": 14,
"weight": 12
},
{
"source": 2,
"target": 2,
"weight": 14
},
{
"source": 2,
"target": 16,
"weight": 2
},
{
"source": 2,
"target": 1,
"weight": 1
},
{
"source": 2,
"target": 11,
"weight": 2
},
{
"source": 2,
"target": 28,
"weight": 1
},
{
"source": 2,
"target": 19,
"weight": 5
},
{
"source": 2,
"target": 8,
"weight": 1
},
{
"source": 2,
"target": 7,
"weight": 3
},
{
"source": 3,
"target": 13,
"weight": 3
},
{
"source": 3,
"target": 16,
"weight": 1
},
{
"source": 3,
"target": 17,
"weight": 1
},
{
"source": 3,
"target": 3,
"weight": 3
},
{
"source": 3,
"target": 27,
"weight": 1
},
{
"source": 3,
"target": 28,
"weight": 1
},
{
"source": 4,
"target": 13,
"weight": 1
},
{
"source": 5,
"target": 20,
"weight": 1
},
{
"source": 5,
"target": 8,
"weight": 3
},
{
"source": 5,
"target": 21,
"weight": 1
},
{
"source": 5,
"target": 13,
"weight": 14
},
{
"source": 5,
"target": 14,
"weight": 8
},
{
"source": 5,
"target": 9,
"weight": 1
},
{
"source": 5,
"target": 24,
"weight": 1
},
{
"source": 5,
"target": 18,
"weight": 1
},
{
"source": 5,
"target": 16,
"weight": 7
},
{
"source": 5,
"target": 11,
"weight": 2
},
{
"source": 5,
"target": 27,
"weight": 2
},
{
"source": 5,
"target": 28,
"weight": 4
},
{
"source": 5,
"target": 19,
"weight": 2
},
{
"source": 5,
"target": 5,
"weight": 68
},
{
"source": 5,
"target": 2,
"weight": 35
},
{
"source": 5,
"target": 7,
"weight": 3
},
{
"source": 6,
"target": 5,
"weight": 1
},
{
"source": 6,
"target": 21,
"weight": 3
},
{
"source": 6,
"target": 16,
"weight": 5
},
{
"source": 6,
"target": 27,
"weight": 1
},
{
"source": 6,
"target": 28,
"weight": 1
},
{
"source": 6,
"target": 19,
"weight": 1
},
{
"source": 6,
"target": 8,
"weight": 4
},
{
"source": 6,
"target": 6,
"weight": 1
},
{
"source": 6,
"target": 7,
"weight": 1
},
{
"source": 7,
"target": 5,
"weight": 3
},
{
"source": 7,
"target": 13,
"weight": 8
},
{
"source": 7,
"target": 14,
"weight": 1
},
{
"source": 7,
"target": 2,
"weight": 2
},
{
"source": 7,
"target": 16,
"weight": 3
},
{
"source": 7,
"target": 3,
"weight": 1
},
{
"source": 7,
"target": 11,
"weight": 1
},
{
"source": 7,
"target": 26,
"weight": 1
},
{
"source": 7,
"target": 28,
"weight": 6
},
{
"source": 7,
"target": 19,
"weight": 8
},
{
"source": 7,
"target": 8,
"weight": 2
},
{
"source": 7,
"target": 7,
"weight": 10
},
{
"source": 8,
"target": 20,
"weight": 4
},
{
"source": 8,
"target": 5,
"weight": 5
},
{
"source": 8,
"target": 21,
"weight": 3
},
{
"source": 8,
"target": 13,
"weight": 13
},
{
"source": 8,
"target": 14,
"weight": 2
},
{
"source": 8,
"target": 2,
"weight": 4
},
{
"source": 8,
"target": 16,
"weight": 15
},
{
"source": 8,
"target": 18,
"weight": 1
},
{
"source": 8,
"target": 27,
"weight": 3
},
{
"source": 8,
"target": 28,
"weight": 33
},
{
"source": 8,
"target": 19,
"weight": 1
},
{
"source": 8,
"target": 8,
"weight": 68
},
{
"source": 8,
"target": 6,
"weight": 2
},
{
"source": 9,
"target": 1,
"weight": 2
},
{
"source": 9,
"target": 9,
"weight": 11
},
{
"source": 9,
"target": 23,
"weight": 16
},
{
"source": 9,
"target": 16,
"weight": 7
},
{
"source": 9,
"target": 18,
"weight": 11
},
{
"source": 9,
"target": 13,
"weight": 2
},
{
"source": 9,
"target": 27,
"weight": 1
},
{
"source": 9,
"target": 28,
"weight": 2
},
{
"source": 9,
"target": 19,
"weight": 1
},
{
"source": 9,
"target": 8,
"weight": 1
},
{
"source": 10,
"target": 3,
"weight": 1
},
{
"source": 10,
"target": 18,
"weight": 1
},
{
"source": 11,
"target": 20,
"weight": 1
},
{
"source": 11,
"target": 5,
"weight": 2
},
{
"source": 11,
"target": 13,
"weight": 3
},
{
"source": 11,
"target": 14,
"weight": 1
},
{
"source": 11,
"target": 16,
"weight": 1
},
{
"source": 11,
"target": 19,
"weight": 1
},
{
"source": 11,
"target": 8,
"weight": 1
},
{
"source": 11,
"target": 7,
"weight": 2
},
{
"source": 12,
"target": 28,
"weight": 2
},
{
"source": 12,
"target": 16,
"weight": 2
},
{
"source": 13,
"target": 1,
"weight": 1
},
{
"source": 13,
"target": 2,
"weight": 20
},
{
"source": 13,
"target": 3,
"weight": 3
},
{
"source": 13,
"target": 4,
"weight": 1
},
{
"source": 13,
"target": 5,
"weight": 22
},
{
"source": 13,
"target": 6,
"weight": 1
},
{
"source": 13,
"target": 7,
"weight": 8
},
{
"source": 13,
"target": 8,
"weight": 20
},
{
"source": 13,
"target": 9,
"weight": 1
},
{
"source": 13,
"target": 13,
"weight": 422
},
{
"source": 13,
"target": 14,
"weight": 4
},
{
"source": 13,
"target": 16,
"weight": 47
},
{
"source": 13,
"target": 17,
"weight": 1
},
{
"source": 13,
"target": 18,
"weight": 2
},
{
"source": 13,
"target": 19,
"weight": 12
},
{
"source": 13,
"target": 20,
"weight": 23
},
{
"source": 13,
"target": 21,
"weight": 3
},
{
"source": 13,
"target": 23,
"weight": 1
},
{
"source": 13,
"target": 24,
"weight": 6
},
{
"source": 13,
"target": 26,
"weight": 6
},
{
"source": 13,
"target": 27,
"weight": 7
},
{
"source": 13,
"target": 28,
"weight": 23
},
{
"source": 14,
"target": 5,
"weight": 8
},
{
"source": 14,
"target": 13,
"weight": 1
},
{
"source": 14,
"target": 14,
"weight": 11
},
{
"source": 14,
"target": 2,
"weight": 19
},
{
"source": 14,
"target": 19,
"weight": 1
},
{
"source": 14,
"target": 8,
"weight": 2
},
{
"source": 15,
"target": 2,
"weight": 1
},
{
"source": 15,
"target": 15,
"weight": 4
},
{
"source": 15,
"target": 0,
"weight": 1
},
{
"source": 16,
"target": 20,
"weight": 23
},
{
"source": 16,
"target": 12,
"weight": 3
},
{
"source": 16,
"target": 21,
"weight": 2
},
{
"source": 16,
"target": 13,
"weight": 32
},
{
"source": 16,
"target": 22,
"weight": 1
},
{
"source": 16,
"target": 9,
"weight": 8
},
{
"source": 16,
"target": 23,
"weight": 13
},
{
"source": 16,
"target": 24,
"weight": 11
},
{
"source": 16,
"target": 16,
"weight": 1144
},
{
"source": 16,
"target": 17,
"weight": 1
},
{
"source": 16,
"target": 18,
"weight": 1
},
{
"source": 16,
"target": 11,
"weight": 2
},
{
"source": 16,
"target": 27,
"weight": 63
},
{
"source": 16,
"target": 28,
"weight": 101
},
{
"source": 16,
"target": 15,
"weight": 1
},
{
"source": 16,
"target": 19,
"weight": 5
},
{
"source": 16,
"target": 8,
"weight": 23
},
{
"source": 16,
"target": 6,
"weight": 7
},
{
"source": 16,
"target": 2,
"weight": 5
},
{
"source": 16,
"target": 7,
"weight": 3
},
{
"source": 17,
"target": 20,
"weight": 1
},
{
"source": 17,
"target": 13,
"weight": 1
},
{
"source": 17,
"target": 16,
"weight": 1
},
{
"source": 17,
"target": 17,
"weight": 1
},
{
"source": 17,
"target": 27,
"weight": 1
},
{
"source": 17,
"target": 19,
"weight": 1
},
{
"source": 17,
"target": 7,
"weight": 1
},
{
"source": 18,
"target": 8,
"weight": 1
},
{
"source": 18,
"target": 0,
"weight": 1
},
{
"source": 18,
"target": 13,
"weight": 1
},
{
"source": 18,
"target": 9,
"weight": 11
},
{
"source": 18,
"target": 23,
"weight": 2
},
{
"source": 18,
"target": 16,
"weight": 1
},
{
"source": 18,
"target": 10,
"weight": 1
},
{
"source": 18,
"target": 24,
"weight": 1
},
{
"source": 18,
"target": 27,
"weight": 2
},
{
"source": 18,
"target": 28,
"weight": 1
},
{
"source": 18,
"target": 18,
"weight": 94
},
{
"source": 18,
"target": 2,
"weight": 1
},
{
"source": 19,
"target": 8,
"weight": 1
},
{
"source": 19,
"target": 21,
"weight": 1
},
{
"source": 19,
"target": 13,
"weight": 8
},
{
"source": 19,
"target": 14,
"weight": 1
},
{
"source": 19,
"target": 2,
"weight": 7
},
{
"source": 19,
"target": 16,
"weight": 17
},
{
"source": 19,
"target": 17,
"weight": 2
},
{
"source": 19,
"target": 3,
"weight": 2
},
{
"source": 19,
"target": 11,
"weight": 3
},
{
"source": 19,
"target": 27,
"weight": 2
},
{
"source": 19,
"target": 28,
"weight": 5
},
{
"source": 19,
"target": 19,
"weight": 9
},
{
"source": 19,
"target": 5,
"weight": 1
},
{
"source": 19,
"target": 6,
"weight": 1
},
{
"source": 19,
"target": 7,
"weight": 8
},
{
"source": 20,
"target": 20,
"weight": 4
},
{
"source": 20,
"target": 8,
"weight": 1
},
{
"source": 20,
"target": 21,
"weight": 2
},
{
"source": 20,
"target": 13,
"weight": 38
},
{
"source": 20,
"target": 2,
"weight": 2
},
{
"source": 20,
"target": 23,
"weight": 1
},
{
"source": 20,
"target": 16,
"weight": 16
},
{
"source": 20,
"target": 27,
"weight": 7
},
{
"source": 20,
"target": 28,
"weight": 6
},
{
"source": 20,
"target": 5,
"weight": 2
},
{
"source": 21,
"target": 21,
"weight": 4
},
{
"source": 21,
"target": 13,
"weight": 3
},
{
"source": 21,
"target": 14,
"weight": 1
},
{
"source": 21,
"target": 2,
"weight": 1
},
{
"source": 21,
"target": 16,
"weight": 3
},
{
"source": 21,
"target": 18,
"weight": 1
},
{
"source": 21,
"target": 19,
"weight": 3
},
{
"source": 21,
"target": 8,
"weight": 2
},
{
"source": 21,
"target": 6,
"weight": 4
},
{
"source": 21,
"target": 7,
"weight": 1
},
{
"source": 22,
"target": 25,
"weight": 2
},
{
"source": 23,
"target": 1,
"weight": 1
},
{
"source": 23,
"target": 9,
"weight": 15
},
{
"source": 23,
"target": 23,
"weight": 33
},
{
"source": 23,
"target": 16,
"weight": 15
},
{
"source": 23,
"target": 24,
"weight": 1
},
{
"source": 23,
"target": 13,
"weight": 2
},
{
"source": 23,
"target": 28,
"weight": 2
},
{
"source": 23,
"target": 18,
"weight": 1
},
{
"source": 24,
"target": 20,
"weight": 1
},
{
"source": 24,
"target": 13,
"weight": 1
},
{
"source": 24,
"target": 9,
"weight": 4
},
{
"source": 24,
"target": 16,
"weight": 12
},
{
"source": 24,
"target": 24,
"weight": 2
},
{
"source": 24,
"target": 27,
"weight": 1
},
{
"source": 24,
"target": 28,
"weight": 2
},
{
"source": 24,
"target": 19,
"weight": 1
},
{
"source": 25,
"target": 22,
"weight": 1
},
{
"source": 25,
"target": 16,
"weight": 1
},
{
"source": 26,
"target": 13,
"weight": 5
},
{
"source": 26,
"target": 2,
"weight": 1
},
{
"source": 26,
"target": 26,
"weight": 5
},
{
"source": 26,
"target": 16,
"weight": 1
},
{
"source": 27,
"target": 20,
"weight": 2
},
{
"source": 27,
"target": 5,
"weight": 2
},
{
"source": 27,
"target": 2,
"weight": 4
},
{
"source": 27,
"target": 13,
"weight": 14
},
{
"source": 27,
"target": 9,
"weight": 2
},
{
"source": 27,
"target": 23,
"weight": 1
},
{
"source": 27,
"target": 16,
"weight": 37
},
{
"source": 27,
"target": 17,
"weight": 1
},
{
"source": 27,
"target": 18,
"weight": 2
},
{
"source": 27,
"target": 27,
"weight": 95
},
{
"source": 27,
"target": 28,
"weight": 12
},
{
"source": 27,
"target": 15,
"weight": 1
},
{
"source": 27,
"target": 8,
"weight": 8
},
{
"source": 27,
"target": 6,
"weight": 2
},
{
"source": 27,
"target": 19,
"weight": 4
},
{
"source": 27,
"target": 7,
"weight": 2
},
{
"source": 28,
"target": 20,
"weight": 2
},
{
"source": 28,
"target": 5,
"weight": 8
},
{
"source": 28,
"target": 0,
"weight": 2
},
{
"source": 28,
"target": 21,
"weight": 1
},
{
"source": 28,
"target": 13,
"weight": 30
},
{
"source": 28,
"target": 14,
"weight": 1
},
{
"source": 28,
"target": 2,
"weight": 7
},
{
"source": 28,
"target": 23,
"weight": 2
},
{
"source": 28,
"target": 24,
"weight": 2
},
{
"source": 28,
"target": 18,
"weight": 1
},
{
"source": 28,
"target": 16,
"weight": 110
},
{
"source": 28,
"target": 11,
"weight": 2
},
{
"source": 28,
"target": 27,
"weight": 3
},
{
"source": 28,
"target": 28,
"weight": 405
},
{
"source": 28,
"target": 19,
"weight": 9
},
{
"source": 28,
"target": 8,
"weight": 16
},
{
"source": 28,
"target": 12,
"weight": 1
},
{
"source": 28,
"target": 7,
"weight": 4
}
],
"multigraph": false
}
{"description":"adj-matrix","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"chart_data.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"chart_data.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"main.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/oTNoNdI.gif"}
// Adj matrix
// Configurable params
var config = {
cellWidth: 18,
cellGap: 1,
color: d3.scale.category20b()
};
function generateRandomAdjMatrixData(n) {
var matrix = [];
var labels = [];
var i, j;
for (i=0; i<n; i++) {
matrix.push([]);
labels.push('a' + i);
}
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
if (i===j) {
matrix[i][j] = 0;
} else {
matrix[i][j] = Math.random() < 0.2 ? 1 : 0;
}
}
}
return {
labels: labels,
matrix: matrix
};
}
function generateMatrix(links, numNodes) {
var i, j;
var matrix = [];
for (i=0; i<numNodes; i++) {
matrix.push([]);
for (j=0; j<numNodes; j++) {
matrix[i].push(0);
}
}
for (i=0; i<links.length; i++) {
var link = links[i];
matrix[link.source][link.target] = link.weight;
}
return matrix;
}
var data = tributary.chart_data;
var matrix = generateMatrix(data.links, data.nodes.length);
var labels = data.nodes.map(function (o) { return o.id; });
var weightRange = d3.extent(data.links, function (l) { return l.weight; });
drawMatrix({labels: labels, matrix: matrix, weightRange: weightRange});
//var randomData = generateRandomAdjMatrixData(20);
//drawMatrix(randomData);
function drawMatrix(data) {
var n = data.labels.length;
var i, j;
var weightRange = data.weightRange || [1, 100];
var opacityScale = d3.scale.linear().domain(weightRange).range([0.3, 1]);
var svg = d3.select('svg');
var gRoot = svg.append('svg:g')
.attr('transform', 'translate(176, 131)');
for (i=0; i<n; i++) {
var gRow = gRoot.append('svg:g').classed('row', true);
for (j=0; j<n; j++) {
gRow.selectAll('.cell')
.data(data.matrix[i])
.enter()
.append('svg:rect')
.classed('cell', true)
//.datum(data.matrix[i][j])
.attr({
x: function (d, k) {
return k*(config.cellWidth + config.cellGap);
},
y: function (d) {
return i*(config.cellWidth + config.cellGap);
},
width: config.cellWidth,
height: config.cellWidth
})
.style({
fill: function (d) {
if (d) {
return '#000';
//return '#1ca8dd';
//return config.color(d);
}
return '#eee';
},
opacity: function (d) {
if (!d) {
return 1;
}
return opacityScale(d);
}
});
}
gRoot.append('svg:text')
.attr({
transform: 'translate('+(config.cellWidth/2 + i*(config.cellWidth + config.cellGap))+','+i*(config.cellWidth+config.cellGap)+')rotate(-90)',
x: function (d, k) {
return config.cellWidth/2 + i*(config.cellWidth + config.cellGap);
},
y: 0
})
.text(data.labels[i])
.style({
'font-size': 10,
'writing-mode1': 'tb',
'text-anchor1': 'end'
});
gRoot.append('svg:text')
.attr({
y: function (d, k) {
return config.cellWidth/2 + i*(config.cellWidth + config.cellGap);
},
x: -5
})
.text(data.labels[i])
.style({
'font-size': 10,
'text-anchor': 'end'
});
}
}
svg {
background-color: white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment