|
| 1 | +/***************************************************************************** |
| 2 | + * Open MCT Web, Copyright (c) 2014-2015, United States Government |
| 3 | + * as represented by the Administrator of the National Aeronautics and Space |
| 4 | + * Administration. All rights reserved. |
| 5 | + * |
| 6 | + * Open MCT Web is licensed under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations |
| 15 | + * under the License. |
| 16 | + * |
| 17 | + * Open MCT Web includes source code licensed under additional open source |
| 18 | + * licenses. See the Open Source Licenses file (LICENSES.md) included with |
| 19 | + * this source code distribution or the Licensing information page available |
| 20 | + * at runtime from the About dialog for additional information. |
| 21 | + *****************************************************************************/ |
| 22 | + |
| 23 | +define( |
| 24 | + ["zepto"], |
| 25 | + function ($) { |
| 26 | + |
| 27 | + /** |
| 28 | + * The mct-conductor-axis renders a horizontal axis with regular |
| 29 | + * labelled 'ticks'. It requires 'start' and 'end' integer values to |
| 30 | + * be specified as attributes. |
| 31 | + */ |
| 32 | + function ConductorTOIController($scope, conductor, conductorViewService, $timeout) { |
| 33 | + this.conductor = conductor; |
| 34 | + this.conductorViewService = conductorViewService; |
| 35 | + |
| 36 | + //Bind all class functions to 'this' |
| 37 | + Object.keys(ConductorTOIController.prototype).filter(function (key) { |
| 38 | + return typeof ConductorTOIController.prototype[key] === 'function'; |
| 39 | + }).forEach(function (key) { |
| 40 | + this[key] = ConductorTOIController.prototype[key].bind(this); |
| 41 | + }.bind(this)); |
| 42 | + |
| 43 | + this.conductor.on('timeOfInterest', this.changeTimeOfInterest); |
| 44 | + this.conductorViewService.on('zoom', this.setOffsetFromBounds); |
| 45 | + this.conductorViewService.on('pan', this.setOffsetFromBounds); |
| 46 | + |
| 47 | + this.$timeout = $timeout; |
| 48 | + |
| 49 | + var generateRandomTOI = function () { |
| 50 | + var bounds = conductor.bounds(); |
| 51 | + var range = bounds.end - bounds.start; |
| 52 | + var toi = Math.random() * range + bounds.start; |
| 53 | + console.log('calculated random TOI of ' + toi); |
| 54 | + conductor.timeOfInterest(toi); |
| 55 | + //this.timeoutHandle = $timeout(generateRandomTOI, 1000); |
| 56 | + }.bind(this); |
| 57 | + |
| 58 | + //this.timeoutHandle = $timeout(generateRandomTOI, 2000); |
| 59 | + |
| 60 | + $scope.$on('$destroy', this.destroy); |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + ConductorTOIController.prototype.destroy = function () { |
| 65 | + this.conductor.off('timeOfInterest', this.setOffsetFromBounds); |
| 66 | + this.conductorViewService.off('zoom', this.setOffsetFromBounds); |
| 67 | + this.conductorViewService.off('pan', this.setOffsetFromBounds); |
| 68 | + |
| 69 | + this.$timeout.cancel(this.timeoutHandle); |
| 70 | + }; |
| 71 | + |
| 72 | + ConductorTOIController.prototype.setOffsetFromBounds = function (bounds) { |
| 73 | + var toi = this.conductor.timeOfInterest(); |
| 74 | + var offset = toi - bounds.start; |
| 75 | + this.left = offset / (bounds.end - bounds.start) * 100; |
| 76 | + }; |
| 77 | + |
| 78 | + ConductorTOIController.prototype.changeTimeOfInterest = function () { |
| 79 | + var bounds = this.conductor.bounds(); |
| 80 | + if (bounds) { |
| 81 | + this.setOffsetFromBounds(bounds); |
| 82 | + this.pinned = true; |
| 83 | + } |
| 84 | + }; |
| 85 | + |
| 86 | + ConductorTOIController.prototype.click = function (e) { |
| 87 | + if (e.altKey) { |
| 88 | + var element = $(e.currentTarget); |
| 89 | + var width = element.width(); |
| 90 | + var relativeX = e.pageX - element.offset().left; |
| 91 | + var percX = relativeX / width; |
| 92 | + var bounds = this.conductor.bounds(); |
| 93 | + var timeRange = bounds.end - bounds.start; |
| 94 | + |
| 95 | + this.conductor.timeOfInterest(timeRange * percX + bounds.start); |
| 96 | + } |
| 97 | + }; |
| 98 | + |
| 99 | + /* |
| 100 | + ConductorTOIController.prototype.zoom = function (bounds) { |
| 101 | + this.changeTOI(bounds) |
| 102 | + }; |
| 103 | +
|
| 104 | + ConductorTOIController.prototype.pan = function (bounds) { |
| 105 | + this.changeTOI(bounds) |
| 106 | + };*/ |
| 107 | + |
| 108 | + ConductorTOIController.prototype.resize = function () { |
| 109 | + //Do something |
| 110 | + }; |
| 111 | + |
| 112 | + return ConductorTOIController; |
| 113 | + } |
| 114 | +); |
0 commit comments