Browse Source

Added handling of settings for camera

codeClimate
Wim Rijnders 8 years ago
parent
commit
f3e5643119
1 changed files with 50 additions and 44 deletions
  1. +50
    -44
      lib/graph3d/Graph3d.js

+ 50
- 44
lib/graph3d/Graph3d.js View File

@ -98,6 +98,12 @@ var DEFAULTS = {
fill : '#7DC1FF', fill : '#7DC1FF',
stroke : '#3267D2', stroke : '#3267D2',
strokeWidth: 1 // px 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.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? this.eye = new Point3d(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window?
// the column indexes // the column indexes
@ -396,12 +398,12 @@ Graph3d.prototype._calcTranslations = function(points, sort) {
* 'Special' here means: setting requires more than a simple copy * 'Special' here means: setting requires more than a simple copy
*/ */
Graph3d.prototype._setSpecialSettings = function(src, dst) { Graph3d.prototype._setSpecialSettings = function(src, dst) {
if (src.backgroundColor !== undefined) { if (src.backgroundColor !== undefined) {
this._setBackgroundColor(src.backgroundColor, dst); this._setBackgroundColor(src.backgroundColor, dst);
} }
this._setDataColor(src.dataColor, dst); this._setDataColor(src.dataColor, dst);
this._setCameraPosition(src.cameraPosition, dst);
/* TODO /* TODO
setStyle(src.style, dst); setStyle(src.style, dst);
@ -410,11 +412,12 @@ Graph3d.prototype._setSpecialSettings = function(src, dst) {
dst.showTooltip = src.tooltip; dst.showTooltip = src.tooltip;
} }
setCameraPosition(src.cameraPosition, dst);
End TODO */ End TODO */
} }
/** /**
* Set the background styling for the graph * Set the background styling for the graph
* @param {string | {fill: string, stroke: string, strokeWidth: string}} backgroundColor * @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 // 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.zMax !== undefined) this.defaultZMax = options.zMax;
if (options.valueMin !== undefined) this.defaultValueMin = options.valueMin; if (options.valueMin !== undefined) this.defaultValueMin = options.valueMin;
if (options.valueMax !== undefined) this.defaultValueMax = options.valueMax; 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); this.setSize(this.width, this.height);

Loading…
Cancel
Save