1 define([ 2 'jquery', 3 'underscore', 4 'viewcontroller', 5 'chroma', 6 'slickformatters', 7 'slickeditors' 8 ], function($, _, ViewControllers, chroma, slickformatters, slickeditors) { 9 10 // we only use the base attribute class, no need to get the base class 11 /** @private */ 12 var EmperorAttributeABC = ViewControllers.EmperorAttributeABC; 13 /** 14 * @class VisibilityController 15 * 16 * Manipulates and displays the visibility of objects on screen. 17 * 18 * @param {UIState} uiState The shared state 19 * @param {Node} container Container node to create the controller in. 20 * @param {Object} decompViewDict This object is keyed by unique 21 * identifiers and the values are DecompositionView objects referring to a 22 * set of objects presented on screen. This dictionary will usually be shared 23 * by all the tabs in the application. This argument is passed by reference. 24 * 25 * @return {VisibilityController} An instance of VisibilityController 26 * @constructs VisibilityController 27 * @extends EmperorAttributeABC 28 */ 29 function VisibilityController(uiState, container, decompViewDict) { 30 var helpmenu = 'Change the visibility of the attributes on the plot, ' + 31 'such as spheres, vectors and ellipsoids.'; 32 var title = 'Visibility'; 33 34 // Constant for width in slick-grid 35 var SLICK_WIDTH = 25, scope = this; 36 37 // Build the options dictionary 38 var options = {'valueUpdatedCallback': function(e, args) { 39 var visible = args.item.value; 40 var group = args.item.plottables; 41 var element = scope.getView(); 42 scope.setPlottableAttributes(element, visible, group); 43 }, 44 'categorySelectionCallback': function(evt, params) { 45 var category = scope.$select.val(); 46 47 var decompViewDict = scope.getView(); 48 49 // getting all unique values per categories 50 var uniqueVals = decompViewDict.decomp.getUniqueValuesByCategory( 51 category); 52 // getting color for each uniqueVals 53 var attributes = {}; 54 _.each(uniqueVals, function(value) { 55 attributes[value] = true; 56 }); 57 // fetch the slickgrid-formatted data 58 var data = decompViewDict.setCategory( 59 attributes, scope.setPlottableAttributes, category); 60 61 scope.setSlickGridDataset(data); 62 }, 63 'slickGridColumn': {id: 'title', name: '', field: 'value', 64 sortable: false, maxWidth: SLICK_WIDTH, 65 minWidth: SLICK_WIDTH, 66 formatter: Slick.Formatters.Checkmark, 67 editor: Slick.Editors.Checkbox}}; 68 69 EmperorAttributeABC.call(this, uiState, container, title, helpmenu, 70 decompViewDict, options); 71 return this; 72 } 73 VisibilityController.prototype = Object.create(EmperorAttributeABC.prototype); 74 VisibilityController.prototype.constructor = EmperorAttributeABC; 75 76 /** 77 * 78 * Private method to reset all objects to be visible. 79 * 80 * @extends EmperorAttributeABC 81 * @private 82 * 83 */ 84 VisibilityController.prototype._resetAttribute = function() { 85 EmperorAttributeABC.prototype._resetAttribute.call(this); 86 87 _.each(this.decompViewDict, function(view) { 88 view.setVisibility(true); 89 view.showEdgesForPlottables(); 90 }); 91 }; 92 93 /** 94 * Helper function to set the visibility of plottable 95 * 96 * @param {Object} scope the scope where the plottables exist 97 * @param {boolean} visible Visibility of the plottables 98 * @param {Object[]} group Array of objects that should be changed in scope 99 */ 100 VisibilityController.prototype.setPlottableAttributes = 101 function(scope, visible, group) { 102 scope.setVisibility(visible, group); 103 }; 104 105 return VisibilityController; 106 }); 107