mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
1 line
2.6 KiB
JavaScript
1 line
2.6 KiB
JavaScript
!function(t){"use strict";var e=t.tablesorter,a=[],r=[],o=[],s=[],n=[],c=[],i=[],h=[],l=e.chart={nonDigit:/[^\d,.\-()]/g,init:function(t,e){t.$table.off(e.chart_event).on(e.chart_event,function(){if(this.hasInitialized){var t=this.config;l.getCols(t,t.widgetOptions),l.getData(t,t.widgetOptions)}})},getCols:function(r,o){var s;for(a=[],c=[],h=[],s=0;s<r.columns;s++)o.chart_useSelector&&e.hasWidget(r.table,"columnSelector")&&!r.selector.auto?(r.selector.states[s]&&t.inArray(s,o.chart_ignoreColumns)<0||s===o.chart_labelCol||s===o.chart_sort[0][0])&&a.push(s):(t.inArray(s,o.chart_ignoreColumns)<0||s===o.chart_labelCol||s===o.chart_sort[0][0])&&a.push(s)},getData:function(e,a){l.getHeaders(e,a),l.getRows(e,a),s=[r],t.each(o,function(t,e){s.push(e)}),e.chart={data:s,categories:n,series:c,category:i,dataset:h}},getHeaders:function(e,o){var s;c=[],h=[],(r=[]).push(e.headerContent[o.chart_labelCol]),t.each(a,function(t,a){if(a===o.chart_labelCol)return!0;s=e.headerContent[a],r.push(s),c.push({name:s,data:[]}),h.push({seriesname:s,data:[]})})},getRows:function(a,r){var s=a.cache[0].normalized,u=[];o=[],n=[],i=[],t.each(s,function(e,o){var s,n,c=o[a.columns].$row,i=c.children("th,td"),h=[];if(/v/i.test(r.chart_incRows)&&c.is(":visible")||/f/i.test(r.chart_incRows)&&!c.hasClass(r.filter_filteredRow||"filtered")||!/(v|f)/i.test(r.chart_incRows)){for(s=0;s<a.columns;s++)t.inArray(e,r.chart_parsed)>=0?h.push(o[s]):(n=i[s].getAttribute(a.textAttribute)||i[s].textContent||i.eq(s).text(),h.push(t.trim(n)));u.push(h)}}),u.sort(function(t,a){return 1===r.chart_sort[0][1]?e.sortNatural(a[r.chart_sort[0][0]],t[r.chart_sort[0][0]]):e.sortNatural(t[r.chart_sort[0][0]],a[r.chart_sort[0][0]])}),t.each(u,function(s,u){var _,f=0,d=[],g=u[r.chart_labelCol];d.push(""+g),t.each(u,function(o,s){var u;if(o===r.chart_labelCol)return n.push(s),i.push({label:s}),!0;_=!1,r.chart_useSelector&&e.hasWidget(a.table,"columnSelector")&&!a.selector.auto?a.selector.states[o]&&t.inArray(o,r.chart_ignoreColumns)<0&&(_=""+s):t.inArray(o,r.chart_ignoreColumns)<0&&(_=""+s),!1!==_&&(/s/i.test(""+r.chart_layout[o])?(d.push(_),c[f].data.push(_),h[f].data.push(_)):(u=e.formatFloat(_.replace(l.nonDigit,""),a.table),u=isNaN(u)?_:u,d.push(u),c[f].data.push(u),h[f].data.push({value:u})),f++)}),o.push(d)})},remove:function(t,e){t.$table.off(e.chart_event)}};e.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(t,e,a,r){l.init(a,r)},remove:function(t,e,a){l.remove(e,a)}})}(jQuery); |