Skip to content

Instantly share code, notes, and snippets.

@jrosenberg
Created December 5, 2010 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrosenberg/728723 to your computer and use it in GitHub Desktop.
Save jrosenberg/728723 to your computer and use it in GitHub Desktop.
Energy Flow Diagrams, 1949-2009

This Sankey diagram was created using the layout created by Brian Staats (http://groups.google.com/group/protovis/browse_thread/thread/a5a97d4bfc7a44bc/74d26723e289798e?#74d26723e289798e) -- thanks Brian!

It is based on the Lawrence Livermore National Labs energy flow charts, https://flowcharts.llnl.gov.

My version currently has a couple of bugs:

  1. My friend helped get it working in its current incarnation by adding in a check to see "if (vis == null)". He said it has to do with the fact that I'm using "getVal" for each value every time the slider moves and "updateDisplay" is called. This isn't done on the two other time-series JQuery examples I've been following, but I can't figure out how to change mine. Any suggestions? Here are those two examples:

http://jagger.me.berkeley.edu/~twheeler/classes/cs294-10/a4/statehood.html

http://vis.stanford.edu/protovis/ex/cartogram-full.html

  1. I'm not sure how to make it so that I can color each line individually. Really I need to code each flow with a specific color, since multiple flows might need the same color. You can see what I mean on the reference chart:

https://flowcharts.llnl.gov/

Smaller issues:

  1. 1949 is messed up -- not sure why.

  2. There is a buildup of labels in the upper-left corner of the chart.

  3. Some of the flow lines are wrong, but I've been stuck on these other issues.

Other things I'm hoping to add: Rollover highlighting and numbers, maybe the ability to remove data sets with check boxes, maybe conversions to other units, probably the US use in relation to the rest of the world (see http://www.sankey-diagrams.com/extended-llnl-sankey-diagram/).

Thanks for any help!

Joel

jrosenberg@berkeley.edu

var comm = [{"year":"1949","coal":"1,554,118","natGas":"359,992","petroleum":"736,198","hydro":"0","geotherm":"0","solar":"0","biomass":"19,986","elec":"200,104"},
{"year":"1950","coal":"1,541,548","natGas":"401,412","petroleum":"873,828","hydro":"0","geotherm":"0","solar":"0","biomass":"19,075","elec":"225,094"},
{"year":"1951","coal":"1,306,595","natGas":"480,560","petroleum":"934,228","hydro":"0","geotherm":"0","solar":"0","biomass":"18,198","elec":"252,360"},
{"year":"1952","coal":"1,169,140","natGas":"533,717","petroleum":"954,922","hydro":"0","geotherm":"0","solar":"0","biomass":"17,114","elec":"273,287"},
{"year":"1953","coal":"965,664","natGas":"549,223","petroleum":"983,920","hydro":"0","geotherm":"0","solar":"0","biomass":"15,738","elec":"296,928"},
{"year":"1954","coal":"824,598","natGas":"605,430","petroleum":"1,014,678","hydro":"0","geotherm":"0","solar":"0","biomass":"15,170","elec":"319,346"},
{"year":"1955","coal":"800,706","natGas":"651,242","petroleum":"1,097,050","hydro":"0","geotherm":"0","solar":"0","biomass":"14,706","elec":"349,891"},
{"year":"1956","coal":"714,627","natGas":"741,961","petroleum":"1,138,874","hydro":"0","geotherm":"0","solar":"0","biomass":"14,018","elec":"380,177"},
{"year":"1957","coal":"534,873","natGas":"803,073","petroleum":"1,100,699","hydro":"0","geotherm":"0","solar":"0","biomass":"13,330","elec":"410,679"},
{"year":"1958","coal":"500,532","natGas":"902,286","petroleum":"1,144,180","hydro":"0","geotherm":"0","solar":"0","biomass":"13,089","elec":"435,256"},
{"year":"1959","coal":"415,164","natGas":"1,009,236","petroleum":"1,216,137","hydro":"0","geotherm":"0","solar":"0","biomass":"12,298","elec":"487,860"},
{"year":"1960","coal":"406,723","natGas":"1,055,930","petroleum":"1,251,742","hydro":"0","geotherm":"0","solar":"0","biomass":"11,868","elec":"542,999"},
{"year":"1961","coal":"370,815","natGas":"1,114,539","petroleum":"1,272,267","hydro":"0","geotherm":"0","solar":"0","biomass":"11,146","elec":"572,042"},
{"year":"1962","coal":"361,908","natGas":"1,248,901","petroleum":"1,306,553","hydro":"0","geotherm":"0","solar":"0","biomass":"10,630","elec":"620,863"},
{"year":"1963","coal":"317,492","natGas":"1,307,084","petroleum":"1,290,848","hydro":"0","geotherm":"0","solar":"0","biomass":"10,165","elec":"687,563"},
{"year":"1964","coal":"274,245","natGas":"1,418,708","petroleum":"1,279,450","hydro":"0","geotherm":"0","solar":"0","biomass":"9,460","elec":"737,790"},
{"year":"1965","coal":"265,285","natGas":"1,489,845","petroleum":"1,417,604","hydro":"0","geotherm":"0","solar":"0","biomass":"8,858","elec":"788,603"},
{"year":"1966","coal":"263,123","natGas":"1,676,290","petroleum":"1,465,776","hydro":"0","geotherm":"0","solar":"0","biomass":"8,617","elec":"859,233"},
{"year":"1967","coal":"225,425","natGas":"2,021,657","petroleum":"1,512,346","hydro":"0","geotherm":"0","solar":"0","biomass":"8,325","elec":"925,178"},
{"year":"1968","coal":"207,688","natGas":"2,140,084","petroleum":"1,542,966","hydro":"0","geotherm":"0","solar":"0","biomass":"8,136","elec":"1,013,959"},
{"year":"1969","coal":"194,941","natGas":"2,323,055","petroleum":"1,558,261","hydro":"0","geotherm":"0","solar":"0","biomass":"7,860","elec":"1,107,733"},
{"year":"1970","coal":"164,513","natGas":"2,472,864","petroleum":"1,589,634","hydro":"0","geotherm":"0","solar":"0","biomass":"7,534","elec":"1,201,163"},
{"year":"1971","coal":"179,005","natGas":"2,586,755","petroleum":"1,548,394","hydro":"0","geotherm":"0","solar":"0","biomass":"7,190","elec":"1,288,009"},
{"year":"1972","coal":"153,479","natGas":"2,678,398","petroleum":"1,569,850","hydro":"0","geotherm":"0","solar":"0","biomass":"7,190","elec":"1,407,566"},
{"year":"1973","coal":"159,902","natGas":"2,648,978","petroleum":"1,603,764","hydro":"0","geotherm":"0","solar":"0","biomass":"6,708","elec":"1,516,653"},
{"year":"1974","coal":"174,517","natGas":"2,616,952","petroleum":"1,456,888","hydro":"0","geotherm":"0","solar":"0","biomass":"7,018","elec":"1,501,334"},
{"year":"1975","coal":"146,633","natGas":"2,558,459","petroleum":"1,341,945","hydro":"0","geotherm":"0","solar":"0","biomass":"8,067","elec":"1,597,826"},
{"year":"1976","coal":"144,168","natGas":"2,718,427","petroleum":"1,495,350","hydro":"0","geotherm":"0","solar":"0","biomass":"9,099","elec":"1,677,943"},
{"year":"1977","coal":"147,756","natGas":"2,548,308","petroleum":"1,546,205","hydro":"0","geotherm":"0","solar":"0","biomass":"10,286","elec":"1,753,866"},
{"year":"1978","coal":"164,529","natGas":"2,642,724","petroleum":"1,484,141","hydro":"0","geotherm":"0","solar":"0","biomass":"11,834","elec":"1,813,270"},
{"year":"1979","coal":"149,253","natGas":"2,836,108","petroleum":"1,362,799","hydro":"0","geotherm":"0","solar":"0","biomass":"13,812","elec":"1,854,121"},
{"year":"1980","coal":"114,903","natGas":"2,650,868","petroleum":"1,314,493","hydro":"0","geotherm":"0","solar":"0","biomass":"21,000","elec":"1,906,089"},
{"year":"1981","coal":"136,759","natGas":"2,557,340","petroleum":"1,117,521","hydro":"0","geotherm":"0","solar":"0","biomass":"21,050","elec":"2,033,239"},
{"year":"1982","coal":"155,216","natGas":"2,649,510","petroleum":"1,032,489","hydro":"0","geotherm":"0","solar":"0","biomass":"22,130","elec":"2,077,048"},
{"year":"1983","coal":"161,619","natGas":"2,486,430","petroleum":"1,164,385","hydro":"0","geotherm":"0","solar":"0","biomass":"22,277","elec":"2,116,437"},
{"year":"1984","coal":"168,936","natGas":"2,582,477","petroleum":"1,221,867","hydro":"0","geotherm":"0","solar":"0","biomass":"22,351","elec":"2,264,475"},
{"year":"1985","coal":"137,411","natGas":"2,487,744","petroleum":"1,076,850","hydro":"0","geotherm":"0","solar":"0","biomass":"24,374","elec":"2,351,282"},
{"year":"1986","coal":"135,475","natGas":"2,367,339","petroleum":"1,157,702","hydro":"0","geotherm":"0","solar":"0","biomass":"27,464","elec":"2,438,629"},
{"year":"1987","coal":"124,600","natGas":"2,489,053","petroleum":"1,126,234","hydro":"0","geotherm":"0","solar":"0","biomass":"29,542","elec":"2,538,756"},
{"year":"1988","coal":"131,088","natGas":"2,730,880","petroleum":"1,094,633","hydro":"0","geotherm":"0","solar":"0","biomass":"32,537","elec":"2,675,108"},
{"year":"1989","coal":"115,227","natGas":"2,784,801","petroleum":"1,036,404","hydro":"685","geotherm":"2,500","solar":"0","biomass":"98,986","elec":"2,766,640"},
{"year":"1990","coal":"124,456","natGas":"2,682,201","petroleum":"985,341","hydro":"1,432","geotherm":"2,800","solar":"0","biomass":"93,997","elec":"2,860,154"},
{"year":"1991","coal":"115,505","natGas":"2,795,401","petroleum":"928,417","hydro":"1,369","geotherm":"3,000","solar":"0","biomass":"95,366","elec":"2,918,092"},
{"year":"1992","coal":"116,570","natGas":"2,871,185","petroleum":"887,526","hydro":"1,266","geotherm":"3,200","solar":"0","biomass":"104,942","elec":"2,900,224"},
{"year":"1993","coal":"117,302","natGas":"2,923,260","petroleum":"812,039","hydro":"1,028","geotherm":"3,400","solar":"0","biomass":"109,185","elec":"3,018,755"},
{"year":"1994","coal":"118,119","natGas":"2,961,981","petroleum":"819,155","hydro":"957","geotherm":"4,200","solar":"0","biomass":"106,422","elec":"3,115,517"},
{"year":"1995","coal":"116,788","natGas":"3,095,988","petroleum":"763,259","hydro":"1,220","geotherm":"4,500","solar":"0","biomass":"112,717","elec":"3,252,036"},
{"year":"1996","coal":"121,613","natGas":"3,226,318","petroleum":"782,922","hydro":"1,300","geotherm":"5,300","solar":"0","biomass":"128,840","elec":"3,343,969"},
{"year":"1997","coal":"129,391","natGas":"3,285,320","petroleum":"735,612","hydro":"1,228","geotherm":"5,700","solar":"0","biomass":"131,284","elec":"3,502,848"},
{"year":"1998","coal":"93,436","natGas":"3,082,975","petroleum":"694,770","hydro":"1,228","geotherm":"7,100","solar":"0","biomass":"118,461","elec":"3,677,989"},
{"year":"1999","coal":"102,524","natGas":"3,115,031","petroleum":"699,129","hydro":"1,173","geotherm":"6,700","solar":"0","biomass":"120,748","elec":"3,766,238"},
{"year":"2000","coal":"91,895","natGas":"3,251,562","petroleum":"797,929","hydro":"1,018","geotherm":"7,600","solar":"0","biomass":"119,102","elec":"3,955,691"},
{"year":"2001","coal":"96,858","natGas":"3,097,263","petroleum":"781,331","hydro":"687","geotherm":"8,270","solar":"0","biomass":"91,661","elec":"4,062,047"},
{"year":"2002","coal":"89,820","natGas":"3,224,982","petroleum":"717,330","hydro":"130","geotherm":"8,753","solar":"0","biomass":"94,996","elec":"4,109,861"},
{"year":"2003","coal":"81,963","natGas":"3,260,916","petroleum":"818,934","hydro":"740","geotherm":"11,000","solar":"0","biomass":"101,287","elec":"4,090,059"},
{"year":"2004","coal":"102,904","natGas":"3,200,965","petroleum":"800,846","hydro":"1,052","geotherm":"12,000","solar":"0","biomass":"105,319","elec":"4,198,209"},
{"year":"2005","coal":"96,999","natGas":"3,073,213","petroleum":"754,030","hydro":"860","geotherm":"13,600","solar":"0","biomass":"104,778","elec":"4,350,570"},
{"year":"2006","coal":"64,789","natGas":"2,901,680","petroleum":"655,126","hydro":"927","geotherm":"14,000","solar":"0","biomass":"102,290","elec":"4,434,725"},
{"year":"2007","coal":"70,035","natGas":"3,094,061","petroleum":"641,661","hydro":"764","geotherm":"14,400","solar":"0","biomass":"102,355","elec":"4,559,507"},
{"year":"2008","coal":"69,059","natGas":"3,211,318","petroleum":"638,086","hydro":"591","geotherm":"14,800","solar":"1","biomass":"109,328","elec":"4,558,368"},
{"year":"2009","coal":"61,491","natGas":"3,187,309","petroleum":"599,975","hydro":"679","geotherm":"16,700","solar":"1","biomass":"108,063","elec":"4,514,039"}]
var elec = [{"year":"1949","coal":"1,995,055","natGas":"569,375","petroleum":"414,632","nuclear":"0","hydro":"1,349,185","geotherm":"0","solar":"0","wind":"0","biomass":"5,803","netImports":"5,420"},
{"year":"1950","coal":"2,199,111","natGas":"650,931","petroleum":"471,666","nuclear":"0","hydro":"1,346,015","geotherm":"0","solar":"0","wind":"0","biomass":"5,466","netImports":"6,094"},
{"year":"1951","coal":"2,506,808","natGas":"790,635","petroleum":"399,898","nuclear":"0","hydro":"1,360,698","geotherm":"0","solar":"0","wind":"0","biomass":"5,331","netImports":"7,461"},
{"year":"1952","coal":"2,557,397","natGas":"941,971","petroleum":"420,367","nuclear":"0","hydro":"1,404,274","geotherm":"0","solar":"0","wind":"0","biomass":"6,435","netImports":"7,740"},
{"year":"1953","coal":"2,777,361","natGas":"1,070,472","petroleum":"514,299","nuclear":"0","hydro":"1,356,353","geotherm":"0","solar":"0","wind":"0","biomass":"5,019","netImports":"6,852"},
{"year":"1954","coal":"2,840,759","natGas":"1,206,291","petroleum":"417,409","nuclear":"0","hydro":"1,304,094","geotherm":"0","solar":"0","wind":"0","biomass":"3,209","netImports":"7,983"},
{"year":"1955","coal":"3,458,271","natGas":"1,193,644","petroleum":"470,747","nuclear":"0","hydro":"1,321,695","geotherm":"0","solar":"0","wind":"0","biomass":"3,234","netImports":"13,879"},
{"year":"1956","coal":"3,789,674","natGas":"1,282,687","petroleum":"454,719","nuclear":"0","hydro":"1,397,960","geotherm":"0","solar":"0","wind":"0","biomass":"1,738","netImports":"15,519"},
{"year":"1957","coal":"3,855,246","natGas":"1,382,906","petroleum":"498,383","nuclear":"112","hydro":"1,480,092","geotherm":"0","solar":"0","wind":"0","biomass":"2,008","netImports":"12,288"},
{"year":"1958","coal":"3,721,340","natGas":"1,420,903","petroleum":"485,713","nuclear":"1,915","hydro":"1,554,805","geotherm":"0","solar":"0","wind":"0","biomass":"1,940","netImports":"11,320"},
{"year":"1959","coal":"4,029,357","natGas":"1,685,507","petroleum":"551,978","nuclear":"2,187","hydro":"1,511,462","geotherm":"0","solar":"0","wind":"0","biomass":"1,677","netImports":"12,127"},
{"year":"1960","coal":"4,227,551","natGas":"1,785,129","petroleum":"552,715","nuclear":"6,026","hydro":"1,569,167","geotherm":"774","solar":"0","wind":"0","biomass":"1,508","netImports":"15,474"},
{"year":"1961","coal":"4,354,953","natGas":"1,888,996","petroleum":"557,278","nuclear":"19,678","hydro":"1,620,627","geotherm":"2,181","solar":"0","wind":"0","biomass":"1,339","netImports":"7,689"},
{"year":"1962","coal":"4,622,376","natGas":"2,034,783","petroleum":"559,585","nuclear":"26,394","hydro":"1,780,151","geotherm":"2,331","solar":"0","wind":"0","biomass":"1,349","netImports":"1,829"},
{"year":"1963","coal":"5,050,213","natGas":"2,210,952","petroleum":"584,707","nuclear":"38,147","hydro":"1,737,441","geotherm":"3,726","solar":"0","wind":"0","biomass":"1,341","netImports":"334"},
{"year":"1964","coal":"5,379,553","natGas":"2,397,228","petroleum":"633,882","nuclear":"39,819","hydro":"1,852,542","geotherm":"4,520","solar":"0","wind":"0","biomass":"1,549","netImports":"6,671"},
{"year":"1965","coal":"5,821,061","natGas":"2,395,376","petroleum":"722,002","nuclear":"43,164","hydro":"2,026,320","geotherm":"4,197","solar":"0","wind":"0","biomass":"2,810","netImports":"-482"},
{"year":"1966","coal":"6,301,644","natGas":"2,696,077","petroleum":"883,230","nuclear":"64,158","hydro":"2,028,381","geotherm":"4,170","solar":"0","wind":"0","biomass":"3,478","netImports":"3,725"},
{"year":"1967","coal":"6,444,982","natGas":"2,834,236","petroleum":"1,010,541","nuclear":"88,456","hydro":"2,310,877","geotherm":"6,886","solar":"0","wind":"0","biomass":"3,293","netImports":"-1,020"},
{"year":"1968","coal":"6,993,639","natGas":"3,245,494","petroleum":"1,181,450","nuclear":"141,534","hydro":"2,313,457","geotherm":"9,416","solar":"0","wind":"0","biomass":"3,900","netImports":"-2,152"},
{"year":"1969","coal":"7,219,295","natGas":"3,595,759","petroleum":"1,571,294","nuclear":"153,722","hydro":"2,613,763","geotherm":"13,281","solar":"0","wind":"0","biomass":"3,342","netImports":"3,656"},
{"year":"1970","coal":"7,227,462","natGas":"4,053,747","petroleum":"2,117,337","nuclear":"239,347","hydro":"2,599,507","geotherm":"11,347","solar":"0","wind":"0","biomass":"3,740","netImports":"6,688"},
{"year":"1971","coal":"7,299,131","natGas":"4,099,275","petroleum":"2,494,999","nuclear":"412,939","hydro":"2,790,405","geotherm":"11,862","solar":"0","wind":"0","biomass":"3,261","netImports":"12,046"},
{"year":"1972","coal":"7,810,652","natGas":"4,084,289","petroleum":"3,097,087","nuclear":"583,752","hydro":"2,829,445","geotherm":"31,479","solar":"0","wind":"0","biomass":"3,431","netImports":"26,227"},
{"year":"1973","coal":"8,658,401","natGas":"3,748,016","petroleum":"3,514,815","nuclear":"910,177","hydro":"2,826,675","geotherm":"42,605","solar":"0","wind":"0","biomass":"3,411","netImports":"48,715"},
{"year":"1974","coal":"8,534,031","natGas":"3,519,184","petroleum":"3,365,031","nuclear":"1,272,083","hydro":"3,143,378","geotherm":"53,158","solar":"0","wind":"0","biomass":"2,613","netImports":"43,311"},
{"year":"1975","coal":"8,785,839","natGas":"3,239,769","petroleum":"3,165,675","nuclear":"1,899,798","hydro":"3,122,285","geotherm":"70,153","solar":"0","wind":"0","biomass":"1,989","netImports":"21,103"},
{"year":"1976","coal":"9,720,234","natGas":"3,151,728","petroleum":"3,477,133","nuclear":"2,111,121","hydro":"2,942,893","geotherm":"78,154","solar":"0","wind":"0","biomass":"2,764","netImports":"29,378"},
{"year":"1977","coal":"10,262,025","natGas":"3,283,745","petroleum":"3,900,624","nuclear":"2,701,762","hydro":"2,300,652","geotherm":"77,418","solar":"0","wind":"0","biomass":"5,018","netImports":"59,422"},
{"year":"1978","coal":"10,238,271","natGas":"3,296,767","petroleum":"3,986,863","nuclear":"3,024,126","hydro":"2,905,420","geotherm":"64,350","solar":"0","wind":"0","biomass":"3,498","netImports":"67,318"},
{"year":"1979","coal":"11,259,923","natGas":"3,612,691","petroleum":"3,283,366","nuclear":"2,775,827","hydro":"2,896,591","geotherm":"83,788","solar":"0","wind":"0","biomass":"5,156","netImports":"69,381"},
{"year":"1980","coal":"12,122,684","natGas":"3,778,114","petroleum":"2,633,561","nuclear":"2,739,169","hydro":"2,867,306","geotherm":"109,776","solar":"0","wind":"0","biomass":"4,500","netImports":"71,399"},
{"year":"1981","coal":"12,583,461","natGas":"3,730,441","petroleum":"2,201,663","nuclear":"3,007,589","hydro":"2,724,925","geotherm":"123,043","solar":"0","wind":"0","biomass":"3,845","netImports":"113,406"},
{"year":"1982","coal":"12,582,150","natGas":"3,311,941","petroleum":"1,567,653","nuclear":"3,131,148","hydro":"3,232,512","geotherm":"104,746","solar":"0","wind":"0","biomass":"3,355","netImports":"100,026"},
{"year":"1983","coal":"13,212,591","natGas":"2,972,356","petroleum":"1,543,683","nuclear":"3,202,549","hydro":"3,494,005","geotherm":"129,339","solar":"0","wind":"28","biomass":"3,983","netImports":"120,547"},
{"year":"1984","coal":"14,019,485","natGas":"3,198,572","petroleum":"1,286,116","nuclear":"3,552,531","hydro":"3,352,809","geotherm":"164,896","solar":"55","wind":"68","biomass":"9,249","netImports":"135,323"},
{"year":"1985","coal":"14,542,209","natGas":"3,134,505","petroleum":"1,090,459","nuclear":"4,075,563","hydro":"2,937,168","geotherm":"198,282","solar":"111","wind":"60","biomass":"14,447","netImports":"139,655"},
{"year":"1986","coal":"14,443,716","natGas":"2,670,290","petroleum":"1,451,843","nuclear":"4,380,109","hydro":"3,038,157","geotherm":"219,178","solar":"147","wind":"44","biomass":"12,292","netImports":"122,481"},
{"year":"1987","coal":"15,173,411","natGas":"2,915,915","petroleum":"1,256,859","nuclear":"4,753,933","hydro":"2,601,572","geotherm":"229,119","solar":"109","wind":"37","biomass":"15,389","netImports":"158,101"},
{"year":"1988","coal":"15,849,966","natGas":"2,692,620","petroleum":"1,563,425","nuclear":"5,586,968","hydro":"2,301,629","geotherm":"217,290","solar":"94","wind":"9","biomass":"17,285","netImports":"108,399"},
{"year":"19897","coal":"16,137,221","natGas":"3,172,568","petroleum":"1,703,091","nuclear":"5,602,161","hydro":"2,808,182","geotherm":"307,863","solar":"2,614","wind":"22,033","biomass":"231,530","netImports":"37,450"},
{"year":"1990","coal":"16,260,952","natGas":"3,308,538","petroleum":"1,289,433","nuclear":"6,104,350","hydro":"3,014,012","geotherm":"325,601","solar":"3,818","wind":"29,007","biomass":"316,506","netImports":"7,888"},
{"year":"1991","coal":"16,249,709","natGas":"3,377,359","petroleum":"1,198,261","nuclear":"6,422,132","hydro":"2,984,899","geotherm":"335,247","solar":"4,923","wind":"30,796","biomass":"354,353","netImports":"66,965"},
{"year":"1992","coal":"16,465,595","natGas":"3,511,502","petroleum":"990,707","nuclear":"6,479,206","hydro":"2,585,662","geotherm":"337,509","solar":"4,133","wind":"29,863","biomass":"402,457","netImports":"86,733"},
{"year":"1993","coal":"17,195,927","natGas":"3,537,501","petroleum":"1,123,789","nuclear":"6,410,499","hydro":"2,860,991","geotherm":"351,116","solar":"4,767","wind":"30,987","biomass":"414,619","netImports":"94,910"},
{"year":"1994","coal":"17,260,875","natGas":"3,977,299","petroleum":"1,058,783","nuclear":"6,693,877","hydro":"2,620,314","geotherm":"324,908","solar":"5,020","wind":"35,560","biomass":"433,890","netImports":"152,937"},
{"year":"1995","coal":"17,466,285","natGas":"4,301,971","petroleum":"754,597","nuclear":"7,075,436","hydro":"3,149,392","geotherm":"279,793","solar":"5,123","wind":"32,630","biomass":"421,664","netImports":"133,856"},
{"year":"1996","coal":"18,429,027","natGas":"3,862,449","petroleum":"817,356","nuclear":"7,086,674","hydro":"3,527,582","geotherm":"300,329","solar":"5,389","wind":"33,440","biomass":"438,273","netImports":"137,144"},
{"year":"1997","coal":"18,904,538","natGas":"4,125,512","petroleum":"926,801","nuclear":"6,596,992","hydro":"3,581,168","geotherm":"308,659","solar":"5,221","wind":"33,581","biomass":"445,973","netImports":"116,203"},
{"year":"1998","coal":"19,215,682","natGas":"4,674,900","petroleum":"1,306,235","nuclear":"7,067,809","hydro":"3,241,286","geotherm":"310,503","solar":"5,124","wind":"30,853","biomass":"444,495","netImports":"88,224"},
{"year":"1999","coal":"19,279,487","natGas":"4,902,148","petroleum":"1,211,350","nuclear":"7,610,256","hydro":"3,217,744","geotherm":"311,619","solar":"5,063","wind":"45,894","biomass":"453,224","netImports":"98,924"},
{"year":"2000","coal":"20,220,171","natGas":"5,293,433","petroleum":"1,144,320","nuclear":"7,862,349","hydro":"2,767,916","geotherm":"296,196","solar":"5,033","wind":"57,057","biomass":"452,754","netImports":"115,199"},
{"year":"2001","coal":"19,613,673","natGas":"5,458,101","petroleum":"1,276,552","nuclear":"8,028,853","hydro":"2,208,671","geotherm":"288,784","solar":"5,608","wind":"69,617","biomass":"337,136","netImports":"75,156"},
{"year":"2002","coal":"19,782,781","natGas":"5,766,795","petroleum":"961,313","nuclear":"8,145,429","hydro":"2,649,979","geotherm":"304,564","solar":"5,644","wind":"105,334","biomass":"379,973","netImports":"71,595"},
{"year":"2003","coal":"20,184,743","natGas":"5,246,249","petroleum":"1,204,985","nuclear":"7,958,858","hydro":"2,780,551","geotherm":"303,154","solar":"5,469","wind":"114,571","biomass":"397,170","netImports":"21,905"},
{"year":"2004","coal":"20,305,035","natGas":"5,594,924","petroleum":"1,212,374","nuclear":"8,221,985","hydro":"2,656,470","geotherm":"311,282","solar":"5,764","wind":"141,749","biomass":"388,066","netImports":"38,597"},
{"year":"2005","coal":"20,737,241","natGas":"6,014,544","petroleum":"1,234,529","nuclear":"8,160,810","hydro":"2,670,131","geotherm":"308,776","solar":"5,502","wind":"178,088","biomass":"405,695","netImports":"84,401"},
{"year":"2006","coal":"20,461,883","natGas":"6,375,123","petroleum":"648,065","nuclear":"8,215,414","hydro":"2,839,353","geotherm":"306,176","solar":"5,036","wind":"263,738","biomass":"412,482","netImports":"62,849"},
{"year":"2007","coal":"20,807,722","natGas":"7,005,227","petroleum":"657,128","nuclear":"8,455,364","hydro":"2,429,909","geotherm":"307,630","solar":"6,047","wind":"340,503","biomass":"423,447","netImports":"106,632"},
{"year":"2008","coal":"20,512,955","natGas":"6,828,858","petroleum":"467,707","nuclear":"8,427,297","hydro":"2,494,003","geotherm":"314,232","solar":"8,516","wind":"545,548","biomass":"435,274","netImports":"112,381"},
{"year":"2009","coal":"18,296,167","natGas":"7,038,575","petroleum":"389,846","nuclear":"8,349,279","hydro":"2,662,571","geotherm":"319,661","solar":"7,961","wind":"697,278","biomass":"425,842","netImports":"117,094"}]
var ind = [{"year":"1949","coal":"5,433,101","coalImports":"-6,671","natGas":"3,188,492","petroleum":"3,467,786","hydro":"75,537","geotherm":"0","biomass":"468,287","elec":"418,280"},
{"year":"1950","coal":"5,781,230","coalImports":"992","natGas":"3,545,775","petroleum":"3,951,448","hydro":"69,396","geotherm":"0","biomass":"532,237","elec":"499,785"},
{"year":"1951","coal":"6,202,033","coalImports":"-21,452","natGas":"4,051,750","petroleum":"4,269,714","hydro":"63,097","geotherm":"0","biomass":"552,928","elec":"566,965"},
{"year":"1952","coal":"5,516,614","coalImports":"-11,879","natGas":"4,180,739","petroleum":"4,363,110","hydro":"61,538","geotherm":"0","biomass":"551,656","elec":"600,947"},
{"year":"1953","coal":"5,931,042","coalImports":"-9,002","natGas":"4,304,080","petroleum":"4,479,891","hydro":"56,506","geotherm":"0","biomass":"565,897","elec":"677,685"},
{"year":"1954","coal":"4,729,559","coalImports":"-6,746","natGas":"4,319,248","petroleum":"4,631,718","hydro":"55,678","geotherm":"0","biomass":"576,200","elec":"711,282"},
{"year":"1955","coal":"5,619,559","coalImports":"-10,044","natGas":"4,700,929","petroleum":"5,110,972","hydro":"38,149","geotherm":"0","biomass":"631,137","elec":"887,033"},
{"year":"1956","coal":"5,666,866","coalImports":"-13,020","natGas":"4,873,967","petroleum":"5,336,377","hydro":"36,751","geotherm":"0","biomass":"661,409","elec":"975,653"},
{"year":"1957","coal":"5,535,641","coalImports":"-17,459","natGas":"5,107,288","petroleum":"5,235,445","hydro":"35,521","geotherm":"0","biomass":"616,431","elec":"1,003,093"},
{"year":"1958","coal":"4,532,752","coalImports":"-6,721","natGas":"5,207,612","petroleum":"5,407,533","hydro":"37,162","geotherm":"0","biomass":"619,647","elec":"977,708"},
{"year":"1959","coal":"4,412,743","coalImports":"-8,358","natGas":"5,646,563","petroleum":"5,739,027","hydro":"37,003","geotherm":"0","biomass":"691,973","elec":"1,075,239"},
{"year":"1960","coal":"4,543,268","coalImports":"-5,630","natGas":"5,973,307","petroleum":"5,747,449","hydro":"38,808","geotherm":"0","biomass":"679,864","elec":"1,106,859"},
{"year":"1961","coal":"4,345,141","coalImports":"-7,886","natGas":"6,169,756","petroleum":"5,754,855","hydro":"35,836","geotherm":"0","biomass":"695,413","elec":"1,149,250"},
{"year":"1962","coal":"4,384,545","coalImports":"-5,506","natGas":"6,450,960","petroleum":"5,995,639","hydro":"35,990","geotherm":"0","biomass":"728,179","elec":"1,227,821"},
{"year":"1963","coal":"4,589,849","coalImports":"-7,390","natGas":"6,748,069","petroleum":"6,226,679","hydro":"33,914","geotherm":"0","biomass":"774,843","elec":"1,287,790"},
{"year":"1964","coal":"4,914,603","coalImports":"-10,441","natGas":"7,113,920","petroleum":"6,547,914","hydro":"33,772","geotherm":"0","biomass":"826,735","elec":"1,382,027"},
{"year":"1965","coal":"5,126,507","coalImports":"-18,451","natGas":"7,339,214","petroleum":"6,788,942","hydro":"32,757","geotherm":"0","biomass":"854,943","elec":"1,462,817"},
{"year":"1966","coal":"5,214,973","coalImports":"-24,949","natGas":"7,795,123","petroleum":"7,109,514","hydro":"33,138","geotherm":"0","biomass":"901,916","elec":"1,581,815"},
{"year":"1967","coal":"4,933,631","coalImports":"-15,326","natGas":"8,043,389","petroleum":"7,120,489","hydro":"35,787","geotherm":"0","biomass":"894,658","elec":"1,654,872"},
{"year":"1968","coal":"4,854,763","coalImports":"-17,310","natGas":"8,626,478","petroleum":"7,391,018","hydro":"35,172","geotherm":"0","biomass":"981,948","elec":"1,778,105"},
{"year":"1969","coal":"4,712,038","coalImports":"-36,109","natGas":"9,233,790","petroleum":"7,695,551","hydro":"34,220","geotherm":"0","biomass":"1,014,232","elec":"1,908,623"},
{"year":"1970","coal":"4,656,202","coalImports":"-57,660","natGas":"9,536,150","petroleum":"7,787,190","hydro":"34,040","geotherm":"0","biomass":"1,018,911","elec":"1,947,755"},
{"year":"1971","coal":"3,943,900","coalImports":"-33,108","natGas":"9,891,596","petroleum":"7,856,223","hydro":"33,746","geotherm":"0","biomass":"1,039,998","elec":"2,011,197"},
{"year":"1972","coal":"3,993,412","coalImports":"-25,966","natGas":"9,884,277","petroleum":"8,533,677","hydro":"34,420","geotherm":"0","biomass":"1,112,668","elec":"2,187,017"},
{"year":"1973","coal":"4,056,731","coalImports":"-7,465","natGas":"10,388,282","petroleum":"9,103,687","hydro":"34,773","geotherm":"0","biomass":"1,164,853","elec":"2,340,923"},
{"year":"1974","coal":"3,870,195","coalImports":"56,098","natGas":"10,003,628","petroleum":"8,694,133","hydro":"33,202","geotherm":"0","biomass":"1,159,074","elec":"2,336,794"},
{"year":"1975","coal":"3,666,883","coalImports":"13,541","natGas":"8,531,835","petroleum":"8,146,363","hydro":"32,321","geotherm":"0","biomass":"1,063,270","elec":"2,346,363"},
{"year":"1976","coal":"3,660,519","coalImports":"-99","natGas":"8,761,571","petroleum":"9,010,133","hydro":"33,372","geotherm":"0","biomass":"1,219,876","elec":"2,572,883"},
{"year":"1977","coal":"3,454,372","coalImports":"14,582","natGas":"8,635,448","petroleum":"9,774,446","hydro":"32,601","geotherm":"0","biomass":"1,281,245","elec":"2,681,959"},
{"year":"1978","coal":"3,313,502","coalImports":"124,719","natGas":"8,539,025","petroleum":"9,867,257","hydro":"31,563","geotherm":"0","biomass":"1,400,424","elec":"2,760,574"},
{"year":"1979","coal":"3,592,916","coalImports":"62,843","natGas":"8,549,111","petroleum":"10,567,674","hydro":"34,094","geotherm":"0","biomass":"1,404,862","elec":"2,872,573"},
{"year":"1980","coal":"3,155,014","coalImports":"-35,018","natGas":"8,332,531","petroleum":"9,524,922","hydro":"32,838","geotherm":"0","biomass":"1,600,000","elec":"2,781,009"},
{"year":"1981","coal":"3,156,925","coalImports":"-15,946","natGas":"8,184,540","petroleum":"8,284,869","hydro":"33,043","geotherm":"0","biomass":"1,694,665","elec":"2,817,437"},
{"year":"1982","coal":"2,551,983","coalImports":"-21,650","natGas":"7,067,856","petroleum":"7,794,543","hydro":"33,046","geotherm":"0","biomass":"1,649,682","elec":"2,541,766"},
{"year":"1983","coal":"2,489,563","coalImports":"-15,624","natGas":"6,776,273","petroleum":"7,419,523","hydro":"33,255","geotherm":"0","biomass":"1,874,435","elec":"2,647,710"},
{"year":"1984","coal":"2,842,174","coalImports":"-11,482","natGas":"7,404,995","petroleum":"8,009,844","hydro":"33,002","geotherm":"0","biomass":"1,918,254","elec":"2,858,697"},
{"year":"1985","coal":"2,759,927","coalImports":"-13,491","natGas":"7,031,597","petroleum":"7,738,197","hydro":"33,024","geotherm":"0","biomass":"1,917,674","elec":"2,855,066"},
{"year":"1986","coal":"2,640,504","coalImports":"-16,740","natGas":"6,646,262","petroleum":"7,879,710","hydro":"33,021","geotherm":"0","biomass":"1,914,902","elec":"2,833,770"},
{"year":"1987","coal":"2,672,911","coalImports":"8,630","natGas":"7,282,837","petroleum":"8,064,729","hydro":"32,936","geotherm":"0","biomass":"1,913,882","elec":"2,928,291"},
{"year":"1988","coal":"2,827,555","coalImports":"39,556","natGas":"7,655,459","petroleum":"8,338,922","hydro":"32,635","geotherm":"0","biomass":"1,989,103","elec":"3,058,852"},
{"year":"1989","coal":"2,787,002","coalImports":"30,405","natGas":"8,087,553","petroleum":"8,120,338","hydro":"28,396","geotherm":"1,800","biomass":"1,840,752","elec":"3,158,347"},
{"year":"1990","coal":"2,756,008","coalImports":"4,786","natGas":"8,451,066","petroleum":"8,278,311","hydro":"30,947","geotherm":"1,900","biomass":"1,684,187","elec":"3,226,120"},
{"year":"1991","coal":"2,600,840","coalImports":"9,697","natGas":"8,572,317","petroleum":"7,986,531","hydro":"29,675","geotherm":"2,100","biomass":"1,651,985","elec":"3,229,743"},
{"year":"1992","coal":"2,514,821","coalImports":"34,621","natGas":"8,917,798","petroleum":"8,580,863","hydro":"30,508","geotherm":"2,200","biomass":"1,704,534","elec":"3,318,900"},
{"year":"1993","coal":"2,496,288","coalImports":"27,106","natGas":"9,070,486","petroleum":"8,416,875","hydro":"29,593","geotherm":"2,400","biomass":"1,740,709","elec":"3,334,084"},
{"year":"1994","coal":"2,509,686","coalImports":"58,330","natGas":"9,126,046","petroleum":"8,799,130","hydro":"62,186","geotherm":"2,800","biomass":"1,862,384","elec":"3,439,232"},
{"year":"1995","coal":"2,488,267","coalImports":"61,058","natGas":"9,591,824","petroleum":"8,612,754","hydro":"54,695","geotherm":"3,000","biomass":"1,934,273","elec":"3,455,310"},
{"year":"1996","coal":"2,434,394","coalImports":"22,816","natGas":"9,900,567","petroleum":"9,052,006","hydro":"60,773","geotherm":"2,900","biomass":"1,969,033","elec":"3,526,750"},
{"year":"1997","coal":"2,395,064","coalImports":"46,450","natGas":"9,932,937","petroleum":"9,288,590","hydro":"58,062","geotherm":"3,100","biomass":"1,995,999","elec":"3,542,328"},
{"year":"1998","coal":"2,335,259","coalImports":"67,084","natGas":"9,763,364","petroleum":"9,114,094","hydro":"54,539","geotherm":"3,000","biomass":"1,871,691","elec":"3,586,705"},
{"year":"1999","coal":"2,226,783","coalImports":"57,685","natGas":"9,375,302","petroleum":"9,394,662","hydro":"48,658","geotherm":"4,100","biomass":"1,881,524","elec":"3,610,635"},
{"year":"2000","coal":"2,256,498","coalImports":"65,348","natGas":"9,499,885","petroleum":"9,119,032","hydro":"42,183","geotherm":"4,400","biomass":"1,881,486","elec":"3,631,185"},
{"year":"2001","coal":"2,191,638","coalImports":"29,264","natGas":"8,676,343","petroleum":"9,217,373","hydro":"32,500","geotherm":"4,760","biomass":"1,681,427","elec":"3,400,431"},
{"year":"2002","coal":"2,019,358","coalImports":"60,760","natGas":"8,845,493","petroleum":"9,209,266","hydro":"38,908","geotherm":"4,787","biomass":"1,675,980","elec":"3,378,691"},
{"year":"2003","coal":"2,041,412","coalImports":"50,518","natGas":"8,488,339","petroleum":"9,231,981","hydro":"43,242","geotherm":"3,400","biomass":"1,678,865","elec":"3,454,218"},
{"year":"2004","coal":"2,046,877","coalImports":"137,739","natGas":"8,535,934","petroleum":"9,864,015","hydro":"32,556","geotherm":"3,800","biomass":"1,816,565","elec":"3,472,903"},
{"year":"2005","coal":"1,954,042","coalImports":"44,194","natGas":"7,903,408","petroleum":"9,673,266","hydro":"31,951","geotherm":"4,300","biomass":"1,836,924","elec":"3,477,360"},
{"year":"2006","coal":"1,914,466","coalImports":"60,810","natGas":"7,846,224","petroleum":"9,805,482","hydro":"28,756","geotherm":"4,400","biomass":"1,896,634","elec":"3,450,547"},
{"year":"2007","coal":"1,864,612","coalImports":"25,197","natGas":"8,090,315","petroleum":"9,485,958","hydro":"15,715","geotherm":"4,700","biomass":"1,943,987","elec":"3,506,963"},
{"year":"2008","coal":"1,795,585","coalImports":"40,771","natGas":"8,067,148","petroleum":"8,546,661","hydro":"16,514","geotherm":"5,000","biomass":"2,031,192","elec":"3,443,733"},
{"year":"2009","coal":"1,396,482","coalImports":"-23,808","natGas":"7,584,317","petroleum":"7,774,885","hydro":"18,328","geotherm":"4,200","biomass":"1,996,721","elec":"3,009,054"}]
<html>
<head>
<title>Sankey Diagram</title>
<script type="text/javascript" src="http://vis.stanford.edu/protovis/protovis-d3.2.js"></script>
<script type="text/javascript" src="Sankey.js"></script>
<script type="text/javascript" src="comm.js"></script>
<script type="text/javascript" src="elec.js"></script>
<script type="text/javascript" src="ind.js"></script>
<script type="text/javascript" src="res.js"></script>
<script type="text/javascript" src="trans.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" rel="stylesheet" />
<style type="text/css">
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.js"></script>
<!-- <script type="text/javascript" src="jquery/jquery.ui.core.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.widget.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.slider.js"></script>
-->
<!-- This is the javascript initialization for the slider, run when the page loads
see http://jqueryui.com/demos/slider/ for more info
-->
<script type="text/javascript+protovis">
$(function() {
$("#slider").slider({
value:1952,
min: 1949,
max: 2009,
step: 1,
slide: function(event, ui) {
$("#year").val(ui.value);
console.log(ui.value);
//myYear = ui.value;
//alert ("value: " + ui.value);
//alert ("myYear: " + myYear);
//vis.render();
updateDisplay(ui.value);
}
});
// set everything back to value after refreshing
// sets year's value to slider's value
$("#year").val($("#slider").slider("value"));
});
</script>
</head>
<body>
<div id="container">
<h1>Pick a year to see where our power came from and where it went</h1>
<!-- Step 1: Call The Slider -->
<div id="slider"></div>
<!-- Step 2: Write Input Field -->
<p>
<label for="year">Year:</label>
<input type="text" id="year" style="border:0; color:#f6931f; font-weight:bold;" />
</p>
</div>
<script type="text/javascript+protovis">
// For now it's just for 2009, but can be put into a function
//function whatever(myYear) {}
var myYear = year.value;
var vis;
///////////////////////////////////
// This function is from Dan Bluestein (aka getMyAwesomeValue)
// Takes in a year, a table (category), and a column in "quotes"
// NOTE: This usage simulates an "associative array" --
// http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)
// Returns a scaled integer
///////////////////////////////////
function getVal(myYear, category, column) {
// defines and sets val equal to e.g. for 1949 -> elec[0]["natGas"]
var val = category[myYear-1949][column];
// str_replace (string replace) to replace commas with nothing
var valNoCommas = val.replace(/,/g,'');
// then parseInt on return value of that (wrap it around other function call)
var valInteger = parseInt(valNoCommas);
// scale it down by 600,000
var valScaled = valInteger / 600000
return valScaled;
}
///////////////////////////////////
//
///////////////////////////////////
function updateDisplay(myYear) {
//alert ("myYear: " + myYear);
var a = getVal(myYear,res,"solar"); // resSolar;
var b = getVal(myYear,elec,"solar"); // elecSolar;
var c = getVal(myYear,elec,"nuclear"); // elecNuclear;
// hydro
var d = getVal(myYear,elec,"hydro"); // elecHydro;
var e = getVal(myYear,ind,"hydro"); // indHydro;
var f = getVal(myYear,comm,"hydro"); // commHydro;
// wind
var g = getVal(myYear,elec,"wind"); // elecWind;
// geothermal
var h = getVal(myYear,elec,"geotherm"); // elecGeotherm;
var i = getVal(myYear,res,"geotherm"); // resGeotherm;
var j = getVal(myYear,comm,"geotherm"); // commGeotherm;
var k = getVal(myYear,ind,"geotherm"); // indGeotherm;
// natural gas
var l = getVal(myYear,trans,"natGas"); // transNatGas;
var m = getVal(myYear,ind,"natGas"); // indNatGas;
var n = getVal(myYear,comm,"natGas"); // commNatGas;
var o = getVal(myYear,elec,"natGas"); // elecNatGas;
var p = getVal(myYear,res,"natGas"); // resNatGas;
// coal
var q = getVal(myYear,elec,"coal"); // elecCoal;
var r = getVal(myYear,res,"coal"); // resCoal;
var s = getVal(myYear,comm,"coal"); // commCoal;
var t = getVal(myYear,ind,"coal"); // indCoal;
// biomass
var u = getVal(myYear,elec,"biomass"); // elecBiomass;
var v = getVal(myYear,res,"biomass"); // resBiomass;
var w = getVal(myYear,comm,"biomass"); // commBiomass;
var x = getVal(myYear,ind,"biomass"); // indBiomass;
var y = getVal(myYear,trans,"biomass"); // transBiomass;
// petroleum
var z = getVal(myYear,elec,"petroleum"); // elecPetroleum;
var aa = getVal(myYear,res,"petroleum"); // resPetroleum;
var bb = getVal(myYear,comm,"petroleum"); // commPetroleum;
var cc = getVal(myYear,ind,"petroleum"); // indPetroleum;
var dd = getVal(myYear,trans,"petroleum"); // transPetroleum;
// electricity
var ff = getVal(myYear,trans,"elec") // transElec;
var gg = getVal(myYear,ind,"elec") // indElec;
var hh = getVal(myYear,comm,"elec") // commElec;
var ii = getVal(myYear,res,"elec") // resElec;
var nn = getVal(myYear,elec,"netImports"); // elecImport;
var ee = ii + hh + gg + ff - nn;
// resElec + commElec + indElec + transElec - elecImport;
// total inputs
var resIn = ii + a + i + p + r + v + aa;
// resElec + resSolar + resGeotherm + resNatGas + resCoal + resBiomass + resPetroleum;
// ii + a + i + p + r + v + aa;
var commIn = hh + f + j + n + s + w + bb;
// commElec + commHydro + commGeotherm + commNatGas + commCoal + commBiomass + commPetroleum;
// hh + f + j + n + s + w + bb;
var indIn = gg + e + k + m + t + x + cc;
// indElec + indHydro + indGeotherm + indNatGas + indCoal + indBiomass + indPetroleum;
// gg + e + k + m + t + x + cc;
var transIn = ff + l + y + dd;
// transElec + transNatGas + transBiomass + transPetroleum;
// ff + l + y + dd;
// partial outputs
var jj = 0.8 * resIn; // 80% efficient residential
var kk = 0.8 * commIn; // 80% efficient commercial
var ll = 0.8 * indIn; // 80% efficient industry
var mm = 0.25 * transIn; // 25% efficient transporatation
var oo = b + c + d + g + h + o + q + u + z - nn - ff - gg - hh - ii;
// elecSolar + elecNuclear + elecHydro + elecWind + elecGeotherm + elecNatGas + elecCoal + elecBiomass + elecPetroleum
// - elecImport - transElec - indElec - commElec - resElec;
var pp = 0.2 * resIn;
var qq = 0.2 * commIn;
var rr = 0.2 * indIn;
var ss = 0.75 * transIn;
var graph = {
nodes:[
{nodeName:"0 Solar"},
{nodeName:"1 Nuclear"},
{nodeName:"2 Hydro"},
{nodeName:"3 Wind"},
{nodeName:"4 Geothermal"},
{nodeName:"5 Natural Gas"},
{nodeName:"6 Coal"},
{nodeName:"7 Biomass"},
{nodeName:"8 Petroleum"},
{nodeName:"9 Electricity Generation"},
{nodeName:"10 Residential"},
{nodeName:"11 Commercial"},
{nodeName:"12 Industrial"},
{nodeName:"13 Transportation"},
{nodeName:"14 Rejected Energy"},
{nodeName:"15 Energy Services"},
],
links:[
// these set up the overall structure of the graph
// there might be a better way than this -- these will be ghosts
{flow:[0,9,10,14], value:0},
{flow:[0,9,10,15], value:0},
{flow:[0,9,11,15], value:0},
{flow:[0,9,12,14], value:0},
{flow:[0,9,13,15], value:0},
// sources to 9 electrical
{flow:[0,9], value:b}, // 0 solar
{flow:[1,9], value:c}, // 1 nuclear
{flow:[2,9], value:d}, // 2 hydro
{flow:[3,9], value:g}, // 3 wind
{flow:[4,9], value:h}, // 4 geothermal
{flow:[5,9], value:o}, // 5 natural gas
{flow:[6,9], value:q}, // 6 coal
{flow:[7,9], value:u}, // 7 biomass
{flow:[8,9], value:z}, // 8 petroleum
// sources to 10 residential
{flow:[0,10], value:a}, // 0 solar
{flow:[4,10], value:i}, // 4 geothermal
{flow:[5,10], value:p}, // 5 natural gas
{flow:[7,10], value:v}, // 7 biomass
{flow:[8,10], value:aa}, // 8 petroleum
{flow:[9,10], value:ii}, // 9 electricity
// sources to 11 commercial
{flow:[4,11], value:j}, // 4 geothermal
{flow:[5,11], value:n}, // 5 natural gas
{flow:[7,11], value:w}, // 7 biomass
{flow:[8,11], value:bb}, // 8 petroleum
{flow:[9,11], value:gg}, // 9 electricity
// sources to 12 industrial
{flow:[2,12], value:e}, // 2 hydro
{flow:[5,12], value:m}, // 5 natural gas
{flow:[6,12], value:t}, // 6 coal
{flow:[7,12], value:x}, // 7 biomass
{flow:[8,12], value:cc}, // 8 petroleum
// sources to 13 transportation
{flow:[5,13], value:l}, // 5 natural gas
{flow:[7,13], value:y}, // 7 biomass
{flow:[8,13], value:dd}, // 8 petroleum
// 9 electricity to sectors
{flow:[9,10], value:ii}, // to 10 residential
{flow:[9,11], value:hh}, // to 11 commercial
{flow:[9,12], value:gg}, // to 12 industrial
{flow:[9,13], value:ff}, // to 13 transportation
// sectors to 14 rejected
{flow:[9,14], value:oo}, // 9 electricity
{flow:[10,14], value:pp}, // 10 residential
{flow:[11,14], value:qq}, // 11 commercial
{flow:[12,14], value:rr}, // 12 industrial
{flow:[13,14], value:ss}, // 13 transporation
// sectors to 15 useful
{flow:[10,15], value:jj}, // 10 residential
{flow:[11,15], value:kk}, // 11 commercial
{flow:[12,15], value:ll}, // 12 industrial
{flow:[13,15], value:mm} // 13 transportation
]
};
var h = 400,
w = 600;
if ( vis == null ) {
vis = new pv.Panel()
.width(w)
.height(h)
.top(10)
.left(50)
.right(100)
.bottom(50);
}
var layout = vis.add(pv.Panel)
.add(pv.Layout.Sankey)
.orient('left')
.curve(0.2)
.center(true)
.nodes(graph.nodes)
.flow(graph.links);
layout.link.add(pv.Line) // SPECIAL FIELD: link
.strokeStyle(pv.Colors.category10());
layout.label.add(pv.Label) // SPECIAL FIELD: label
.textAlign(function(d) d.depth==0 ? 'right' : d.depth==1 ? 'left' : 'center');
vis.render();
}
updateDisplay(myYear);
</script>
</body>
</html>
var res = [{"year":"1949","coal":"1,271,551","natGas":"1,027,283","petroleum":"1,111,771","geotherm":"0","solar":"0","biomass":"1,055,186","elec":"227,894"},
{"year":"1950","coal":"1,261,267","natGas":"1,240,312","petroleum":"1,328,886","geotherm":"0","solar":"0","biomass":"1,005,529","elec":"246,348"},
{"year":"1951","coal":"1,158,679","natGas":"1,526,340","petroleum":"1,468,377","geotherm":"0","solar":"0","biomass":"958,212","elec":"283,513"},
{"year":"1952","coal":"1,079,206","natGas":"1,678,735","petroleum":"1,508,547","geotherm":"0","solar":"0","biomass":"899,164","elec":"319,175"},
{"year":"1953","coal":"965,664","natGas":"1,744,496","petroleum":"1,518,568","geotherm":"0","solar":"0","biomass":"831,947","elec":"355,347"},
{"year":"1954","coal":"858,255","natGas":"1,960,547","petroleum":"1,652,403","geotherm":"0","solar":"0","biomass":"799,748","elec":"396,571"},
{"year":"1955","coal":"867,431","natGas":"2,198,290","petroleum":"1,776,245","geotherm":"0","solar":"0","biomass":"775,066","elec":"438,103"},
{"year":"1956","coal":"838,910","natGas":"2,409,029","petroleum":"1,862,616","geotherm":"0","solar":"0","biomass":"738,706","elec":"489,542"},
{"year":"1957","coal":"653,734","natGas":"2,587,778","petroleum":"1,810,671","geotherm":"0","solar":"0","biomass":"701,812","elec":"534,740"},
{"year":"1958","coal":"663,496","natGas":"2,809,250","petroleum":"1,975,019","geotherm":"0","solar":"0","biomass":"688,447","elec":"578,308"},
{"year":"1959","coal":"573,321","natGas":"3,014,542","petroleum":"1,966,473","geotherm":"0","solar":"0","biomass":"646,926","elec":"629,664"},
{"year":"1960","coal":"585,284","natGas":"3,211,778","petroleum":"2,241,048","geotherm":"0","solar":"0","biomass":"626,630","elec":"687,393"},
{"year":"1961","coal":"533,611","natGas":"3,362,278","petroleum":"2,307,068","geotherm":"0","solar":"0","biomass":"586,864","elec":"731,686"},
{"year":"1962","coal":"520,794","natGas":"3,600,313","petroleum":"2,414,039","geotherm":"0","solar":"0","biomass":"560,084","elec":"794,320"},
{"year":"1963","coal":"438,442","natGas":"3,700,281","petroleum":"2,430,769","geotherm":"0","solar":"0","biomass":"536,967","elec":"855,568"},
{"year":"1964","coal":"378,720","natGas":"3,908,485","petroleum":"2,342,415","geotherm":"0","solar":"0","biomass":"499,058","elec":"927,525"},
{"year":"1965","coal":"351,657","natGas":"4,027,692","petroleum":"2,449,499","geotherm":"0","solar":"0","biomass":"468,150","elec":"992,935"},
{"year":"1966","coal":"348,790","natGas":"4,274,822","petroleum":"2,440,611","geotherm":"0","solar":"0","biomass":"454,974","elec":"1,081,223"},
{"year":"1967","coal":"298,819","natGas":"4,451,330","petroleum":"2,527,475","geotherm":"0","solar":"0","biomass":"433,973","elec":"1,160,469"},
{"year":"1968","coal":"264,330","natGas":"4,588,315","petroleum":"2,652,296","geotherm":"0","solar":"0","biomass":"425,511","elec":"1,301,916"},
{"year":"1969","coal":"248,107","natGas":"4,874,858","petroleum":"2,700,289","geotherm":"0","solar":"0","biomass":"415,053","elec":"1,456,024"},
{"year":"1970","coal":"209,380","natGas":"4,987,392","petroleum":"2,716,706","geotherm":"0","solar":"0","biomass":"400,777","elec":"1,590,983"},
{"year":"1971","coal":"171,986","natGas":"5,125,812","petroleum":"2,738,502","geotherm":"0","solar":"0","biomass":"381,874","elec":"1,704,403"},
{"year":"1972","coal":"115,782","natGas":"5,264,384","petroleum":"2,855,549","geotherm":"0","solar":"0","biomass":"379,776","elec":"1,837,735"},
{"year":"1973","coal":"93,911","natGas":"4,976,975","petroleum":"2,786,956","geotherm":"0","solar":"0","biomass":"354,096","elec":"1,976,337"},
{"year":"1974","coal":"82,126","natGas":"4,900,995","petroleum":"2,539,297","geotherm":"0","solar":"0","biomass":"370,952","elec":"1,972,763"},
{"year":"1975","coal":"62,843","natGas":"5,022,606","petroleum":"2,462,632","geotherm":"0","solar":"0","biomass":"425,408","elec":"2,006,735"},
{"year":"1976","coal":"58,885","natGas":"5,147,336","petroleum":"2,685,940","geotherm":"0","solar":"0","biomass":"481,634","elec":"2,069,215"},
{"year":"1977","coal":"57,461","natGas":"4,913,093","petroleum":"2,659,741","geotherm":"0","solar":"0","biomass":"541,783","elec":"2,201,555"},
{"year":"1978","coal":"49,145","natGas":"4,981,454","petroleum":"2,585,556","geotherm":"0","solar":"0","biomass":"621,849","elec":"2,301,278"},
{"year":"1979","coal":"37,313","natGas":"5,054,742","petroleum":"2,084,955","geotherm":"0","solar":"0","biomass":"728,076","elec":"2,329,778"},
{"year":"1980","coal":"30,544","natGas":"4,824,836","petroleum":"1,720,880","geotherm":"0","solar":"0","biomass":"850,000","elec":"2,448,093"},
{"year":"1981","coal":"30,020","natGas":"4,614,199","petroleum":"1,516,042","geotherm":"0","solar":"0","biomass":"870,000","elec":"2,464,368"},
{"year":"1982","coal":"31,791","natGas":"4,711,251","petroleum":"1,416,918","geotherm":"0","solar":"0","biomass":"970,000","elec":"2,489,121"},
{"year":"1983","coal":"30,785","natGas":"4,477,633","petroleum":"1,333,520","geotherm":"0","solar":"0","biomass":"970,000","elec":"2,562,235"},
{"year":"1984","coal":"39,627","natGas":"4,660,558","petroleum":"1,513,426","geotherm":"0","solar":"0","biomass":"980,000","elec":"2,661,673"},
{"year":"1985","coal":"38,757","natGas":"4,534,282","petroleum":"1,546,091","geotherm":"0","solar":"0","biomass":"1,010,000","elec":"2,708,902"},
{"year":"1986","coal":"40,467","natGas":"4,405,156","petroleum":"1,524,840","geotherm":"0","solar":"0","biomass":"920,000","elec":"2,794,729"},
{"year":"1987","coal":"37,218","natGas":"4,419,575","petroleum":"1,600,790","geotherm":"0","solar":"0","biomass":"850,000","elec":"2,901,600"},
{"year":"1988","coal":"36,973","natGas":"4,735,083","petroleum":"1,658,366","geotherm":"0","solar":"0","biomass":"910,000","elec":"3,046,459"},
{"year":"1989","coal":"30,630","natGas":"4,898,635","petroleum":"1,644,980","geotherm":"5,000","solar":"52,677","biomass":"920,000","elec":"3,089,650"},
{"year":"1990","coal":"31,114","natGas":"4,490,914","petroleum":"1,374,806","geotherm":"5,500","solar":"55,900","biomass":"580,000","elec":"3,152,752"},
{"year":"1991","coal":"25,355","natGas":"4,667,223","petroleum":"1,358,967","geotherm":"5,900","solar":"57,765","biomass":"610,000","elec":"3,259,884"},
{"year":"1992","coal":"25,589","natGas":"4,804,582","petroleum":"1,393,660","geotherm":"6,400","solar":"59,753","biomass":"640,000","elec":"3,193,423"},
{"year":"1993","coal":"25,749","natGas":"5,063,298","petroleum":"1,415,631","geotherm":"6,800","solar":"61,691","biomass":"550,000","elec":"3,394,192"},
{"year":"1994","coal":"20,845","natGas":"4,959,839","petroleum":"1,388,297","geotherm":"6,200","solar":"63,528","biomass":"520,000","elec":"3,440,939"},
{"year":"1995","coal":"17,451","natGas":"4,954,189","petroleum":"1,351,936","geotherm":"6,600","solar":"64,734","biomass":"520,000","elec":"3,557,015"},
{"year":"1996","coal":"16,584","natGas":"5,354,389","petroleum":"1,456,274","geotherm":"7,000","solar":"65,444","biomass":"540,000","elec":"3,693,530"},
{"year":"1997","coal":"15,992","natGas":"5,092,919","petroleum":"1,396,041","geotherm":"7,500","solar":"65,016","biomass":"430,000","elec":"3,670,903"},
{"year":"1998","coal":"11,548","natGas":"4,646,087","petroleum":"1,279,579","geotherm":"7,700","solar":"64,663","biomass":"380,000","elec":"3,855,932"},
{"year":"1999","coal":"13,981","natGas":"4,834,899","petroleum":"1,434,738","geotherm":"8,500","solar":"63,730","biomass":"390,000","elec":"3,906,478"},
{"year":"2000","coal":"11,358","natGas":"5,104,649","petroleum":"1,521,137","geotherm":"8,600","solar":"61,355","biomass":"420,000","elec":"4,068,627"},
{"year":"2001","coal":"11,971","natGas":"4,889,018","petroleum":"1,498,668","geotherm":"9,450","solar":"59,846","biomass":"370,000","elec":"4,099,882"},
{"year":"2002","coal":"12,248","natGas":"5,014,472","petroleum":"1,425,694","geotherm":"10,204","solar":"58,747","biomass":"380,000","elec":"4,316,794"},
{"year":"2003","coal":"12,247","natGas":"5,209,427","petroleum":"1,489,953","geotherm":"13,000","solar":"58,151","biomass":"400,000","elec":"4,353,111"},
{"year":"2004","coal":"11,434","natGas":"4,980,821","petroleum":"1,491,210","geotherm":"14,000","solar":"58,736","biomass":"410,000","elec":"4,408,241"},
{"year":"2005","coal":"8,435","natGas":"4,946,351","petroleum":"1,421,962","geotherm":"15,900","solar":"60,628","biomass":"430,000","elec":"4,637,683"},
{"year":"2006","coal":"6,408","natGas":"4,475,902","petroleum":"1,197,132","geotherm":"18,300","solar":"67,186","biomass":"390,000","elec":"4,611,386"},
{"year":"2007","coal":"7,782","natGas":"4,849,561","petroleum":"1,222,760","geotherm":"22,000","solar":"74,896","biomass":"430,000","elec":"4,750,326"},
{"year":"2008","coal":"7,673","natGas":"4,989,358","petroleum":"1,203,572","geotherm":"26,400","solar":"88,140","biomass":"450,000","elec":"4,708,496"},
{"year":"2009","coal":"6,832","natGas":"4,874,276","petroleum":"1,161,906","geotherm":"32,800","solar":"100,600","biomass":"430,000","elec":"4,650,110"}]
/**
* Constructs a new, empty Sankey layout. Layouts are not typically constructed
* directly; instead, they are added to an existing panel via
* {@link pv.Mark#add}.
*
* @class Implements a layout for Sankey diagrams. An Sankey diagram is a directed weighted
* network visualization where typically the nodes are ordered into groups/levels and hidden
* to simply revel the weighted links between them.
*
*<p>A typical definition of a Sankey diagram is a directional flow chart where the width of
* the streams is proportional to the quantity of flow, and where the flows can be combined,
* split and traced through a series of events or stages. (source: CHEMICAL ENGINEERING Blog
* http://molecular-engineering.blogspot.com/2006/11/sankey-diagram.html).
*
*<p>There are several ways to layout a Sankey diagram. This particular implementation
* maps flows between nodes as define for each link. Example below:
*
*<pre>
** var graph = {
* nodes:[
* {nodeName:"n0"},
* {nodeName:"n1"},
* {nodeName:"n2"},
* {nodeName:"n3"}
* ],
* links:[
* {flow:[0,1], value:5},
* {flow:[0,2], value:5},
* {flow:[0,3], value:5}
* ]
* };
*
*</pre>
*
*This simple graph has a single source node with three outFlows going to 3 sink nodes.
* Nodes are ordered from left to right as defined by the flows in the links.
*
*<p>TODO:
* <ul>
* <li>Implement orientation for top and bottom (currently only left and right)
* <li>Line drawing priority: thinner lines need to be drawn last (on top)
* <li>????
*</ul>
*
* </ul>For more details on how this layout is structured and can be customized,
* see {@link pv.Layout.Network}.
*
* @extends pv.Layout.Network
**/
pv.Layout.Sankey = function() {
pv.Layout.Network.call(this); // Network diagram
this.link.lineWidth(function(d, p) { return p.linkValue; });
var that = this,
interpolate,
curve,
buildImplied = that.buildImplied;
this.buildImplied = function(s) {
curve = s.curve;
buildImplied.call(this, s);
};
function curveX(src,tar,level){
switch (level) {
case 0: return src.x;
case 1: return src.x+((src.x-tar.x)*-curve);
case 2: return tar.x-((tar.x-src.x)*curve);
case 3: return tar.x;
};
};
function curveY(fnode,lnode,link,level){
var links = level<2 ? 'outLinks' : 'inLinks';
if(level>1){
fnode = link.targetNode;
lnode = link.sourceNode;
}
var prevWidths = pv.sum(fnode[links].slice(0,fnode[links].indexOf(link)),function(d){return d.value});
return fnode.y - that.size( fnode.maxWidth/2 ) + that.size( prevWidths+link.value/2 );
};
function curveLink(link, level){
var curvedlink = pv.extend(link)
src = curvedlink.sourceNode,
tar = curvedlink.targetNode;
curvedlink.x = curveX(src,tar,level);
curvedlink.y = curveY(src,tar,link,level);
return curvedlink;
};
this.link.data(function(link) {
link.linkValue = that.size(link.value);
return [curveLink(link,0),
curveLink(link,1),
curveLink(link,2),
curveLink(link,3)];
})
.interpolate(function() { return interpolate ? interpolate : "monotone"; });
};
pv.Layout.Sankey.prototype = pv.extend(pv.Layout.Network)
.property("orient", String) // left, right, TODO: top, bottom
.property("center", Boolean) // true, false TODO: center negates widths, account for widths
.property('order', String) // null, ascending, descending
.property('spacing', Number) // spacingin between nodes in data scale (not pixels)
.property('curve', Number) // line curve
.property("flow", function(v) {
return v.map(function(d) {
if (isNaN(d.linkValue)) d.linkValue = isNaN(d.value) ? 1 : d.value;
return d;
});
});
pv.Layout.Sankey.prototype.defaults = new pv.Layout.Sankey()
.extend(pv.Layout.Network.prototype.defaults)
.orient('left')
.center(false)
.spacing(5)
.curve(0.2);
/** @private */
pv.Layout.Sankey.prototype.$scaletype = undefined;
pv.Layout.Sankey.prototype.$scale = undefined;
pv.Layout.Sankey.prototype.scale = function(f) {
this.$scaletype = f;
return this;
};
pv.Layout.Sankey.prototype.applyscale = function(min,max,rmin,rmax) {
if(this.$scaletype){
return this.$scaletype.apply(this, [min,max]).range(rmin,rmax);
}else{
return null;
}
};
pv.Layout.Sankey.prototype.size = function(value) {
if(this.$scaletype){
return this.$scale(value);
}else{
return value;
}
};
pv.Layout.Sankey.node = function(n){
var node = new pv.Dom.Node(n);
node.nodeName = node.nodeValue.nodeName;
node.inValue = node.outValue = node.maxWidth = 0;
node.inLinks = [],
node.outLinks = [],
node.parentNodes = [];
return node;
};
pv.Layout.Sankey.nodes = function(){
return pv.map(this.nodes(), function(n,i){ return pv.Layout.Sankey.node(n) });
};
pv.Layout.Sankey.mergeLinks = function(links){
var merged = [],
nest = pv.nest(links)
.key(function(d){return d.source})
.key(function(d){return d.target})
.map();
for(var source in nest){
for(var target in nest[source]){
merged.push( {source: parseInt(source), target: parseInt(target),
value: pv.sum(nest[source][target], function(d){ return d.value; }) } );
}
}
return merged;
};
/** @private Compute the implied links. (Links are null by default.) */
pv.Layout.Sankey.prototype.buildImplied = function(s){
var that = this,
maxdepth = 0,
maxBreadths = [],
maxWidths = [],
groups = {},
orderedGroups = {},
links = [],
filter = (s.filter) ? s.filter[0] : [],
nodes = s.nodes = pv.Layout.Sankey.nodes.call(that);
s.flow.forEach(function(link){
if(link.flow.length > maxdepth) maxdepth = link.flow.length;
link.flow.forEach(function(f,i){
// create all links
if(link.flow[i-1]!=undefined){
links.push( { source:link.flow[i-1], target:f, value: link.value } )
}
// determine groups
if(groups[i]==undefined){
groups[i] = [nodes[f]];
}else{
if(groups[i].indexOf(nodes[f])==-1) groups[i].push(nodes[f]);
}
});
});
s.links = pv.Layout.Sankey.mergeLinks(links);
s.links.forEach(function(l){
l.sourceNode = nodes[parseInt(l.source)];
l.targetNode = nodes[parseInt(l.target)];
if(l.sourceNode.outLinks.indexOf(l)==-1) l.sourceNode.outValue += l.value; l.sourceNode.outLinks.push(l);
if(l.targetNode.inLinks.indexOf(l)==-1) l.targetNode.inValue += l.value; l.targetNode.inLinks.push(l);
l.sourceNode.maxWidth = pv.max([l.sourceNode.maxWidth, l.sourceNode.outValue, l.sourceNode.inValue]);
l.targetNode.maxWidth = pv.max([l.targetNode.maxWidth, l.targetNode.outValue, l.targetNode.inValue]);
});
if(s.order){
for(var g in groups){
var orderedNodes = [];
pv.map(groups[g], function(n,i){
orderedNodes.push(n)
if(s.order=='ascending'){
n.outLinks.sort(function(a, b){ return pv.reverseOrder(a.value, b.value)} );
n.inLinks.sort(function(a, b){ return pv.reverseOrder(a.value, b.value)} );
}else if(s.order=='descending'){
n.outLinks.sort(function(a, b){ return pv.naturalOrder(a.value, b.value)} );
n.inLinks.sort(function(a, b){ return pv.naturalOrder(a.value, b.value)} );
}
});
// sort nodes
if(s.order=='ascending'){
orderedNodes.sort(function(a, b){ return pv.reverseOrder(a.maxWidth, b.maxWidth)} );
}else if(s.order=='descending'){
orderedNodes.sort(function(a, b){ return pv.naturalOrder(a.maxWidth, b.maxWidth)} );
}
orderedGroups[g] = orderedNodes;
};
groups = orderedGroups;
}
if (pv.Layout.Network.prototype.buildImplied.call(that, s)) return;
s.scales = {};
for(var g in groups){
var maxWidth = 0, maxBreadth = 0;
pv.map(groups[g], function(n){
n.depth = g==0 ? 0 : g * (1/(maxdepth-1));
n.breadth = 1/groups[g].length;
maxWidth += n.maxWidth+s.spacing;
maxBreadth = Math.max(maxBreadth, groups[g].length);
n.siblingIndex = groups[g].indexOf(n);
});
s.scales[g] = that.applyscale(0, maxWidth,0, s.height)
maxWidths.push(maxWidth)
maxBreadths.push(maxBreadth)
};
s.groups = groups;
that.$scale = that.applyscale(0, pv.max(maxWidths),0,s.height)
pv.Layout.Sankey.NodeLink.buildImplied.call(that, s);
};
pv.Layout.Sankey.NodeLink = {
/** @private */
buildImplied: function(s) {
var that = this,
orient = s.orient,
center = s.center,
space = that.size(s.spacing),
w = s.width,
h = s.height;
function x(n) {
switch (orient) {
case "left": return n.depth * w;
case "right": return w - n.depth * w;
// case "top": return n.breadth * w;
// case "bottom": return w - n.breadth * w;
}
}
function y(prevWidth,width) {
switch (orient) {
case "left": return prevWidth + width / 2;
case "right": return prevWidth + width / 2;
// case "top": return n.depth * h;
// case "bottom": return h - n.depth * h;
}
}
for(var g in s.groups){
var prevWidth = 0;
var scale = s.scales[g];
pv.map(s.groups[g], function(n){
var width = (scale) ? scale(n.maxWidth) : n.maxWidth;
n.x = x(n);
n.y = y(prevWidth,width);
if(center) n.y = (h * n.breadth * (n.siblingIndex + 0.5) );
prevWidth = n.y + width / 2 + space ;
});
}
}
};
var trans = [{"year":"1949","coal":"1,727,246","natGas":"","petroleum":"6,152,335","biomass":"0","elec":"22,114"},
{"year":"1950","coal":"1,563,933","natGas":"129,940","petroleum":"6,689,655","biomass":"0","elec":"23,178"},
{"year":"1951","coal":"1,378,693","natGas":"199,233","petroleum":"7,355,826","biomass":"0","elec":"24,093"},
{"year":"1952","coal":"984,040","natGas":"214,459","petroleum":"7,708,736","biomass":"0","elec":"21,823"},
{"year":"1953","coal":"732,992","natGas":"238,375","petroleum":"8,059,152","biomass":"0","elec":"21,932"},
{"year":"1954","coal":"461,404","natGas":"238,687","petroleum":"8,122,969","biomass":"0","elec":"20,048"},
{"year":"1955","coal":"421,262","natGas":"253,830","petroleum":"8,799,940","biomass":"0","elec":"19,877"},
{"year":"1956","coal":"339,821","natGas":"306,331","petroleum":"9,144,888","biomass":"0","elec":"18,537"},
{"year":"1957","coal":"241,264","natGas":"309,708","petroleum":"9,286,470","biomass":"0","elec":"16,187"},
{"year":"1958","coal":"115,156","natGas":"323,149","petroleum":"9,514,492","biomass":"0","elec":"14,517"},
{"year":"1959","coal":"87,830","natGas":"361,575","petroleum":"9,849,036","biomass":"0","elec":"14,418"},
{"year":"1960","coal":"74,959","natGas":"359,223","petroleum":"10,126,271","biomass":"0","elec":"10,460"},
{"year":"1961","coal":"18,927","natGas":"390,823","petroleum":"10,324,929","biomass":"0","elec":"10,316"},
{"year":"1962","coal":"16,874","natGas":"395,883","petroleum":"10,773,164","biomass":"0","elec":"10,167"},
{"year":"1963","coal":"16,421","natGas":"436,920","petroleum":"11,167,824","biomass":"0","elec":"9,955"},
{"year":"1964","coal":"17,403","natGas":"449,508","petroleum":"11,497,596","biomass":"0","elec":"10,011"},
{"year":"1965","coal":"15,972","natGas":"516,541","petroleum":"11,867,636","biomass":"0","elec":"9,974"},
{"year":"1966","coal":"14,754","natGas":"553,020","petroleum":"12,501,392","biomass":"0","elec":"9,642"},
{"year":"1967","coal":"11,227","natGas":"594,176","petroleum":"13,112,811","biomass":"0","elec":"10,010"},
{"year":"1968","coal":"10,014","natGas":"609,285","petroleum":"14,211,722","biomass":"0","elec":"10,215"},
{"year":"1969","coal":"7,426","natGas":"650,522","petroleum":"14,812,932","biomass":"0","elec":"10,420"},
{"year":"1970","coal":"6,849","natGas":"744,553","petroleum":"15,309,830","biomass":"0","elec":"10,627"},
{"year":"1971","coal":"4,693","natGas":"765,612","petroleum":"15,923,176","biomass":"0","elec":"10,462"},
{"year":"1972","coal":"3,676","natGas":"786,842","petroleum":"16,890,568","biomass":"0","elec":"10,371"},
{"year":"1973","coal":"2,620","natGas":"742,741","petroleum":"17,830,704","biomass":"0","elec":"10,532"},
{"year":"1974","coal":"1,794","natGas":"684,843","petroleum":"17,399,279","biomass":"0","elec":"9,721"},
{"year":"1975","coal":"538","natGas":"594,622","petroleum":"17,613,972","biomass":"0","elec":"10,149"},
{"year":"1976","coal":"270","natGas":"558,741","petroleum":"18,506,132","biomass":"0","elec":"10,059"},
{"year":"1977","coal":"201","natGas":"542,790","petroleum":"19,241,152","biomass":"0","elec":"10,429"},
{"year":"1978","coal":"0","natGas":"538,938","petroleum":"20,041,477","biomass":"0","elec":"10,027"},
{"year":"1979","coal":"0","natGas":"611,781","petroleum":"19,824,588","biomass":"0","elec":"10,117"},
{"year":"1980","coal":"0","natGas":"649,853","petroleum":"19,008,500","biomass":"0","elec":"11,069"},
{"year":"1981","coal":"0","natGas":"658,383","petroleum":"18,810,956","biomass":"6,727","elec":"10,871"},
{"year":"1982","coal":"0","natGas":"611,918","petroleum":"18,420,004","biomass":"18,295","elec":"11,002"},
{"year":"1983","coal":"0","natGas":"505,233","petroleum":"18,592,810","biomass":"33,739","elec":"12,675"},
{"year":"1984","coal":"0","natGas":"544,617","petroleum":"19,020,074","biomass":"41,289","elec":"14,293"},
{"year":"1985","coal":"0","natGas":"519,383","petroleum":"19,470,552","biomass":"49,766","elec":"14,148"},
{"year":"1986","coal":"0","natGas":"499,107","petroleum":"20,181,986","biomass":"57,470","elec":"15,057"},
{"year":"1987","coal":"0","natGas":"535,264","petroleum":"20,816,441","biomass":"66,109","elec":"15,567"},
{"year":"1988","coal":"0","natGas":"631,715","petroleum":"21,566,645","biomass":"67,163","elec":"15,930"},
{"year":"1989","coal":"0","natGas":"648,817","petroleum":"21,706,301","biomass":"68,129","elec":"16,276"},
{"year":"1990","coal":"0","natGas":"679,889","petroleum":"21,624,643","biomass":"60,455","elec":"16,211"},
{"year":"1991","coal":"0","natGas":"620,324","petroleum":"21,373,185","biomass":"70,134","elec":"16,236"},
{"year":"1992","coal":"0","natGas":"608,106","petroleum":"21,673,830","biomass":"79,791","elec":"16,056"},
{"year":"1993","coal":"0","natGas":"644,729","petroleum":"21,975,499","biomass":"93,713","elec":"16,278"},
{"year":"1994","coal":"0","natGas":"708,538","petroleum":"22,495,563","biomass":"104,899","elec":"17,040"},
{"year":"1995","coal":"0","natGas":"723,953","petroleum":"22,953,631","biomass":"112,553","elec":"16,973"},
{"year":"1996","coal":"0","natGas":"736,886","petroleum":"23,564,159","biomass":"80,706","elec":"16,797"},
{"year":"1997","coal":"0","natGas":"780,313","petroleum":"23,812,076","biomass":"102,023","elec":"16,744"},
{"year":"1998","coal":"0","natGas":"666,097","petroleum":"24,421,146","biomass":"112,907","elec":"16,929"},
{"year":"1999","coal":"0","natGas":"675,335","petroleum":"25,097,376","biomass":"117,862","elec":"17,491"},
{"year":"2000","coal":"0","natGas":"671,991","petroleum":"25,680,938","biomass":"134,964","elec":"18,363"},
{"year":"2001","coal":"0","natGas":"658,046","petroleum":"25,411,557","biomass":"142,204","elec":"19,531"},
{"year":"2002","coal":"0","natGas":"701,644","petroleum":"25,911,874","biomass":"169,745","elec":"18,825"},
{"year":"2003","coal":"0","natGas":"627,446","petroleum":"26,061,714","biomass":"229,942","elec":"23,235"},
{"year":"2004","coal":"0","natGas":"601,955","petroleum":"26,923,875","biomass":"289,881","elec":"24,647"},
{"year":"2005","coal":"0","natGas":"623,903","petroleum":"27,307,219","biomass":"339,200","elec":"25,612"},
{"year":"2006","coal":"0","natGas":"624,975","petroleum":"27,649,213","biomass":"475,201","elec":"25,104"},
{"year":"2007","coal":"0","natGas":"665,401","petroleum":"27,761,771","biomass":"602,804","elec":"27,885"},
{"year":"2008","coal":"0","natGas":"694,470","petroleum":"26,422,968","biomass":"826,582","elec":"26,271"},
{"year":"2009","coal":"0","natGas":"686,927","petroleum":"25,341,614","biomass":"922,353","elec":"26,233"}]
@jrosenberg
Copy link
Author

This diagram is based on the Lawrence Livermore National Labs energy flow charts, https://flowcharts.llnl.gov. The time-series idea came before I discovered a 1973 publication that explored this very idea using fold-outs in a printed book (download it from http://energyeducationreferences.pbworks.com/w/file/UnderstandingNationalEnergyDilemma.pdf). This version has a couple of bugs:

  1. 1949, the first year, is messed up.
  2. there is a buildup of labels in the upper-left corner of the chart
  3. some of the lines are wrong
  4. I can't figure out how to change the colors of the many different lines, that is, to code each one as in the examples linked to above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment