-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add onPan and onZoom to the PanZoom interaction #3087
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
namespace Plottable.Interactions { | ||
|
||
export type PanCallback = (e: Event) => void; | ||
export type ZoomCallback = (e: Event) => void; | ||
|
||
export class PanZoom extends Interaction { | ||
/** | ||
* The number of pixels occupied in a line. | ||
|
@@ -22,6 +26,9 @@ namespace Plottable.Interactions { | |
private _minDomainExtents: Utils.Map<QuantitativeScale<any>, any>; | ||
private _maxDomainExtents: Utils.Map<QuantitativeScale<any>, any>; | ||
|
||
private _panEndCallbacks = new Utils.CallbackSet<PanCallback>(); | ||
private _zoomEndCallbacks = new Utils.CallbackSet<ZoomCallback>(); | ||
|
||
/** | ||
* A PanZoom Interaction updates the domains of an x-scale and/or a y-scale | ||
* in response to the user panning or zooming. | ||
|
@@ -171,6 +178,10 @@ namespace Plottable.Interactions { | |
ids.forEach((id) => { | ||
this._touchIds.remove(id.toString()); | ||
}); | ||
|
||
if (this._touchIds.size() > 0) { | ||
this._zoomEndCallbacks.callCallbacks(e); | ||
} | ||
} | ||
|
||
private _magnifyScale<D>(scale: QuantitativeScale<D>, magnifyAmount: number, centerValue: number) { | ||
|
@@ -205,6 +216,7 @@ namespace Plottable.Interactions { | |
this.yScales().forEach((yScale) => { | ||
this._magnifyScale(yScale, zoomAmount, translatedP.y); | ||
}); | ||
this._zoomEndCallbacks.callCallbacks(e); | ||
} | ||
} | ||
|
||
|
@@ -242,6 +254,7 @@ namespace Plottable.Interactions { | |
}); | ||
lastDragPoint = endPoint; | ||
}); | ||
this._dragInteraction.onDragEnd((e) => this._panEndCallbacks.callCallbacks(e)); | ||
} | ||
|
||
private _nonLinearScaleWithExtents(scale: QuantitativeScale<any>) { | ||
|
@@ -424,5 +437,49 @@ namespace Plottable.Interactions { | |
this._maxDomainExtents.set(quantitativeScale, maxDomainExtent); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a callback to be called when panning ends. | ||
* | ||
* @param {PanCallback} callback | ||
* @returns {Event} The calling PanZoom Interaction. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and other registration calls should return |
||
*/ | ||
public onPanEnd(callback: PanCallback) { | ||
this._panEndCallbacks.add(callback); | ||
return this; | ||
} | ||
|
||
/** | ||
* Removes a callback that would be called when panning ends. | ||
* | ||
* @param {PanCallback} callback | ||
* @returns {Event} The calling PanZoom Interaction. | ||
*/ | ||
public offPanEnd(callback: PanCallback) { | ||
this._panEndCallbacks.delete(callback); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a callback to be called when zooming ends. | ||
* | ||
* @param {ZoomCallback} callback | ||
* @returns {Event} The calling PanZoom Interaction. | ||
*/ | ||
public onZoomEnd(callback: ZoomCallback) { | ||
this._zoomEndCallbacks.add(callback); | ||
return this; | ||
} | ||
|
||
/** | ||
* Removes a callback that would be called when zooming ends. | ||
* | ||
* @param {ZoomCallback} callback | ||
* @returns {Event} The calling PanZoom Interaction. | ||
*/ | ||
public offZoomEnd(callback: ZoomCallback) { | ||
this._zoomEndCallbacks.delete(callback); | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure these callbacks should take
Event
s -- that's sort of atypical if you compare to the callbacks passed toClick
,Drag
, andPointer
Interaction
s. I would expect the final domains of theScale
s or something like that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was a little unsure as to what to return, but you can take multiple
scales right, so would it be an array of domains returned?
On Thu, 14 Jul 2016, 19:27 jtlan, notifications@github.com wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it would be something like:
but the typing on
PanZoom
doesn't allow for that since it's not generic on<X, Y>
(also object-keyedMap
isn't standard yet). For now we might want the callback to pass nothing (but still keep it type-defined), since the users can retrieve the domain information from theScale
s directly.