Skip to content

Commit

Permalink
Removed bundle definition of MctAxisController
Browse files Browse the repository at this point in the history
Documenting code
  • Loading branch information
akhenry committed Oct 24, 2016
1 parent a942541 commit 93735bc
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 108 deletions.
7 changes: 7 additions & 0 deletions platform/commonUI/formats/src/UTCTimeFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ define([
})[0][0];
}

/**
* Returns a description of the current range of the time conductor's
* bounds.
* @param timeRange
* @returns {*}
*/
UTCTimeFormat.prototype.timeUnits = function (timeRange) {
var momentified = moment.duration(timeRange);

return [
["Decades", function (r) {
return r.years() > 15;
Expand Down
9 changes: 0 additions & 9 deletions platform/features/conductor-v2/conductor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ define([
"formatService"
]
},
{
"key": "ConductorAxisController",
"implementation": ConductorAxisController,
"depends": [
"openmct",
"formatService",
"timeConductorViewService"
]
},
{
"key": "ConductorTOIController",
"implementation": ConductorTOIController,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
class="time-conductor-zoom-current-range flex-elem flex-fixed holder">{{timeUnits}}</span>
<input class="time-conductor-zoom flex-elem" type="range"
ng-model="tcController.currentZoom"
ng-mouseUp="tcController.zoomStop(tcController.currentZoom)"
ng-change="tcController.zoomDrag(tcController.currentZoom)"
ng-mouseUp="tcController.onZoomStop(tcController.currentZoom)"
ng-change="tcController.onZoom(tcController.currentZoom)"
min="0.01"
step="0.01"
max="0.99" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ define(
* labelled 'ticks'. It requires 'start' and 'end' integer values to
* be specified as attributes.
*/
function ConductorAxisController(openmct, formatService, conductorViewService) {
function ConductorAxisController(openmct, formatService, conductorViewService, scope, element) {
// Dependencies
this.d3 = d3;
this.formatService = formatService;
this.conductor = openmct.conductor;
this.conductorViewService = conductorViewService;

// Runtime properties (set by 'link' function)
this.target = undefined;
this.xScale = undefined;
this.xAxis = undefined;
this.axisElement = undefined;
this.scope = scope;
this.initialized = false;
this.msPerPixel = undefined;

this.bounds = this.conductor.bounds();
this.timeSystem = this.conductor.timeSystem();
Expand All @@ -56,6 +51,8 @@ define(
}).forEach(function (key) {
this[key] = ConductorAxisController.prototype[key].bind(this);
}.bind(this));

this.initialize(element);
}

ConductorAxisController.prototype.destroy = function () {
Expand All @@ -65,13 +62,52 @@ define(
this.conductorViewService.off("zoom-stop", this.onZoomStop)
};

/**
* Set defaults, and apply d3 axis to the
* @param scope
* @param element
*/
ConductorAxisController.prototype.initialize = function (element) {
this.target = element[0].firstChild;
var height = this.target.offsetHeight;
var vis = this.d3.select(this.target)
.append("svg:svg")
.attr("width", "100%")
.attr("height", height);

this.xAxis = this.d3.axisTop();

// draw x axis with labels and move to the bottom of the chart area
this.axisElement = vis.append("g")
.attr("transform", "translate(0," + (height - PADDING) + ")");

this.initialized = true;

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

//Respond to changes in conductor
this.conductor.on("timeSystem", this.changeTimeSystem);
this.conductor.on("bounds", this.changeBounds);

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

this.conductorViewService.on("zoom", this.onZoom);
this.conductorViewService.on("zoom-stop", this.onZoomStop);
};

ConductorAxisController.prototype.changeBounds = function (bounds) {
this.bounds = bounds;
if (this.initialized && !this.zooming) {
this.setScale();
}
};

/**
* Set the scale of the axis, based on current conductor bounds.
*/
ConductorAxisController.prototype.setScale = function () {
var width = this.target.offsetWidth;
var timeSystem = this.conductor.timeSystem();
Expand All @@ -91,6 +127,11 @@ define(
this.msPerPixel = (bounds.end - bounds.start) / width;
};

/**
* When the time system changes, update the scale and formatter used
* for showing times.
* @param timeSystem
*/
ConductorAxisController.prototype.changeTimeSystem = function (timeSystem) {
this.timeSystem = timeSystem;

Expand All @@ -99,13 +140,16 @@ define(
var format = this.formatService.getFormat(key);
var bounds = this.conductor.bounds();

//The D3 scale used depends on the type of time system as d3
// supports UTC out of the box.
if (timeSystem.isUTCBased()) {
this.xScale = this.d3.scaleUtc();
} else {
this.xScale = this.d3.scaleLinear();
}

this.xAxis.scale(this.xScale);

//Define a custom format function
this.xAxis.tickFormat(function (tickValue) {
// Normalize date representations to numbers
Expand All @@ -121,38 +165,6 @@ define(
}
};

ConductorAxisController.prototype.link = function (scope, element) {
this.target = element[0].firstChild;
this.scope = scope;
var height = this.target.offsetHeight;
var vis = this.d3.select(this.target)
.append("svg:svg")
.attr("width", "100%")
.attr("height", height);

this.xAxis = this.d3.axisTop();

// draw x axis with labels and move to the bottom of the chart area
this.axisElement = vis.append("g")
.attr("transform", "translate(0," + (height - PADDING) + ")");

this.initialized = true;

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

//Respond to changes in conductor
this.conductor.on("timeSystem", this.changeTimeSystem);
this.conductor.on("bounds", this.changeBounds);

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

this.conductorViewService.on("zoom", this.onZoom);
this.conductorViewService.on("zoom-stop", this.onZoomStop);
};

ConductorAxisController.prototype.panStop = function () {
//resync view bounds with time conductor bounds
this.conductorViewService.emit("pan-stop");
Expand All @@ -170,6 +182,12 @@ define(
this.zooming = false;
};

/**
* Initiate panning via a click + drag gesture on the time conductor
* scale. Panning triggers a "pan" event
* @param {number} delta the offset from the original click event
* @see TimeConductorViewService#
*/
ConductorAxisController.prototype.pan = function (delta) {
if (!this.conductor.follow()) {
var deltaInMs = delta[0] * this.msPerPixel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ define(
this.conductorViewService.off('pan', this.setOffsetFromBounds);
};

/**
* Given some bounds, set horizontal position of TOI indicator based
* on current conductor TOI value. Bounds are provided so that
* ephemeral bounds from zoom and pan events can be used as well
* as current conductor bounds, allowing TOI to be updated in
* realtime during scroll and zoom.
* @param {TimeConductorBounds} bounds
*/
ConductorTOIController.prototype.setOffsetFromBounds = function (bounds) {
var toi = this.conductor.timeOfInterest();
if (toi !== undefined) {
Expand All @@ -79,7 +87,12 @@ define(
}
};

/**
* Set time of interest
* @param e The angular $event object
*/
ConductorTOIController.prototype.click = function (e) {
//TOI is set using the alt key modified + primary click
if (e.altKey) {
var element = $(e.currentTarget);
var width = element.width();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

define([], function () {
define(['./ConductorAxisController'], function (ConductorAxisController) {

function MctConductorAxis() {
/**
Expand All @@ -30,11 +30,15 @@ define([], function () {
*/

return {
controller: 'ConductorAxisController',
controller: [
'openmct',
'formatService',
'timeConductorViewService',
'$scope',
'$element',
ConductorAxisController
],
controllerAs: 'axis',
link: function(scope, element, attrs, controller){
controller.link(scope, element);
},

restrict: 'E',
priority: 1000,
Expand Down
Loading

0 comments on commit 93735bc

Please sign in to comment.