Browse Source

Added fields tooltip and showLegend to defaults

codeClimate
Wim Rijnders 8 years ago
parent
commit
7c9bab862d
1 changed files with 37 additions and 18 deletions
  1. +37
    -18
      lib/graph3d/Graph3d.js

+ 37
- 18
lib/graph3d/Graph3d.js View File

@ -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;

Loading…
Cancel
Save