Giter Club home page Giter Club logo

guiglue's Introduction

guiGlue.js - a dat.gui wrapper

Google's dat.gui is a great tool for exposing parameters in a web experiment, however I found the syntax cumbersome. I wanted a simple way to abstract all the parameters needed, with all the neat options dat.gui supports, like min/max for range values, and options for selectors, and onChange events and listeners and stepping etc etc, but I wanted to define them all in one place.

How it works

Insead of...

var params = {
  var1 : 'a',
  var2 : 1
};

window.onload = function() {
  var gui = new dat.GUI();
  gui.add(params, 'var1', {'a', 'b', 'c'});
  gui.add(params, 'var2', 0, 1).step(0.01).onChange(function(){ ... });
};

We do...

var params = {
	var1 : {
		display : 'selector',
		value : 'a',
		options : {'choice 1':'value 1', 'choice 2':'value 2', 'choice 3':'value 3'}
	},
	var2 : {
		display : 'range',
		value : 1,
		min : 0,
		max : 1,
		step : 0.01,
		onChange : function(){ ... }
	}
};

window.onload = function(){
	guiGlue(paramsGUI);
};

Looks like more lines of code! Well, yes it is, but there are no more magic variables defined in the GUI as opposed to in your parameter file!... You'll thank me later.

Subfolders

Best of all... automatic subfolders! Just make nested JSON objects.

var params = {
	folder1 : {
		var1 : {
			display : 'range',
			value : 0.8,
			min : -5,
			max : 5
		},
		var2 : {
			display : 'range',
			value : 1,
			min : 0,
			max : 1,
			step : .01,
			onChange : function(){ ... }
		},
		subFolder : {
			var1 : {
				display : 'selector',
				value : 'a',
				options : ['a', 'b', 'c'],
				listen : true
			},
			subsubFolder : {
				var1 : {
					display : 'color',
					value : '#bada55',
					listen : true
				}
			}			
		}
	},
	folder2 : {
		var1 : {
			display : 'range',
			value : 1,
			min: 0,
			max: 1
		}
	}	
};

Stripped Parameter File

The parameter object can get pretty bloated. Though dat.gui may need all the min/max stuff, your code likely doesn't. Because of this, a call to guiGlue returns a stripped version of the parameter file, where all that remains are the value keys. For example

var params = {
	var1 : {
		display : 'selector',
		value : 'a',
		options : {'choice 1':'value 1', 'choice 2':'value 2', 'choice 3':'value 3'},
		onChange : function(value) {}
	},
	var2 : {
		display : 'range',
		value : 1,
		min : 0,
		max : 1,
		step : 0.01,
		onChange : function(){ ... }
	}
};

var params = guiGlue(paramsGUI);	//params = {var1 : 'a', var2 : 1}

This works as you'd expect for nested objects. The most important part is that these stripped parameters are still synced with the GUI. Changes in the GUI change the value of the parameter, and if {listen : true} is set, then changes in the parameter are mirrored in the GUI.

Options

Pass any options defined for dat.gui into guiGlue via an optional (no pun intended) second parameter.

guiGlue(paramsGUI, options);

We add one extra options currently, which is whether you want your folders auto-expanded or not. To collapse all folders pass in {folded : true}, otherwise it defaults to {folded : false}.

guiglue's People

Contributors

dmvaldman avatar glidias avatar yshing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.