Skip to content

Commit

Permalink
[Time Conductor] Refactored out use of angular event bus in favor of …
Browse files Browse the repository at this point in the history
…making TimeConductorViewService an event emitter.
  • Loading branch information
akhenry committed Sep 23, 2016
1 parent 49ee5cb commit 3c95c09
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion platform/features/conductor-v2/conductor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ define([
"implementation": ConductorAxisController,
"depends": [
"timeConductor",
"formatService"
"formatService",
"timeConductorViewService"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ define(
* labelled 'ticks'. It requires 'start' and 'end' integer values to
* be specified as attributes.
*/
function ConductorAxisController(conductor, formatService) {
function ConductorAxisController(conductor, formatService, conductorViewService) {
// Dependencies
this.d3 = d3;
this.formatService = formatService;
this.conductor = conductor;
this.conductorViewService = conductorViewService;

// Runtime properties (set by 'link' function)
this.target = undefined;
Expand All @@ -53,8 +54,8 @@ define(
Object.keys(ConductorAxisController.prototype).filter(function (key) {
return typeof ConductorAxisController.prototype[key] === 'function';
}).forEach(function (key) {
self[key] = self[key].bind(self);
});
this[key] = ConductorAxisController.prototype[key].bind(this);
}.bind(this));
}

ConductorAxisController.prototype.destroy = function () {
Expand Down Expand Up @@ -137,7 +138,7 @@ define(

if (this.timeSystem !== undefined) {
this.changeTimeSystem(this.timeSystem);
this.setScale(this.bounds);
this.setScale();
}

//Respond to changes in conductor
Expand All @@ -146,15 +147,17 @@ define(

this.scope.$on("$destroy", this.destroy);

scope.$on("zoom", function (evt, bounds){
this.changeBounds(bounds);
}.bind(this));
this.conductorViewService.on("zoom", this.zoom);
};

ConductorAxisController.prototype.panEnd = function () {
ConductorAxisController.prototype.panStop = function () {
//resync view bounds with time conductor bounds
this.conductor.bounds(this.bounds);
this.scope.$emit("pan-stop");
this.conductorViewService.emit("pan-stop");
};

ConductorAxisController.prototype.zoom = function (bounds) {
this.changeBounds(bounds);
};

ConductorAxisController.prototype.pan = function (delta) {
Expand All @@ -168,7 +171,7 @@ define(
end: end
};
this.setScale();
this.scope.$emit("pan", this.bounds);
this.conductorViewService.emit("pan", this.bounds);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define([], function () {

template: '<div class="l-axis-holder" ' +
' mct-drag-down="axis.panStart()"' +
' mct-drag-up="axis.panEnd(delta)"' +
' mct-drag-up="axis.panStop(delta)"' +
' mct-drag="axis.pan(delta)"' +
' mct-resize="axis.resize()"></div>'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,9 @@ define(

// Watch scope for selection of mode or time system by user
this.$scope.$watch('modeModel.selectedKey', this.setMode);
this.$scope.$on('pan', function (e, bounds) {
this.$scope.panning = true;
this.setFormFromBounds(bounds);
}.bind(this));
this.conductorViewService.on('pan', this.pan);

this.$scope.$on('pan-stop', function () {
this.$scope.panning = false;
}.bind(this));
this.conductorViewService.on('pan-stop', this.panStop);

this.$scope.$on('$destroy', this.destroy);
};
Expand All @@ -114,6 +109,15 @@ define(
this.conductor.off('timeSystem', this.changeTimeSystem);
};

TimeConductorController.prototype.pan = function (bounds) {
this.$scope.panning = true;
this.setFormFromBounds(bounds);
};

TimeConductorController.prototype.panStop = function () {
this.$scope.panning = false;
};

/**
* Called when the bounds change in the time conductor. Synchronizes
* the bounds values in the time conductor with those in the form
Expand All @@ -123,7 +127,7 @@ define(
TimeConductorController.prototype.setFormFromBounds = function (bounds) {
this.$scope.boundsModel.start = bounds.start;
this.$scope.boundsModel.end = bounds.end;
//this.$scope.currentZoom = bounds.end - bounds.start;

this.$scope.currentZoom = this.toSliderValue(bounds.end - bounds.start);
if (!this.pendingUpdate) {
this.pendingUpdate = true;
Expand Down Expand Up @@ -272,7 +276,7 @@ define(
var bounds = this.toTimeSpan(sliderValue);
this.setFormFromBounds(bounds);

this.$scope.$broadcast("zoom", bounds);
this.conductorViewService.emit("zoom", bounds);
};

TimeConductorController.prototype.zoomStop = function (sliderValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

define(
[
'EventEmitter',
'./TimeConductorMode'
],
function (TimeConductorMode) {
function (EventEmitter, TimeConductorMode) {

/**
* A class representing the state of the time conductor view. This
Expand All @@ -36,6 +37,9 @@ define(
* @constructor
*/
function TimeConductorViewService(conductor, timeSystems) {

EventEmitter.call(this);

this.systems = timeSystems.map(function (timeSystemConstructor) {
return timeSystemConstructor();
});
Expand Down Expand Up @@ -97,6 +101,8 @@ define(
}
}

TimeConductorViewService.prototype = Object.create(EventEmitter.prototype);

/**
* Getter/Setter for the Time Conductor Mode. Modes determine the
* behavior of the time conductor, especially with regards to the
Expand Down

0 comments on commit 3c95c09

Please sign in to comment.