From 47e3d25dce77a2f6f1b7d35c8c0830e2c7da5f97 Mon Sep 17 00:00:00 2001 From: fabriziofortino Date: Sun, 28 Sep 2014 18:01:06 +0100 Subject: [PATCH] graph3d: added custom ticks label support for z axis --- examples/graph3d/example12_ticks.html | 6 +++++- lib/graph3d/Graph3d.js | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/graph3d/example12_ticks.html b/examples/graph3d/example12_ticks.html index 98f6e9d6..0d4c4cdb 100644 --- a/examples/graph3d/example12_ticks.html +++ b/examples/graph3d/example12_ticks.html @@ -14,7 +14,7 @@ var graph = null; function custom(x, y) { - return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10); + return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10) * 1000; } // Called when the Visualization API is loaded. @@ -66,6 +66,10 @@ return value * 10 + '%'; }, + zValueLabel: function(value) { + return value / 1000 + 'K'; + }, + keepAspectRatio: true, verticalRatio: 0.5 }; diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 912a9c66..9031aeaf 100644 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -37,8 +37,10 @@ function Graph3d(container, data, options) { this.yLabel = 'y'; this.zLabel = 'z'; - this.xValueLabel = function(v) { return v; }; - this.yValueLabel = function(v) { return v; }; + var passValueFn = function(v) { return v; }; + this.xValueLabel = passValueFn; + this.yValueLabel = passValueFn; + this.zValueLabel = passValueFn; this.filterLabel = 'time'; this.legendLabel = 'value'; @@ -835,6 +837,7 @@ Graph3d.prototype.setOptions = function (options) { if (options.xValueLabel !== undefined) this.xValueLabel = options.xValueLabel; if (options.yValueLabel !== undefined) this.yValueLabel = options.yValueLabel; + if (options.zValueLabel !== undefined) this.zValueLabel = options.zValueLabel; if (options.style !== undefined) { var styleNumber = this._getStyleNumber(options.style); @@ -1270,7 +1273,7 @@ Graph3d.prototype._redrawAxis = function() { ctx.textAlign = 'right'; ctx.textBaseline = 'middle'; ctx.fillStyle = this.colorAxis; - ctx.fillText(step.getCurrent() + ' ', from.x - 5, from.y); + ctx.fillText(this.zValueLabel(step.getCurrent()) + ' ', from.x - 5, from.y); step.next(); }