-
Notifications
You must be signed in to change notification settings - Fork 31
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
Animation #146
Animation #146
Changes from 51 commits
d992b88
c6cc202
3714011
78f2383
476b555
d930e75
790129a
3c9b2fa
9044382
5c686cc
8e4ac07
bcabaab
4b26046
fbf8ece
6db1d0c
7e68666
029f7b3
e53a9a6
1f38def
ffdaaec
41314c3
ef59362
a04ae25
81157ba
40fb511
08622f1
9e574b9
88df7b4
15d7407
e31bbd4
d3a837c
8d59e91
d061f2c
5558099
8abc73e
712585d
25c7a4f
07e967c
c6d6e03
78a6222
0e5701c
67cbccc
823c0d6
3552adf
87d3223
3f33a4d
7d087a1
81f2e9d
cf74095
d097389
576d7b6
2061e91
6ce0cc9
8403e81
8217863
f274b1e
b2ded8c
f0a0f95
4d2b051
02fc054
ee93619
b2d7929
bc52acc
15c0499
2795510
23f8095
19fdbc5
4ee966f
9a92ae1
e478628
ef7daa0
4ff2664
262374f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"esversion": 6 | ||
"esversion": 8 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
define(["Colorer"], function(Colorer) { | ||
/** | ||
* | ||
* @class AnimationPanel | ||
ElDeveloper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Creates tab for the animation panel and handles their events events. | ||
* | ||
* @param{Object} animator The object that creates the animations | ||
* | ||
* @return {AnimatePanel} | ||
* construct AnimatePanel | ||
*/ | ||
function AnimatePanel(animator) { | ||
// used in event triggers | ||
this.animator = animator; | ||
|
||
// animation GUI components | ||
this.colorSelect = document.getElementById("animate-color-select"); | ||
this.gradient = document.getElementById("animate-gradient"); | ||
this.trajectory = document.getElementById("animate-trajectory"); | ||
this.hideChk = document.getElementById("animate-hide-non-feature"); | ||
this.lWidth = document.getElementById("animate-line-width"); | ||
this.startBtn = document.getElementById("animate-start-btn"); | ||
this.stopBtn = document.getElementById("animate-stop-btn"); | ||
this.pauseBtn = document.getElementById("animate-pause-btn"); | ||
this.resumeBtn = document.getElementById("animate-resume-btn"); | ||
this.prevFrameBtn = document.getElementById("animate-prev-btn"); | ||
this.nextFrameBtn = document.getElementById("animate-next-btn"); | ||
} | ||
|
||
/** | ||
* Makes the play button visible. This is the menu shown before user has | ||
* started the animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @private | ||
*/ | ||
AnimatePanel.prototype.__startOptions = function() { | ||
// hide the following buttons | ||
this.stopBtn.classList.add("hidden"); | ||
this.pauseBtn.classList.add("hidden"); | ||
this.resumeBtn.classList.add("hidden"); | ||
this.prevFrameBtn.classList.add("hidden"); | ||
this.nextFrameBtn.classList.add("hidden"); | ||
|
||
// show the following buttons | ||
this.startBtn.classList.remove("hidden"); | ||
}; | ||
|
||
/** | ||
* Makes the stop/pause buttons visible. This is the menu shown during the | ||
* animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @private | ||
*/ | ||
AnimatePanel.prototype.__pauseOptions = function() { | ||
// hide the following buttons | ||
this.startBtn.classList.add("hidden"); | ||
this.resumeBtn.classList.add("hidden"); | ||
this.prevFrameBtn.classList.add("hidden"); | ||
this.nextFrameBtn.classList.add("hidden"); | ||
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. In my opinion at least :), it would be nice to have the prev/next-frame buttons present from the start of the animation -- it wasn't clear to me initially that these buttons were even available until I pressed 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. @fedarko thanks for the suggestion! My goal with the GUI is to make things as intuitive and easy to use. One way I try to accomplish this is by only presenting options to the user that can be applied at that moment. Since the prev/next features can only be used when the animation is paused, I decided to hide those options unless the user pauses the animation. Instead of hiding those buttons, I can disable them while the animation is running and enable them when the animation is paused. Also, I can start the animation is the pause state instead of the run state so users who wanted to manually step through the animation could do so without having to first pause the animation first. @ElDeveloper how does Emperor handle this? 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. In emperor we disable the buttons and still leave them visible (instead of hiding them). |
||
|
||
// show the following buttons | ||
this.stopBtn.classList.remove("hidden"); | ||
this.pauseBtn.classList.remove("hidden"); | ||
}; | ||
|
||
/** | ||
* Makes the prev/next/stop/resume buttons visible. This is the menu shown | ||
* when user pauses the animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @private | ||
*/ | ||
AnimatePanel.prototype.__resumeOptions = function() { | ||
// hide the following buttons | ||
this.pauseBtn.classList.add("hidden"); | ||
this.startBtn.classList.add("hidden"); | ||
|
||
// show the following buttons | ||
this.stopBtn.classList.remove("hidden"); | ||
this.resumeBtn.classList.remove("hidden"); | ||
this.prevFrameBtn.classList.remove("hidden"); | ||
this.nextFrameBtn.classList.remove("hidden"); | ||
|
||
// dont show previous button on frame 1 | ||
if (this.animator.onFirstFrame()) { | ||
this.prevFrameBtn.classList.add("hidden"); | ||
} | ||
|
||
// dont show next button on last frame | ||
if (this.animator.onLastFrame()) { | ||
this.nextFrameBtn.classList.add("hidden"); | ||
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. A slight problem with this approach is that the buttons are positioned such that, when the Second-from-last frame in an animation This means that, for people who are manually clicking through the animation, they'll likely accidentally press IMO it would be better to absolutely position these buttons, to attempt to stave off this problem. 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. Nice catch! I'll update the PR to disable the prev/next button when on the first/last frame instead of hiding them. |
||
} | ||
}; | ||
|
||
/** | ||
* enables/disable the drop down menus. When the animation is playing, | ||
* the drop down menus are disable in order to prevent user from changing | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* the gradient/trajectory during an animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @private | ||
*/ | ||
AnimatePanel.prototype.__toogleSelects = function(disableStatus) { | ||
this.colorSelect.disabled = disableStatus; | ||
this.gradient.disabled = disableStatus; | ||
this.trajectory.disabled = disableStatus; | ||
}; | ||
|
||
/** | ||
* Initializes GUI components/set up callback events | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
AnimatePanel.prototype.addAnimationTab = function() { | ||
// used in closers | ||
var ap = this; | ||
|
||
// hide play/pause/next/previous/stop buttons | ||
this.__startOptions(); | ||
|
||
// The color map selector | ||
Colorer.addColorsToSelect(this.colorSelect); | ||
|
||
// retrive gradient/trajectory categories | ||
var categories = this.animator.getSampleCategories(); | ||
|
||
// add categories options to gradient drop down menu | ||
for (var i = 0; i < categories.length; i++) { | ||
var opt = document.createElement("option"); | ||
opt.value = categories[i]; | ||
opt.innerHTML = categories[i]; | ||
this.gradient.appendChild(opt); | ||
} | ||
|
||
// copy options and add them to trajectory drop down menu | ||
var options = this.gradient.innerHTML; | ||
this.trajectory.innerHTML = options; | ||
|
||
/** | ||
* Event: triggers when user clicks on the hide branch checkbox. | ||
* Sets hide parameter in animation state machine. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.hideChk.onchange = function() { | ||
ap.animator.setHide(ap.hideChk.checked); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user changes value of line width. | ||
* Sets line width parameter in animation state machine. | ||
*/ | ||
this.lWidth.onchange = function() { | ||
var val = ap.lWidth.value; | ||
|
||
// make sure line width is positve | ||
if (val < 1) { | ||
val = 1; | ||
ap.lWidth = val; | ||
} | ||
|
||
// pass line width to state machine | ||
ap.animator.setLineWidth(val); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on the start button. | ||
* Starts the animation. | ||
* | ||
* @return {null} | ||
*/ | ||
this.startBtn.onclick = function() { | ||
// change GUI components | ||
ap.__toogleSelects(true); | ||
ap.__pauseOptions(); | ||
|
||
// collect starting conditions for the animation | ||
var gradient = ap.gradient.value; | ||
var trajectory = ap.trajectory.value; | ||
var cm = ap.colorSelect.value; | ||
var hide = ap.hideChk.checked; | ||
var lWidth = ap.lWidth.value; | ||
|
||
// pass parameters to state machine | ||
ap.animator.setAnimationParameters( | ||
trajectory, | ||
gradient, | ||
cm, | ||
hide, | ||
lWidth | ||
); | ||
|
||
// start animation | ||
ap.animator.startAnimation(); | ||
ElDeveloper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on pause button. | ||
* Pauses the animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.pauseBtn.onclick = function() { | ||
ap.__resumeOptions(); | ||
ap.animator.pauseAnimation(); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on resume button. | ||
* Resumes the animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.resumeBtn.onclick = function() { | ||
ap.__pauseOptions(); | ||
ap.animator.resumeAnimation(); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on stop button. | ||
* Stops the animation and clears the state machine | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.stopBtn.onclick = function() { | ||
ap.__toogleSelects(false); | ||
ap.__startOptions(); | ||
ap.animator.stopAnimation(); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on previous button. | ||
* Shows the previous frame in the animation | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.prevFrameBtn.onclick = function() { | ||
ap.animator.prevFrame(); | ||
ap.__resumeOptions(); | ||
}; | ||
|
||
/** | ||
* Event: triggers when user clicks on next button. | ||
* Shows the next frame in the animation. | ||
* | ||
* @return {null} | ||
kwcantrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
this.nextFrameBtn.onclick = function() { | ||
ap.animator.nextFrame(); | ||
ap.__resumeOptions(); | ||
}; | ||
}; | ||
|
||
return AnimatePanel; | ||
}); |
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.
I think sample metadata is in general fine loaded as a string. Have you encountered any issues?