From 3eb3d7db139f61cb637ec4f8b54ee79fb5e21da3 Mon Sep 17 00:00:00 2001 From: Alexander Kryklia Date: Tue, 18 Dec 2012 18:11:19 +0200 Subject: [PATCH] units implemented --- .../js/src/graphical_slider_tool/graph.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js b/common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js index 28edf873c7..452f6ecb92 100644 --- a/common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js +++ b/common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js @@ -63,7 +63,7 @@ define('Graph', ['logme'], function (logme) { 'max': 10 }; if (typeof config.plot['xticks'] === 'string') { - processTicks(config.plot['xticks'], xaxis); + processTicks(config.plot['xticks'], xaxis, 'xunits'); } else { logme('MESSAGE: "xticks" were not specified. Using defaults.'); } @@ -76,14 +76,14 @@ define('Graph', ['logme'], function (logme) { 'max': 10 }; if (typeof config.plot['yticks'] === 'string') { - processTicks(config.plot['yticks'], yaxis); + processTicks(config.plot['yticks'], yaxis, 'yunits'); } else { logme('MESSAGE: "yticks" were not specified. Using defaults.'); } return; - function processTicks(ticksStr, ticksObj) { + function processTicks(ticksStr, ticksObj, unitsType) { var ticksBlobs, tempFloat; // The 'ticks' setting is a string containing 3 floating-point @@ -134,6 +134,17 @@ define('Graph', ['logme'], function (logme) { ticksObj.tickSize = (ticksObj.max - ticksObj.min) / 10.0; } + + // units: change last tick to units + if (typeof config.plot[unitsType] === 'string') { + var ticks = _.map(_.range(ticksObj.min, + ticksObj.max + ticksObj.tickSize, ticksObj.tickSize), + function(x){ return [x, + x > ticksObj.max - ticksObj.tickSize ? config.plot[unitsType] : x]; + }); + ticksObj.tickSize = null; + ticksObj.ticks = ticks; + } } }