Skip to content

Commit 4bc0bd2

Browse files
committed
Added data-graph-skip attribute
Added th attribute "graph-skip" which ignores the all the column. Remove some duplicate code during the column initialisation.
1 parent 955522b commit 4bc0bd2

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

jquery.highchartTable.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
var ths = $('thead th', table);
7979
var columns = [];
8080
var vlines = [];
81+
var skippedColumns = 0;
8182
var graphIsStacked = false;
8283
ths.each(function(indexTh, th) {
8384
var columnScale = $(th).data('graph-value-scale');
@@ -96,35 +97,39 @@
9697
nbYaxis = 2;
9798
}
9899

100+
var isColumnSkipped = $(th).data('graph-skip') == 1;
101+
if (isColumnSkipped)
102+
{
103+
skippedColumns = skippedColumns + 1
104+
}
105+
106+
var object = {
107+
libelle: $(th).text(),
108+
skip: isColumnSkipped,
109+
indexTd: indexTh - skippedColumns - 1,
110+
color: $(th).data('graph-color'),
111+
visible: !$(th).data('graph-hidden'),
112+
yAxis: typeof $(th).data('graph-yaxis') != 'undefined' ? $(th).data('graph-yaxis') : 0,
113+
dashStyle: $(th).data('graph-dash-style') || 'solid'
114+
};
115+
99116
if (typeof $(th).data('graph-vline-x') == 'undefined') {
100-
columns[indexTh] = {
101-
libelle: $(th).text(),
102-
scale: typeof columnScale != 'undefined' ? parseFloat(columnScale) : 1,
103-
graphType: serieGraphType,
104-
stack: serieStackGroup,
105-
color: $(th).data('graph-color'),
106-
visible: !$(th).data('graph-hidden'),
107-
unit: $(th).data('graph-unit'),
108-
yAxis: typeof $(th).data('graph-yaxis') != 'undefined' ? $(th).data('graph-yaxis') : 0,
109-
dashStyle: $(th).data('graph-dash-style') || 'solid'
110-
};
117+
object.scale = typeof columnScale != 'undefined' ? parseFloat(columnScale) : 1;
118+
object.graphType = serieGraphType;
119+
object.stack = serieStackGroup;
120+
object.unit = $(th).data('graph-unit');
121+
columns[indexTh] = object;
111122
} else {
112-
vlines[indexTh] = {
113-
libelle: $(th).text(),
114-
x: $(th).data('graph-vline-x'),
115-
height: $(th).data('graph-vline-height'),
116-
color: $(th).data('graph-color'),
117-
visible: !$(th).data('graph-hidden'),
118-
name: $(th).data('graph-vline-name'),
119-
yAxis: typeof $(th).data('graph-yaxis') != 'undefined' ? $(th).data('graph-yaxis') : 0,
120-
dashStyle: $(th).data('graph-dash-style') || 'solid'
121-
};
123+
object.x = $(th).data('graph-vline-x');
124+
object.height = $(th).data('graph-vline-height');
125+
object.name = $(th).data('graph-vline-name');
126+
vlines[indexTh] = object;
122127
}
123128
});
124129

125130
var series = [];
126131
$(columns).each(function(indexColumn, column) {
127-
if(indexColumn!=0) {
132+
if(indexColumn!=0 && !column.skip) {
128133
series.push({
129134
name: column.libelle + (column.unit ? ' (' + column.unit + ')' : ''),
130135
data: [],
@@ -147,7 +152,7 @@
147152
});
148153

149154
$(vlines).each(function(indexColumn, vline) {
150-
if (typeof vline != 'undefined') {
155+
if (typeof vline != 'undefined' && !vline.skip) {
151156
series.push({
152157
name: vline.libelle,
153158
data: [{x: vline.x, y:0, name: vline.name}, {x:vline.x, y:vline.height, name: vline.name}],
@@ -171,16 +176,23 @@
171176
var tds = $('td', row);
172177
tds.each(function(indexTd, td) {
173178
var cellValue;
179+
var column = columns[indexTd];
180+
181+
if (column.skip) {
182+
return;
183+
}
174184
if (indexTd==0) {
175185
cellValue = $(td).text();
176186
xValues.push(cellValue);
177187
} else {
178188
var rawCellValue = $(td).text();
189+
var serie = series[column.indexTd];
190+
179191
if (rawCellValue.length==0) {
180-
series[indexTd-1].data.push(null);
192+
serie.data.push(null);
181193
} else {
182194
var cleanedCellValue = rawCellValue.replace(/ /g, '').replace(/,/, '.');
183-
cellValue = Math.round(parseFloat(cleanedCellValue) * columns[indexTd].scale * 100) / 100;
195+
cellValue = Math.round(parseFloat(cleanedCellValue) * column.scale * 100) / 100;
184196

185197
var dataGraphX = $(td).data('graph-x');
186198

@@ -206,7 +218,7 @@
206218
};
207219
}
208220

209-
if (columns[indexTd].graphType === 'pie') {
221+
if (column.graphType === 'pie') {
210222
if ($(td).data('graph-item-highlight')) {
211223
serieDataItem.sliced = 1;
212224
}
@@ -216,7 +228,7 @@
216228
serieDataItem.color = $(td).data('graph-item-color');
217229
}
218230

219-
series[indexTd-1].data.push(serieDataItem);
231+
serie.data.push(serieDataItem);
220232
}
221233
}
222234
});

0 commit comments

Comments
 (0)