# dat.GUI API Details about the classes, methods, and properties provided by dat.GUI. For more hands-on examples, see the dat.GUI [tutorial](http://workshop.chromeexperiments.com/examples/gui). ## Classes
GUI

A lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.

Controller

An "abstract" class that represents a given property of an object.

NumberControllerdat.controllers.Controller

Represents a given property of an object that is a number.

## GUI A lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly. **Kind**: global class * [GUI](#GUI) * [new GUI([params])](#new_GUI_new) * [.domElement](#GUI+domElement) : DOMElement * [.parent](#GUI+parent) : dat.gui.GUI * [.autoPlace](#GUI+autoPlace) : Boolean * [.closeOnTop](#GUI+closeOnTop) : Boolean * [.preset](#GUI+preset) : String * [.width](#GUI+width) : Number * [.name](#GUI+name) : String * [.closed](#GUI+closed) : Boolean * [.load](#GUI+load) : Object * [.useLocalStorage](#GUI+useLocalStorage) : Boolean * [.add(object, property, [min], [max], [step])](#GUI+add) ⇒ [Controller](#Controller) * [.addColor(object, property)](#GUI+addColor) ⇒ [Controller](#Controller) * [.remove(controller)](#GUI+remove) * [.destroy()](#GUI+destroy) * [.addFolder(name)](#GUI+addFolder) ⇒ dat.gui.GUI * [.removeFolder(folder)](#GUI+removeFolder) * [.open()](#GUI+open) * [.close()](#GUI+close) * [.getRoot()](#GUI+getRoot) ⇒ dat.gui.GUI * [.getSaveObject()](#GUI+getSaveObject) ⇒ Object ### new GUI([params]) | Param | Type | Default | Description | | --- | --- | --- | --- | | [params] | Object | | | | [params.name] | String | | The name of this GUI. | | [params.load] | Object | | JSON object representing the saved state of this GUI. | | [params.parent] | dat.gui.GUI | | The GUI I'm nested in. | | [params.autoPlace] | Boolean | true | | | [params.hideable] | Boolean | true | If true, GUI is closed by the h keypress. | | [params.closed] | Boolean | false | If true, starts closed | | [params.closeOnTop] | Boolean | false | If true, close/open button shows on top of the GUI | **Example** ```js // Creating a GUI with options. var gui = new dat.GUI({name: 'My GUI'}); ``` **Example** ```js // Creating a GUI and a subfolder. var gui = new dat.GUI(); var folder1 = gui.addFolder('Flow Field'); ``` ### gui.domElement : DOMElement Outermost DOM Element **Kind**: instance property of [GUI](#GUI) ### gui.parent : dat.gui.GUI The parent GUI **Kind**: instance property of [GUI](#GUI) ### gui.autoPlace : Boolean Handles GUI's element placement for you **Kind**: instance property of [GUI](#GUI) ### gui.closeOnTop : Boolean Handles GUI's position of open/close button **Kind**: instance property of [GUI](#GUI) ### gui.preset : String The identifier for a set of saved values **Kind**: instance property of [GUI](#GUI) ### gui.width : Number The width of GUI element **Kind**: instance property of [GUI](#GUI) ### gui.name : String The name of GUI. Used for folders. i.e a folder's name **Kind**: instance property of [GUI](#GUI) ### gui.closed : Boolean Whether the GUI is collapsed or not **Kind**: instance property of [GUI](#GUI) ### gui.load : Object Contains all presets **Kind**: instance property of [GUI](#GUI) ### gui.useLocalStorage : Boolean Determines whether or not to use localStorage as the means for remembering **Kind**: instance property of [GUI](#GUI) ### gui.add(object, property, [min], [max], [step]) ⇒ [Controller](#Controller) Adds a new [Controller](#Controller) to the GUI. The type of controller created is inferred from the initial value of object[property]. For color properties, see [addColor](addColor). **Kind**: instance method of [GUI](#GUI) **Returns**: [Controller](#Controller) - The controller that was added to the GUI. | Param | Type | Description | | --- | --- | --- | | object | Object | The object to be manipulated | | property | String | The name of the property to be manipulated | | [min] | Number | Minimum allowed value | | [max] | Number | Maximum allowed value | | [step] | Number | Increment by which to change value | **Example** ```js // Add a string controller. var person = {name: 'Sam'}; gui.add(person, 'name'); ``` **Example** ```js // Add a number controller slider. var person = {age: 45}; gui.add(person, 'age', 0, 100); ``` ### gui.addColor(object, property) ⇒ [Controller](#Controller) Adds a new color controller to the GUI. **Kind**: instance method of [GUI](#GUI) **Returns**: [Controller](#Controller) - The controller that was added to the GUI. | Param | | --- | | object | | property | **Example** ```js var palette = { color1: '#FF0000', // CSS string color2: [ 0, 128, 255 ], // RGB array color3: [ 0, 128, 255, 0.3 ], // RGB with alpha color4: { h: 350, s: 0.9, v: 0.3 } // Hue, saturation, value }; gui.addColor(palette, 'color1'); gui.addColor(palette, 'color2'); gui.addColor(palette, 'color3'); gui.addColor(palette, 'color4'); ``` ### gui.remove(controller) Removes the given controller from the GUI. **Kind**: instance method of [GUI](#GUI) | Param | Type | | --- | --- | | controller | [Controller](#Controller) | ### gui.destroy() Removes the root GUI from the document and unbinds all event listeners. For subfolders, use `gui.removeFolder(folder)` instead. **Kind**: instance method of [GUI](#GUI) ### gui.addFolder(name) ⇒ dat.gui.GUI Creates a new subfolder GUI instance. **Kind**: instance method of [GUI](#GUI) **Returns**: dat.gui.GUI - The new folder. **Throws**: - Error if this GUI already has a folder by the specified name | Param | | --- | | name | ### gui.removeFolder(folder) Removes a subfolder GUI instance. **Kind**: instance method of [GUI](#GUI) | Param | Type | Description | | --- | --- | --- | | folder | dat.gui.GUI | The folder to remove. | ### gui.open() Opens the GUI. **Kind**: instance method of [GUI](#GUI) ### gui.close() Closes the GUI. **Kind**: instance method of [GUI](#GUI) ### gui.getRoot() ⇒ dat.gui.GUI **Kind**: instance method of [GUI](#GUI) **Returns**: dat.gui.GUI - the topmost parent GUI of a nested GUI. ### gui.getSaveObject() ⇒ Object **Kind**: instance method of [GUI](#GUI) **Returns**: Object - a JSON object representing the current state of this GUI as well as its remembered properties. ## Controller An "abstract" class that represents a given property of an object. **Kind**: global class * [Controller](#Controller) * [new Controller(object, property)](#new_Controller_new) * [.domElement](#Controller+domElement) : DOMElement * [.object](#Controller+object) : Object * [.property](#Controller+property) : String * [.options(options)](#Controller+options) ⇒ [Controller](#Controller) * [.name(name)](#Controller+name) ⇒ [Controller](#Controller) * [.listen()](#Controller+listen) ⇒ [Controller](#Controller) * [.remove()](#Controller+remove) ⇒ [Controller](#Controller) * [.onChange(fnc)](#Controller+onChange) ⇒ [Controller](#Controller) * [.onFinishChange(fnc)](#Controller+onFinishChange) ⇒ [Controller](#Controller) * [.setValue(newValue)](#Controller+setValue) * [.getValue()](#Controller+getValue) ⇒ Object * [.updateDisplay()](#Controller+updateDisplay) ⇒ [Controller](#Controller) * [.isModified()](#Controller+isModified) ⇒ Boolean ### new Controller(object, property) | Param | Type | Description | | --- | --- | --- | | object | Object | The object to be manipulated | | property | string | The name of the property to be manipulated | ### controller.domElement : DOMElement Those who extend this class will put their DOM elements in here. **Kind**: instance property of [Controller](#Controller) ### controller.object : Object The object to manipulate **Kind**: instance property of [Controller](#Controller) ### controller.property : String The name of the property to manipulate **Kind**: instance property of [Controller](#Controller) ### controller.options(options) ⇒ [Controller](#Controller) **Kind**: instance method of [Controller](#Controller) | Param | Type | | --- | --- | | options | Array \| Object | ### controller.name(name) ⇒ [Controller](#Controller) Sets the name of the controller. **Kind**: instance method of [Controller](#Controller) | Param | Type | | --- | --- | | name | string | ### controller.listen() ⇒ [Controller](#Controller) Sets controller to listen for changes on its underlying object. **Kind**: instance method of [Controller](#Controller) ### controller.remove() ⇒ [Controller](#Controller) Removes the controller from its parent GUI. **Kind**: instance method of [Controller](#Controller) ### controller.onChange(fnc) ⇒ [Controller](#Controller) Specify that a function fire every time someone changes the value with this Controller. **Kind**: instance method of [Controller](#Controller) **Returns**: [Controller](#Controller) - this | Param | Type | Description | | --- | --- | --- | | fnc | function | This function will be called whenever the value is modified via this Controller. | ### controller.onFinishChange(fnc) ⇒ [Controller](#Controller) Specify that a function fire every time someone "finishes" changing the value wih this Controller. Useful for values that change incrementally like numbers or strings. **Kind**: instance method of [Controller](#Controller) **Returns**: [Controller](#Controller) - this | Param | Type | Description | | --- | --- | --- | | fnc | function | This function will be called whenever someone "finishes" changing the value via this Controller. | ### controller.setValue(newValue) Change the value of object[property] **Kind**: instance method of [Controller](#Controller) | Param | Type | Description | | --- | --- | --- | | newValue | Object | The new value of object[property] | ### controller.getValue() ⇒ Object Gets the value of object[property] **Kind**: instance method of [Controller](#Controller) **Returns**: Object - The current value of object[property] ### controller.updateDisplay() ⇒ [Controller](#Controller) Refreshes the visual display of a Controller in order to keep sync with the object's current value. **Kind**: instance method of [Controller](#Controller) **Returns**: [Controller](#Controller) - this ### controller.isModified() ⇒ Boolean **Kind**: instance method of [Controller](#Controller) **Returns**: Boolean - true if the value has deviated from initialValue ## NumberController ⇐ dat.controllers.Controller Represents a given property of an object that is a number. **Kind**: global class **Extends**: dat.controllers.Controller * [NumberController](#NumberController) ⇐ dat.controllers.Controller * [new NumberController(object, property, [params])](#new_NumberController_new) * [.min(minValue)](#NumberController+min) ⇒ dat.controllers.NumberController * [.max(maxValue)](#NumberController+max) ⇒ dat.controllers.NumberController * [.step(stepValue)](#NumberController+step) ⇒ dat.controllers.NumberController ### new NumberController(object, property, [params]) | Param | Type | Description | | --- | --- | --- | | object | Object | The object to be manipulated | | property | string | The name of the property to be manipulated | | [params] | Object | Optional parameters | | [params.min] | Number | Minimum allowed value | | [params.max] | Number | Maximum allowed value | | [params.step] | Number | Increment by which to change value | ### numberController.min(minValue) ⇒ dat.controllers.NumberController Specify a minimum value for object[property]. **Kind**: instance method of [NumberController](#NumberController) **Returns**: dat.controllers.NumberController - this | Param | Type | Description | | --- | --- | --- | | minValue | Number | The minimum value for object[property] | ### numberController.max(maxValue) ⇒ dat.controllers.NumberController Specify a maximum value for object[property]. **Kind**: instance method of [NumberController](#NumberController) **Returns**: dat.controllers.NumberController - this | Param | Type | Description | | --- | --- | --- | | maxValue | Number | The maximum value for object[property] | ### numberController.step(stepValue) ⇒ dat.controllers.NumberController Specify a step value that dat.controllers.NumberController increments by. **Kind**: instance method of [NumberController](#NumberController) **Default**: if minimum and maximum specified increment is 1% of the difference otherwise stepValue is 1 **Returns**: dat.controllers.NumberController - this | Param | Type | Description | | --- | --- | --- | | stepValue | Number | The step value for dat.controllers.NumberController |