pivottable
Version:
Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop
3 lines (2 loc) • 3.05 kB
JavaScript
(function(){var t;(t=function(t){return"object"==typeof exports&&"object"==typeof module?t(require("jquery"),require("plotly.js")):"function"==typeof define&&define.amd?define(["jquery","plotly.js"],t):t(jQuery,Plotly)})(function(t,e){var o,n;return o=function(o,n,r){return null==o&&(o={}),null==n&&(n={}),null==r&&(r=!1),function(l,i){var a,s,h,u,g,p,y,d,c,f,v,m,w,b,j,x;if(p={localeStrings:{vs:"vs",by:"by"},plotly:{},plotlyConfig:{}},i=t.extend(!0,{},p,i),w=l.getRowKeys(),a=l.getColKeys(),x=r?a:w,0===x.length&&x.push([]),g=r?w:a,0===g.length&&g.push([]),y=l.aggregatorName,l.valAttrs.length&&(y+="("+l.valAttrs.join(", ")+")"),u=x.map(function(e){var n,i,a,s,h,u,p;for(p=[],a=[],i=0,s=g.length;i<s;i++)n=g[i],u=parseFloat(l.getAggregator(r?n:e,r?e:n).value()),p.push(isFinite(u)?u:null),a.push(n.join("-")||" ");return h={name:e.join("-")||y},"pie"===o.type?(h.values=p,h.labels=a.length>1?a:[y]):(h.x=r?p:a,h.y=r?a:p),t.extend(h,o)}),r?(c=l.rowAttrs.join("-"),d=l.colAttrs.join("-")):(c=l.colAttrs.join("-"),d=l.rowAttrs.join("-")),j=y,""!==c&&(j+=" "+i.localeStrings.vs+" "+c),""!==d&&(j+=" "+i.localeStrings.by+" "+d),v={title:j,hovermode:"closest",width:window.innerWidth/1.4,height:window.innerHeight/1.4-50},"pie"===o.type){s=Math.ceil(Math.sqrt(u.length)),b=Math.ceil(u.length/s),v.grid={columns:s,rows:b};for(f in u)h=u[f],h.domain={row:Math.floor(f/s),column:f-s*Math.floor(f/s)},u.length>1&&(h.title=h.name);1===u[0].labels.length&&(v.showlegend=!1)}else v.xaxis={title:r?y:null,automargin:!0},v.yaxis={title:r?null:y,automargin:!0};return m=t("<div>").appendTo(t("body")),e.newPlot(m[0],u,t.extend(v,n,i.plotly),i.plotlyConfig),m.detach()}},n=function(){return function(o,n){var r,l,i,a,s,h,u,g,p,y,d,c,f,v;for(a={localeStrings:{vs:"vs",by:"by"},plotly:{},plotlyConfig:{}},n=t.extend(!0,{},a,n),f=o.getRowKeys(),0===f.length&&f.push([]),l=o.getColKeys(),0===l.length&&l.push([]),i={x:[],y:[],text:[],type:"scatter",mode:"markers"},s=0,g=f.length;s<g;s++)for(c=f[s],h=0,p=l.length;h<p;h++)r=l[h],v=o.getAggregator(c,r).value(),null!=v&&(i.x.push(r.join("-")),i.y.push(c.join("-")),i.text.push(v));return u={title:o.rowAttrs.join("-")+" vs "+o.colAttrs.join("-"),hovermode:"closest",xaxis:{title:o.colAttrs.join("-"),automargin:!0},yaxis:{title:o.rowAttrs.join("-"),automargin:!0},width:window.innerWidth/1.5,height:window.innerHeight/1.4-50},y=t("<div>",{style:"display:none;"}).appendTo(t("body")),d=t("<div>").appendTo(y),e.newPlot(d[0],[i],t.extend(u,n.plotly),n.plotlyConfig),d.detach(),y.remove(),d}},t.pivotUtilities.plotly_renderers={"Horizontal Bar Chart":o({type:"bar",orientation:"h"},{barmode:"group"},!0),"Horizontal Stacked Bar Chart":o({type:"bar",orientation:"h"},{barmode:"relative"},!0),"Bar Chart":o({type:"bar"},{barmode:"group"}),"Stacked Bar Chart":o({type:"bar"},{barmode:"relative"}),"Line Chart":o(),"Area Chart":o({stackgroup:1}),"Scatter Chart":n(),"Multiple Pie Chart":o({type:"pie",scalegroup:1,hoverinfo:"label+value",textinfo:"none"},{},!0)}})}).call(this);
//# sourceMappingURL=plotly_renderers.min.js.map