| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
;(function($) { |
| 7 |
'use strict'; |
| 8 |
|
| 9 |
var ts = $.tablesorter, |
| 10 |
|
| 11 |
|
| 12 |
chart_cols = [], |
| 13 |
chart_headers = [], |
| 14 |
|
| 15 |
chart_rows = [], |
| 16 |
chart_data = [], |
| 17 |
|
| 18 |
chart_categories = [], |
| 19 |
chart_series = [], |
| 20 |
|
| 21 |
chart_category = [], |
| 22 |
chart_dataset = [], |
| 23 |
|
| 24 |
chart = ts.chart = { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
nonDigit : /[^\d,.\-()]/g, |
| 29 |
|
| 30 |
init: function(c, wo) { |
| 31 |
c.$table |
| 32 |
.off(wo.chart_event) |
| 33 |
.on(wo.chart_event, function() { |
| 34 |
if (this.hasInitialized) { |
| 35 |
|
| 36 |
var c = this.config; |
| 37 |
chart.getCols(c, c.widgetOptions); |
| 38 |
chart.getData(c, c.widgetOptions); |
| 39 |
} |
| 40 |
}); |
| 41 |
}, |
| 42 |
|
| 43 |
getCols: function(c, wo) { |
| 44 |
var i; |
| 45 |
chart_cols = []; |
| 46 |
chart_series = []; |
| 47 |
chart_dataset = []; |
| 48 |
|
| 49 |
for ( i = 0; i < c.columns; i++ ) { |
| 50 |
if ( wo.chart_useSelector && ts.hasWidget( c.table, 'columnSelector' ) && !c.selector.auto ) { |
| 51 |
if ( ( c.selector.states[i] && $.inArray(i, wo.chart_ignoreColumns) < 0 ) || |
| 52 |
i === wo.chart_labelCol || i === wo.chart_sort[0][0] ) { |
| 53 |
chart_cols.push(i); |
| 54 |
} |
| 55 |
} else { |
| 56 |
if ( $.inArray(i, wo.chart_ignoreColumns) < 0 || i === wo.chart_labelCol || i === wo.chart_sort[0][0] ) { |
| 57 |
chart_cols.push(i); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
}, |
| 62 |
|
| 63 |
getData: function(c, wo) { |
| 64 |
chart.getHeaders(c, wo); |
| 65 |
chart.getRows(c, wo); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
chart_data = [ chart_headers ]; |
| 118 |
$.each(chart_rows, function(k, row) { |
| 119 |
chart_data.push(row); |
| 120 |
}); |
| 121 |
|
| 122 |
c.chart = { |
| 123 |
|
| 124 |
data: chart_data, |
| 125 |
|
| 126 |
categories: chart_categories, |
| 127 |
series: chart_series, |
| 128 |
|
| 129 |
category: chart_category, |
| 130 |
dataset: chart_dataset |
| 131 |
}; |
| 132 |
}, |
| 133 |
|
| 134 |
getHeaders: function(c, wo) { |
| 135 |
var text; |
| 136 |
chart_headers = []; |
| 137 |
chart_series = []; |
| 138 |
chart_dataset = []; |
| 139 |
chart_headers.push( c.headerContent[wo.chart_labelCol] ); |
| 140 |
$.each(chart_cols, function(k, col) { |
| 141 |
if (col === wo.chart_labelCol) { |
| 142 |
return true; |
| 143 |
} |
| 144 |
text = c.headerContent[col]; |
| 145 |
chart_headers.push( text ); |
| 146 |
chart_series.push( { name: text, data: [] } ); |
| 147 |
chart_dataset.push( { seriesname: text, data: [] } ); |
| 148 |
}); |
| 149 |
}, |
| 150 |
|
| 151 |
getRows: function(c, wo) { |
| 152 |
var norm_rows = c.cache[0].normalized, |
| 153 |
rows = []; |
| 154 |
chart_rows = []; |
| 155 |
chart_categories = []; |
| 156 |
chart_category = []; |
| 157 |
|
| 158 |
$.each(norm_rows, function(indx, rowVal) { |
| 159 |
var i, txt, |
| 160 |
$tr = rowVal[c.columns].$row, |
| 161 |
$cells = $tr.children('th,td'), |
| 162 |
row = []; |
| 163 |
if ( |
| 164 |
(/v/i.test(wo.chart_incRows) && $tr.is(':visible')) || |
| 165 |
(/f/i.test(wo.chart_incRows) && !$tr.hasClass(wo.filter_filteredRow || 'filtered')) || |
| 166 |
(!/(v|f)/i.test(wo.chart_incRows)) |
| 167 |
) { |
| 168 |
|
| 169 |
for (i = 0; i < c.columns; i++) { |
| 170 |
if ( $.inArray(indx, wo.chart_parsed) >= 0 ) { |
| 171 |
row.push( rowVal[i] ); |
| 172 |
} else { |
| 173 |
txt = $cells[i].getAttribute( c.textAttribute ) || $cells[i].textContent || $cells.eq(i).text(); |
| 174 |
row.push( $.trim( txt ) ); |
| 175 |
} |
| 176 |
} |
| 177 |
rows.push(row); |
| 178 |
} |
| 179 |
}); |
| 180 |
|
| 181 |
|
| 182 |
rows.sort(function(a, b) { |
| 183 |
if ( wo.chart_sort[0][1] === 1 ) { |
| 184 |
return ts.sortNatural( b[wo.chart_sort[0][0]], a[wo.chart_sort[0][0]] ); |
| 185 |
} |
| 186 |
return ts.sortNatural( a[wo.chart_sort[0][0]], b[wo.chart_sort[0][0]] ); |
| 187 |
}); |
| 188 |
|
| 189 |
$.each(rows, function(i, rowVal) { |
| 190 |
var value, |
| 191 |
objIndex = 0, |
| 192 |
row = [], |
| 193 |
label = rowVal[wo.chart_labelCol]; |
| 194 |
|
| 195 |
row.push( '' + label ); |
| 196 |
|
| 197 |
$.each(rowVal, function(indx, cellValue) { |
| 198 |
var tempVal; |
| 199 |
if (indx === wo.chart_labelCol) { |
| 200 |
chart_categories.push( cellValue ); |
| 201 |
chart_category.push({ 'label': cellValue }); |
| 202 |
return true; |
| 203 |
} |
| 204 |
value = false; |
| 205 |
if ( wo.chart_useSelector && ts.hasWidget( c.table, 'columnSelector' ) && !c.selector.auto ) { |
| 206 |
if ( c.selector.states[indx] && $.inArray(indx, wo.chart_ignoreColumns) < 0 ) { |
| 207 |
value = '' + cellValue; |
| 208 |
} |
| 209 |
} else { |
| 210 |
if ($.inArray(indx, wo.chart_ignoreColumns) < 0) { |
| 211 |
value = '' + cellValue; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
if (value !== false) { |
| 216 |
if ( /s/i.test( '' + wo.chart_layout[indx] ) ) { |
| 217 |
row.push( value ); |
| 218 |
chart_series[objIndex].data.push( value ); |
| 219 |
chart_dataset[objIndex].data.push( value ); |
| 220 |
} else { |
| 221 |
|
| 222 |
tempVal = ts.formatFloat( value.replace( chart.nonDigit, '' ), c.table ); |
| 223 |
tempVal = isNaN(tempVal) ? value : tempVal; |
| 224 |
|
| 225 |
row.push( tempVal ); |
| 226 |
chart_series[objIndex].data.push( tempVal ); |
| 227 |
chart_dataset[objIndex].data.push( { value : tempVal } ); |
| 228 |
} |
| 229 |
objIndex++; |
| 230 |
} |
| 231 |
}); |
| 232 |
chart_rows.push(row); |
| 233 |
}); |
| 234 |
}, |
| 235 |
|
| 236 |
remove: function(c, wo) { |
| 237 |
c.$table.off(wo.chart_event); |
| 238 |
} |
| 239 |
|
| 240 |
}; |
| 241 |
|
| 242 |
ts.addWidget({ |
| 243 |
id: 'chart', |
| 244 |
options: { |
| 245 |
|
| 246 |
chart_incRows: 'filtered', |
| 247 |
|
| 248 |
chart_useSelector: false, |
| 249 |
|
| 250 |
chart_ignoreColumns: [], |
| 251 |
|
| 252 |
chart_parsed: [], |
| 253 |
|
| 254 |
chart_layout: { |
| 255 |
|
| 256 |
0: 'string' |
| 257 |
}, |
| 258 |
|
| 259 |
chart_labelCol: 0, |
| 260 |
|
| 261 |
chart_sort: [ [ 0, 0 ] ], |
| 262 |
|
| 263 |
chart_event: 'chartData' |
| 264 |
}, |
| 265 |
|
| 266 |
init: function(table, thisWidget, c, wo) { |
| 267 |
chart.init(c, wo); |
| 268 |
}, |
| 269 |
|
| 270 |
remove: function(table, c, wo) { |
| 271 |
chart.remove(c, wo); |
| 272 |
} |
| 273 |
}); |
| 274 |
|
| 275 |
})(jQuery); |