diff --git a/.travis.yml b/.travis.yml index 765671d..cc4105b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ node_js: - '0.11' env: - JQUERY_VERSION=1.11.3 HIGHCHARTS_VERSION=2.2.4 - - JQUERY_VERSION=1.11.1 HIGHCHARTS_VERSION=2.2.4 + - JQUERY_VERSION=2.1.4 HIGHCHARTS_VERSION=2.2.4 diff --git a/jquery.highchartTable.js b/jquery.highchartTable.js index 3c03126..3f07b25 100644 --- a/jquery.highchartTable.js +++ b/jquery.highchartTable.js @@ -265,30 +265,44 @@ }); + var getYaxisAttr = function($table, yAxisNum, name) { + var oldConvention = $table.data('graph-yaxis-' + yAxisNum + '-' + name); + if (typeof oldConvention != 'undefined') { + return oldConvention; + } + + return $table.data('graph-yaxis' + yAxisNum + '-' + name); + }; + var yAxisConfig = []; var yAxisNum; for (yAxisNum=1 ; yAxisNum <= nbYaxis ; yAxisNum++) { var yAxisConfigCurrentAxis = { title: { - text: typeof $table.data('graph-yaxis-'+yAxisNum+'-title-text') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-title-text') : null + text: typeof getYaxisAttr($table, yAxisNum, 'title-text') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'title-text') : null }, - max: typeof $table.data('graph-yaxis-'+yAxisNum+'-max') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-max') : null, - min: typeof $table.data('graph-yaxis-'+yAxisNum+'-min') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-min') : null, - reversed: $table.data('graph-yaxis-'+yAxisNum+'-reversed') == '1', - opposite: $table.data('graph-yaxis-'+yAxisNum+'-opposite') == '1', - tickInterval: $table.data('graph-yaxis-'+yAxisNum+'-tick-interval') || null, + max: typeof getYaxisAttr($table, yAxisNum, 'max') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'max') : null, + min: typeof getYaxisAttr($table, yAxisNum, 'min') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'min') : null, + reversed: getYaxisAttr($table, yAxisNum, 'reversed') == '1', + opposite: getYaxisAttr($table, yAxisNum, 'opposite') == '1', + tickInterval: getYaxisAttr($table, yAxisNum, 'tick-interval') || null, labels: { - rotation: $table.data('graph-yaxis-'+yAxisNum+'-rotation') || 0 + rotation: getYaxisAttr($table, yAxisNum, 'rotation') || 0 }, - startOnTick: $table.data('graph-yaxis-'+yAxisNum+'-start-on-tick') !== "0", - endOnTick: $table.data('graph-yaxis-'+yAxisNum+'-end-on-tick') !== "0", + startOnTick: getYaxisAttr($table, yAxisNum, 'start-on-tick') != "0", + endOnTick: getYaxisAttr($table, yAxisNum, 'end-on-tick') != "0", stackLabels : { - enabled: $table.data('graph-yaxis-'+yAxisNum+'-stacklabels-enabled') == '1' + enabled: getYaxisAttr($table, yAxisNum, 'stacklabels-enabled') == '1' }, - gridLineInterpolation: $table.data('graph-yaxis-'+yAxisNum+'-grid-line-interpolation') || null + gridLineInterpolation: getYaxisAttr($table, yAxisNum, 'grid-line-interpolation') || null }; var callableYAxisFormatter = getCallable(table, 'graph-yaxis-'+yAxisNum+'-formatter-callback'); + + if (!callableYAxisFormatter) { + callableYAxisFormatter = getCallable(table, 'graph-yaxis'+yAxisNum+'-formatter-callback'); + } + if (callableYAxisFormatter) { yAxisConfigCurrentAxis.labels.formatter = function () { return callableYAxisFormatter(this.value); diff --git a/tests/baseSpec.js b/tests/baseSpec.js index dc50b39..235be60 100644 --- a/tests/baseSpec.js +++ b/tests/baseSpec.js @@ -29,8 +29,10 @@ describe("Base test", function() { ' ' + ' '; - $('#fixture').remove(); - $('body').append(htmlContent); + $('body') + .empty() + .append(htmlContent) + ; }); @@ -48,7 +50,21 @@ describe("Base test", function() { expect(highChartConfig.series[0].data[1].name).toBe('12000'); expect(highChartConfig.series[0].data[1].y).toBe(12000); expect(highChartConfig.series[0].data[2].name).toBe('18000'); - expect(highChartConfig.series[0].data[2].y).toBe(18000); + expect(highChartConfig.series[0].data[2].y).toBe(18000) + expect(highChartConfig.yAxis[0].reversed).toBe(false); + + expect(highChartConfig.yAxis[0].reversed).toBe(false); + expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(false); + expect(highChartConfig.yAxis[0].min).toBeNull(); + expect(highChartConfig.yAxis[0].max).toBeNull(); + expect(highChartConfig.yAxis[0].title.text).toBeNull(); + expect(highChartConfig.yAxis[0].opposite).toBe(false); + expect(highChartConfig.yAxis[0].tickInterval).toBe(null); + expect(highChartConfig.yAxis[0].labels.rotation).toBe(0); + expect(highChartConfig.yAxis[0].gridLineInterpolation).toBeNull(); + expect(highChartConfig.yAxis[0].startOnTick).toBe(true); + expect(highChartConfig.yAxis[0].endOnTick).toBe(true); + expect(highChartConfig.yAxis[0].labels.formatter).toBeUndefined(); }) .highchartTable() ; diff --git a/tests/yaxisAttributesSpec.js b/tests/yaxisAttributesSpec.js new file mode 100644 index 0000000..98e3035 --- /dev/null +++ b/tests/yaxisAttributesSpec.js @@ -0,0 +1,155 @@ + +describe("Test yaxis ttributes", function() { + + var fixture; + + it("With numeric", function() { + + if ($.fn.jquery.substr(0, 1) == 2) { + return; + } + + graph_absInvertedFormatter = function (value) { + return Math.abs(value) * -1; + }; + + var htmlContent = ' ' + + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + '
Example of title
MonthSales
January8000
February12000
March18000
'; + + $('body') + .empty() + .append(htmlContent) + ; + + var beforeRenderCalled = false; + + $('table') + .bind('highchartTable.beforeRender', function(event, highChartConfig) { + beforeRenderCalled = true; + expect(highChartConfig.yAxis[0].reversed).toBe(true); + expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(true); + expect(highChartConfig.yAxis[0].min).toBe(1000); + expect(highChartConfig.yAxis[0].max).toBe(25000); + expect(highChartConfig.yAxis[0].title.text).toBe("title example"); + expect(highChartConfig.yAxis[0].opposite).toBe(true); + expect(highChartConfig.yAxis[0].tickInterval).toBe(1000); + expect(highChartConfig.yAxis[0].labels.rotation).toBe(90); + expect(highChartConfig.yAxis[0].gridLineInterpolation).toBe("circle"); + expect(highChartConfig.yAxis[0].startOnTick).toBe(false); + expect(highChartConfig.yAxis[0].endOnTick).toBe(false); + expect(highChartConfig.yAxis[0].labels.formatter).toBeDefined(); + + }) + .highchartTable() + ; + + expect(beforeRenderCalled).toBe(true); + }); + + + it("Without numeric", function() { + + graph_absInvertedFormatter = function (value) { + return Math.abs(value) * -1; + }; + + var htmlContent = ' ' + + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + '
Example of title
MonthSales
January8000
February12000
March18000
'; + + $('body') + .empty() + .append(htmlContent) + ; + + + + var beforeRenderCalled = false; + + $('table') + .bind('highchartTable.beforeRender', function(event, highChartConfig) { + beforeRenderCalled = true; + expect(highChartConfig.yAxis[0].reversed).toBe(true); + expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(true); + expect(highChartConfig.yAxis[0].min).toBe(1000); + expect(highChartConfig.yAxis[0].max).toBe(25000); + expect(highChartConfig.yAxis[0].title.text).toBe("title example"); + expect(highChartConfig.yAxis[0].opposite).toBe(true); + expect(highChartConfig.yAxis[0].tickInterval).toBe(1000); + expect(highChartConfig.yAxis[0].labels.rotation).toBe(90); + expect(highChartConfig.yAxis[0].gridLineInterpolation).toBe("circle"); + expect(highChartConfig.yAxis[0].startOnTick).toBe(false); + expect(highChartConfig.yAxis[0].endOnTick).toBe(false); + expect(highChartConfig.yAxis[0].labels.formatter).toBeDefined(); + }) + .highchartTable() + ; + + expect(beforeRenderCalled).toBe(true); + }); +}); + +