Browse Source

Fixes after testing

codeClimate
Wim Rijnders 8 years ago
parent
commit
13752ed435
1 changed files with 28 additions and 26 deletions
  1. +28
    -26
      lib/graph3d/Graph3d.js

+ 28
- 26
lib/graph3d/Graph3d.js View File

@ -208,17 +208,17 @@ Graph3d.prototype._convertPointToTranslation = function(point3d) {
ay = point3d.y * this.scale.y, ay = point3d.y * this.scale.y,
az = point3d.z * this.scale.z, az = point3d.z * this.scale.z,
cx = CameraLocation.x,
cy = CameraLocation.y,
cz = CameraLocation.z,
cx = cameraLocation.x,
cy = cameraLocation.y,
cz = cameraLocation.z,
// calculate angles // calculate angles
sinTx = Math.sin(CameraRotation.x),
cosTx = Math.cos(CameraRotation.x),
sinTy = Math.sin(CameraRotation.y),
cosTy = Math.cos(CameraRotation.y),
sinTz = Math.sin(CameraRotation.z),
cosTz = Math.cos(CameraRotation.z),
sinTx = Math.sin(cameraRotation.x),
cosTx = Math.cos(cameraRotation.x),
sinTy = Math.sin(cameraRotation.y),
cosTy = Math.cos(cameraRotation.y),
sinTz = Math.sin(cameraRotation.z),
cosTz = Math.cos(cameraRotation.z),
// calculate translation // calculate translation
dx = cosTy * (sinTz * (ay - cy) + cosTz * (ax - cx)) - sinTy * (az - cz), dx = cosTy * (sinTz * (ay - cy) + cosTz * (ax - cx)) - sinTy * (az - cz),
@ -979,6 +979,8 @@ Graph3d.prototype._redrawLegend = function() {
step.start(true); step.start(true);
var y; var y;
var from;
var to;
while (!step.end()) { while (!step.end()) {
y = bottom - (step.getCurrent() - legendMin) / (legendMax - legendMin) * height; y = bottom - (step.getCurrent() - legendMin) / (legendMax - legendMin) * height;
from = new Point2d(left - gridLineLen, y); from = new Point2d(left - gridLineLen, y);
@ -1362,6 +1364,21 @@ Graph3d.prototype._hsv2rgb = function(H, S, V) {
}; };
Graph3d.prototype._drawGridLine = function(ctx, from, to) {
if (from === undefined || to === undefined) {
return;
}
// calculate Hue from the current value. At zMin the hue is 240, at zMax the hue is 0
var zAvg = (from.point.z + to.point.z) / 2;
var h = (1 - (zAvg - this.zMin) * this.scale.z / this.verticalRatio) * 240;
ctx.lineWidth = this._getStrokeWidth(from) * 2;
ctx.strokeStyle = this._hsv2rgb(h, 1, 1);
this._line(ctx, from.screen, to.screen);
};
/** /**
* Draw all datapoints as a grid * Draw all datapoints as a grid
* This function can be used when the style is 'grid' * This function can be used when the style is 'grid'
@ -1444,25 +1461,10 @@ Graph3d.prototype._redrawDataGrid = function() {
} }
} }
else { // grid style else { // grid style
var drawGridLine = function(ctx, from, to) {
if (from === undefined || to === undefined) {
return;
}
// calculate Hue from the current value. At zMin the hue is 240, at zMax the hue is 0
zAvg = (from.point.z + to.point.z) / 2;
h = (1 - (zAvg - this.zMin) * this.scale.z / this.verticalRatio) * 240;
ctx.lineWidth = this._getStrokeWidth(from) * 2;
ctx.strokeStyle = this._hsv2rgb(h, 1, 1);
this._line(ctx, from.screen, to.screen);
};
for (i = 0; i < this.dataPoints.length; i++) { for (i = 0; i < this.dataPoints.length; i++) {
point = this.dataPoints[i]; point = this.dataPoints[i];
drawGridLine(ctx, point, point.pointRight);
drawGridLine(ctx, point, point.pointTop);
this._drawGridLine(ctx, point, point.pointRight);
this._drawGridLine(ctx, point, point.pointTop);
} }
} }
}; };

Loading…
Cancel
Save