From 1446540a26b9c69bd6a25fe11f208c399b3d6e70 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 09:27:08 +0200 Subject: [PATCH 1/6] Added handling of settings backgroundColor and dataColor --- lib/graph3d/Graph3d.js | 127 ++++++++++++++++++++++++++++------------- 1 file changed, 86 insertions(+), 41 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 19bc59ef..61a6cdf6 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -82,13 +82,23 @@ var DEFAULTS = { axisColor : '#4D4D4D', gridColor : '#D3D3D3', xCenter : '55%', - yCenter : '50%' + yCenter : '50%', // Following not in defaults (yet) but present in user settings // These will be initialized as 'undefined' //'showAnimationControls', //'animationAutoStart' + + // Following not in OPTIONKEYS because they require special handling, + + backgroundColor : undefined, + + dataColor : { + fill : '#7DC1FF', + stroke : '#3267D2', + strokeWidth: 1 // px + } }; @@ -160,6 +170,8 @@ function Graph3d(container, data, options) { this.dataTable = null; // The original data table this.dataPoints = null; // The table with point objects + // create a frame and canvas + this.create(); // // Start Settings @@ -174,6 +186,9 @@ function Graph3d(container, data, options) { this.showTooltip = false; this.dotSizeRatio = 0.02; // size of the dots as a fraction of the graph width + // Handle the more complex ('special') fields + this._setSpecialSettings(DEFAULTS, this); + // The rest of the fields. // These require special attention in some way // TODO: handle these @@ -210,21 +225,10 @@ function Graph3d(container, data, options) { this.yBarWidth = 1; // TODO: customize axis range - // colors - this.dataColor = { - fill: '#7DC1FF', - stroke: '#3267D2', - strokeWidth: 1 // px - }; - - // // End Settings // - // create a frame and canvas - this.create(); - // apply options (also when undefined) this.setOptions(options); @@ -381,11 +385,41 @@ Graph3d.prototype._calcTranslations = function(points, sort) { }; +// ----------------------------------------------------------------------------- +// Methods for handling settings +// ----------------------------------------------------------------------------- + + +/** + * Special handling for certain parameters + * + * 'Special' here means: setting requires more than a simple copy + */ +Graph3d.prototype._setSpecialSettings = function(src, dst) { + + if (src.backgroundColor !== undefined) { + this._setBackgroundColor(src.backgroundColor, dst); + } + + this._setDataColor(src.dataColor, dst); + +/* TODO + setStyle(src.style, dst); + + if (src.tooltip !== undefined) { + dst.showTooltip = src.tooltip; + } + + setCameraPosition(src.cameraPosition, dst); +End TODO */ +} + + /** * Set the background styling for the graph * @param {string | {fill: string, stroke: string, strokeWidth: string}} backgroundColor */ -Graph3d.prototype._setBackgroundColor = function(backgroundColor) { +Graph3d.prototype._setBackgroundColor = function(backgroundColor, dst) { var fill = 'white'; var stroke = 'gray'; var strokeWidth = 1; @@ -400,20 +434,49 @@ Graph3d.prototype._setBackgroundColor = function(backgroundColor) { if (backgroundColor.stroke !== undefined) stroke = backgroundColor.stroke; if (backgroundColor.strokeWidth !== undefined) strokeWidth = backgroundColor.strokeWidth; } - else if (backgroundColor === undefined) { - // use use defaults - } else { throw new Error('Unsupported type of backgroundColor'); } - this.frame.style.backgroundColor = fill; - this.frame.style.borderColor = stroke; - this.frame.style.borderWidth = strokeWidth + 'px'; - this.frame.style.borderStyle = 'solid'; + dst.frame.style.backgroundColor = fill; + dst.frame.style.borderColor = stroke; + dst.frame.style.borderWidth = strokeWidth + 'px'; + dst.frame.style.borderStyle = 'solid'; }; +Graph3d.prototype._setDataColor = function(dataColor, dst) { + if (dataColor === undefined) { + return; // Nothing to do + } + + if (dst.dataColor === undefined) { + dst.dataColor = {}; + } + + if (typeof dataColor === 'string') { + dst.dataColor.fill = dataColor; + dst.dataColor.stroke = dataColor; + } + else { + if (dataColor.fill) { + dst.dataColor.fill = dataColor.fill; + } + if (dataColor.stroke) { + dst.dataColor.stroke = dataColor.stroke; + } + if (dataColor.strokeWidth !== undefined) { + dst.dataColor.strokeWidth = dataColor.strokeWidth; + } + } +} + + +// ----------------------------------------------------------------------------- +// End methods for handling settings +// ----------------------------------------------------------------------------- + + /// enumerate the available styles Graph3d.STYLE = { BAR: 0, @@ -995,6 +1058,9 @@ Graph3d.prototype.setOptions = function (options) { // Handle the parameters which can be simply copied over safeCopy(options, this, OPTIONKEYS); + // Handle the more complex ('special') fields + this._setSpecialSettings(options, this); + // Handle the rest of the parameters if (options.showLegend !== undefined) this.defaultShowLegend = options.showLegend; @@ -1019,7 +1085,6 @@ Graph3d.prototype.setOptions = function (options) { if (options.zMax !== undefined) this.defaultZMax = options.zMax; if (options.valueMin !== undefined) this.defaultValueMin = options.valueMin; if (options.valueMax !== undefined) this.defaultValueMax = options.valueMax; - if (options.backgroundColor !== undefined) this._setBackgroundColor(options.backgroundColor); if (options.cameraPosition !== undefined) cameraPosition = options.cameraPosition; @@ -1027,26 +1092,6 @@ Graph3d.prototype.setOptions = function (options) { this.camera.setArmRotation(cameraPosition.horizontal, cameraPosition.vertical); this.camera.setArmLength(cameraPosition.distance); } - - // colors - if (options.dataColor) { - if (typeof options.dataColor === 'string') { - this.dataColor.fill = options.dataColor; - this.dataColor.stroke = options.dataColor; - } - else { - if (options.dataColor.fill) { - this.dataColor.fill = options.dataColor.fill; - } - if (options.dataColor.stroke) { - this.dataColor.stroke = options.dataColor.stroke; - } - if (options.dataColor.strokeWidth !== undefined) { - this.dataColor.strokeWidth = options.dataColor.strokeWidth; - } - } - } - } this.setSize(this.width, this.height); From f3e564311954512cd71898c796c5eb3b9e16aadd Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 10:00:38 +0200 Subject: [PATCH 2/6] Added handling of settings for camera --- lib/graph3d/Graph3d.js | 94 ++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 61a6cdf6..08ccd6bb 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -98,6 +98,12 @@ var DEFAULTS = { fill : '#7DC1FF', stroke : '#3267D2', strokeWidth: 1 // px + }, + + cameraPosition : { + horizontal: 1.0, + vertical : 0.5, + distance : 1.7 } }; @@ -197,10 +203,6 @@ function Graph3d(container, data, options) { this.style = Graph3d.STYLE.DOT; - - this.camera = new Camera(); - this.camera.setArmRotation(1.0, 0.5); - this.camera.setArmLength(1.7); this.eye = new Point3d(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window? // the column indexes @@ -396,12 +398,12 @@ Graph3d.prototype._calcTranslations = function(points, sort) { * 'Special' here means: setting requires more than a simple copy */ Graph3d.prototype._setSpecialSettings = function(src, dst) { - if (src.backgroundColor !== undefined) { this._setBackgroundColor(src.backgroundColor, dst); } this._setDataColor(src.dataColor, dst); + this._setCameraPosition(src.cameraPosition, dst); /* TODO setStyle(src.style, dst); @@ -410,11 +412,12 @@ Graph3d.prototype._setSpecialSettings = function(src, dst) { dst.showTooltip = src.tooltip; } - setCameraPosition(src.cameraPosition, dst); End TODO */ } + + /** * Set the background styling for the graph * @param {string | {fill: string, stroke: string, strokeWidth: string}} backgroundColor @@ -472,6 +475,47 @@ Graph3d.prototype._setDataColor = function(dataColor, dst) { } +Graph3d.prototype._setCameraPosition = function(cameraPosition, dst) { + var camPos = cameraPosition; + if (camPos === undefined) { + return; + } + + if (dst.camera === undefined) { + dst.camera = new Camera(); + } + + dst.camera.setArmRotation(camPos.horizontal, camPos.vertical); + dst.camera.setArmLength(camPos.distance); +}; + + +// +// Public methods for specific settings +// + +/** + * Set the rotation and distance of the camera + * @param {Object} pos An object with the camera position. The object + * contains three parameters: + * - horizontal {Number} + * The horizontal rotation, between 0 and 2*PI. + * Optional, can be left undefined. + * - vertical {Number} + * The vertical rotation, between 0 and 0.5*PI + * if vertical=0.5*PI, the graph is shown from the + * top. Optional, can be left undefined. + * - distance {Number} + * The (normalized) distance of the camera to the + * center of the graph, a value between 0.71 and 5.0. + * Optional, can be left undefined. + */ +Graph3d.prototype.setCameraPosition = function(pos) { + this._setCameraPosition(pos, this); + this.redraw(); +}; + + // ----------------------------------------------------------------------------- // End methods for handling settings // ----------------------------------------------------------------------------- @@ -964,37 +1008,6 @@ Graph3d.prototype._resizeCenter = function() { } }; -/** - * Set the rotation and distance of the camera - * @param {Object} pos An object with the camera position. The object - * contains three parameters: - * - horizontal {Number} - * The horizontal rotation, between 0 and 2*PI. - * Optional, can be left undefined. - * - vertical {Number} - * The vertical rotation, between 0 and 0.5*PI - * if vertical=0.5*PI, the graph is shown from the - * top. Optional, can be left undefined. - * - distance {Number} - * The (normalized) distance of the camera to the - * center of the graph, a value between 0.71 and 5.0. - * Optional, can be left undefined. - */ -Graph3d.prototype.setCameraPosition = function(pos) { - if (pos === undefined) { - return; - } - - if (pos.horizontal !== undefined && pos.vertical !== undefined) { - this.camera.setArmRotation(pos.horizontal, pos.vertical); - } - - if (pos.distance !== undefined) { - this.camera.setArmLength(pos.distance); - } - - this.redraw(); -}; /** @@ -1085,13 +1098,6 @@ Graph3d.prototype.setOptions = function (options) { if (options.zMax !== undefined) this.defaultZMax = options.zMax; if (options.valueMin !== undefined) this.defaultValueMin = options.valueMin; if (options.valueMax !== undefined) this.defaultValueMax = options.valueMax; - - if (options.cameraPosition !== undefined) cameraPosition = options.cameraPosition; - - if (cameraPosition !== undefined) { - this.camera.setArmRotation(cameraPosition.horizontal, cameraPosition.vertical); - this.camera.setArmLength(cameraPosition.distance); - } } this.setSize(this.width, this.height); From 9a028a8634a2b7e2e0a835de9b44166f533a1015 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 12:50:48 +0200 Subject: [PATCH 3/6] Added step to defaults; fixes to detect and survive inconstent data --- lib/graph3d/Graph3d.js | 135 +++++++++++++++++++++++++++----------- lib/graph3d/StepNumber.js | 21 ++++++ 2 files changed, 119 insertions(+), 37 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 08ccd6bb..273d6cf8 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -12,6 +12,21 @@ var StepNumber = require('./StepNumber'); // Definitions private to module // ----------------------------------------------------------------------------- +/// enumerate the available styles +var STYLE = { + BAR : 0, + BARCOLOR: 1, + BARSIZE : 2, + DOT : 3, + DOTLINE : 4, + DOTCOLOR: 5, + DOTSIZE : 6, + GRID : 7, + LINE : 8, + SURFACE : 9 +}; + + /** * Field names in the options hash which are of relevance to the user. * @@ -32,9 +47,9 @@ var OPTIONKEYS = [ 'showGrid', 'showPerspective', 'showShadow', - 'showAnimationControls', 'keepAspectRatio', 'verticalRatio', + 'showAnimationControls', 'animationInterval', 'animationPreload', 'animationAutoStart', @@ -76,28 +91,28 @@ var DEFAULTS = { showPerspective : true, showShadow : false, keepAspectRatio : true, - verticalRatio : 0.5, // 0.1 to 1.0, where 1.0 results in a 'cube' - animationInterval: 1000, // milliseconds - animationPreload : false, + verticalRatio : 0.5, // 0.1 to 1.0, where 1.0 results in a 'cube' + + showAnimationControls: undefined, // auto by default + animationInterval : 1000, // milliseconds + animationPreload : false, + animationAutoStart : undefined, // auto by default + axisColor : '#4D4D4D', gridColor : '#D3D3D3', xCenter : '55%', yCenter : '50%', - // Following not in defaults (yet) but present in user settings - // These will be initialized as 'undefined' - //'showAnimationControls', - //'animationAutoStart' - // Following not in OPTIONKEYS because they require special handling, + style : STYLE.DOT, // Can't use Graph3d.STYLE here, not defined yet backgroundColor : undefined, dataColor : { fill : '#7DC1FF', stroke : '#3267D2', - strokeWidth: 1 // px + strokeWidth: 1 // px }, cameraPosition : { @@ -154,6 +169,15 @@ function safeCopy(src, dst, fields) { // Class Graph3d // ----------------------------------------------------------------------------- +/** + * Enumerate the available styles. + * + * This definition retained for external compatibility + * (It should be internal, but you never know) + */ +Graph3d.STYLE = STYLE; + + /** * @constructor Graph3d * Graph3d displays data in 3d. @@ -201,8 +225,6 @@ function Graph3d(container, data, options) { this.showLegend = undefined; // auto by default (based on graph style) - this.style = Graph3d.STYLE.DOT; - this.eye = new Point3d(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window? // the column indexes @@ -403,10 +425,10 @@ Graph3d.prototype._setSpecialSettings = function(src, dst) { } this._setDataColor(src.dataColor, dst); + this._setStyle(src.style, dst); this._setCameraPosition(src.cameraPosition, dst); /* TODO - setStyle(src.style, dst); if (src.tooltip !== undefined) { dst.showTooltip = src.tooltip; @@ -416,6 +438,39 @@ End TODO */ } +Graph3d.prototype._setStyle = function(style, dst) { + if (style === undefined) { + return; // Nothing to do + } + + var styleNumber; + + if (typeof style === 'string') { + styleNumber = this._getStyleNumber(style); + + if (styleNumber === -1 ) { + throw new Error('Style \'' + style + '\' is invalid'); + } + } else { + // Do a pedantic check on style number value + var valid = false; + for (var n in STYLE) { + if (STYLE[n] === style) { + valid = true; + break; + } + } + + if (!valid) { + throw new Error('Style \'' + style + '\' is invalid'); + } + + styleNumber = style; + } + + dst.style = styleNumber; +} + /** @@ -521,19 +576,7 @@ Graph3d.prototype.setCameraPosition = function(pos) { // ----------------------------------------------------------------------------- -/// enumerate the available styles -Graph3d.STYLE = { - BAR: 0, - BARCOLOR: 1, - BARSIZE: 2, - DOT : 3, - DOTLINE : 4, - DOTCOLOR: 5, - DOTSIZE: 6, - GRID : 7, - LINE: 8, - SURFACE : 9 -}; + /** * Retrieve the style index from given styleName @@ -686,13 +729,11 @@ Graph3d.prototype._dataInitialize = function (rawData, style) { this.colX = 'x'; this.colY = 'y'; this.colZ = 'z'; - this.colValue = 'style'; - this.colFilter = 'filter'; - - // check if a filter column is provided if (data[0].hasOwnProperty('filter')) { + this.colFilter = 'filter'; // Bugfix: only set this field if it's actually present! + if (this.dataFilter === undefined) { this.dataFilter = new Filter(rawData, this.colFilter, this); this.dataFilter.setOnLoadCallback(function() {me.redraw();}); @@ -750,7 +791,9 @@ Graph3d.prototype._dataInitialize = function (rawData, style) { if (this.zMax <= this.zMin) this.zMax = this.zMin + 1; this.zStep = (this.defaultZStep !== undefined) ? this.defaultZStep : (this.zMax-this.zMin)/5; - if (this.colValue !== undefined) { + // Bugfix: Only handle field 'style' if it's actually present + if (data[0].hasOwnProperty('style')) { + this.colValue = 'style'; var valueRange = this.getColumnRange(data,this.colValue); this.valueMin = (this.defaultValueMin !== undefined) ? this.defaultValueMin : valueRange.min; this.valueMax = (this.defaultValueMax !== undefined) ? this.defaultValueMax : valueRange.max; @@ -850,6 +893,30 @@ Graph3d.prototype._getDataPoints = function (data) { } } else { // 'dot', 'dot-line', etc. + + // Bugfix: ensure value field is present in data if expected + var hasValueField = this.style === Graph3d.STYLE.BARCOLOR + || this.style === Graph3d.STYLE.BARSIZE + || this.style === Graph3d.STYLE.DOTCOLOR + || this.style === Graph3d.STYLE.DOTSIZE; + + if (hasValueField) { + if (this.colValue === undefined) { + throw new Error('Expected data to have ' + + ' field \'style\' ' + + ' for graph style \'' + this.style + '\'' + ); + } + + if (data[0][this.colValue] === undefined) { + throw new Error('Expected data to have ' + + ' field \'' + this.colValue + '\' ' + + ' for graph style \'' + this.style + '\'' + ); + } + } + + // copy all values from the google data table to a list with Point3d objects for (i = 0; i < data.length; i++) { point = new Point3d(); @@ -1077,12 +1144,6 @@ Graph3d.prototype.setOptions = function (options) { // Handle the rest of the parameters if (options.showLegend !== undefined) this.defaultShowLegend = options.showLegend; - if (options.style !== undefined) { - var styleNumber = this._getStyleNumber(options.style); - if (styleNumber !== -1) { - this.style = styleNumber; - } - } if (options.tooltip !== undefined) this.showTooltip = options.tooltip; if (options.xBarWidth !== undefined) this.defaultXBarWidth = options.xBarWidth; diff --git a/lib/graph3d/StepNumber.js b/lib/graph3d/StepNumber.js index 72a73839..9675b4f8 100644 --- a/lib/graph3d/StepNumber.js +++ b/lib/graph3d/StepNumber.js @@ -35,6 +35,17 @@ function StepNumber(start, end, step, prettyStep) { this.setRange(start, end, step, prettyStep); }; + +/** + * Check for input values, to prevent disasters from happening + * + * Source: http://stackoverflow.com/a/1830844 + */ +StepNumber.prototype.isNumeric = function(n) { + return !isNaN(parseFloat(n)) && isFinite(n); +}; + + /** * Set a new range: start, end and step. * @@ -45,6 +56,16 @@ function StepNumber(start, end, step, prettyStep) { * To a pretty step size (like 1, 2, 5, 10, 20, 50, ...) */ StepNumber.prototype.setRange = function(start, end, step, prettyStep) { + if (!this.isNumeric(start)) { + throw new Error('Parameter \'start\' is not numeric; value: ' + start); + } + if (!this.isNumeric(end)) { + throw new Error('Parameter \'end\' is not numeric; value: ' + start); + } + if (!this.isNumeric(step)) { + throw new Error('Parameter \'step\' is not numeric; value: ' + start); + } + this._start = start ? start : 0; this._end = end ? end : 0; From e6351b63bdd8e9dd9db72bfba89fe001c47060bf Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 13:32:31 +0200 Subject: [PATCH 4/6] Adjusted STYLE enum to previous --- lib/graph3d/Graph3d.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 273d6cf8..fbb909cb 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -13,7 +13,7 @@ var StepNumber = require('./StepNumber'); // ----------------------------------------------------------------------------- /// enumerate the available styles -var STYLE = { +Graph3d.STYLE = { BAR : 0, BARCOLOR: 1, BARSIZE : 2, @@ -106,7 +106,7 @@ var DEFAULTS = { // Following not in OPTIONKEYS because they require special handling, - style : STYLE.DOT, // Can't use Graph3d.STYLE here, not defined yet + style : Graph3d.STYLE.DOT, backgroundColor : undefined, dataColor : { @@ -169,14 +169,6 @@ function safeCopy(src, dst, fields) { // Class Graph3d // ----------------------------------------------------------------------------- -/** - * Enumerate the available styles. - * - * This definition retained for external compatibility - * (It should be internal, but you never know) - */ -Graph3d.STYLE = STYLE; - /** * @constructor Graph3d @@ -454,8 +446,8 @@ Graph3d.prototype._setStyle = function(style, dst) { } else { // Do a pedantic check on style number value var valid = false; - for (var n in STYLE) { - if (STYLE[n] === style) { + for (var n in Graph3d.STYLE) { + if (Graph3d.STYLE[n] === style) { valid = true; break; } From 7c9bab862d07d8c223cd65d7b827f47bf62b4fd2 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 17:29:01 +0200 Subject: [PATCH 5/6] Added fields tooltip and showLegend to defaults --- lib/graph3d/Graph3d.js | 55 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index fbb909cb..268395fb 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -107,6 +107,8 @@ var DEFAULTS = { // Following not in OPTIONKEYS because they require special handling, style : Graph3d.STYLE.DOT, + tooltip : false, + showLegend : undefined, // auto by default (based on graph style) backgroundColor : undefined, dataColor : { @@ -203,10 +205,11 @@ function Graph3d(container, data, options) { forceCopy(DEFAULTS, this, OPTIONKEYS); // Following are internal fields, not part of the user settings - this.margin = 10; // px - this.showGrayBottom = false; // TODO: this does not work correctly + this.margin = 10; // px + this.showGrayBottom = false; // TODO: this does not work correctly this.showTooltip = false; - this.dotSizeRatio = 0.02; // size of the dots as a fraction of the graph width + this.dotSizeRatio = 0.02; // size of the dots as a fraction of the graph width + this.eye = new Point3d(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window? // Handle the more complex ('special') fields this._setSpecialSettings(DEFAULTS, this); @@ -215,9 +218,6 @@ function Graph3d(container, data, options) { // These require special attention in some way // TODO: handle these - this.showLegend = undefined; // auto by default (based on graph style) - - this.eye = new Point3d(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window? // the column indexes this.colX = undefined; @@ -418,16 +418,41 @@ Graph3d.prototype._setSpecialSettings = function(src, dst) { this._setDataColor(src.dataColor, dst); this._setStyle(src.style, dst); + this._setShowLegend(src.showLegend, dst); this._setCameraPosition(src.cameraPosition, dst); -/* TODO - + // As special fields go, this is an easy one; just a translation of the name. + // Can't use this.tooltip directly, because that field exists internally if (src.tooltip !== undefined) { dst.showTooltip = src.tooltip; } +}; -End TODO */ -} + +/** + * Set the value of setting 'showLegend' + * + * This depends on the value of the style fields, so it must be called + * after the style field has been initialized. + */ +Graph3d.prototype._setShowLegend = function(showLegend, dst) { + if (showLegend === undefined) { + // If the default was auto, make a choice for this field + var isAutoByDefault = (DEFAULTS.showLegend === undefined); + + if (isAutoByDefault) { + // these styles default to having legends + var isLegendGraphStyle = this.style === Graph3d.STYLE.DOTCOLOR + || this.style === Graph3d.STYLE.DOTSIZE; + + this.showLegend = isLegendGraphStyle; + } else { + // Leave current value as is + } + } else { + dst.showLegend = showLegend; + } +}; Graph3d.prototype._setStyle = function(style, dst) { @@ -461,7 +486,7 @@ Graph3d.prototype._setStyle = function(style, dst) { } dst.style = styleNumber; -} +}; @@ -519,7 +544,7 @@ Graph3d.prototype._setDataColor = function(dataColor, dst) { dst.dataColor.strokeWidth = dataColor.strokeWidth; } } -} +}; Graph3d.prototype._setCameraPosition = function(cameraPosition, dst) { @@ -792,10 +817,6 @@ Graph3d.prototype._dataInitialize = function (rawData, style) { if (this.valueMax <= this.valueMin) this.valueMax = this.valueMin + 1; } - // these styles default to having legends - var isLegendGraphStyle = this.style === Graph3d.STYLE.DOTCOLOR || this.style === Graph3d.STYLE.DOTSIZE; - this.showLegend = (this.defaultShowLegend !== undefined) ? this.defaultShowLegend : isLegendGraphStyle; - // set the scale dependent on the ranges. this._setScale(); }; @@ -1134,8 +1155,6 @@ Graph3d.prototype.setOptions = function (options) { this._setSpecialSettings(options, this); // Handle the rest of the parameters - if (options.showLegend !== undefined) this.defaultShowLegend = options.showLegend; - if (options.tooltip !== undefined) this.showTooltip = options.tooltip; if (options.xBarWidth !== undefined) this.defaultXBarWidth = options.xBarWidth; From ffa2e19e24c4a38680eaee38a8c6693d6695afdd Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 19 Oct 2016 17:53:39 +0200 Subject: [PATCH 6/6] Fixed oversight with showTooltip --- lib/graph3d/Graph3d.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 268395fb..695be17c 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -1155,8 +1155,6 @@ Graph3d.prototype.setOptions = function (options) { this._setSpecialSettings(options, this); // Handle the rest of the parameters - if (options.tooltip !== undefined) this.showTooltip = options.tooltip; - if (options.xBarWidth !== undefined) this.defaultXBarWidth = options.xBarWidth; if (options.yBarWidth !== undefined) this.defaultYBarWidth = options.yBarWidth; if (options.xMin !== undefined) this.defaultXMin = options.xMin;