Skip to content

Commit

Permalink
'Merge' grid adjustment on dragging code from 'provenance-visualizati…
Browse files Browse the repository at this point in the history
…on-feature' branch.
  • Loading branch information
sluger committed Jan 24, 2015
1 parent 066bf9c commit ca4031e
Showing 1 changed file with 202 additions and 110 deletions.
312 changes: 202 additions & 110 deletions refinery/ui/src/js/provvis_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,31 +427,97 @@ var provvisRender = function () {
/* Update data. */
n.col = Math.round(n.x / cell.width);
n.row = Math.round(n.y / cell.height);
/*

/* When a node is dragged to a negative col or row,
* the graph is shifted by the absolute amount of the negative cell count.
*/
/* Update grid. */
/*
var shiftCols = 0,
shiftRows = 0,
i = 0,
j = 0;

if (n.hidden) {
for (var j = n.row, k = 0; j < n.row+draggedSubanalyses.length; j++, k++) {
vis.graph.l.grid[n.col][j] = draggedSubanalyses[k];
}
} else {
vis.graph.l.grid[n.col][n.row] = n;
}
if (n.col < 0 || n.row < 0 || n.col >= vis.graph.l.depth || n.row >= vis.graph.l.width) {
if (n.col < 0 || n.row < 0) {
shiftCols = n.col < 0 ? Math.abs(n.col) : 0;
shiftRows = n.row < 0 ? Math.abs(n.row) : 0;

var deltaTrans = {x: -shiftCols * cell.width, y: -shiftRows * cell.height},
oldTransCoords = d3.transform(vis.canvas.attr("transform")),
x = oldTransCoords.translate[0],
y = oldTransCoords.translate[1],
s = oldTransCoords.scale;

/* Transform vis to the cell out of bound. */
vis.canvas.attr("transform", "translate(" + (x + deltaTrans.x) + "," + (y + deltaTrans.y) + ")scale(" + s + ")");
vis.zoom.translate([parseInt(x + deltaTrans.x,10), parseInt(y + deltaTrans.y,10)]);
vis.zoom.scale(parseFloat(s));

vis.graph.aNodes.forEach(function (an) {
an.col += shiftCols;
an.row += shiftRows;
an.x = an.col * cell.width;
an.y = an.row * cell.height;

updateNode(d3.select("#gNodeId-" + an.autoId), an, an.x, an.y);
updateLink(an, an.x, an.y);
});
} else if (n.col >= vis.graph.l.depth || n.row >= vis.graph.l.width) {
shiftCols = n.col >= vis.graph.l.depth ? n.col - vis.graph.l.depth + 1 : 0;
shiftRows = n.row >= vis.graph.l.width ? n.row - vis.graph.l.width + 1 : 0;
}

console.log(vis.graph.l.grid);
*/
/* Enlarge grid. */

n.x = n.col * cell.width;
n.y = n.row * cell.height;
/* Add columns. */
for (i = 0; i < shiftCols;i++) {
vis.graph.l.grid.push([]);
for (j = 0; j < vis.graph.l.width; j++) {
vis.graph.l.grid[vis.graph.l.depth+i][j] = "undefined";
}
}

vis.graph.l.depth += shiftCols;

/* Align selected node. */
updateNode(self, n, n.x, n.y);
/* Add rows. */
for(i = 0; i < shiftRows;i++) {
for (j = 0; j < vis.graph.l.depth; j++) {
vis.graph.l.grid[j][vis.graph.l.width+i] = "undefined";
}
}

vis.graph.l.width += shiftRows;

/* Align adjacent links. */
updateLink(n, n.x, n.y);
/* Update grid dom. */
updateGrid(vis.graph);

for(i = 0; i < vis.graph.l.depth;i++) {
for(j = 0; j < vis.graph.l.width;j++) {
vis.graph.l.grid[i][j] = "undefined";
}
}

/* Update grid cells. */
vis.graph.aNodes.forEach(function (an) {
vis.graph.l.grid[an.col][an.row] = an;
});

/* Align selected node. */
updateNode(self, n, n.x, n.y);

/* Align adjacent links. */
updateLink(n, n.x, n.y);
} else {
/* TODO: May reduce grid to min/max column row cells.*/

n.x = n.col * cell.width;
n.y = n.row * cell.height;

/* Align selected node. */
updateNode(self, n, n.x, n.y);

/* Align adjacent links. */
updateLink(n, n.x, n.y);
}

setTimeout(function () {
draggingActive = false;
Expand Down Expand Up @@ -1235,71 +1301,91 @@ var provvisRender = function () {
/* Dynamically adjust layout. */

/*if (d.nodeType === "analysis") {
pos.col = d.col;
pos.row = d.row;
} else if (d.nodeType === "subanalysis") {
pos.col = d.col + d.parent.col;
pos.row = d.row + d.parent.row;
}
*//* Shift vertically. *//*
if (d.nodeType === "analysis") {
console.log("#expand analysis");
*//* TODO: Check if grid cells for subanalysis are occupied. *//*
var shiftedCells = [],
s = pos.col,
t = pos.row + 1;
console.log(vis.graph.l.grid[1]);
for (t; t < vis.graph.l.width; t++) {
shiftedCells.push(vis.graph.l.grid[s][t]);
}
console.log("#shiftedcells");
console.log(shiftedCells);
var newWidth = vis.graph.l.width - 1 + d.l.width;
*//* Enlarge grid width if necessary. *//*
for (i = 0; i < vis.graph.l.depth; i++) {
for (j = vis.graph.l.width; j < newWidth; j++) {
vis.graph.l.grid[i][j] = "undefined";
}
}
*//* Set new width for grid. *//*
vis.graph.l.width = newWidth;
*//* Update grid dom. *//*
updateGrid(vis.graph);
*//* Substitute analysis with subanalysis nodes. *//*
for (i = pos.row, j = 0; i < pos.row + d.l.width; i++, j++) {
vis.graph.l.grid[pos.col][i] = d.l.grid[0][j];
}
*//* Shift remaining cells in column. *//*
for (i = pos.row + d.l.width, j = 0; i < newWidth; i++, j++) {
vis.graph.l.grid[pos.col][i] = shiftedCells[j];
var curCell = vis.graph.l.grid[pos.col][i];
if (curCell !== "undefined") {
*//* Set new row. *//*
curCell.row = i;
*//* Align selected node. *//*
curCell.x = curCell.col * cell.width;
curCell.y = curCell.row * cell.height;
updateNode(d3.select("#gNodeId-" + curCell.autoId), curCell, curCell.x, curCell.y);
*//* Align adjacent links. *//*
updateLink(curCell, curCell.x, curCell.y);
}
}
}*/
pos.col = d.col;
pos.row = d.row;
} else if (d.nodeType === "subanalysis") {
pos.col = d.col + d.parent.col;
pos.row = d.row + d.parent.row;
}
*/
/* Shift vertically. */
/*
if (d.nodeType === "analysis") {
console.log("#expand analysis");
*/
/* TODO: Check if grid cells for subanalysis are occupied. */
/*
var shiftedCells = [],
s = pos.col,
t = pos.row + 1;
console.log(vis.graph.l.grid[1]);
for (t; t < vis.graph.l.width; t++) {
shiftedCells.push(vis.graph.l.grid[s][t]);
}
console.log("#shiftedcells");
console.log(shiftedCells);
var newWidth = vis.graph.l.width - 1 + d.l.width;
*/
/* Enlarge grid width if necessary. */
/*
for (i = 0; i < vis.graph.l.depth; i++) {
for (j = vis.graph.l.width; j < newWidth; j++) {
vis.graph.l.grid[i][j] = "undefined";
}
}
*/
/* Set new width for grid. */
/*
vis.graph.l.width = newWidth;
*/
/* Update grid dom. */
/*
updateGrid(vis.graph);
*/
/* Substitute analysis with subanalysis nodes. */
/*
for (i = pos.row, j = 0; i < pos.row + d.l.width; i++, j++) {
vis.graph.l.grid[pos.col][i] = d.l.grid[0][j];
}
*/
/* Shift remaining cells in column. */
/*
for (i = pos.row + d.l.width, j = 0; i < newWidth; i++, j++) {
vis.graph.l.grid[pos.col][i] = shiftedCells[j];
var curCell = vis.graph.l.grid[pos.col][i];
if (curCell !== "undefined") {
*/
/* Set new row. */
/*
curCell.row = i;
*/
/* Align selected node. */
/*
curCell.x = curCell.col * cell.width;
curCell.y = curCell.row * cell.height;
updateNode(d3.select("#gNodeId-" + curCell.autoId), curCell, curCell.x, curCell.y);
*/
/* Align adjacent links. */
/*
updateLink(curCell, curCell.x, curCell.y);
}
}
}*/

/* Set node visibility. */
d3.select("#nodeId-" + d.autoId).classed("hiddenNode", true);
Expand Down Expand Up @@ -1389,33 +1475,39 @@ var provvisRender = function () {
/* Dynamically adjust layout. */

/*pos.col = d.parent.col;
pos.row = d.parent.row;
*//* Shift vertically. *//*
if (d.nodeType === "subanalysis") {
console.log("#collapse analysis" + d.parent.autoId);
*//* Get subanalysis range within grid column. *//*
var min = d.parent.row + d3.min(d.parent.children.values(), function (san) {
return san.row;
}), max = d.parent.row + d3.max(d.parent.children.values(), function (san) {
return san.row;
});
console.log("min" + min + " " + "max" + max);
console.log(d.nodeType);
console.log(pos.col);
console.log(min);
//console.log(vis.graph.l.grid[pos.col][min].nodeType);
if (vis.graph.l.grid[pos.col][min].nodeType === "subanalysis") {
*//* Collapse grid cells. *//*
for (i = min; i <= max; i++) {
vis.graph.l.grid[pos.col][i] = "undefined";
}
vis.graph.l.grid[pos.col][min] = d.parent;
}
console.log(vis.graph.l.grid);
}*/
pos.row = d.parent.row;
*/
/* Shift vertically. */
/*
if (d.nodeType === "subanalysis") {
console.log("#collapse analysis" + d.parent.autoId);
*/
/* Get subanalysis range within grid column. */
/*
var min = d.parent.row + d3.min(d.parent.children.values(), function (san) {
return san.row;
}), max = d.parent.row + d3.max(d.parent.children.values(), function (san) {
return san.row;
});
console.log("min" + min + " " + "max" + max);
console.log(d.nodeType);
console.log(pos.col);
console.log(min);
//console.log(vis.graph.l.grid[pos.col][min].nodeType);
if (vis.graph.l.grid[pos.col][min].nodeType === "subanalysis") {
*/
/* Collapse grid cells. */
/*
for (i = min; i <= max; i++) {
vis.graph.l.grid[pos.col][i] = "undefined";
}
vis.graph.l.grid[pos.col][min] = d.parent;
}
console.log(vis.graph.l.grid);
}*/


/* Set node visibility. */
Expand Down

0 comments on commit ca4031e

Please sign in to comment.