You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.highchartTable.min.js 8.4KB

1
  1. !function(a){a.fn.highchartTable=function(){var d=["column","line","area","spline","pie"],e=function(b,c){var d=a(b).data(c);if("undefined"!=typeof d){for(var e=d.split("."),f=window[e[0]],g=1,h=e.length;h>g;g++)f=f[e[g]];return f}};return this.each(function(){var f,g=a(this),h=a(g),i=1,j=a("caption",g),k=j.length?a(j[0]).text():"";if(1!=h.data("graph-container-before")){var l=h.data("graph-container");if(!l)throw"graph-container data attribute is mandatory";if("#"===l[0]||-1===l.indexOf(".."))f=a(l);else{for(var m=g,n=l;-1!==n.indexOf("..");)n=n.replace(/^.. /,""),m=m.parent();f=a(n,m)}if(1!==f.length)throw"graph-container is not available in this DOM or available multiple times";f=f[0]}else h.before("<div></div>"),f=h.prev(),f=f[0];var o=h.data("graph-type");if(!o)throw"graph-type data attribute is mandatory";if(-1==a.inArray(o,d))throw"graph-container data attribute must be one of "+d.join(", ");var p=h.data("graph-stacking");p||(p="normal");var q=h.data("graph-datalabels-enabled"),r=1==h.data("graph-inverted"),s=a("thead th",g),t=[],u=[],v=0,w=!1;s.each(function(b,c){var e=a(c),f=e.data("graph-value-scale"),g=e.data("graph-type");-1==a.inArray(g,d)&&(g=o);var j=e.data("graph-stack-group");j&&(w=!0);var k=e.data("graph-datalabels-enabled");"undefined"==typeof k&&(k=q);var l=e.data("graph-yaxis");"undefined"!=typeof l&&"1"==l&&(i=2);var m=1==e.data("graph-skip");m&&(v+=1);var n={"libelle":e.text(),"skip":m,"indexTd":b-v-1,"color":e.data("graph-color"),"visible":!e.data("graph-hidden"),"yAxis":"undefined"!=typeof l?l:0,"dashStyle":e.data("graph-dash-style")||"solid","dataLabelsEnabled":1==k,"dataLabelsColor":e.data("graph-datalabels-color")||h.data("graph-datalabels-color")},p=e.data("graph-vline-x");"undefined"==typeof p?(n.scale="undefined"!=typeof f?parseFloat(f):1,n.graphType="column"==g&&r?"bar":g,n.stack=j,n.unit=e.data("graph-unit"),t[b]=n):(n.x=p,n.height=e.data("graph-vline-height"),n.name=e.data("graph-vline-name"),u[b]=n)});var x=[];a(t).each(function(a,b){if(0!=a&&!b.skip){var c={"name":b.libelle+(b.unit?" ("+b.unit+")":""),"data":[],"type":b.graphType,"stack":b.stack,"color":b.color,"visible":b.visible,"yAxis":b.yAxis,"dashStyle":b.dashStyle,"marker":{"enabled":!1},"dataLabels":{"enabled":b.dataLabelsEnabled,"color":b.dataLabelsColor,"align":h.data("graph-datalabels-align")||("column"==o&&1==r?void 0:"center")}};if(b.dataLabelsEnabled){var d=e(g,"graph-datalabels-formatter");d&&(c.dataLabels.formatter=function(){return d(this.y)})}x.push(c)}}),a(u).each(function(a,b){"undefined"==typeof b||b.skip||x.push({"name":b.libelle,"data":[{"x":b.x,"y":0,"name":b.name},{"x":b.x,"y":b.height,"name":b.name}],"type":"spline","color":b.color,"visible":b.visible,"marker":{"enabled":!1}})});var y=[],z=e(g,"graph-point-callback"),A="datetime"==h.data("graph-xaxis-type"),B=a("tbody:first tr",g);B.each(function(b,d){if(!a(d).data("graph-skip")){var e=a("td",d);e.each(function(e,f){var g,i=t[e];if(!i.skip){var j=a(f);if(0==e)g=j.text(),y.push(g);else{var k=j.text(),l=x[i.indexTd];if(0==k.length)A||l.data.push(null);else{var m=k.replace(/\s/g,"").replace(/,/,"."),n={"value":m,"rawValue":k,"td":j,"tr":a(d),"indexTd":e,"indexTr":b};h.trigger("highchartTable.cleanValue",n),g=Math.round(parseFloat(n.value)*i.scale*100)/100;var o=j.data("graph-x");if(A){o=a("td",a(d)).first().text();var p=c(o);o=p.getTime()-60*p.getTimezoneOffset()*1e3}var q=j.data("graph-name"),r={"name":"undefined"!=typeof q?q:k,"y":g,"x":o};z&&(r.events={"click":function(){return z(this)}}),"pie"===i.graphType&&j.data("graph-item-highlight")&&(r.sliced=1);var s=j.data("graph-item-color");"undefined"!=typeof s&&(r.color=s),l.data.push(r)}}}})}});var C,D=function(a,b,c){var d=a.data("graph-yaxis-"+b+"-"+c);return"undefined"!=typeof d?d:a.data("graph-yaxis"+b+"-"+c)},E=[];for(C=1;i>=C;C++){var F={"title":{"text":"undefined"!=typeof D(h,C,"title-text")?D(h,C,"title-text"):null},"max":"undefined"!=typeof D(h,C,"max")?D(h,C,"max"):null,"min":"undefined"!=typeof D(h,C,"min")?D(h,C,"min"):null,"reversed":"1"==D(h,C,"reversed"),"opposite":"1"==D(h,C,"opposite"),"tickInterval":D(h,C,"tick-interval")||null,"labels":{"rotation":D(h,C,"rotation")||0},"startOnTick":"0"!=D(h,C,"start-on-tick"),"endOnTick":"0"!=D(h,C,"end-on-tick"),"stackLabels":{"enabled":"1"==D(h,C,"stacklabels-enabled")},"gridLineInterpolation":D(h,C,"grid-line-interpolation")||null},G=e(g,"graph-yaxis-"+C+"-formatter-callback");G||(G=e(g,"graph-yaxis"+C+"-formatter-callback")),G&&(F.labels.formatter=function(){return G(this.value)}),E.push(F)}for(var H=["#4572A7","#AA4643","#89A54E","#80699B","#3D96AE","#DB843D","#92A8CD","#A47D7C","#B5CA92"],I=[],J="undefined"!=typeof Highcharts.theme&&"undefined"!=typeof Highcharts.theme.colors?Highcharts.theme.colors:[],K=h.data("graph-line-shadow"),L=h.data("graph-line-width")||2,M=Math.max(H.length,J.length),N=0;M>N;N++){var O="graph-color-"+(N+1);I.push("undefined"!=typeof h.data(O)?h.data(O):"undefined"!=typeof J[N]?J[N]:H[N])}var P=h.data("graph-margin-top"),Q=h.data("graph-margin-right"),R=h.data("graph-margin-bottom"),S=h.data("graph-margin-left"),T=h.data("graph-xaxis-labels-enabled"),U={},V=h.data("graph-xaxis-labels-font-size");"undefined"!=typeof V&&(U.fontSize=V);var W={"colors":I,"chart":{"renderTo":f,"inverted":r,"marginTop":"undefined"!=typeof P?P:null,"marginRight":"undefined"!=typeof Q?Q:null,"marginBottom":"undefined"!=typeof R?R:null,"marginLeft":"undefined"!=typeof S?S:null,"spacingTop":h.data("graph-spacing-top")||10,"height":h.data("graph-height")||null,"zoomType":h.data("graph-zoom-type")||null,"polar":h.data("graph-polar")||null},"title":{"text":k},"subtitle":{"text":h.data("graph-subtitle-text")||""},"legend":{"enabled":"1"!=h.data("graph-legend-disabled"),"layout":h.data("graph-legend-layout")||"horizontal","symbolWidth":h.data("graph-legend-width")||30,"x":h.data("graph-legend-x")||15,"y":h.data("graph-legend-y")||0},"xAxis":{"categories":"datetime"!=h.data("graph-xaxis-type")?y:void 0,"type":"datetime"==h.data("graph-xaxis-type")?"datetime":void 0,"reversed":"1"==h.data("graph-xaxis-reversed"),"opposite":"1"==h.data("graph-xaxis-opposite"),"showLastLabel":"undefined"!=typeof h.data("graph-xaxis-show-last-label")?h.data("graph-xaxis-show-last-label"):!0,"tickInterval":h.data("graph-xaxis-tick-interval")||null,"dateTimeLabelFormats":{"second":"%e. %b","minute":"%e. %b","hour":"%e. %b","day":"%e. %b","week":"%e. %b","month":"%e. %b","year":"%e. %b"},"labels":{"rotation":h.data("graph-xaxis-rotation")||void 0,"align":h.data("graph-xaxis-align")||void 0,"enabled":"undefined"!=typeof T?T:!0,"style":U},"startOnTick":h.data("graph-xaxis-start-on-tick"),"endOnTick":h.data("graph-xaxis-end-on-tick"),"min":b(g,"min"),"max":b(g,"max"),"alternateGridColor":h.data("graph-xaxis-alternateGridColor")||null,"title":{"text":h.data("graph-xaxis-title-text")||null},"gridLineWidth":h.data("graph-xaxis-gridLine-width")||0,"gridLineDashStyle":h.data("graph-xaxis-gridLine-style")||"ShortDot","tickmarkPlacement":h.data("graph-xaxis-tickmark-placement")||"between","lineWidth":h.data("graph-xaxis-line-width")||0},"yAxis":E,"tooltip":{"formatter":function(){if("datetime"==h.data("graph-xaxis-type"))return"<b>"+this.series.name+"</b><br/>"+Highcharts.dateFormat("%e. %b",this.x)+" : "+this.y;var a="undefined"!=typeof y[this.point.x]?y[this.point.x]:this.point.x;return"pie"===o?"<strong>"+this.series.name+"</strong><br />"+a+" : "+this.point.y:"<strong>"+this.series.name+"</strong><br />"+a+" : "+this.point.name}},"credits":{"enabled":!1},"plotOptions":{"line":{"dataLabels":{"enabled":!0},"lineWidth":L},"area":{"lineWidth":L,"shadow":"undefined"!=typeof K?K:!0,"fillOpacity":h.data("graph-area-fillOpacity")||.75},"pie":{"allowPointSelect":!0,"dataLabels":{"enabled":!0},"showInLegend":"1"==h.data("graph-pie-show-in-legend"),"size":"80%"},"series":{"animation":!1,"stickyTracking":!1,"stacking":w?p:null,"groupPadding":h.data("graph-group-padding")||0}},"series":x,"exporting":{"filename":k.replace(/ /g,"_"),"buttons":{"exportButton":{"menuItems":null,"onclick":function(){this.exportChart()}}}}};h.trigger("highchartTable.beforeRender",W),new Highcharts.Chart(W)}),this};var b=function(b,d){var e=a(b).data("graph-xaxis-"+d);if("undefined"!=typeof e){if("datetime"==a(b).data("graph-xaxis-type")){var f=c(e);return f.getTime()-60*f.getTimezoneOffset()*1e3}return e}return null},c=function(a){var b=a.split(" "),c=b[0].split("-"),d=null,e=null;if(b[1]){var f=b[1].split(":");d=parseInt(f[0],10),e=parseInt(f[1],10)}return new Date(parseInt(c[0],10),parseInt(c[1],10)-1,parseInt(c[2],10),d,e)}}(jQuery);