      1 define([
      2     'jquery',
      3     'underscore',
      4     'viewcontroller'
      5 ], function($, _, ViewControllers) {
      6   var ScalarViewControllerABC = ViewControllers.ScalarViewControllerABC;
      7
      8   /**
      9    * @class ScaleViewController
     10    *
     11    * Alters the scale of points displayed on the screen.
     12    *
     13    * @param {UIState} uiState The shared state
     14    * @param {Node} container Container node to create the controller in.
     15    * @param {Object} decompViewDict This object is keyed by unique
     16    * identifiers and the values are DecompositionView objects referring to a
     17    * set of objects presented on screen. This dictionary will usually be shared
     18    * by all the tabs in the application. This argument is passed by reference.
     19    * Note that only the decompositions of type 'scatter' will be controlled,
     20    * other types will be ignored.
     21    *
     22    * @return {ScaleViewController}
     23    * @constructs ScaleViewController
     24    * @extends ScalarViewControllerABC
     25    *
     26    **/
     27   function ScaleViewController(uiState, container, decompViewDict) {
     28     var helpmenu = 'Change the size of the attributes on the plot, allowing ' +
     29                    'highlighting of points using size.';
     30     var title = 'Scale';
     31
     32     // shapes are only supported for scatter types
     33     var scalable = {};
     34     for (var key in decompViewDict) {
     35       if (decompViewDict[key].decomp.isScatterType()) {
     36         scalable[key] = decompViewDict[key];
     37       }
     38     }
     39
     40     ScalarViewControllerABC.call(this, uiState, container, title, helpmenu,
     41                                  0, 5, 0.1, scalable);
     42     return this;
     43   }
     44   ScaleViewController.prototype = Object.create(
     45     ScalarViewControllerABC.prototype);
     46   ScaleViewController.prototype.constructor = ScalarViewControllerABC;
     47
     48   /**
     49    * Helper function to set the scale of plottable
     50    *
     51    * @param {Object} scope The scope where the plottables exist
     52    * @param {Boolean} scale New scaling factor of the plottables
     53    * (1.0 being standard scale)
     54    * @param {Object[]} group list of mesh objects that should be changed
     55    * in scope
     56    *
     57    */
     58   ScaleViewController.prototype.setPlottableAttributes = function(scope, scale,
     59                                                                   group) {
     60     scope.setScale(scale, group);
     61   };
     62
     63   /**
     64    *
     65    * Modify the scale of all the markers in the current view
     66    *
     67    * @param {float} value The new opacity of the lements in the current view.
     68    * Should be a value between 0.1 and 5 (inclusive).
     69    *
     70    * @extends ScalarViewControllerABC
     71    *
     72    */
     73   ScaleViewController.prototype.setAllPlottableAttributes = function(value) {
     74     this.getView().setScale(value);
     75   };
     76
     77   /**
     78    *
     79    * Scaling function to use when sample scaling is based on a metadata
     80    * category.
     81    *
     82    * @param {float} val The metadata value for the current sample.
     83    * @param {float} min The minimum metadata value in the dataset.
     84    * @param {float} range The span of the metadata values.
     85    *
     86    * @return {float} Scale value for a given sample.
     87    *
     88    */
     89   ScaleViewController.prototype.scaleValue = function(val, min, range) {
     90     return Math.round((1 + (val - min) * 4 / range) * 10000) / 10000;
     91   };
     92
     93   return ScaleViewController;
     94 });
     95