BVB Source Codes

dat.gui Show NumberController.js Source code

Return Download dat.gui: download NumberController.js Source code - Download dat.gui Source code - Type:.js
  1. /**
  2.  * dat-gui JavaScript Controller Library
  3.  * http://code.google.com/p/dat-gui
  4.  *
  5.  * Copyright 2011 Data Arts Team, Google Creative Lab
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  * http://www.apache.org/licenses/LICENSE-2.0
  12.  */
  13.  
  14. import Controller from './Controller';
  15. import common from '../utils/common';
  16.  
  17. function numDecimals(x) {
  18.   const _x = x.toString();
  19.   if (_x.indexOf('.') > -1) {
  20.     return _x.length - _x.indexOf('.') - 1;
  21.   }
  22.  
  23.   return 0;
  24. }
  25.  
  26. /**
  27.  * @class Represents a given property of an object that is a number.
  28.  *
  29.  * @extends dat.controllers.Controller
  30.  *
  31.  * @param {Object} object The object to be manipulated
  32.  * @param {string} property The name of the property to be manipulated
  33.  * @param {Object} [params] Optional parameters
  34.  * @param {Number} [params.min] Minimum allowed value
  35.  * @param {Number} [params.max] Maximum allowed value
  36.  * @param {Number} [params.step] Increment by which to change value
  37.  *
  38.  * @member dat.controllers
  39.  */
  40. class NumberController extends Controller {
  41.   constructor(object, property, params) {
  42.     super(object, property);
  43.  
  44.     const _params = params || {};
  45.  
  46.     this.__min = _params.min;
  47.     this.__max = _params.max;
  48.     this.__step = _params.step;
  49.  
  50.     if (common.isUndefined(this.__step)) {
  51.       if (this.initialValue === 0) {
  52.         this.__impliedStep = 1; // What are we, psychics?
  53.       } else {
  54.         // Hey Doug, check this out.
  55.         this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(this.initialValue)) / Math.LN10)) / 10;
  56.       }
  57.     } else {
  58.       this.__impliedStep = this.__step;
  59.     }
  60.  
  61.     this.__precision = numDecimals(this.__impliedStep);
  62.   }
  63.  
  64.   setValue(v) {
  65.     let _v = v;
  66.  
  67.     if (this.__min !== undefined && _v < this.__min) {
  68.       _v = this.__min;
  69.     } else if (this.__max !== undefined && _v > this.__max) {
  70.       _v = this.__max;
  71.     }
  72.  
  73.     if (this.__step !== undefined && _v % this.__step !== 0) {
  74.       _v = Math.round(_v / this.__step) * this.__step;
  75.     }
  76.  
  77.     return super.setValue(_v);
  78.   }
  79.  
  80.   /**
  81.    * Specify a minimum value for <code>object[property]</code>.
  82.    *
  83.    * @param {Number} minValue The minimum value for
  84.    * <code>object[property]</code>
  85.    * @returns {dat.controllers.NumberController} this
  86.    */
  87.   min(v) {
  88.     this.__min = v;
  89.     return this;
  90.   }
  91.  
  92.   /**
  93.    * Specify a maximum value for <code>object[property]</code>.
  94.    *
  95.    * @param {Number} maxValue The maximum value for
  96.    * <code>object[property]</code>
  97.    * @returns {dat.controllers.NumberController} this
  98.    */
  99.   max(v) {
  100.     this.__max = v;
  101.     return this;
  102.   }
  103.  
  104.   /**
  105.    * Specify a step value that dat.controllers.NumberController
  106.    * increments by.
  107.    *
  108.    * @param {Number} stepValue The step value for
  109.    * dat.controllers.NumberController
  110.    * @default if minimum and maximum specified increment is 1% of the
  111.    * difference otherwise stepValue is 1
  112.    * @returns {dat.controllers.NumberController} this
  113.    */
  114.   step(v) {
  115.     this.__step = v;
  116.     this.__impliedStep = v;
  117.     this.__precision = numDecimals(v);
  118.     return this;
  119.   }
  120. }
  121.  
  122. export default NumberController;
  123.  
downloadNumberController.js Source code - Download dat.gui Source code
Related Source Codes/Software:
tmate - Instant Terminal Sharing ht... 2017-04-16
WNXHuntForCity - City find By Objective - C 2017-04-16
st2 - StackStorm (aka IFTTT for Ops) is event-driven aut... 2017-04-16
css-in-js - React: CSS in JS techniques comparison. 2017-04-16
android-viewflow - A horizontal view scroller library for Android 2017-04-16
capybara-webkit - A Capybara driver for headless WebKit to test Java... 2017-04-16
fullstackpython.com - Full Stack Python source with Pelican, Bootstrap a... 2017-04-16
naxsi - NAXSI is an open-source, high performance, low rul... 2017-04-16
ToGL - Direct3D to OpenGL abstraction layer 2017-04-16
LiveScript - LiveScript is a language which compiles to JavaScr... 2017-04-16
MaterialSearchView - Express it in the library to implement SearchView ... 2017-04-23
ptpython - A better Python REPL 2017-04-23
Laravel-4-Bootstrap-Starter-Site - Laravel 4 Starter Site is a basic blog application... 2017-04-23
official-images - Primary source of truth for the Docker "Official I... 2017-04-23
awesome-chrome-devtools - Awesome tooling and resources in the Chrome DevToo... 2017-04-23
EventStore - The open-source, functional database with Complex ... 2017-04-23
screencat - 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23

 Back to top