From 81316cd7ea2c0ad1e4b094a93a3c9e490f075648 Mon Sep 17 00:00:00 2001 From: David Heppell Date: Sat, 17 Feb 2018 17:03:43 +1100 Subject: [PATCH] #2251 squashed for merge cleared unused commented test case and cleared up spelling errors. #2251 fixed testcase and somehow removed return statement. #2251 x-axis tick format is no longer truncated for negative values. #2251 x-axis tick format is no longer truncated for negative values. --- spec/axis-spec.js | 19 +++++++++++++++++++ src/axis.js | 11 +++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/axis-spec.js b/spec/axis-spec.js index 1904c97..520cc4e 100644 --- a/spec/axis-spec.js +++ b/spec/axis-spec.js @@ -153,6 +153,25 @@ describe('c3 chart axis', function () { }); describe('axis.x.tick.values', function () { + describe('formatted correctly when negative', function() { + var xValues = [-3.3, -2.2, -1.1, 1.1, 2.2, 3.3]; + beforeEach(function() { + args.data = { + x: 'x', + columns: [ + ['x'].concat(xValues), + ['data1', 30, 200, 100, 400, 150, 250], + ] + }; + }); + + it ('should not generate whole number for negative values', function() { + var tickValues = []; + d3.select('.c3-axis-x').selectAll('g.tick').selectAll('tspan').each(function(d, i) { expect(tickValues.push(parseFloat(d.splitted)) === xValues[i]); }); + + }); + }); + describe('function is provided', function () { var tickGenerator = function () { var values = []; diff --git a/src/axis.js b/src/axis.js index 8405237..ea7d6aa 100644 --- a/src/axis.js +++ b/src/axis.js @@ -475,8 +475,15 @@ c3_axis_fn.getId = function getId(id) { return id in config.data_axes ? config.data_axes[id] : 'y'; }; c3_axis_fn.getXAxisTickFormat = function getXAxisTickFormat() { - var $$ = this.owner, config = $$.config, - format = $$.isTimeSeries() ? $$.defaultAxisTimeFormat : $$.isCategorized() ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + // #2251 previously set any negative values to a whole number, + // however both should be truncated according to the users format specification + var $$ = this.owner, config = $$.config; + let format = ($$.isTimeSeries()) + ? $$.defaultAxisTimeFormat + : ($$.isCategorized()) + ? $$.categoryName + : function (v) { return v; }; + if (config.axis_x_tick_format) { if (isFunction(config.axis_x_tick_format)) { format = config.axis_x_tick_format;