3 lines
81 KiB
JavaScript
3 lines
81 KiB
JavaScript
|
!function(t,e){"function"==typeof define&&define.amd?define(["d3","jquery"],e):"object"==typeof exports?module.exports=e(require("d3"),require("jquery")):t.MG=e(t.d3,t.jQuery)}(this,function(t,e){function r(t,e,r){MG.charts[t]={descriptor:e,defaults:r||{}}}function n(r){"use strict";var n=Ie(r.target);if(n.select(".mg-header").remove(),r.target&&r.title){var a=n.insert("text").attr("class","mg-header").attr("x",(r.width+r.left-r.right)/2).attr("y",r.title_y_position).attr("text-anchor","middle").attr("dy","0.55em");if(a.append("tspan").attr("class","mg-chart-title").text(r.title),r.show_tooltips&&r.description){a.append("tspan").attr("class","mg-chart-description").attr("dx","0.3em").text("");var o=e(a.node());o.popover({html:!0,animation:!1,placement:"top",content:r.description,container:r.target,trigger:"manual",template:'<div class="popover mg-popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'}).on("mouseenter",function(){t.selectAll(r.target).selectAll(".mg-popover").remove(),e(this).popover("show"),e(r.target).select(".popover").on("mouseleave",function(){o.popover("hide")})}).on("mouseleave",function(){setTimeout(function(){e(".popover:hover").length||o.popover("hide")},120)})}}r.error&&er(r)}function a(t){"use strict";t.rug_buffer_size="point"===t.chart_type?t.buffer/2:2*t.buffer/3;var e=Ce(t,"mg-y-rug");e.attr("x1",t.left+1).attr("x2",t.left+t.rug_buffer_size).attr("y1",t.scalefns.yf).attr("y2",t.scalefns.yf),Fe(e,t,"mg-y-rug-mono")}function o(e,r){return"bar"===e.chart_type&&(r.min=0,r.max=t.max(e.data[0],function(t){var r=[];return r.push(t[e.y_accessor]),null!==e.baseline_accessor&&r.push(t[e.baseline_accessor]),null!==e.predictor_accessor&&r.push(t[e.predictor_accessor]),Math.max.apply(null,r)})),r}function i(e){var r=e.yax_format;return r||("count"===e.format?(e.processed.max_y<1e-4?e.decimals=6:e.processed.max_y<.1&&(e.decimals=4),r=function(r){if(1>r)return e.yax_units+t.round(r,e.decimals);var n=t.formatPrefix(r);return e.yax_units+n.scale(r)+n.symbol}):r=function(e){var r=t.format("2p");return r(e)}),r}function s(e){var r=Re(e.data);"log"===e.y_scale_type&&(r=r.filter(function(t){return t[e.y_accessor]>0})),e.baselines&&(r=r.concat(e.baselines));var n=t.extent(r,function(t){return t[e.y_accessor]}),a={};a.min=n[0],a.max=n[1],a.min>=0&&!e.min_y&&!e.min_y_from_data&&(a.min=0),o(e,a),a.min=null!==e.min_y?e.min_y:a.min,a.max=null!==e.max_y?e.max_y:a.max<0?a.max+(a.max-a.max*e.inflator):a.max*e.inflator,"log"!==e.y_scale_type&&a.min<0&&(a.min=a.min-(a.min-a.min*e.inflator)),!e.min_y&&e.min_y_from_data&&(a.min=a.min/e.inflator),e.processed.min_y=a.min,e.processed.max_y=a.max}function l(t,e){return e.domain([t.processed.min_y,t.processed.max_y]).range([we(t),t.top]),e}function c(e){var r="log"===e.y_scale_type?t.scale.log():t.scale.linear();"log"===e.y_scale_type&&("histogram"===e.chart_type?e.processed.min_y=.2:e.processed.min_y<=0&&(e.processed.min_y=1)),e.scales.Y=l(e,r),e.scales.Y.clamp("log"===e.y_scale_type),e.scales.Y_axis=l(e,t.scale.linear())}function u(t,e){e.y_label&&t.append("text").attr("class","label").attr("x",function(){return-1*(Me(e)+(we(e)-Me(e))/2)}).attr("y",function(){return e.left/2}).attr("dy","0.4em").attr("text-anchor","middle").text(function(t){return e.y_label}).attr("transform",function(t){return"rotate(-90)"})}function f(t){function e(t){return 1e3===t?3:1e6===t?7:Math.log(t)/Math.LN10}var r=t.scales.Y.ticks(t.yax_count);"log"===t.y_scale_type&&(r=r.filter(function(t){return Math.abs(e(t))%1<1e-6||Math.abs(e(t))%1>1-1e-6}));var n=t.scales.Y.ticks(t.yax_count).length,a=!0;t.data.forEach(function(e,r){e.forEach(function(e,r){return e[t.y_accessor]%1!==0?(a=!1,!1):void 0})}),a&&n>t.processed.max_y&&"count"===t.format&&(r=r.filter(function(t){return t%1===0})),t.processed.y_ticks=r}function d(t,e){var r=e.processed.y_ticks.length;if(!e.x_extended_ticks&&!e.y_extended_ticks&&r){var n,a;e.axes_not_compact&&"bar"!==e.chart_type?(n=e.height-e.bottom,a=e.top):r?(n=e.scales.Y(e.processed.y_ti
|
||
|
target_ref||(target_ref=Be(),t.setAttribute("data-mg-uid",target_ref)),target_ref):(console.warn("The specified target should be a string or an HTMLElement.",t),He(t))}function He(t){return t.replace(/[^a-zA-Z0-9 _-]+/g,"").replace(/ +?/g,"")}function Ue(e,r){return Number(t.select(e).style(r).replace(/px/g,""))}function Qe(t){return Ue(t,"width")}function Ze(t){return Ue(t,"height")}function Ve(t){return or(Array.prototype.slice.call(arguments,1),function(e){if(e)for(var r in e)void 0===t[r]&&(t[r]=e[r])}),t}function We(t,e){var r,n=[],a=[];for(r=0;r<e.length;r++)n[e[r]]=!0;for(r=0;r<t.length;r++)n[t[r]]||a.push(t[r]);return a}function Je(t,e){console.warn("Deprecation: "+t+(e?". This feature will be removed in "+e+".":" the near future.")),console.trace()}function Ke(t,e,r){var n,a=0;for(t.textContent=e,n=t.getBBox();n.width>r&&(t.textContent=e.slice(0,--a)+"...",n=t.getBBox(),"..."!==t.textContent););}function tr(e,r,n,a){e.each(function(){for(var e,o=t.select(this),i=o.text().split(n||/\s+/).reverse(),s=[],l=0,c=1.1,u=(o.attr("y"),0),f=o.text(null).append("tspan").attr("x",0).attr("y",u+"em").attr(a||{});e=i.pop();)s.push(e),f.text(s.join(" ")),(null===r||f.node().getComputedTextLength()>r)&&(s.pop(),f.text(s.join(" ")),s=[e],f=o.append("tspan").attr("x",0).attr("y",++l*c+u+"em").attr(a||{}).text(e))})}function er(e){console.log("ERROR : ",e.target," : ",e.error),t.select(e.target).select(".mg-chart-title").append("i").attr("class","fa fa-x fa-exclamation-circle warning")}function rr(t){console.log("INTERNAL ERROR : ",t.target," : ",t.internal_error)}window.MG={version:"2.8.0"},MG.register=r,MG._hooks={},MG.add_hook=function(t,e,r){var n;MG._hooks[t]||(MG._hooks[t]=[]),n=MG._hooks[t];var a=n.filter(function(t){return t.func===e}).length>0;if(a)throw"That function is already registered.";n.push({func:e,context:r})},MG.call_hook=function(t){var e,r=MG._hooks[t],n=[].slice.apply(arguments,[1]);return r&&r.forEach(function(t){if(t.func){var r=e||n;r&&r.constructor!==Array&&(r=[r]),r=[].concat.apply([],r),e=t.func.apply(t.context,r)}}),e||n},MG.globals={},MG.deprecations={rollover_callback:{replacement:"mouseover",version:"2.0"},rollout_callback:{replacement:"mouseout",version:"2.0"},x_rollover_format:{replacement:"x_mouseover",version:"2.10"},y_rollover_format:{replacement:"y_mouseover",version:"2.10"},show_years:{replacement:"show_secondary_x_label",version:"2.1"},xax_start_at_min:{replacement:"axes_not_compact",version:"2.7"}},MG.globals.link=!1,MG.globals.version="1.1",MG.charts={},MG.data_graphic=function(t){"use strict";var e={missing_is_zero:!1,missing_is_hidden:!1,missing_is_hidden_accessor:null,legend:"",legend_target:"",error:"",animate_on_load:!1,top:65,title_y_position:10,bottom:30,right:10,left:50,buffer:8,width:350,height:220,full_width:!1,full_height:!1,small_height_threshold:120,small_width_threshold:160,xax_count:6,xax_tick_length:5,axes_not_compact:!0,yax_count:5,yax_tick_length:5,x_extended_ticks:!1,y_extended_ticks:!1,y_scale_type:"linear",max_x:null,max_y:null,min_x:null,min_y:null,min_y_from_data:!1,point_size:2.5,x_accessor:"date",xax_units:"",x_label:"",x_sort:!0,x_axis:!0,y_axis:!0,y_accessor:"value",y_label:"",yax_units:"",x_rug:!1,y_rug:!1,x_mouseover:null,y_mouseover:null,transition_on_update:!0,mouseover:null,click:null,show_rollover_text:!0,show_confidence_band:null,xax_format:null,area:!0,chart_type:"line",data:[],decimals:2,format:"count",inflator:10/9,linked:!1,linked_format:"%Y-%m-%d",list:!1,baselines:null,markers:null,scalefns:{},scales:{},utc_time:!1,european_clock:!1,show_year_markers:!1,show_secondary_x_label:!0,target:"#viz",interpolate:"cardinal",interpolate_tension:.7,custom_line_color_map:[],colors:null,max_data_size:null,aggregate_rollover:!1,show_tooltips:!0};MG.call_hook("global.defaults",e),t||(t={});var r=MG.charts[t.chart_type||e.chart_type];Ve(t,r.defaults,e),t.list&&(t.x_accessor=0,t.y_accessor=1);for(var n in MG.deprecations)if(t.hasOwnProperty(n)){var a=MG.deprecations[n],o="Use of `args."+n+"` has been deprecated",i=a.replacement;if(i&&(t[i]?o+=". The replacement - `a
|
||
|
return j(t,e),MG.call_hook("line.after_rollover",t),this},this.rolloverOn=function(t){var e=Ie(t.target),r=de(t);return function(n,a){N(t,e,n),R(t,n,a),e.selectAll("text").filter(function(t,e){return n===t}).attr("opacity",.3),t.show_rollover_text&&Lt(t,e,r,"— ",n,a),t.mouseover&&t.mouseover(n,a)}},this.rolloverOff=function(t){var e=Ie(t.target);return function(r,n){B(t,r,n),t.aggregate_rollover?q(t,e):H(t,e,r),U(e),t.mouseout&&t.mouseout(r,n)}},this.rolloverMove=function(t){return function(e,r){t.mousemove&&t.mousemove(e,r)}},this.windowListeners=function(){return It(this.args),this},this.init(t)}MG.register("line",Q)}.call(this),function(){"use strict";function r(r){this.init=function(t){return this.args=t,Bt(t),Ut(t),bt(t),b(t),h(t),this.mainPlot(),this.markers(),this.rollover(),this.windowListeners(),this},this.mainPlot=function(){var t=Ie(r.target);t.selectAll(".mg-histogram").remove();var e=t.append("g").attr("class","mg-histogram"),n=e.selectAll(".mg-bar").data(r.data[0]).enter().append("g").attr("class","mg-bar").attr("transform",function(t){return"translate("+r.scales.X(t[r.x_accessor]).toFixed(2)+","+r.scales.Y(t[r.y_accessor]).toFixed(2)+")"});return n.append("rect").attr("x",1).attr("width",function(t,e){return 1===r.data[0].length?(r.scalefns.xf(r.data[0][0])-r.bar_margin).toFixed(2):(r.scalefns.xf(r.data[0][1])-r.scalefns.xf(r.data[0][0])-r.bar_margin).toFixed(2)}).attr("height",function(t){return 0===t[r.y_accessor]?0:(r.height-r.bottom-r.buffer-r.scales.Y(t[r.y_accessor])).toFixed(2)}),this},this.markers=function(){return Xt(r),this},this.rollover=function(){var t=Ie(r.target);e(e(r.target).find("svg").get(0));t.selectAll(".mg-rollover-rect").remove(),t.selectAll(".mg-active-datapoint").remove(),t.append("text").attr("class","mg-active-datapoint").attr("xml:space","preserve").attr("x",r.width-r.right).attr("y",.75*r.top).attr("text-anchor","end");var n=t.append("g").attr("class","mg-rollover-rect"),a=n.selectAll(".mg-bar").data(r.data[0]).enter().append("g").attr("class",function(t,e){return r.linked?"mg-rollover-rects roll_"+e:"mg-rollover-rects"}).attr("transform",function(t){return"translate("+r.scales.X(t[r.x_accessor])+",0)"});return a.append("rect").attr("x",1).attr("y",r.buffer+r.title_y_position).attr("width",function(t,e){return 1===r.data[0].length?(r.scalefns.xf(r.data[0][0])-r.bar_margin).toFixed(2):e!==r.data[0].length-1?(r.scalefns.xf(r.data[0][e+1])-r.scalefns.xf(t)).toFixed(2):(r.scalefns.xf(r.data[0][1])-r.scalefns.xf(r.data[0][0])).toFixed(2)}).attr("height",function(t){return r.height}).attr("opacity",0).on("mouseover",this.rolloverOn(r)).on("mouseout",this.rolloverOff(r)).on("mousemove",this.rolloverMove(r)),this},this.rolloverOn=function(e){var r=Ie(e.target);return function(n,a){r.selectAll("text").filter(function(t,e){return n===t}).attr("opacity",.3);var o=e.processed.xax_format||MG.time_format(e.utc_time,"%b %e, %Y"),i=le(e);r.selectAll(".mg-bar rect").filter(function(t,e){return e===a}).classed("active",!0),e.linked&&!MG.globals.link&&(MG.globals.link=!0,t.selectAll(".mg-rollover-rects.roll_"+a+" rect").each(function(e){t.select(this).on("mouseover")(e,a)})),e.show_rollover_text&&r.select(".mg-active-datapoint").text(function(){if(e.time_series){var t=new Date(+n[e.x_accessor]);return t.setDate(t.getDate()),o(t)+" "+e.yax_units+i(n[e.y_accessor])}return e.x_accessor+": "+i(n[e.x_accessor])+", "+e.y_accessor+": "+e.yax_units+i(n[e.y_accessor])}),e.mouseover&&e.mouseover(n,a)}},this.rolloverOff=function(e){var r=Ie(e.target);return function(n,a){e.linked&&MG.globals.link&&(MG.globals.link=!1,t.selectAll(".mg-rollover-rects.roll_"+a+" rect").each(function(e){t.select(this).on("mouseout")(e,a)})),r.selectAll(".mg-bar rect").classed("active",!1),r.select(".mg-active-datapoint").text(""),e.mouseout&&e.mouseout(n,a)}},this.rolloverMove=function(t){return function(e,r){t.mousemove&&t.mousemove(e,r)}},this.windowListeners=function(){return It(this.args),this},this.init(r)}var n={mouseover:function(e,r){t.select("#histogram svg .mg-active-datapoint").text("Frequency Count: "+e.y)},binn
|