|
@ -2,6 +2,9 @@ |
|
|
// This modules handles the options for Graph3d.
|
|
|
// This modules handles the options for Graph3d.
|
|
|
//
|
|
|
//
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
var Camera = require('./Camera'); |
|
|
|
|
|
var Point3d = require('./Point3d'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// enumerate the available styles
|
|
|
// enumerate the available styles
|
|
|
var STYLE = { |
|
|
var STYLE = { |
|
@ -89,6 +92,26 @@ var PREFIXEDOPTIONKEYS = [ |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Placeholder for DEFAULTS reference
|
|
|
|
|
|
var DEFAULTS = undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Check if given hash is empty. |
|
|
|
|
|
* |
|
|
|
|
|
* Source: http://stackoverflow.com/a/679937
|
|
|
|
|
|
*/ |
|
|
|
|
|
function isEmpty(obj) { |
|
|
|
|
|
for(var prop in obj) { |
|
|
|
|
|
if (obj.hasOwnProperty(prop)) |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Make first letter of parameter upper case. |
|
|
* Make first letter of parameter upper case. |
|
|
* |
|
|
* |
|
@ -166,13 +189,32 @@ function safeCopy(src, dst, fields, prefix) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setDefaults(dst) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialize dst with the values in src. |
|
|
|
|
|
* |
|
|
|
|
|
* src is the hash with the default values. |
|
|
|
|
|
* A reference DEFAULTS to this hash is stored locally for |
|
|
|
|
|
* further handling. |
|
|
|
|
|
* |
|
|
|
|
|
* For now, dst is assumed to be a Graph3d instance. |
|
|
|
|
|
*/ |
|
|
|
|
|
function setDefaults(src, dst) { |
|
|
|
|
|
if (src === undefined || isEmpty(src)) { |
|
|
|
|
|
throw new Error('No DEFAULTS passed'); |
|
|
|
|
|
} |
|
|
|
|
|
if (dst === undefined) { |
|
|
|
|
|
throw new Error('No dst passed'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Remember defaults for future reference
|
|
|
|
|
|
DEFAULTS = src; |
|
|
|
|
|
|
|
|
// Handle the defaults which can be simply copied over
|
|
|
// Handle the defaults which can be simply copied over
|
|
|
forceCopy(DEFAULTS, dst, OPTIONKEYS); |
|
|
|
|
|
forceCopy(DEFAULTS, dst, PREFIXEDOPTIONKEYS, 'default'); |
|
|
|
|
|
|
|
|
forceCopy(src, dst, OPTIONKEYS); |
|
|
|
|
|
forceCopy(src, dst, PREFIXEDOPTIONKEYS, 'default'); |
|
|
|
|
|
|
|
|
// Handle the more complex ('special') fields
|
|
|
// Handle the more complex ('special') fields
|
|
|
setSpecialSettings(DEFAULTS, dst); |
|
|
|
|
|
|
|
|
setSpecialSettings(src, dst); |
|
|
|
|
|
|
|
|
// Following are internal fields, not part of the user settings
|
|
|
// Following are internal fields, not part of the user settings
|
|
|
dst.margin = 10; // px
|
|
|
dst.margin = 10; // px
|
|
@ -187,6 +229,14 @@ function setOptions(options, dst) { |
|
|
if (options === undefined) { |
|
|
if (options === undefined) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
if (dst === undefined) { |
|
|
|
|
|
throw new Error('No dst passed'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (DEFAULTS === undefined || isEmpty(DEFAULTS)) { |
|
|
|
|
|
throw new Error('DEFAULTS not set for module Settings'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the parameters which can be simply copied over
|
|
|
// Handle the parameters which can be simply copied over
|
|
|
safeCopy(options, dst, OPTIONKEYS); |
|
|
safeCopy(options, dst, OPTIONKEYS); |
|
@ -253,7 +303,7 @@ function setShowLegend(showLegend, dst) { |
|
|
* when not found |
|
|
* when not found |
|
|
*/ |
|
|
*/ |
|
|
function getStyleNumberByName(styleName) { |
|
|
function getStyleNumberByName(styleName) { |
|
|
var number = STYLENAME[stylename]; |
|
|
|
|
|
|
|
|
var number = STYLENAME[styleName]; |
|
|
|
|
|
|
|
|
if (number === undefined) { |
|
|
if (number === undefined) { |
|
|
return -1; |
|
|
return -1; |
|
|