diff --git a/js/cvit/draw/glyph/glyph.js b/js/cvit/draw/glyph/glyph.js index f516a19..2791cdd 100755 --- a/js/cvit/draw/glyph/glyph.js +++ b/js/cvit/draw/glyph/glyph.js @@ -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; diff --git a/js/cvit/draw/glyph/marker/marker.js b/js/cvit/draw/glyph/marker/marker.js index 6baf45a..c23ba9c 100755 --- a/js/cvit/draw/glyph/marker/marker.js +++ b/js/cvit/draw/glyph/marker/marker.js @@ -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]); diff --git a/js/cvit/draw/glyph/position/circle.js b/js/cvit/draw/glyph/position/circle.js index 254fc5e..537c196 100755 --- a/js/cvit/draw/glyph/position/circle.js +++ b/js/cvit/draw/glyph/position/circle.js @@ -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"; @@ -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]); diff --git a/js/cvit/draw/glyph/position/doublecircle.js b/js/cvit/draw/glyph/position/doublecircle.js index 081065c..102229f 100755 --- a/js/cvit/draw/glyph/position/doublecircle.js +++ b/js/cvit/draw/glyph/position/doublecircle.js @@ -64,9 +64,6 @@ 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; @@ -74,6 +71,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]); diff --git a/js/cvit/draw/glyph/position/rect.js b/js/cvit/draw/glyph/position/rect.js index b1e5da7..0cd1980 100755 --- a/js/cvit/draw/glyph/position/rect.js +++ b/js/cvit/draw/glyph/position/rect.js @@ -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"; @@ -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]); diff --git a/js/cvit/draw/glyph/range/range.js b/js/cvit/draw/glyph/range/range.js index 0af562c..af566df 100755 --- a/js/cvit/draw/glyph/range/range.js +++ b/js/cvit/draw/glyph/range/range.js @@ -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"; @@ -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]); diff --git a/js/cvit/draw/glyph/utilities.js b/js/cvit/draw/glyph/utilities.js index 048ba2e..7b0e97e 100755 --- a/js/cvit/draw/glyph/utilities.js +++ b/js/cvit/draw/glyph/utilities.js @@ -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 * @@ -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); + } }, /** @@ -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 = $("" + groupName + "\""); var openButton = $("").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 = $("
  • ");