Skip to content

Commit 535ebb2

Browse files
committed
Merge pull request #75 from agallou/yaxis_jquery2
fix yaxis attributes on jquery2
2 parents 1f794d9 + 36f1f78 commit 535ebb2

File tree

4 files changed

+202
-17
lines changed

4 files changed

+202
-17
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ node_js:
33
- '0.11'
44
env:
55
global:
6-
- secure: G+VyUjYXpYO3djiUL62Vj/0PuQmWpHyyXZtKXW+Df77C45Uc+/G0DQL/YGn4tqc4DeAX5W5myTmfAm2q+B1fkg687HFH5HBHp3/RhY++KcitnLZ+8DlvBCIMuvUjgYdq1+pWr+kXg0OCybyyecqdXgRZ3FNTpatf6PIXC5a8PFA=
7-
- secure: boiNPr9oRstsVXgXKqs/XfgWPJDNQYCkGjJ8tnZmGF2SVTCK5fOmwycbDpRk1oAzjwHc6pXoiLvqgRySFBoebpz8rIWEbjmxp06+9sN9bw51Za0RPCM2g+4XEg2yU/bzmEj3ZyI/ZEEpm5AOcxhGSyjyQjWiK8sefUB6WV8YkcI=
6+
- secure: CvvR0KZBaTnVfo3ylWPc/qssKzkay5rejVoHWjR7DrIHaesj3O17puOAr+jYJJ220Q4mn2RwpdTIyYAjjSxblq5g+F/MJMwslRh7mEYfdn39LnF30JYp6BkMrcygsJS8xAQ18i17lVMqqeMyJ/+Hu7GvWu1r6ZaWkr2HZ/P26v4=
7+
- secure: gT/SPMZhtp3dNjS9VIKez/+sKzihE/5ffNtKczhTi71CQkvptgd9xdcLigidIgwaWptd3t8HwNFaUutx78xTIb40oP0mZNo95LiwoI6W7vzLyJjst2BVKz+hqj4Jg1P8FHkD5/fop4E/pL4lXmMB1p1Zd5QEebX6hcXgFz/ha7U=
88
matrix:
99
- JQUERY_VERSION=1.11.3 HIGHCHARTS_VERSION=2.2.4
10-
- JQUERY_VERSION=1.11.1 HIGHCHARTS_VERSION=2.2.4
10+
- JQUERY_VERSION=2.1.4 HIGHCHARTS_VERSION=2.2.4

jquery.highchartTable.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,30 +265,44 @@
265265

266266
});
267267

268+
var getYaxisAttr = function($table, yAxisNum, name) {
269+
var oldConvention = $table.data('graph-yaxis-' + yAxisNum + '-' + name);
270+
if (typeof oldConvention != 'undefined') {
271+
return oldConvention;
272+
}
273+
274+
return $table.data('graph-yaxis' + yAxisNum + '-' + name);
275+
};
276+
268277
var yAxisConfig = [];
269278
var yAxisNum;
270279
for (yAxisNum=1 ; yAxisNum <= nbYaxis ; yAxisNum++) {
271280
var yAxisConfigCurrentAxis = {
272281
title: {
273-
text: typeof $table.data('graph-yaxis-'+yAxisNum+'-title-text') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-title-text') : null
282+
text: typeof getYaxisAttr($table, yAxisNum, 'title-text') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'title-text') : null
274283
},
275-
max: typeof $table.data('graph-yaxis-'+yAxisNum+'-max') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-max') : null,
276-
min: typeof $table.data('graph-yaxis-'+yAxisNum+'-min') != 'undefined' ? $table.data('graph-yaxis-'+yAxisNum+'-min') : null,
277-
reversed: $table.data('graph-yaxis-'+yAxisNum+'-reversed') == '1',
278-
opposite: $table.data('graph-yaxis-'+yAxisNum+'-opposite') == '1',
279-
tickInterval: $table.data('graph-yaxis-'+yAxisNum+'-tick-interval') || null,
284+
max: typeof getYaxisAttr($table, yAxisNum, 'max') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'max') : null,
285+
min: typeof getYaxisAttr($table, yAxisNum, 'min') != 'undefined' ? getYaxisAttr($table, yAxisNum, 'min') : null,
286+
reversed: getYaxisAttr($table, yAxisNum, 'reversed') == '1',
287+
opposite: getYaxisAttr($table, yAxisNum, 'opposite') == '1',
288+
tickInterval: getYaxisAttr($table, yAxisNum, 'tick-interval') || null,
280289
labels: {
281-
rotation: $table.data('graph-yaxis-'+yAxisNum+'-rotation') || 0
290+
rotation: getYaxisAttr($table, yAxisNum, 'rotation') || 0
282291
},
283-
startOnTick: $table.data('graph-yaxis-'+yAxisNum+'-start-on-tick') !== "0",
284-
endOnTick: $table.data('graph-yaxis-'+yAxisNum+'-end-on-tick') !== "0",
292+
startOnTick: getYaxisAttr($table, yAxisNum, 'start-on-tick') != "0",
293+
endOnTick: getYaxisAttr($table, yAxisNum, 'end-on-tick') != "0",
285294
stackLabels : {
286-
enabled: $table.data('graph-yaxis-'+yAxisNum+'-stacklabels-enabled') == '1'
295+
enabled: getYaxisAttr($table, yAxisNum, 'stacklabels-enabled') == '1'
287296
},
288-
gridLineInterpolation: $table.data('graph-yaxis-'+yAxisNum+'-grid-line-interpolation') || null
297+
gridLineInterpolation: getYaxisAttr($table, yAxisNum, 'grid-line-interpolation') || null
289298
};
290299

291300
var callableYAxisFormatter = getCallable(table, 'graph-yaxis-'+yAxisNum+'-formatter-callback');
301+
302+
if (!callableYAxisFormatter) {
303+
callableYAxisFormatter = getCallable(table, 'graph-yaxis'+yAxisNum+'-formatter-callback');
304+
}
305+
292306
if (callableYAxisFormatter) {
293307
yAxisConfigCurrentAxis.labels.formatter = function () {
294308
return callableYAxisFormatter(this.value);

tests/baseSpec.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ describe("Base test", function() {
2929
' </tbody>' +
3030
' </table>';
3131

32-
$('#fixture').remove();
33-
$('body').append(htmlContent);
32+
$('body')
33+
.empty()
34+
.append(htmlContent)
35+
;
3436
});
3537

3638

@@ -48,7 +50,21 @@ describe("Base test", function() {
4850
expect(highChartConfig.series[0].data[1].name).toBe('12000');
4951
expect(highChartConfig.series[0].data[1].y).toBe(12000);
5052
expect(highChartConfig.series[0].data[2].name).toBe('18000');
51-
expect(highChartConfig.series[0].data[2].y).toBe(18000);
53+
expect(highChartConfig.series[0].data[2].y).toBe(18000)
54+
expect(highChartConfig.yAxis[0].reversed).toBe(false);
55+
56+
expect(highChartConfig.yAxis[0].reversed).toBe(false);
57+
expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(false);
58+
expect(highChartConfig.yAxis[0].min).toBeNull();
59+
expect(highChartConfig.yAxis[0].max).toBeNull();
60+
expect(highChartConfig.yAxis[0].title.text).toBeNull();
61+
expect(highChartConfig.yAxis[0].opposite).toBe(false);
62+
expect(highChartConfig.yAxis[0].tickInterval).toBe(null);
63+
expect(highChartConfig.yAxis[0].labels.rotation).toBe(0);
64+
expect(highChartConfig.yAxis[0].gridLineInterpolation).toBeNull();
65+
expect(highChartConfig.yAxis[0].startOnTick).toBe(true);
66+
expect(highChartConfig.yAxis[0].endOnTick).toBe(true);
67+
expect(highChartConfig.yAxis[0].labels.formatter).toBeUndefined();
5268
})
5369
.highchartTable()
5470
;

tests/yaxisAttributesSpec.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
2+
describe("Test yaxis ttributes", function() {
3+
4+
var fixture;
5+
6+
it("With numeric", function() {
7+
8+
if ($.fn.jquery.substr(0, 1) == 2) {
9+
return;
10+
}
11+
12+
graph_absInvertedFormatter = function (value) {
13+
return Math.abs(value) * -1;
14+
};
15+
16+
var htmlContent = ' <table class="highchart" data-graph-container-before="1" data-graph-type="column" style="display:block"' +
17+
' data-graph-yaxis-1-reversed="1" data-graph-yaxis-1-stacklabels-enabled="1" ' +
18+
' data-graph-yaxis-1-min="1000" data-graph-yaxis-1-max="25000" ' +
19+
' data-graph-yaxis-1-title-text="title example" ' +
20+
' data-graph-yaxis-1-opposite="1" ' +
21+
' data-graph-yaxis-1-tick-interval="1000" ' +
22+
' data-graph-yaxis-1-rotation="90" ' +
23+
' data-graph-yaxis-1-grid-line-interpolation="circle" ' +
24+
' data-graph-yaxis-1-start-on-tick="0" ' +
25+
' data-graph-yaxis-1-end-on-tick="0" ' +
26+
' data-graph-yaxis-1-formatter-callback="graph_absInvertedFormatter" ' +
27+
'>' +
28+
'<caption>Example of title</caption>' +
29+
'<thead>' +
30+
' <tr>' +
31+
' <th>Month</th>' +
32+
' <th>Sales</th>' +
33+
' </tr>' +
34+
' </thead>' +
35+
' <tbody>' +
36+
' <tr>' +
37+
' <td>January</td>' +
38+
' <td>8000</td>' +
39+
' </tr>' +
40+
' <tr>' +
41+
' <td>February</td>' +
42+
' <td>12000</td>' +
43+
' </tr>' +
44+
' <tr>' +
45+
' <td>March</td>' +
46+
' <td>18000</td>' +
47+
' </tr>' +
48+
' </tbody>' +
49+
' </table>';
50+
51+
$('body')
52+
.empty()
53+
.append(htmlContent)
54+
;
55+
56+
var beforeRenderCalled = false;
57+
58+
$('table')
59+
.bind('highchartTable.beforeRender', function(event, highChartConfig) {
60+
beforeRenderCalled = true;
61+
expect(highChartConfig.yAxis[0].reversed).toBe(true);
62+
expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(true);
63+
expect(highChartConfig.yAxis[0].min).toBe(1000);
64+
expect(highChartConfig.yAxis[0].max).toBe(25000);
65+
expect(highChartConfig.yAxis[0].title.text).toBe("title example");
66+
expect(highChartConfig.yAxis[0].opposite).toBe(true);
67+
expect(highChartConfig.yAxis[0].tickInterval).toBe(1000);
68+
expect(highChartConfig.yAxis[0].labels.rotation).toBe(90);
69+
expect(highChartConfig.yAxis[0].gridLineInterpolation).toBe("circle");
70+
expect(highChartConfig.yAxis[0].startOnTick).toBe(false);
71+
expect(highChartConfig.yAxis[0].endOnTick).toBe(false);
72+
expect(highChartConfig.yAxis[0].labels.formatter).toBeDefined();
73+
74+
})
75+
.highchartTable()
76+
;
77+
78+
expect(beforeRenderCalled).toBe(true);
79+
});
80+
81+
82+
it("Without numeric", function() {
83+
84+
graph_absInvertedFormatter = function (value) {
85+
return Math.abs(value) * -1;
86+
};
87+
88+
var htmlContent = ' <table class="highchart" data-graph-container-before="1" data-graph-type="column" style="display:block"' +
89+
' data-graph-yaxis1-reversed="1" data-graph-yaxis1-stacklabels-enabled="1" ' +
90+
' data-graph-yaxis1-min="1000" data-graph-yaxis1-max="25000" ' +
91+
' data-graph-yaxis1-title-text="title example" ' +
92+
' data-graph-yaxis1-opposite="1" ' +
93+
' data-graph-yaxis1-tick-interval="1000" ' +
94+
' data-graph-yaxis1-rotation="90" ' +
95+
' data-graph-yaxis1-grid-line-interpolation="circle" ' +
96+
' data-graph-yaxis1-start-on-tick="0" ' +
97+
' data-graph-yaxis1-end-on-tick="0" ' +
98+
' data-graph-yaxis1-formatter-callback="graph_absInvertedFormatter" ' +
99+
'>' +
100+
'<caption>Example of title</caption>' +
101+
'<thead>' +
102+
' <tr>' +
103+
' <th>Month</th>' +
104+
' <th>Sales</th>' +
105+
' </tr>' +
106+
' </thead>' +
107+
' <tbody>' +
108+
' <tr>' +
109+
' <td>January</td>' +
110+
' <td>8000</td>' +
111+
' </tr>' +
112+
' <tr>' +
113+
' <td>February</td>' +
114+
' <td>12000</td>' +
115+
' </tr>' +
116+
' <tr>' +
117+
' <td>March</td>' +
118+
' <td>18000</td>' +
119+
' </tr>' +
120+
' </tbody>' +
121+
' </table>';
122+
123+
$('body')
124+
.empty()
125+
.append(htmlContent)
126+
;
127+
128+
129+
130+
var beforeRenderCalled = false;
131+
132+
$('table')
133+
.bind('highchartTable.beforeRender', function(event, highChartConfig) {
134+
beforeRenderCalled = true;
135+
expect(highChartConfig.yAxis[0].reversed).toBe(true);
136+
expect(highChartConfig.yAxis[0].stackLabels.enabled).toBe(true);
137+
expect(highChartConfig.yAxis[0].min).toBe(1000);
138+
expect(highChartConfig.yAxis[0].max).toBe(25000);
139+
expect(highChartConfig.yAxis[0].title.text).toBe("title example");
140+
expect(highChartConfig.yAxis[0].opposite).toBe(true);
141+
expect(highChartConfig.yAxis[0].tickInterval).toBe(1000);
142+
expect(highChartConfig.yAxis[0].labels.rotation).toBe(90);
143+
expect(highChartConfig.yAxis[0].gridLineInterpolation).toBe("circle");
144+
expect(highChartConfig.yAxis[0].startOnTick).toBe(false);
145+
expect(highChartConfig.yAxis[0].endOnTick).toBe(false);
146+
expect(highChartConfig.yAxis[0].labels.formatter).toBeDefined();
147+
})
148+
.highchartTable()
149+
;
150+
151+
expect(beforeRenderCalled).toBe(true);
152+
});
153+
});
154+
155+

0 commit comments

Comments
 (0)