tablesorter/dist/js/widgets/widget-chart.min.js
Rob Garrison f006d8aa5f v2.28.6
2017-04-02 06:34:02 -05:00

1 line
2.6 KiB
JavaScript

!function(a){"use strict";var b=a.tablesorter,c=[],d=[],e=[],f=[],g=[],h=[],i=[],j=[],k=b.chart={nonDigit:/[^\d,.\-()]/g,init:function(a,b){a.$table.off(b.chart_event).on(b.chart_event,function(){if(this.hasInitialized){var a=this.config;k.getCols(a,a.widgetOptions),k.getData(a,a.widgetOptions)}})},getCols:function(d,e){var f;for(c=[],h=[],j=[],f=0;f<d.columns;f++)e.chart_useSelector&&b.hasWidget(d.table,"columnSelector")&&!d.selector.auto?(d.selector.states[f]&&a.inArray(f,e.chart_ignoreColumns)<0||f===e.chart_labelCol||f===e.chart_sort[0][0])&&c.push(f):(a.inArray(f,e.chart_ignoreColumns)<0||f===e.chart_labelCol||f===e.chart_sort[0][0])&&c.push(f)},getData:function(b,c){k.getHeaders(b,c),k.getRows(b,c),f=[d],a.each(e,function(a,b){f.push(b)}),b.chart={data:f,categories:g,series:h,category:i,dataset:j}},getHeaders:function(b,e){var f;d=[],h=[],j=[],d.push(b.headerContent[e.chart_labelCol]),a.each(c,function(a,c){if(c===e.chart_labelCol)return!0;f=b.headerContent[c],d.push(f),h.push({name:f,data:[]}),j.push({seriesname:f,data:[]})})},getRows:function(c,d){var f=c.cache[0].normalized,l=[];e=[],g=[],i=[],a.each(f,function(b,e){var f,g,h=e[c.columns].$row,i=h.children("th,td"),j=[];if(/v/i.test(d.chart_incRows)&&h.is(":visible")||/f/i.test(d.chart_incRows)&&!h.hasClass(d.filter_filteredRow||"filtered")||!/(v|f)/i.test(d.chart_incRows)){for(f=0;f<c.columns;f++)a.inArray(b,d.chart_parsed)>=0?j.push(e[f]):(g=i[f].getAttribute(c.textAttribute)||i[f].textContent||i.eq(f).text(),j.push(a.trim(g)));l.push(j)}}),l.sort(function(a,c){return 1===d.chart_sort[0][1]?b.sortNatural(c[d.chart_sort[0][0]],a[d.chart_sort[0][0]]):b.sortNatural(a[d.chart_sort[0][0]],c[d.chart_sort[0][0]])}),a.each(l,function(f,l){var m,n=0,o=[],p=l[d.chart_labelCol];o.push(""+p),a.each(l,function(e,f){var l;if(e===d.chart_labelCol)return g.push(f),i.push({label:f}),!0;m=!1,d.chart_useSelector&&b.hasWidget(c.table,"columnSelector")&&!c.selector.auto?c.selector.states[e]&&a.inArray(e,d.chart_ignoreColumns)<0&&(m=""+f):a.inArray(e,d.chart_ignoreColumns)<0&&(m=""+f),m!==!1&&(/s/i.test(""+d.chart_layout[e])?(o.push(m),h[n].data.push(m),j[n].data.push(m)):(l=b.formatFloat(m.replace(k.nonDigit,""),c.table),l=isNaN(l)?m:l,o.push(l),h[n].data.push(l),j[n].data.push({value:l})),n++)}),e.push(o)})},remove:function(a,b){a.$table.off(b.chart_event)}};b.addWidget({id:"chart",options:{chart_incRows:"filtered",chart_useSelector:!1,chart_ignoreColumns:[],chart_parsed:[],chart_layout:{0:"string"},chart_labelCol:0,chart_sort:[[0,0]],chart_event:"chartData"},init:function(a,b,c,d){k.init(c,d)},remove:function(a,b,c){k.remove(b,c)}})}(jQuery);