var leafHandlerLoaded = void 0; var rootHandlerLoaded = void 0; $(document).ready(function(){ /* SD 2012-03-13 The dropdowns had an onchange event * that redirected the page to selected value. If you hit * the browser back button the page went back to the original * page, except for the dropdown that stayed the same. This * was because the browser caches the form values; particularly IE. * In order to avoid caching of the form elements we shall.. * 1. remove the onchange attributes on the dropdown * 2. transfer the onchange to a JQuery onchange event * 3. When an onchange is triggered, capture the new selected value * 4. Revert the dropdowns to the original values, then * 5. redirect the page to the newly selected values. * This is an ugly solution. It could have been put in the * meta tags in the original html files. */ if($('select[name="Drop1"]').length > 0) { /* *SD 2012-03-13 The following 5 lines may not be necessary, but they do make the html valid-html. */ var dropdown = $('select[name="Drop1"]').html(); dropdown = dropdown.replace('SELECTED=""','selected="selected"'); dropdown = dropdown.replace('SELECTED','selected="selected"'); dropdown = dropdown.replace('selected=""','selected="selected"'); $('select[name="Drop1"]').html(dropdown); //Drop1 $('select[name="Drop1"]').removeAttr('onchange'); var originalSelection = $('select[name="Drop1"] option:selected').attr('value'); $('select[name="Drop1"]').change(function(){ var currentSelection = $(this).attr('value'); $('select[name="Drop1"]').find('option[value="'+originalSelection+'"]').attr('selected','selected'); window.location = currentSelection; return false; }); } //DropF if($('select[name="DropF"]').length > 0) { $('select[name="DropF"]').removeAttr('onchange'); var originalSelectionF = $('select[name="DropF"] option:selected').attr('value'); $('select[name="DropF"]').change(function(){ var currentSelectionF = $(this).attr('value'); $('select[name="DropF"]').find('option[value="'+originalSelectionF+'"]').attr('selected','selected'); window.location = currentSelectionF; return false; }); } }); (function(){ /* EIA Highcharts Theme v1.1.5 2014-04-10 Created by Shivan Computers Corporation on behalf of the U.S. Energy Information Administration: Authors : Ryan Lynch (Ryan.Lynch@eia.gov) and Scott Gearhart (Scott.Gearhart@eia.gov) */ (function(g){function qa(a,b,e){300>$(b.chart.container).width()&&!(b.chart.width&&300<=b.chart.width)&&(b.exporting.buttons.contextButton.text=null);return b}function ra(a){var b=[],e,f;if(a.yAxis instanceof Array){if(1=a.yAxis.length)2=b&&(f.data.push(a.data[e]),n>b&&a.data.splice(e,1))}a.data.reverse();ba.call(this,f);return f}return null}function fa(a){var b=0,e=0,f=0;switch(a.xType){case 4:e=7;break;case 3:b=1;break;case 2:b=3;break;case 1:f=1}for(var n=void 0,c=void 0,g=!1,l=0;l$(b.chart.container).width()&&!(b.chart.width&&300<=b.chart.width)&&(b.exporting.buttons.contextButton.text=null);if(!ra(b))return b.lang.noData="
You have chosen data series resulting in more than 4 axes.
Series with the same units will be plotted on the same axis. Axes will be added for each unique unit.
You must select series that result in 4 or fewer axes.
",b.noData.style= {fontSize:"14px",fontWeight:"bold",color:"red"},b.series=[],b;a=b.chart.renderTo;a="string"==typeof a?$("#"+a):$(a);var f=e=0,n=$.isArray(b.yAxis)?b.yAxis:[b.yAxis],c=$("
").appendTo("body").css({position:"absolute",top:-9999}),h=new g.Renderer(c[0],0,0);this.dummyChart={options:b,counters:{wrapColor:function(a){this.color>=a&&(this.color=0)},wrapSymbol:function(a){this.symbol>=a&&(this.symbol=0)},color:0,symbol:0},series:[],xAxis:[],yAxis:[]};if(b.xAxis instanceof Array)for(f=0;f=b.series[f].xType&&1<=b.series[f].xType&&b.chart.breakLines&&fa(b.series[f]);l&&(b.series.splice(f+1,0,l),f++)}P.call(this,b);b.chart.zoomType=$.support.touch?"none":void 0!==b.chart.zoomType?b.chart.zoomType:va.call(this.dummyChart)}b.tooltip.shared&&(b.tooltip.crosshairs=b.tooltip.shared);for(f=0;f").css({height:"auto",width:"auto"}).addClass("outerChartContainer"),f=$("
").css({height:"auto",width:"auto"}).addClass("printChartContainer"),b.before(e),f.appendTo(e),b.appendTo(f));a.chart.outerContainer=e[0];a.chart.printContainer=f[0];a.chart.container=b[0]}}function wa(a,b){var e=jQuery.extend(!0,{},R,a).title,f=0,n=0,c,h=e.originalAlign||(void 0=== e.align?"above":e.align.toLowerCase());c=0;"above"==h&&(c=b.text(e.text,0,0).attr({rotation:0}).css(e.style).add(),c=c.getBBox(),"above"==e.align&&(this.dummyChart.options.chart&&this.dummyChart.options.chart.type&&"bar"==this.dummyChart.options.chart.type?jQuery.extend(!0,a,{title:{align:"low"}}):jQuery.extend(!0,a,{title:{offset:-1*c.width+(a.opposite?20:10),rotation:0,align:"high",x:a.opposite?c.width-20:0,y:-1*c.height}})),c=c.height);jQuery.extend(!0,a,{title:{originalAlign:h}});a.labels&&a.labels.formatter|| jQuery.extend(!0,a,{labels:{formatter:function(){var a=this.value.toString(),c=/\d+\.?(\d*)/;c.test(a)&&(n=Math.max(this.value.toString().match(c)[1].length,n),void 0===f&&(f=n),this.isLast&&(n!=f&&(f=n,S=!0),n=0),a=g.numberFormat(this.value,f,".",","));return a}}});return c}function ga(a,b,e){var f=0;if(a&&a.text)for(a.text=a.text.replace(//gi," "),b=T.prototype.splitText(a.text,a.style,e,b),a.text=$.map(b,function(a){return a.line}).join("
"),i=0;ir,f|=0f.getUTCMonth()+1?"0":"")+(f.getUTCMonth()+1).toString();break;case g.xTypes.weekly:case g.xTypes.daily:e=f.getUTCFullYear().toString()+(10>f.getUTCMonth()+1?"0":"")+(f.getUTCMonth()+1).toString()+(10>f.getUTCDate()?"0":"")+f.getUTCDate().toString();break;case g.xTypes.quarterly:e= f.getUTCFullYear().toString()+"Q"+Math.ceil((f.getUTCMonth()+1)/3).toString();break;case g.xTypes.hourly:e=f.getUTCFullYear().toString()+(10>f.getUTCMonth()+1?"0":"")+(f.getUTCMonth()+1).toString()+(10>f.getUTCDate()?"0":"")+f.getUTCDate().toString()+"T"+(10>f.getUTCHours()?"0":"")+f.getUTCHours()+"Z"}return e}var T=g.Chart,z=g.extend,E=g.each,U=g.map,Ga=g.Axis,I=g.pick,la=g.PREFIX,Ha=g.Tick,ma=Math,Ia=ma.floor,Y=ma.max,na=function(a){return void 0!==a&&null!==a},J=g.splat||function(a){$.isArray(a)|| (a=[a]);return a},Z=g.merge,ta=Math.max,sa=Math.min,za=document,ha=window;(function(){function a(){}return function(b){a.prototype=b;return new a}})();var aa=null!=navigator.userAgent.match(/MSIE/),R,oa,S,N,pa;z(g,{eia_theme_version:"1.1.3",logos:{none:0,eia:1,reuters:2,bloomberg:3},eia_blue:"#0096d7",eia_tan:"#bd732a",eia_green:"#5D9732",eia_yellow:"#ffc702",eia_red:"#a33340",eia_brown:"#403203",eia_lt_blue:"#76d5ff",eia_lt_green:"#bed5ad",eia_dk_red:"#410e14",eia_grey:"#666666",eia_dk_blue:"#003953", eia_dk_green:"#2a4b11",eia_dk_grey:"#333333",eia_projections_line:{color:"#888",dashStyle:"Dash",width:1,zIndex:3},eia_projections_label:{color:"#888",fontWeight:"bold"},eia_zero_axis_line:{color:"#000",dashStyle:"Solid",zIndex:1,width:1,value:0}});z(g,{eiaTheme:{chart:{animation:!aa,plotBackgroundColor:"rgba(255, 255, 255, .1)",spacingBottom:20,logo:g.logos.eia,events:{redraw:function(){Aa.apply(this,arguments)},load:function(){Ba.apply(this,arguments)}},style:{fontFamily:"Arial, Verdana, Helvetica, sans-serif"}, lineUpYAxisZeros:!1,borderColor:"#ffffff",breakLines:!0},colors:[g.eia_blue,g.eia_tan,g.eia_green,g.eia_yellow,g.eia_red,g.eia_brown,g.eia_lt_blue,g.eia_lt_green,g.eia_dk_red,g.eia_grey,g.eia_dk_blue,g.eia_dk_green,g.eia_dk_grey],title:{align:"left",margin:35,style:{color:"black",fontSize:"16px",fontWeight:"bold",fontFamily:"Arial, Verdana, Helvetica, sans-serif"}},subtitle:{style:{color:"#333",fontSize:"12px",fontFamily:"Arial, Verdana, Helvetica, sans-serif"},align:"left",floating:!1},credits:{style:{color:"#888", fontSize:"11px"},text:"Source: U.S. Energy Information Administration",href:"http://www.eia.gov",position:{align:"left",verticalAlign:"bottom",x:15}},labels:{style:{fontSize:"12px",color:"#333"}},xAxis:{labels:{style:{color:"black"}},endOnTick:!1,startOnTick:!1,tickColor:"#000",lineColor:"#000",title:{style:{color:"#888",fontWeight:"bold",fontSize:"12px",fontFamily:"Arial, Verdana, Helvetica, sans-serif"}},dateTimeLabelFormats:{day:"%e %b. %Y",week:"%e %b. %Y",month:"%b '%y",year:"%Y"}},yAxis:{labels:{style:{color:"#333", fontFamily:"Arial, Verdana, Helvetica, sans-serif"}},lineColor:"#A0A0A0",minorTickInterval:null,tickColor:"#A0A0A0",tickColor:"#A0A0A0",tickWidth:0,title:{align:"above",style:{color:"#888",fontWeight:"bold",fontSize:"12px"}}},tooltip:{backgroundColor:"rgba(255, 255, 255, 0.75)",style:{fontSize:"12px",color:"#000000",padding:5},formatter:function(){return g.universalTooltipFormatter.apply(this,arguments)}},plotOptions:{series:{animation:!aa,tooltip:{showName:!0}},line:{shadow:0,lineWidth:2,borderWidth:0, dataLabels:{color:"#333"},marker:{enabled:!1,states:{hover:{enabled:!0,radius:5}}}},area:{borderWidth:0,shadow:!1,lineWidth:0,marker:{enabled:!1,states:{hover:{enabled:!0,radius:4}}}},spline:{marker:{lineColor:"#333"}},column:{borderWidth:0,shadow:!1,lineWidth:0},bar:{shadow:!1},pie:{allowPointSelect:!0,shadow:!1,dataLabels:{style:{fontSize:"12px",color:"red"}}},scatter:{marker:{radius:3,symbol:"circle",states:{hover:{enabled:!0,lineColor:"rgb(100,100,100)"}}},states:{hover:{marker:{radius:3,enabled:!0}}}}}, legend:{floating:!1,borderWidth:1,borderColor:"#e4e4e4",backgroundColor:"#f1f1f1",borderRadius:0,symbolPadding:5,itemStyle:{textDecoration:"none"},itemHoverStyle:{color:"#189bd7",textDecoration:"underline"},itemHiddenStyle:{color:"#CCC"}},lang:{exportButtonTitle:"Export an image or data"},exporting:{buttons:{contextButton:{symbol:"download",symbolFill:"#666",symbolStroke:"#666",symbolStrokeWidth:1,symbolSize:16,symbolX:8,symbolY:8.5,text:"DOWNLOAD",menuItems:[{text:"Print Chart",onclick:function(){ya.apply(this)}}, {separator:!0},{text:"Download Image",onclick:function(){this.exportChart({url:"/global/scripts/jquery/highcharts/exporting-server/index.cfm",width:this.chartWidth},g.generateEIAExportOptions.apply(this))}},{text:"Download PDF",onclick:function(){this.exportChart({url:"/global/scripts/jquery/highcharts/exporting-server/index.cfm",type:"application/pdf"},g.generateEIAExportOptions.apply(this))}},{text:"Download Data",onclick:function(){this.generateCSV()}},null]}},combineLinkedSeriesInExport:!0}}, yTypes:{mixed:0,positive:1,negative:-1},xTypes:{category:0,annual:1,quarterly:2,monthly:3,weekly:4,daily:5,hourly:6},csvXLabels:"Category;Year;Quarter;Month;Week of;Day".split(";"),tooltipXLabels:";Year;Quarter;Month;Week of;Day".split(";"),xMinRanges:[0,126144E6,31536E6,107136E5,24192E5,6048E5,864E5],parseXValue:function(a,b,e){switch(a){case g.xTypes.annual:a=g.dateFormat("%Y",b);break;case g.xTypes.monthly:a=g.dateFormat("%b %Y",b);break;case g.xTypes.weekly:a=g.dateFormat("%m/%e/%Y",b);break; case g.xTypes.daily:a=g.dateFormat("%m/%e/%Y",b);break;case g.xTypes.quarterly:m=g.dateFormat("%m",b);y=g.dateFormat("%Y",b);a="Q"+Math.ceil(m/3)+" "+y;break;case g.xTypes.hourly:a=g.dateFormat("%m/%e/%Y %HH",b)+("undefined"!=typeof e?" "+e:"");break;default:a=b}return a},universalTooltipFormatter:function(){var a="";if(void 0!=this.point){var b,e,f,n=this.series;b=this.series.chart;e=n.options;e=e.tooltip;var c="pie"==b.options.chart.type;f=n.name;var h=n.options.xType,l=c?"":n.xAxis.options.categoryTitle|| n.xAxis.options.title.text||g.tooltipXLabels[h]||"",p=c?"":n.yAxis.options.title.text||"";c?(f=this.point.name,b=l,e=this.y):(b=(0"+f+"
":"")+b+(""!=b?"
":"")+e}else{var k=this.points;b=k[0].series.chart;c="pie"==b.options.chart.type;h=b.options.maxXType;l=g.tooltipXLabels[h];if(c)for(b=0;b "+e,b");else for(b=(""!=l?l+" : ":"")+g.parseXValue(h,this.x,b.userOptions.timezone),a+=b+"
",b=0;b "+e,b")}return a},generateEIAExportOptions:function(){return{}},numberFormat:function(a,b,e,f){if(null===a||void 0===a||""===a||isNaN(a)||Infinity===Math.abs(a))return"";var n=g.getOptions().lang,c=isNaN(b=Math.abs(b))?Math.min(a.toString().match(/\d+\.?(\d*)/)[1].length,20):b;b=void 0===e?n.decimalPoint:e;f=void 0===f?n.thousandsSep:f;n=0>a?"-":"";e=String(parseInt(a=Math.abs(+a|| 0).toFixed(c)));var h=3]*>.*?<\s*\/\2\s*>|<\s*\/[^>]+>|[^<>\s]+|(<[^>]+>))/g).concat("");h/)){words.splice(h-1,1);break}k=l.getBBox().width}while(k\s+/g, ">")),c=h-1);g.push({line:a,lineHeight:p});l.destroy();l=null}return g},generateCSV:function(){function a(a){if(!H.hasOwnProperty(a)){if(D){for(h=t.length-1;0<=h&&!(a/g,c,h,l,p,k,q,u,r,w,s;r=J(this.options.xAxis)[0];var v,x=!0,D=!1,t=[],A={},B={},H={},G=!1,C=!1,E=this.cleanTitleForCSVExport();if(b)return window.location=b;try{D="datetime"==r.type}catch(z){}try{void 0!== r.title.text&&0\\,]/g,e=/\//g,f=/\s+/g,g=/<[\/\w]+>/ig;try{void 0!==this.options.title.text&&0').val(JSON.stringify(a)); g=$('').val(b);jQuery('
').append(f).append(g).appendTo("body").submit().remove()},addButton:function(a){var b=this,e=b.renderer;a=Z(b.options.navigation.buttonOptions,a);var f=a.onclick,g=a.menuItems,c,h,l={stroke:a.symbolStroke,fill:a.symbolFill},p=a.symbolSize||12;b.btnCount||(b.btnCount=0);b.btnCount++;b.exportDivElements||(b.exportDivElements=[],b.exportSVGElements=[],b.exportEmbedElements=[]); if(!1!==a.enabled){b.buttonGroup||(b.buttonGroup=e.g("buttonGroup").add(),b.exportSVGElements.push(b.buttonGroup));var k=a.theme,q=k.states,u=q&&q.hover,q=q&&q.select,r;delete k.states;f?r=function(){f.apply(b,arguments);for(var a=0;ac)b.push("date_mode=range"),b.push("start="+F(this.options.minXType,h)),b.push("end="+F(this.options.minXType,l));else if(a.hasOwnProperty("date_mode")){b.push("date_mode="+a.date_mode);if("range"==a.date_mode||"start"==a.date_mode)a.hasOwnProperty("start")? b.push("start="+a.start):b.push("start="+F(this.options.minXType,h));"range"==a.date_mode&&(a.hasOwnProperty("end")?b.push("end="+a.end):b.push("end="+F(this.options.minXType,l)));"periods"==a.date_mode&&a.hasOwnProperty("periods")&&b.push("periods="+a.periods)}else b.push("date_mode=all")}return b.join("&")};g.wrap(g.Chart.prototype,"init",function(a,b,e){var f=b,n=b||{};pa=void 0!=f.chart.type&&"pie"==f.chart.type;this.axisZerosAligned=0;this.seriesColorQueue=Highcharts.getOptions().colors.slice(0); N=0;ops=jQuery.extend(!0,{},g.getOptions(),f);if("undefined"!=typeof ops.exporting.embedOptions){b=ops.exporting.buttons.contextButton.menuItems;for(var f=!1,c={text:"Embed Chart",onclick:function(){this.openAPIEmbed()}},h=0;h=c.xType&&1<=c.xType&&h.chart.breakLines&&fa(n);a=a.call(this,b,e,f);l&&(l.linkedTo=a.index,l=this.addSeries(l), a.linkedSeries.push(l));V.call(this);return a});g.wrap(g.Series.prototype,"setData",function(a,b,e,f,g){var c=this.chart;b=$.extend(!0,{},this.options,{data:b});var h=null;!b.projection&&c.dummyChart&&(h=Q.call(c,b),null!==h&&!0===h.projection&&this.linkedSeries&&0").appendTo("body").css({position:"absolute",top:-9999}), c=new g.Renderer(n[0],0,0),h=this.options,l=h.chart.titleAdjust,p=this.container;"undefined"!=typeof b&&null!=b&&(l=ga.call(this,b.title,c,(h.chart.width||$(p).width()||600)-(!1!==h.exporting.enabled?44+(null==h.exporting.buttons.contextButton.text?0:100):0)),"undefined"!=typeof h.chart.title&&(h.chart.title.margin=(isNaN(h.chart.title.margin)?0:h.chart.title.mragin)+(l-h.chart.titleAdjust)),h.chart.titleAdjust=l);"undefined"!=typeof e&&null!=e&&(e.y=(isNaN(l)?0:l)+(isNaN(h.chart.spacingTop)?h.chart.spacing[0]: h.chart.spacingTop)+5);n.remove();return a.call(this,b,e,f)});g.wrap(g.Axis.prototype,"adjustTickAmount",function(a){var b=this.tickPositions?this.tickPositions.length:this.tickAmount,e=this._maxTicksKey,f=this.chart.maxTicks;a=a.call(this);if(f&&f[e]&&b!=this.tickPositions.length&&this.chart.axisZerosAligned&&this.chart.options.chart.lineUpYAxisZeros){for(var g,b=0;b\r\n<")})})(Highcharts); if(/\/hist\//.test(window.location.pathname)){ /** * The Petroleum Navigator leaf page charting function **/ var leafHandler = function($){ return function(){ // Is this the Natural Gas Navigator? var isNG, sourcekey, frequency, navigatorPrefix; //min must not be zero if negative values negativeValues = false; // An array of months for performing lookups var monthsArray = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]; // Returns the Chart Title and Units as an array var getTitleMatch = function(){ //var titleRegex = /[^\(\)]+/g; var title = $('.Title1').html(); //return title.match(titleRegex); <- this didn't work as some series name have parenthical phrases var aTitle = [title.substring(0,title.lastIndexOf('(')-1), title.substring(title.lastIndexOf('(')+1,title.lastIndexOf(')')) ]; return aTitle; } // Returns the table rows in a page for iteration var getTableRows = function(){ if(isNG) return $('body > table:eq(2) tr'); else return $('table.FloatTitle tr'); } // Trims null values from the beginning and end of data // arrays var trimNulls = function(data){ var i; var dataCopy = data.slice(0); for(i=data.length - 1; i>0; i--){ if(data[i][1] === null) dataCopy.pop(); else break; } for(i=0; i -1)console.info(JSON.stringify(ret)); return ret; } //Indicates whether this is a Reutures series var isReuters = function(){ var tr_series = ['RWTC','RBRTE','EER_EPMRU_PF4_Y35NY_DPG','EER_EPMRU_PF4_RGC_DPG','EER_EPMRR_PF4_Y05LA_DPG','EER_EPD2F_PF4_Y35NY_DPG','EER_EPJK_PF4_RGC_DPG','EER_EPLLPA_PF4_Y44MB_DPG', 'RNGWHHD']; for(var j=0;j').width('100%').appendTo(imageParent); // Make the chart 100% width chartTable.width('100%'); // Hide the chart during processing chartParent.children().hide(); return chartParent; } //This copies the referring pages div at the bottom of the page to the top of the page var copyReferringPages = function() { $('
').html($('#refer').html()).insertAfter($('#contsub')); // remove first
in body $('body > br').first().remove(); }(); // Add the source key and link to the api for this series var addSourceKeyIcon = function(chartParent) { var navigatorPrefix = isNG ? 'NG' : 'PET'; $('This series is available through the EIA open data API and can be downloaded to Excel or embedded as an interactive chart or map on your website.') .insertAfter(chartParent.closest('tr')); } // This is the function that creates the chart object. // Executes immediately i.e.: function(args){/*do*/}(args); var createLeafChart = function(){ isNG = window.location.pathname.match(/\/ng\//) !== null; var chartParent = prepareChartParent(); var titleMatch = getTitleMatch(); var data = processData(); addSourceKeyIcon(chartParent); leafChart = new Highcharts.Chart( createOptions( chartParent.get(0), titleMatch[0], titleMatch[1], data ) ); }(); } }(jQuery);/** * Created by Shivan Computers Corporation on behalf of the * U.S. Energy Information Administration: * Author : Ryan Lynch (Ryan.Lynch@eia.gov) * * EIA Analyis Module: * * This module extend the EIA Theme to add various analytical * functions to the chart, along with a set of controls to * activate them. * * Depends on: highcharts.js, eia-theme.js **/ (function(){ // Shortcuts var HC = Highcharts, Chart = HC.Chart; each = HC.each, extend = HC.extend, map = HC.map, eiaTheme = HC.eiaTheme, seasonalPalletAlpha = 0.3; // Default Analysis Options HC.setOptions(extend(eiaTheme, { analysis: { enableMovingAverage:true, enableSeasonalAnalysis:true } })); function seasonalPalletConverter(h){ return 'rgba(' + parseInt(h.substring(1,3), 16) + ',' + parseInt(h.substring(3,5), 16) + ',' + parseInt(h.substring(5), 16) + ',' + seasonalPalletAlpha + ')'; } // Colors for seasonal analysis extend(HC, { eia_seasonal_pallet : map(eiaTheme.colors.slice(1), seasonalPalletConverter) }); ////////////////////////// // Analytical Functions // ////////////////////////// extend(Chart.prototype,{ addMovingAverage : function(index, duration){ var chart = this, baseSeries = chart.series[index], interval = baseSeries.options.xType, baseXData = baseSeries.xData, baseYData = baseSeries.yData, avgData = [], helperArray = [], dayInterval, durationTitle, avg = total = i = j = calcDuration = 0; // If we are dealing with a series that has been destroyed, then // return if(!baseXData) return; // else switch(interval){ case HC.xTypes.Annual: case HC.xTypes.Quarterly: case HC.xTypes.Monthly: return; break; case HC.xTypes.weekly: durationTitle = duration + ' Week'; dayInterval = 7 * 24 * 60 * 60 * 1000; break; case HC.xTypes.daily: durationTitle = duration + ' Day'; dayInterval = 1 * 24 * 60 * 60 * 1000; break; } for(i = duration; helperArray.length == 0; i++){ for(j = i - duration; j < i; j++){ if( baseYData[j] != null && baseXData[j] >= baseXData[i] - dayInterval * duration ){ total += baseYData[j]; helperArray.push({ x : baseXData[j], y : baseYData[j] }); } } } avgData.push([baseXData[i], total/helperArray.length]); for(i = duration + 1; i < baseXData.length; i++){ if( helperArray[0].x <= baseXData[i] - dayInterval * duration ){ total -= helperArray[0].y; helperArray.shift(); } j = i - 1 if( baseYData[j] != null && baseXData[j] >= baseXData[i] - dayInterval * duration ){ total += baseYData[j]; helperArray.push({ x : baseXData[j], y : baseYData[j] }); } avgData.push([baseXData[i], total / helperArray.length]); } //chart.legend.enabled = true; return chart.addSeries({ //name : baseSeries.name + durationTitle + ' Moving Average', name : durationTitle + ' Moving Average', data : avgData }); }, createSeasonalAnalysis : function(index, interval){ var chart = this, baseSeries = chart.series[index], yearOffset, baseXData = baseSeries.xData, baseYData = baseSeries.yData, i = j = 0, series = [], seriesData, xType = baseSeries.options.xType, serie, startDate, currentDate, firstDate, originalStartDate, lastDate, dateString; if(!baseXData) return; j = baseXData.length - 1; startDate = originalStartDate = new Date(baseXData[j]); for(i = 0; i <= interval && j > 0; i++){ endDate = new Date( startDate.getUTCFullYear() - 1, startDate.getUTCMonth(), startDate.getUTCDate() ) seriesData = []; lastDate = new Date(baseXData[j]); while( j >= 0 && (!currentDate || currentDate.getTime() >= endDate.getTime()) ){ currentDate = new Date(baseXData[j]); seriesData.push({ x: Date.UTC( currentDate.getUTCFullYear() + i, currentDate.getUTCMonth(), currentDate.getUTCDate()), tooltipX : currentDate.getTime(), y: baseYData[j] }); firstDate = currentDate; j--; } seriesData.sort(function(a,b) { if(a.x > b.x) { return 1; } else if(a.x < b.x) { return -1; } return 0; }); j++; switch(xType){ case HC.xTypes.daily: dateString = HC.dateFormat('%m/%d/%Y', firstDate.getTime()) + ' to ' + HC.dateFormat('%m/%d/%Y', lastDate.getTime()); break; case HC.xTypes.weekly: dateString = HC.dateFormat('%m/%d/%Y', firstDate.getTime()) + ' to ' + HC.dateFormat('%m/%d/%Y', lastDate.getTime()); break; case HC.xTypes.monthly: dateString = HC.dateFormat('%m/%Y', firstDate.getTime()) + ' to ' + HC.dateFormat('%m/%Y', lastDate.getTime()); break; } serie = { //name:baseSeries.options.name + ' ' + dateString, name: dateString, data:seriesData, legendIndex:i }; if(i > 0) serie.color = HC.eia_seasonal_pallet[i-1]; series.push(serie); startDate = endDate; } chart.removeAllSeries(false); for(j=series.length - 1; j>=0; j--){ chart.addSeries(series[j], false); } chart.resetZoom(); chart.redraw(); } }); function createSeasonalAnalysisOptions(s, index){ var chart = this, xType = s.options.xType; if(s.type == 'line' && xType != HC.xTypes.category){ var link, durations, maxInterval; if(xType > HC.xTypes.annual){ maxInterval = (s.data[s.data.length - 1].x - s.data[0].x) / 31536E6 /*365 days*/; // Add moving averages each([5, 10], function(interval){ if(interval < maxInterval){ //option = $('').html(s.name + ': ' + interval + ' Year Seasonal Analysis') option = $('').html(interval + ' Year Seasonal Analysis') .data({ method:chart.createSeasonalAnalysis, arguments:[index, interval] }); option.appendTo(chart.options.chart.analysisSelect); } }); } } } function createMovingAverageOptions(s, index){ var chart = this, xType = s.options.xType; if(s.type == 'line' && xType != HC.xTypes.category){ var link, durations, maxDuration = s.data.length; if(xType == HC.xTypes.daily){ // Add moving averages each([30, 60, 90], function(duration){ if(duration < maxDuration){ //option = $('').html(s.name + ': ' + duration + ' Day Moving Average ') option = $('').html(duration + ' Day Moving Average ') .data({ method:chart.addMovingAverage, arguments:[index, duration] }); option.appendTo(chart.options.chart.analysisSelect); } }); } if(xType == HC.xTypes.weekly){ each([4, 8, 12], function(duration){ if(duration < maxDuration){ //option = $('').html(s.name + ': ' + duration + ' Week Moving Average ') option = $('').html(duration + ' Week Moving Average ') .data({ method:chart.addMovingAverage, arguments:[index, duration] }); option.appendTo(chart.options.chart.analysisSelect); } }); } } } function processAnalysis(){ var chart = this, ops = chart.options, container = $(chart.options.chart.container), outerContainer = $(chart.options.chart.outerContainer); analysisContainer = $('
').css({ height:'auto', width:'auto', // We set the margin and padding on the // captions container to match the chart // container so that the links are // lined up correctly marginLeft:container.css('marginLeft'), marginRight:container.css('marginRight') /*paddingLeft:container.css('paddingLeft'), paddingRight:container.css('paddingRight')*/ }).addClass('chartAnalysisContainer').append('Chart Tools'), analysisSelect = $(''), analysisTable = $('
'); // Enable or disable analysis based on maxXType switch(ops.maxXType){ case HC.xTypes.annual: ops.analysis.enableMovingAverage &= false; ops.analysis.enableSeasonalAnalysis &= false; break; case HC.xTypes.monthly: ops.analysis.enableMovingAverage &= false; ops.analysis.enableSeasonalAnalysis &= true; break; case HC.xTypes.weekly: ops.analysis.enableMovingAverage &= true; ops.analysis.enableSeasonalAnalysis &= true; break; case HC.xTypes.daily: ops.analysis.enableMovingAverage &= true; ops.analysis.enableSeasonalAnalysis &= true; break; default: ops.analysis.enableMovingAverage &= false; ops.analysis.enableSeasonalAnalysis &= false; break; } if(( ops.analysis.enableMovingAverage || ops.analysis.enableSeasonalAnalysis ) && !ops.chart.analysisContainer){ analysisContainer.appendTo(outerContainer); analysisTable.append( $('').append( $('').append(analysisSelect) ) ).appendTo(analysisContainer); ops.chart.analysisContainer = analysisContainer[0]; ops.chart.analysisSelect = analysisSelect[0]; // Create Analytical function links resetButton = $('').html('Reset').click(function(){ chart.resetSeries(true); }); applyButton = $('').html('Apply').click(function(){ var select = chart.options.chart.analysisSelect, option = select.options[select.selectedIndex], optionData = $(option).data(); chart.resetSeries(false); optionData.method.apply(chart, optionData.arguments); }); if( ops.analysis.enableMovingAverage || ops.analysis.enableSeasonalAnalysis ){ for(i in chart.series){ s = chart.series[i]; if(ops.analysis.enableMovingAverage) createMovingAverageOptions.call(chart, s, i); if(ops.analysis.enableSeasonalAnalysis) createSeasonalAnalysisOptions.call(chart, s, i); } if(analysisSelect.children().length > 0){ analysisSelect.change(function(){ if(analysisSelect.children(':selected').get(0).index ==0){ chart.resetSeries(true); } else { var select = chart.options.chart.analysisSelect, option = select.options[select.selectedIndex], optionData = $(option).data(); chart.resetSeries(false); optionData.method.apply(chart, optionData.arguments); } }); /*analysisTable.find('td') .append(applyButton) .append(resetButton);*/ /*$('').appendTo(analysisTable) .append( $('') .append(applyButton) .append(resetButton) );*/ } else analysisContainer.remove(); } } } Chart.prototype.callbacks.push(processAnalysis); }()); leafHandlerLoaded = true; $(leafHandler); } else{ var rootHandler = function($){ var gbtn, cbtn, navigatorPrefix; function trimNulls(data){ var i; var dataCopy = data.slice(0); for(i=data.length - 1; i>0; i--){ if(data[i][1] === null) dataCopy.pop(); else break; } for(i=0; i') .attr('id', 'hc_container') .css({ height : '600px', width : '800px', backgroundImage : 'url(/global/scripts/jQuery/tabs/loading.gif)', backgroundPosition : 'center', backgroundRepeat : 'no-repeat' }) .appendTo(cont), link = $('') .attr('href', '#hc_container') .attr('id', 'hc_link') .attr('title', 'Click and drag to zoom chart. Use the buttons in upper right of chart for high quality print-outs and downloads.') .appendTo(cont) .fancybox({ titlePosition : 'inside', titleFormat : function(title){ return '' + title + ''; }, autoResize : false // To sidestep issue with Highcharts in Fancybox 2 disappearing when the browser is resized -SNW }); }; function addButtons(){ // Clone the first th element and put the buttons in it var th = $('table.data1 > tbody > tr:eq(1) > th:eq(0)'); th = th.clone().empty().insertAfter(th); gbtn = $('').text('Graph').css('font-size', '90%').click(createChart).attr('disabled', true); cbtn = $('').text('Clear').css('font-size', '90%').click(clearCheckboxes).attr('disabled', true); gbtn.appendTo(th); cbtn.appendTo(th); }; function addCheckboxes(){ var buttonsAdded = false, processRows = $('tr.DataRow td.DataHist a').length > 0; if(processRows){ $('tr.DataRow').each( function(index, tr){ var cbtd, cb, td, tokens, a, href, apiKey; // JQueryify the tr element tr = $(tr); // Get the second td cbtd = tr.children(':eq(1)'); // Clone it cbtd = cbtd.clone().insertBefore(cbtd) .css('text-align', 'center'); // Find the history td td = tr.find('td.DataHist'); if(td && (a = td.children('a')).length > 0){ if(!buttonsAdded){ addButtons(); buttonsAdded = true; } // Get the sourcekey and frequency from the link // We use the html href instead of the jQuery attr('href') // to retrieve an absolute instead of relative link href = a.get(0).href; // Petroleum Navigator tokens = href.match(/s=(.*?)&f=(\w)/); navigatorPrefix = 'PET'; // Natural Gas Navigator if(tokens === null) { tokens = href.match(/([^\/]*?)([WwMmDd4Aa]).(htm|html)/); navigatorPrefix = 'NG'; } // put the checkbox into the checkbox td cbtd.empty(); //increase width to accomodate api keys $(cbtd).attr('width', 84); var seriesId = navigatorPrefix + '.' + tokens[1].toUpperCase() + '.' + tokens[2].toUpperCase(); apiKey = $('') .appendTo(cbtd) .data({ seriesId : seriesId }); cb = $('') .addClass('chartCheckBox') .appendTo(cbtd) // Store the source key and frequency .data({ srcKey : tokens[1].toUpperCase(), freq : tokens[2].toUpperCase(), link : href }); } } ); } }; function createChart(){ var srcKeys = [], srcLinks = {}, srcKey, freq; $('.chartCheckBox:checked').each(function(){ var cb = $(this); srcKey = cb.data('srcKey') srcKeys.push(srcKey); srcLinks[srcKey] = cb.data('link') freq = cb.data('freq'); }); if(srcKeys.length > 0){ $('#hc_container').empty(); $('#hc_link').click(); $.ajax({ type:'POST', url: '/global/includes/dnavs/get_series.php', dataType: 'json', data: { srcKeys : srcKeys.join(','), freq : freq }, success: function(result){ var keys = result.KEYS, axis = result.AXIS, baseAtZero = result.BASEATZERO, axisOpts = [], seriesOpts = [], units = [], seriesInfo; for(unit in axis){ units.push(unit); axisOpts.push({ title : { text : axis[unit] }, min : baseAtZero ? 0 : null, plotLines : [ Highcharts.eia_zero_axis_line ], opposite : axisOpts.length % 2 }) } var source_logo = Highcharts.logos.eia; var api_series_ids = []; for(key in keys){ seriesInfo = keys[key]; if(seriesInfo.SOURCE=="Thomson Reuters") source_logo = Highcharts.logos.reuters; seriesOpts.push({ name : seriesInfo.NAME + (axisOpts.length > 1 ? ' (' + keys[key].UNITSABBREV + ')' : ''), sourceKey : seriesInfo.KEY, sourceLink : srcLinks[key], data : trimNulls(Highcharts.map(seriesInfo.DATA, function(item, index){ var ds = String(item[0]), val = Number(item[1]), y = Number(ds.substring(0, 4)), m = Number(ds.substring(4, 6)) - 1; // Annual data has zero for the month m = m >= 0 ? m : 0; d = Number(ds.substring(6)); // Monthly / Annual data has a zero for the day d = d != 0 ? d : 1; return[Date.UTC(y, m, d), !isNaN(val) ? val : null]; })), yAxis : $.inArray(seriesInfo.UNITSABBREV.toUpperCase(), units) }); api_series_ids.push(navigatorPrefix + '.' + key + '.' + keys[key].FREQ); } chartOpts = { chart : { renderTo: 'hc_container', lineUpYAxisZeros : true, logo : seriesOpts.length > 1 ? Highcharts.logos.none : source_logo }, title : { text : $('.TopLabel2').text() }, xAxis : { type : 'datetime' }, yAxis : axisOpts, series : seriesOpts, exporting : { embedOptions : { series_id : api_series_ids.join(";") } } } var chart = new Highcharts.Chart(chartOpts); } }); } }; function clearCheckboxes(){ $('.chartCheckBox:checked').each(function(){ $(this).attr('checked', false); }); gbtn.attr('disabled', true); cbtn.attr('disabled', true); }; function addFootnote() { var dataTable = $($('tr.DataRow').parents('table').get(0)); var spacerTable = dataTable.next(); // add the footnote table after the spacer table var footnoteTable = $('
Click on the source key icon to learn how to download series into Excel, or to embed a chart or map on your website.
') .insertAfter(spacerTable); // add a second spacer table spacerTable.clone().insertAfter(footnoteTable); }; return function(){ addChartElements(); addCheckboxes(); addFootnote(); $('input.chartCheckBox').on('change', function(event) { if($('input.chartCheckBox:checked').length > 0) { gbtn.attr('disabled', false); cbtn.attr('disabled', false); } else { gbtn.attr('disabled', true); cbtn.attr('disabled', true); } }); }; }(jQuery); rootHandlerLoaded = true; $(rootHandler); } $.getScript('/global/survey/engine/js/survey_engine.js'); }());