Skip to content

Commit

Permalink
'Merge' provenance visualization code from 'provenance-visualization-…
Browse files Browse the repository at this point in the history
…feature' branch.
  • Loading branch information
sluger committed Jan 19, 2015
1 parent bfbdfc2 commit 2490855
Showing 1 changed file with 86 additions and 37 deletions.
123 changes: 86 additions & 37 deletions refinery/ui/src/js/provvis_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ var provvisLayout = function () {
* Layout node columns.
* @param gNodes Layer grouped array of nodes.
* @param parent The parent node.
* @returns {Array} Layered analysis nodes.
*/
var layoutNodes = function (gNodes, parent) {

Expand All @@ -722,6 +723,8 @@ var provvisLayout = function () {
/* TODO: In development. */
/* Update row placements. */
verticalCoordAssignment(bcgNodes, parent);

return bcgNodes;
};


Expand Down Expand Up @@ -1015,40 +1018,83 @@ var provvisLayout = function () {

/**
* Reorder subanalysis layout to minimize edge crossings.
* @param aNodes Analysis nodes.
* @param saNodes Subanalysis nodes.
* @param bclgNodes Barcyenter sorted, layered and grouped analysis nodes.
*/
var reorderSubanalysisNodes = function (aNodes, saNodes) {
var reorderSubanalysisNodes = function (bclgNodes) {

console.log("#REORDER_SUBANALYES");
console.log(aNodes[0].parent.l.grid);

/* Initializations. */
aNodes.filter(function (an) {
return an.nodeType !== "dummy";
}).forEach(function (an) {
bclgNodes.forEach(function (l, i) {
l.forEach(function (an) {

/* Initialize analysis dimensions. */
an.l.depth = 1;
an.l.width = an.children.size();

/* Create grid for subanalyses. */
initNodeGrid(an);

/* List which contains the subanalysis to reorder aftewards. */
var colList = [];

/* Initialize subanalysis col and row attributes. */
an.children.values().forEach(function (san, j) {

/* Only one column does exist in this view. */
san.col = 0;
san.row = j;

/* The preceding analysis marks the fixed layer. */
if (!an.preds.empty()) {

/* Barycenter ordering. */
var degree = 1,
accRows = 0,
usedCoords = [],
delta = 0;

/* Initialize analysis dimensions. */
an.l.depth = 1;
an.l.width = an.children.size();
degree = san.preds.size();

/* Create grid for subanalyses. */
initNodeGrid(an);
/* Accumulate san row as well as an row for each pred. */
san.preds.values().forEach(function (psan) {
accRows += psan.row + ((psan.parent.row) ? psan.parent.row : 0);
});

/* Initialize subanalysis col and row attributes. */
an.children.values().forEach(function (san, i) {
/* If any subanalysis within the analysis has the same barycenter value, increase it by a small value. */
if (usedCoords.indexOf(accRows / degree) === -1) {
san.l.bcOrder = accRows / degree;
usedCoords.push(accRows / degree);
} else {
san.l.bcOrder = accRows / degree + delta;
usedCoords.push(accRows / degree + delta);
delta += 0.01;
}

/* Only one column does exist in this view. */
san.col = 0;
//san.row = an.children.size() - i - 1;
san.row = i;
/* Push into array to reorder afterwards. */
colList.push(san);
}

/* Set grid cell. */
an.l.grid[san.col][san.row] = san;
});

/* TODO: Barycenter ordering. */
/* Sort subanalysis nodes. */
colList.sort(function (a,b) {
return a.l.bcOrder - b.l.bcOrder;
});

/* Reorder subanalysis nodes. */
colList.forEach( function (d,j) {
d.row = j;
});

/* Set grid. */
an.children.values().forEach(function (san) {
/* Set grid cell. */
an.l.grid[san.col][san.row] = san;
});

/* Reset reorder list. */
colList = [];
});
});
};
Expand Down Expand Up @@ -1112,7 +1158,7 @@ var provvisLayout = function () {
console.log(gANodes);

/* TODO: in progress. */
layoutNodes(gANodes, graph);
var bclgNodes = layoutNodes(gANodes, graph);


/* Remove dummy nodes. */
Expand All @@ -1121,25 +1167,28 @@ var provvisLayout = function () {
console.log("#aNodes");
console.log(graph.aNodes);

} else {
console.log("Error: Graph is not acyclic!");
}

/* Reset layout properties for links. */
graph.aNodes.forEach(function (an) {
an.l.ts.removed = false;
});
/* Reset layout properties for links. */
graph.aNodes.forEach(function (an) {
an.l.ts.removed = false;
});

graph.links.forEach(function (l) {
l.l.ts.removed = false;
});
graph.links.forEach(function (l) {
l.l.ts.removed = false;
});

/* SUBANALYSIS LAYOUT. */
console.log("");
console.log("SUBANALYIS");
console.log("==========");
/* SUBANALYSIS LAYOUT. */
console.log("");
console.log("SUBANALYIS");
console.log("==========");

console.log(bclgNodes);

reorderSubanalysisNodes(graph.aNodes, graph.saNodes);
reorderSubanalysisNodes(bclgNodes);

} else {
console.log("Error: Graph is not acyclic!");
}


/* FILES/TOOLS LAYOUT. */
Expand Down

0 comments on commit 2490855

Please sign in to comment.