Skip to content

Commit

Permalink
Merge pull request #369 from palantir/dragbox-resolve-geoff-issues
Browse files Browse the repository at this point in the history
Dragbox resolve geoff issues
  • Loading branch information
teamdandelion committed May 2, 2014
2 parents 7238aec + 8d5f026 commit 3710c19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions quicktests/selection-quicktest.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
.center(renderGroup)
.renderTo("#xy-test");
cb = function(xy) {console.log("XY drag area: ", xy);}
new Plottable.XYDragBoxInteraction(renderGroup).callback(cb).registerWithComponent();
window.xy = new Plottable.XYDragBoxInteraction(renderGroup).callback(cb).registerWithComponent();
}
function xdrag() {
var dataseries = makeRandomData(20, 0.3);
Expand Down Expand Up @@ -65,7 +65,7 @@
.renderTo("#x-test");

cb = function(x) {console.log("X drag area: ", x);}
new Plottable.XDragBoxInteraction(renderGroup).callback(cb).registerWithComponent();
window.x = new Plottable.XDragBoxInteraction(renderGroup).callback(cb).registerWithComponent();
}


Expand Down
15 changes: 15 additions & 0 deletions src/interactions/drag/dragBoxInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ module Plottable {
export class DragBoxInteraction extends DragInteraction {
private static CLASS_DRAG_BOX = "drag-box";
public dragBox: D3.Selection;
public boxIsDrawn = false;

public _dragstart() {
super._dragstart();
if (this.callbackToCall != null && this.boxIsDrawn) {
this.callbackToCall(null);
}
this.clearBox();
}

Expand All @@ -17,6 +21,17 @@ module Plottable {
*/
public clearBox() {
this.dragBox.attr("height", 0).attr("width", 0);
this.boxIsDrawn = false;
return this;
}

public setBox(x0: number, x1: number, y0: number, y1: number) {
var w = Math.abs(x0 - x1);
var h = Math.abs(y0 - y1);
var xo = Math.min(x0, x1);
var yo = Math.min(y0, y1);
this.dragBox.attr({x: xo, y: yo, width: w, height: h});
this.boxIsDrawn = (w > 0 && h > 0);
return this;
}

Expand Down
11 changes: 6 additions & 5 deletions src/interactions/drag/xDragBoxInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ module Plottable {
export class XDragBoxInteraction extends DragBoxInteraction {
public _drag(){
super._drag();
var width = Math.abs(this.origin[0] - this.location[0]);
var height = this.componentToListenTo.availableHeight;
var x = Math.min(this.origin[0] , this.location[0]);
var y = 0
this.dragBox.attr({x: x, y: y, height: height, width: width});
this.setBox(this.origin[0], this.location[0]);
}

public _doDragend(){
Expand All @@ -20,5 +16,10 @@ module Plottable {
var pixelArea = {xMin: xMin, xMax: xMax};
this.callbackToCall(pixelArea);
}

public setBox(x0: number, x1: number) {
super.setBox(x0, x1, 0, this.componentToListenTo.availableHeight);
return this;
}
}
}
7 changes: 1 addition & 6 deletions src/interactions/drag/xyDragBoxInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ module Plottable {
export class XYDragBoxInteraction extends DragBoxInteraction {
public _drag(){
super._drag();
var width = Math.abs(this.origin[0] - this.location[0]);
var height = Math.abs(this.origin[1] - this.location[1]);
var x = Math.min(this.origin[0] , this.location[0]);
var y = Math.min(this.origin[1] , this.location[1]);
this.dragBox.attr({x: x, y: y, height: height, width: width});
this.setBox(this.origin[0], this.location[0], this.origin[1], this.location[1]);
}

public _doDragend(){
if (this.callbackToCall == null) {
return;
}

var xMin = Math.min(this.origin[0], this.location[0]);
var xMax = Math.max(this.origin[0], this.location[0]);
var yMin = Math.min(this.origin[1], this.location[1]);
Expand Down

0 comments on commit 3710c19

Please sign in to comment.