Skip to content

Commit

Permalink
Fix pileup and view toggle controls
Browse files Browse the repository at this point in the history
  • Loading branch information
awilkey committed Feb 5, 2018
1 parent b1967b2 commit 3ef1d95
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 39 deletions.
1 change: 1 addition & 0 deletions js/cvit/draw/glyph/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ define(["require", "jquery", "glyph/utilities"],
view.groupName = viewSettings.groupName;
console.log("CViTjs: Drawing " + view.groupName);
glyphGroup.name = view.groupName;
console.log(glyphGroup);
view.config = view.key === view.groupName ? config[view.key] : thisC.mergeConfig(config[view.key], config[view.groupName]);
view.zoom = view.yScale;
view.pileup = typeof(view.config.pileup_gap) !== "undefined" ? parseInt(view.config.pileup_gap) : 0;
Expand Down
3 changes: 2 additions & 1 deletion js/cvit/draw/glyph/marker/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ define(["jquery", "glyph/utilities"],
var xLoc = (chrEdge + xOffset);
var point = new paper.Point(xLoc, yLoc);
var r = new paper.Path.Line(point, new paper.Point(point.x + featureWidth, point.y));

r.strokeWidth = 2;
marker.name = marker.attribute.name ? marker.attribute.name : "";
r.info = marker.attribute;
r.thisColor = "black";
var strokeColor = r.info.color ? r.info.color : view.config.color;
r.strokeColor = utility.formatColor(strokeColor);
// As per original CViT, marker does not have any pileup control
r.onMouseDown = function () {
utility.attachPopover(r, marker);
};
// As per perl CViT marker doesn't accept pileup control
if (parseInt(view.config.draw_label) === 1) {
point.y = r.position.y;
var label = utility.generateLabel(r, view, targetGroup.children[target]);
Expand Down
7 changes: 4 additions & 3 deletions js/cvit/draw/glyph/position/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ define(["jquery", "glyph/utilities"],
var point = new paper.Point(xLoc, yLoc);
var radius = parseInt(view.config.width) / 2;
var r = new paper.Path.Circle(point.add(radius), radius);
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}

position.name = position.attribute.name ? position.attribute.name : "";
r.info = position.attribute;
r.thisColor = "black";
Expand All @@ -63,6 +61,9 @@ define(["jquery", "glyph/utilities"],
r.onMouseDown = function () {
utility.attachPopover(r, position);
};
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}
if (parseInt(view.config.draw_label) === 1) {
point.y = r.position.y;
var label = utility.generateLabel(r, view, targetGroup.children[target]);
Expand Down
6 changes: 3 additions & 3 deletions js/cvit/draw/glyph/position/doublecircle.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ define(["jquery", "glyph/utilities"],
]
});

if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}
position.name = position.attribute.name ? position.attribute.name : "";
r.info = position.attribute;
var fillColor = position.attribute.color ? position.attribute.color : view.config.color;
r.fillColor = utility.formatColor(fillColor);
r.onMouseDown = function () {
utility.attachPopover(r, position);
};
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}
if (parseInt(view.config.draw_label) === 1) {
point.y = r.position.y;
var label = utility.generateLabel(r, view, targetGroup.children[target]);
Expand Down
7 changes: 4 additions & 3 deletions js/cvit/draw/glyph/position/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ define(["jquery", "glyph/utilities"],
var size = new paper.Size(featureWidth, featureWidth);
var rectangle = new paper.Rectangle(point, size);
var r = new paper.Path.Rectangle(rectangle);
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}

position.name = position.attribute.name ? position.attribute.name : "";
r.info = position.attribute;
r.thisColor = "black";
Expand All @@ -62,6 +60,9 @@ define(["jquery", "glyph/utilities"],
r.onMouseDown = function () {
utility.attachPopover(r, position);
};
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}
if (parseInt(view.config.draw_label) === 1) {
point.y = r.position.y;
var label = utility.generateLabel(r, view, targetGroup.children[target]);
Expand Down
8 changes: 5 additions & 3 deletions js/cvit/draw/glyph/range/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ define(["jquery", "glyph/utilities"],
var size = new paper.Size(featureWidth, (range.end - range.start) * view.zoom);
var rectangle = new paper.Rectangle(point, size);
var r = new paper.Path.Rectangle(rectangle);
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}

range.name = range.attribute.name ? range.attribute.name : "";
r.info = range.attribute;
r.thisColor = "black";
Expand All @@ -63,6 +61,10 @@ define(["jquery", "glyph/utilities"],
r.onMouseDown = function () {
utility.attachPopover(r, range);
};
console.log("rangeTest",view,r,featureGroup);
if (parseInt(view.config.enable_pileup) === 1) {
utility.testCollision(r, featureGroup, view);
}
if (parseInt(view.config.draw_label) === 1) {
point.y = r.position.y;
var label = utility.generateLabel(r, view, targetGroup.children[target]);
Expand Down
89 changes: 63 additions & 26 deletions js/cvit/draw/glyph/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ define(["jquery", "bootstrap"],
/**
* @description Collision detection. pGap can be negative to move left, positive to move right
*
* @param {object} feature - glyph object to test for collision with other objects on the canvas.
* @param {object} feature - glyph object to test for collision with other o
* @param {paper.group} featureGroup - group containing feature
* @param {object} view - view feature is being placed in
*
Expand All @@ -111,46 +111,77 @@ define(["jquery", "bootstrap"],
testCollision: function (feature, featureGroup, view) {
var pGap = view.pileup;
// Set the expected number of hits for the given feature to avoid infinte loop
var minGroup = typeof(feature.children) !== "undefined" ? feature.children.length : 1;
var minGroup = typeof(feature.children) != "undefined" ? feature.children.length : 1;
var getItem = function () {
return paper.project.getItems({
overlapping: feature.strokeBounds,
class: paper.Path
});
};

var testItem = getItem();
var fPName = featureGroup.parent.name;
var baseGroup = featureGroup.parent.parent;
var chrGroup = featureGroup.parent;
var fPName = chrGroup.name;
var baseGroup = chrGroup.parent;
var layer = paper.project.layers[0];
var length = baseGroup.children.length;
var offset = feature.strokeBounds.width + pGap;
var groupTest = function (i) {
var group = baseGroup.children[i];
group.position.x += 2 * offset;
layer.children[group.name + "Label"].position.x += 2 * offset;
view.xloc[group.name] += 2 * offset;
var side = chrGroup.children[0].position.x < feature.position.x ? true : false;
var index = baseGroup.children.indexOf(chrGroup);
var moveBackbone = function (pileupOffset) {
var groupBounds;
var i;
var group;
if (side) {
groupBounds = feature.strokeBounds.right - baseGroup.children[index + 1].strokeBounds.left;
for (i = index + 1; i < length; i++) {
group = baseGroup.children[i];
group.position.x += pileupOffset + groupBounds;
layer.children[group.name + "Label"].position.x += pileupOffset + groupBounds;
}
} else {
groupBounds = baseGroup.children[index - 1].strokeBounds.right - feature.strokeBounds.left;
for (i = index - 1; i > -1; i--) {
group = baseGroup.children[i];
group.position.x -= pileupOffset + groupBounds;
layer.children[group.name + "Label"].position.x -= pileupOffset + groupBounds;
}
}
};
while (testItem.length > minGroup && testItem[0].parent.parent) {
var testPName = testItem[0].parent.parent.name;
if (fPName !== testPName) {

var index = baseGroup.children.indexOf(featureGroup.parent);
if (pGap > -1) {
for (var i = index + 1; i < length; i++) {
groupTest(i);
}
} else {
for (var j = index - 1; j > -1; j--) {
groupTest(j);
}
while (testItem.length > minGroup) {
//need one more layerup in case of compound paths like position/doublecircle
if (testItem[0].parent.className === "CompoundPath") {
testPName = testItem[0].parent.parent.parent.name;
} else {
testPName = testItem[0].parent.parent.name;
}

}
if (fPName != testPName) {
moveBackbone(offset);
} else {
feature.translate(new paper.Point(feature.strokeBounds.width + pGap, 0));
if (side) {
feature.translate(new paper.Point(offset, 0));
} else {
feature.translate(new paper.Point(-offset, 0));
}

}
testItem = getItem();
}

var groupOverlap = paper.project.getItems({
overlapping: feature.strokeBounds,
class: paper.Group,
name: function (value) {
return value !== fPName;
},
_parent: function (value) {
return value.name === "view";
}
});
if (groupOverlap.length > 0) {
moveBackbone(0);
}
},

/**
Expand Down Expand Up @@ -186,12 +217,18 @@ define(["jquery", "bootstrap"],
// TODO: TEST and Fix

generateViewControl: function (groupName, group) {
console.log("vc", group);
var gName = groupName.replace(/\s+/g, "-").toLowerCase();
var viewTitle = $("<span>" + groupName + "</span>\"");
var openButton = $("<button type=\"button\" class=\"btn btn-success view-toggle\" style=\"float:right; margin-right:10px;\">Show</button>").on("click", function () {
$("#" + gName + "-options .btn-success").toggleClass("btn-danger");
group.visible = !group.visible;
paper.view.draw();
for (var i = 0; i < group.children.length; i++) {
var toggleGroup = group.children[i].children[groupName];
if (toggleGroup !== undefined) {
toggleGroup.visible = toggleGroup.visible ? false : true;
}
paper.view.draw();
}
});

var viewLi = $("<li></li>");
Expand Down

0 comments on commit 3ef1d95

Please sign in to comment.