Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ node_js:
- '0.11'
env:
global:
- secure: G+VyUjYXpYO3djiUL62Vj/0PuQmWpHyyXZtKXW+Df77C45Uc+/G0DQL/YGn4tqc4DeAX5W5myTmfAm2q+B1fkg687HFH5HBHp3/RhY++KcitnLZ+8DlvBCIMuvUjgYdq1+pWr+kXg0OCybyyecqdXgRZ3FNTpatf6PIXC5a8PFA=
- secure: boiNPr9oRstsVXgXKqs/XfgWPJDNQYCkGjJ8tnZmGF2SVTCK5fOmwycbDpRk1oAzjwHc6pXoiLvqgRySFBoebpz8rIWEbjmxp06+9sN9bw51Za0RPCM2g+4XEg2yU/bzmEj3ZyI/ZEEpm5AOcxhGSyjyQjWiK8sefUB6WV8YkcI=
- secure: CvvR0KZBaTnVfo3ylWPc/qssKzkay5rejVoHWjR7DrIHaesj3O17puOAr+jYJJ220Q4mn2RwpdTIyYAjjSxblq5g+F/MJMwslRh7mEYfdn39LnF30JYp6BkMrcygsJS8xAQ18i17lVMqqeMyJ/+Hu7GvWu1r6ZaWkr2HZ/P26v4=
- secure: gT/SPMZhtp3dNjS9VIKez/+sKzihE/5ffNtKczhTi71CQkvptgd9xdcLigidIgwaWptd3t8HwNFaUutx78xTIb40oP0mZNo95LiwoI6W7vzLyJjst2BVKz+hqj4Jg1P8FHkD5/fop4E/pL4lXmMB1p1Zd5QEebX6hcXgFz/ha7U=
matrix:
- 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
36 changes: 25 additions & 11 deletions jquery.highchartTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 19 additions & 3 deletions tests/baseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ describe("Base test", function() {
' </tbody>' +
' </table>';

$('#fixture').remove();
$('body').append(htmlContent);
$('body')
.empty()
.append(htmlContent)
;
});


Expand All @@ -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()
;
Expand Down
155 changes: 155 additions & 0 deletions tests/yaxisAttributesSpec.js
Original file line number Diff line number Diff line change
@@ -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 = ' <table class="highchart" data-graph-container-before="1" data-graph-type="column" style="display:block"' +
' data-graph-yaxis-1-reversed="1" data-graph-yaxis-1-stacklabels-enabled="1" ' +
' data-graph-yaxis-1-min="1000" data-graph-yaxis-1-max="25000" ' +
' data-graph-yaxis-1-title-text="title example" ' +
' data-graph-yaxis-1-opposite="1" ' +
' data-graph-yaxis-1-tick-interval="1000" ' +
' data-graph-yaxis-1-rotation="90" ' +
' data-graph-yaxis-1-grid-line-interpolation="circle" ' +
' data-graph-yaxis-1-start-on-tick="0" ' +
' data-graph-yaxis-1-end-on-tick="0" ' +
' data-graph-yaxis-1-formatter-callback="graph_absInvertedFormatter" ' +
'>' +
'<caption>Example of title</caption>' +
'<thead>' +
' <tr>' +
' <th>Month</th>' +
' <th>Sales</th>' +
' </tr>' +
' </thead>' +
' <tbody>' +
' <tr>' +
' <td>January</td>' +
' <td>8000</td>' +
' </tr>' +
' <tr>' +
' <td>February</td>' +
' <td>12000</td>' +
' </tr>' +
' <tr>' +
' <td>March</td>' +
' <td>18000</td>' +
' </tr>' +
' </tbody>' +
' </table>';

$('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 = ' <table class="highchart" data-graph-container-before="1" data-graph-type="column" style="display:block"' +
' data-graph-yaxis1-reversed="1" data-graph-yaxis1-stacklabels-enabled="1" ' +
' data-graph-yaxis1-min="1000" data-graph-yaxis1-max="25000" ' +
' data-graph-yaxis1-title-text="title example" ' +
' data-graph-yaxis1-opposite="1" ' +
' data-graph-yaxis1-tick-interval="1000" ' +
' data-graph-yaxis1-rotation="90" ' +
' data-graph-yaxis1-grid-line-interpolation="circle" ' +
' data-graph-yaxis1-start-on-tick="0" ' +
' data-graph-yaxis1-end-on-tick="0" ' +
' data-graph-yaxis1-formatter-callback="graph_absInvertedFormatter" ' +
'>' +
'<caption>Example of title</caption>' +
'<thead>' +
' <tr>' +
' <th>Month</th>' +
' <th>Sales</th>' +
' </tr>' +
' </thead>' +
' <tbody>' +
' <tr>' +
' <td>January</td>' +
' <td>8000</td>' +
' </tr>' +
' <tr>' +
' <td>February</td>' +
' <td>12000</td>' +
' </tr>' +
' <tr>' +
' <td>March</td>' +
' <td>18000</td>' +
' </tr>' +
' </tbody>' +
' </table>';

$('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);
});
});