From 47e3d25dce77a2f6f1b7d35c8c0830e2c7da5f97 Mon Sep 17 00:00:00 2001 From: fabriziofortino Date: Sun, 28 Sep 2014 18:01:06 +0100 Subject: [PATCH 1/2] 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(); } From 448cd64ebbf75f5ef54ca63888334a0b3b1dcc8b Mon Sep 17 00:00:00 2001 From: fabriziofortino Date: Sun, 28 Sep 2014 18:06:51 +0100 Subject: [PATCH 2/2] updated history and docs --- HISTORY.md | 4 ++-- docs/graph3d.html | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 4c6dc6ae..0e7c11ed 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -26,8 +26,8 @@ http://visjs.org ### Graph3d -- Implemented options `xValueLabel` and `yValueLabel` for custom labels along - the x and y axis. Thanks @fabriziofortino. +- Implemented options `xValueLabel`, `yValueLabel` and `zValueLabel` for custom labels along + the x, y, z axis. Thanks @fabriziofortino. ## 2014-09-16, version 3.5.0 diff --git a/docs/graph3d.html b/docs/graph3d.html index 9e774a4b..8a81c25a 100644 --- a/docs/graph3d.html +++ b/docs/graph3d.html @@ -489,6 +489,14 @@ var options = { none Step size for the grid on the z-axis. + + zValueLabel + function + none + A function for custom formatting of the labels along the z-axis, + for example function (z) {return (z * 100) + '%'}. + + xLabel