daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jun 21st, 2015 255 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype HTML>
  2. <meta charset = 'utf-8'>
  3. <html>
  4.   <head>
  5.    
  6.     <script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script>
  7.     <script src='//dimplejs.org/dist/dimple.v2.1.0.min.js' type='text/javascript'></script>
  8.    
  9.     <style>
  10.     .rChart {
  11.       display: block;
  12.       margin-left: auto;
  13.       margin-right: auto;
  14.       width: 520px;
  15.       height: 480px;
  16.     }  
  17.     </style>
  18.    
  19.   </head>
  20.   <body >
  21.    
  22.     <div id = 'chart1b143e7e815' class = 'rChart dimple'></div>    
  23.     <script type="text/javascript">
  24.   var opts = {
  25.  "dom": "chart1b143e7e815",
  26. "width":    520,
  27. "height":    480,
  28. "xAxis": {
  29.  "type": "addLogAxis",
  30. "showPercent": false,
  31. "overrideMin":     10
  32. },
  33. "yAxis": {
  34.  "type": "addLogAxis",
  35. "showPercent": false,
  36. "overrideMin":  10000
  37. },
  38. "zAxis": [],
  39. "colorAxis": [],
  40. "defaultColors": [],
  41. "layers": [],
  42. "legend": [],
  43. "x": "Citations",
  44. "y": "Followers",
  45. "type": "bubble",
  46. "groups": "Name",
  47. "id": "chart1b143e7e815"
  48. },
  49.     data = [{"Name":"Neil deGrasse Tyson","Occupation":"Astrophysicist","Handle":"@neiltyson","Followers":2400000,"Citations":151,"K.Index":11129,"Tweets":3962,"Institute":"Hayden Planetarium","Country":"United States"},{"Name":"Brian Cox","Occupation":"Physicist","Handle":"@ProfBrianCox","Followers":1440000,"Citations":33301,"K.Index":1188,"Tweets":10300,"Institute":"University of Manchester","Country":"United Kingdom"},{"Name":"Richard Dawkins","Occupation":"Biologist","Handle":"@RichardDawkins","Followers":1020000,"Citations":49631,"K.Index":740,"Tweets":19000,"Institute":"University of Oxford","Country":"United Kingdom"},{"Name":"Ben Goldacre","Occupation":"Physician","Handle":"@bengoldacre","Followers":341000,"Citations":1086,"K.Index":841,"Tweets":47300,"Institute":"London School of Hygiene & Tropical Medicine","Country":"United Kingdom"},{"Name":"Phil Plait","Occupation":"Astronomer","Handle":"@BadAstronomer","Followers":320000,"Citations":254,"K.Index":1256,"Tweets":47000,"Institute":"Bad Astronomy","Country":"United States"},{"Name":"Michio Kaku","Occupation":"Theoretical physicist","Handle":"@michiokaku","Followers":310000,"Citations":5281,"K.Index":461,"Tweets":1130,"Institute":"The City College of New York","Country":"United States"},{"Name":"Sam Harris","Occupation":"Neuroscientist","Handle":"@SamHarrisOrg","Followers":224000,"Citations":2416,"K.Index":428,"Tweets":2600,"Institute":"Project Reason","Country":"United States"},{"Name":"Hans Rosling","Occupation":"Global health scientist","Handle":"@HansRosling","Followers":180000,"Citations":1703,"K.Index":384,"Tweets":2708,"Institute":"Karolinska Institute","Country":"Sweden"},{"Name":"Tim Berners-Lee","Occupation":"Computer scientist","Handle":"@timberners_lee","Followers":179000,"Citations":51204,"K.Index":129,"Tweets":542,"Institute":"Massachusetts Institute of Technology","Country":"United States"},{"Name":"P.Z. Myers","Occupation":"Biologist","Handle":"@pzmyers","Followers":155000,"Citations":1364,"K.Index":355,"Tweets":25400,"Institute":"University of Minnesota, Morris","Country":"United States"},{"Name":"Steven Pinker","Occupation":"Cognitive scientist","Handle":"@sapinker","Followers":142000,"Citations":49933,"K.Index":103,"Tweets":1612,"Institute":"Harvard University","Country":"United States"},{"Name":"Richard Wiseman","Occupation":"Psychologist","Handle":"@RichardWiseman","Followers":134000,"Citations":4687,"K.Index":207,"Tweets":22400,"Institute":"University of Hertfordshire","Country":"United Kingdom"},{"Name":"Lawrence M. Krauss","Occupation":"Theoretical physicist","Handle":"@LKrauss1","Followers":99700,"Citations":10155,"K.Index":120,"Tweets":1548,"Institute":"Arizona State University","Country":"United States"},{"Name":"Atul Gawande","Occupation":"Surgeon/public health scientist","Handle":"@Atul_Gawande","Followers":96800,"Citations":13763,"K.Index":106,"Tweets":2118,"Institute":"Harvard University","Country":"United States"},{"Name":"Oliver Sacks","Occupation":"Neurologist","Handle":"@OliverSacks","Followers":76300,"Citations":13883,"K.Index":83,"Tweets":746,"Institute":"New York University","Country":"United States"},{"Name":"Dan Ariely","Occupation":"Psychologist/behavioral economist","Handle":"@danariely","Followers":73000,"Citations":16307,"K.Index":76,"Tweets":1091,"Institute":"Massachusetts Institute of Technology","Country":"United States"},{"Name":"Eric Topol","Occupation":"Geneticist","Handle":"@EricTopol","Followers":44800,"Citations":151281,"K.Index":23,"Tweets":4966,"Institute":"The Scripps Research Institute","Country":"United States"},{"Name":"Brian Greene","Occupation":"Theoretical physicist","Handle":"@bgreene","Followers":38700,"Citations":11133,"K.Index":45,"Tweets":191,"Institute":"Columbia University","Country":"United States"},{"Name":"Marcus du Sautoy","Occupation":"Mathematician","Handle":"@MarcusduSautoy","Followers":34200,"Citations":1461,"K.Index":77,"Tweets":3555,"Institute":"University of Oxford","Country":"United Kingdom"},{"Name":"Sean Carroll","Occupation":"Theoretical physicist","Handle":"@seanmcarroll","Followers":33200,"Citations":14208,"K.Index":36,"Tweets":7295,"Institute":"California Institute of Technology","Country":"United States"},{"Name":"Robert Winston","Occupation":"Fertility scientist","Handle":"@ProfRWinston","Followers":31900,"Citations":7324,"K.Index":43,"Tweets":445,"Institute":"Imperial College London","Country":"United Kingdom"},{"Name":"Bruce Betts","Occupation":"Planetary scientist","Handle":"@RandomSpaceFact","Followers":28500,"Citations":91,"K.Index":155,"Tweets":1619,"Institute":"The Planetary Society","Country":"United States"},{"Name":"Carolyn Porco","Occupation":"Planetary scientist","Handle":"@carolynporco","Followers":26100,"Citations":2717,"K.Index":48,"Tweets":12700,"Institute":"Space Science Institute","Country":"United States"},{"Name":"Sebastian Thrun","Occupation":"Computer scientist","Handle":"@SebastianThrun","Followers":25200,"Citations":57110,"K.Index":17,"Tweets":185,"Institute":"Stanford University","Country":"United States"},{"Name":"Jonathan Eisen","Occupation":"Biologist","Handle":"@phylogenomics","Followers":24900,"Citations":41289,"K.Index":19,"Tweets":46100,"Institute":"University of California, Davis","Country":"United States"},{"Name":"Vaughan Bell","Occupation":"Neuroscientist","Handle":"@vaughanbell","Followers":23500,"Citations":821,"K.Index":63,"Tweets":10900,"Institute":"King's College London","Country":"United Kingdom"},{"Name":"J. Craig Venter","Occupation":"Genomicist","Handle":"@JCVenter","Followers":23500,"Citations":75338,"K.Index":15,"Tweets":365,"Institute":"J. Craig Venter Institute","Country":"United States"},{"Name":"Robert Simpson","Occupation":"Astronomer","Handle":"@orbitingfrog","Followers":21500,"Citations":2280,"K.Index":42,"Tweets":11500,"Institute":"University of Oxford","Country":"United Kingdom"},{"Name":"Michael E. Mann","Occupation":"Meteorologist","Handle":"@MichaelEMann","Followers":20900,"Citations":15049,"K.Index":22,"Tweets":20000,"Institute":"Pennsylvania State University","Country":"United States"},{"Name":"Jerry Coyne","Occupation":"Biologist","Handle":"@Evolutionistrue","Followers":19500,"Citations":16657,"K.Index":20,"Tweets":7711,"Institute":"University of Chicago","Country":"United States"},{"Name":"Gary King","Occupation":"Statistician","Handle":"@kinggary","Followers":19400,"Citations":36311,"K.Index":16,"Tweets":3080,"Institute":"Harvard University","Country":"United States"},{"Name":"Mike Brown","Occupation":"Astronomer","Handle":"@plutokiller","Followers":18300,"Citations":7870,"K.Index":24,"Tweets":9764,"Institute":"California Institute of Technology","Country":"United States"},{"Name":"Pamela L. Gay","Occupation":"Astronomer","Handle":"@starstryder","Followers":17800,"Citations":238,"K.Index":71,"Tweets":12700,"Institute":"Southern Illinois University, Edwardsville","Country":"United States"},{"Name":"Jean Francois Gariepy","Occupation":"Neuroscientist","Handle":"@JFGariepy","Followers":17700,"Citations":153,"K.Index":82,"Tweets":3231,"Institute":"Duke University","Country":"United States"},{"Name":"Bob Metcalfe","Occupation":"Computer scientist","Handle":"@BobMetcalfe","Followers":16400,"Citations":424,"K.Index":55,"Tweets":16100,"Institute":"University of Texas, Austin","Country":"United States"},{"Name":"Daniel Gilbert","Occupation":"Psychologist/behavioral economist","Handle":"@DanTGilbert","Followers":15500,"Citations":26752,"K.Index":14,"Tweets":1294,"Institute":"Harvard University","Country":"United States"},{"Name":"Daniel Levitin","Occupation":"Neuroscientist","Handle":"@danlevitin","Followers":15400,"Citations":5688,"K.Index":22,"Tweets":3036,"Institute":"McGill University","Country":"Canada"},{"Name":"Andrew Maynard","Occupation":"Environmental health scientist","Handle":"@2020science","Followers":15300,"Citations":10411,"K.Index":18,"Tweets":16200,"Institute":"University of Michigan Risk Science Center","Country":"United States"},{"Name":"Paul Bloom","Occupation":"Psychologist","Handle":"@paulbloomatyale","Followers":15100,"Citations":14135,"K.Index":16,"Tweets":1973,"Institute":"Yale University","Country":"United States"},{"Name":"Seth Shostak","Occupation":"Astronomer","Handle":"@SethShostak","Followers":14500,"Citations":424,"K.Index":48,"Tweets":294,"Institute":"SETI Institute","Country":"United States"},{"Name":"Matt Lieberman","Occupation":"Neuroscientist","Handle":"@social_brains","Followers":14500,"Citations":12763,"K.Index":16,"Tweets":3088,"Institute":"University of California, Los Angeles","Country":"United States"},{"Name":"Daniel MacArthur","Occupation":"Genomicist","Handle":"@dgmacarthur","Followers":14100,"Citations":6884,"K.Index":19,"Tweets":15600,"Institute":"Harvard Medical School","Country":"United States"},{"Name":"John Allen Paulos","Occupation":"Mathematician","Handle":"@JohnAllenPaulos","Followers":14000,"Citations":1489,"K.Index":31,"Tweets":4144,"Institute":"Temple University","Country":"United States"},{"Name":"Ves Dimov","Occupation":"Immunologist","Handle":"@DrVes","Followers":13900,"Citations":211,"K.Index":58,"Tweets":32200,"Institute":"University of Chicago","Country":"United States"},{"Name":"Simon Baron-Cohen","Occupation":"Psychopathologist","Handle":"@sbaroncohen","Followers":13600,"Citations":84132,"K.Index":8,"Tweets":119,"Institute":"University of Cambridge","Country":"United Kingdom"},{"Name":"Amy Mainzer","Occupation":"Astronomer","Handle":"@AmyMainzer","Followers":13600,"Citations":1444,"K.Index":31,"Tweets":2221,"Institute":"Jet Propulsion Laboratory","Country":"United States"},{"Name":"Brian Krueger","Occupation":"Genomicist","Handle":"@LabSpaces","Followers":12500,"Citations":154,"K.Index":58,"Tweets":36700,"Institute":"Duke University","Country":"United States"},{"Name":"Karen James","Occupation":"Biologist","Handle":"@kejames","Followers":12200,"Citations":1007,"K.Index":31,"Tweets":61800,"Institute":"Mount Desert Island Biological Laboratory","Country":"United States"},{"Name":"Michael Eisen","Occupation":"Biologist","Handle":"@mbeisen","Followers":11800,"Citations":68785,"K.Index":8,"Tweets":16300,"Institute":"University of California, Berkeley","Country":"United States"},{"Name":"Micah Allen","Occupation":"Neuroscientist","Handle":"@neuroconscience","Followers":11600,"Citations":81,"K.Index":66,"Tweets":21900,"Institute":"University College London","Country":"United Kingdom"}];
  50.   var svg = dimple.newSvg("#" + opts.id, opts.width, opts.height);
  51.  
  52.   var myChart = new dimple.chart(svg, data);
  53.   if (opts.bounds) {
  54.     myChart.setBounds(opts.bounds.x, opts.bounds.y, opts.bounds.width, opts.bounds.height);//myChart.setBounds(80, 30, 480, 330);
  55.   }
  56.   //dimple allows use of custom CSS with noFormats
  57.   if(opts.noFormats) { myChart.noFormats = opts.noFormats; };
  58.   //for markimekko and addAxis also have third parameter measure
  59.   //so need to evaluate if measure provided
  60.  
  61.   //function to build axes
  62.   function buildAxis(position,layer){
  63.     var axis;
  64.     var axisopts;
  65.     if (!layer[position+"Axis"]){
  66.       axisopts = opts[position+"Axis"];
  67.     } else axisopts = layer[position+"Axis"];
  68.    
  69.     if(axisopts.measure) {
  70.       axis = myChart[axisopts.type](position,layer[position],axisopts.measure);
  71.     } else {
  72.       axis = myChart[axisopts.type](position, layer[position]);
  73.     };
  74.     if(!(axisopts.type === "addPctAxis")) axis.showPercent = axisopts.showPercent;
  75.     if (axisopts.orderRule) axis.addOrderRule(axisopts.orderRule);
  76.     if (axisopts.grouporderRule) axis.addGroupOrderRule(axisopts.grouporderRule);  
  77.     if (axisopts.overrideMin) axis.overrideMin = axisopts.overrideMin;
  78.     if (axisopts.overrideMax) axis.overrideMax = axisopts.overrideMax;
  79.     if (axisopts.inputFormat) axis.dateParseFormat = axisopts.inputFormat;
  80.     if (axisopts.outputFormat) axis.tickFormat = axisopts.outputFormat;    
  81.     return axis;
  82.   };
  83.  
  84.   var c = null;
  85.   if(d3.keys(opts.colorAxis).length > 0) {
  86.     c = myChart[opts.colorAxis.type](opts.colorAxis.colorSeries,opts.colorAxis.palette) ;
  87.   }
  88.  
  89.   //allow manipulation of default colors to use with dimple
  90.   if(opts.defaultColors.length) {
  91.     opts.defaultColors = opts.defaultColors[0];
  92.     if (typeof(opts.defaultColors) == "function") {
  93.       //assume this is a d3 scale
  94.       //for now loop through first 20 but need a better way to handle
  95.       defaultColorsArray = [];
  96.       for (var n=0;n<20;n++) {
  97.         defaultColorsArray.push(opts.defaultColors(n));
  98.       };
  99.       opts.defaultColors = defaultColorsArray;
  100.     }
  101.     opts.defaultColors.forEach(function(d,i) {
  102.       opts.defaultColors[i] = new dimple.color(d);
  103.     })
  104.     myChart.defaultColors = opts.defaultColors;
  105.   }  
  106.  
  107.   //do series
  108.   //set up a function since same for each
  109.   //as of now we have x,y,groups,data,type in opts for primary layer
  110.   //and other layers reside in opts.layers
  111.   function buildSeries(layer, hidden){
  112.     //inherit from primary layer if not intentionally changed or xAxis, yAxis, zAxis null
  113.     if (!layer.xAxis) layer.xAxis = opts.xAxis;    
  114.     if (!layer.yAxis) layer.yAxis = opts.yAxis;
  115.     if (!layer.zAxis) layer.zAxis = opts.zAxis;
  116.    
  117.     var x = buildAxis("x", layer);
  118.     x.hidden = hidden;
  119.    
  120.     var y = buildAxis("y", layer);
  121.     y.hidden = hidden;
  122.    
  123.     //z for bubbles
  124.     var z = null;
  125.     if (!(typeof(layer.zAxis) === 'undefined') && layer.zAxis.type){
  126.       z = buildAxis("z", layer);
  127.     };
  128.    
  129.     //here think I need to evaluate group and if missing do null
  130.     //as the group argument
  131.     //if provided need to use groups from layer
  132.     var s = new dimple.series(myChart, null, x, y, z, c, null, dimple.plot[layer.type], dimple.aggregateMethod.avg, dimple.plot[layer.type].stacked);
  133.    
  134.     //as of v1.1.4 dimple can use different dataset for each series
  135.     if(layer.data){
  136.       //convert to an array of objects
  137.       //avoid lodash for now
  138.       datakeys = d3.keys(layer.data)
  139.       layer.dataarray = layer.data[datakeys[1]].map(function(d,i){
  140.         var tempobj = {}
  141.         datakeys.forEach(function(key){
  142.           tempobj[key] = layer.data[key][i]
  143.         })
  144.         return tempobj
  145.       })
  146.       s.data = layer.dataarray;
  147.     }
  148.    
  149.     //for measure axis dimple sorts at the series level not at axis level
  150.     ['x','y'].map(function(ax){
  151.       if( layer[ax + 'Axis'].type=="addMeasureAxis" && layer[ax + 'Axis'].orderRule ){
  152.         if( typeof layer[ax + 'Axis'].orderRule == "string" ){
  153.           s.addOrderRule( layer[ax + 'Axis'].orderRule );
  154.         } else if ( typeof layer[ax + 'Axis'].orderRule == "object" ) {
  155.           s._orderRules = layer[ax + 'Axis'].orderRule;
  156.         }
  157.       }
  158.     })
  159.    
  160.     if(layer.hasOwnProperty("groups")) {
  161.       s.categoryFields = (typeof layer.groups === "object") ? layer.groups : [layer.groups];
  162.       //series offers an aggregate method that we will also need to check if available
  163.       //options available are avg, count, max, min, sum
  164.     }
  165.     if (!(typeof(layer.aggregate) === 'undefined')) {
  166.       s.aggregate = eval(layer.aggregate);
  167.     }
  168.     if (!(typeof(layer.lineWeight) === 'undefined')) {
  169.       s.lineWeight = layer.lineWeight;
  170.     }
  171.     if (!(typeof(layer.lineMarkers) === 'undefined')) {
  172.       s.lineMarkers = layer.lineMarkers;
  173.     }
  174.     if (!(typeof(layer.barGap) === 'undefined')) {
  175.       s.barGap = layer.barGap;
  176.     }    
  177.     if (!(typeof(layer.interpolation) === 'undefined')) {
  178.       s.interpolation = layer.interpolation;
  179.     }
  180.    
  181.     myChart.series.push(s);
  182.    
  183.     /*placeholder fix domain of primary scale for new series data
  184.     //not working right now but something like this
  185.     //for now just use overrideMin and overrideMax from rCharts
  186.     for( var i = 0; i<2; i++) {
  187.       if (!myChart.axes[i].overrideMin) {
  188.         myChart.series[0]._axisBounds(i==0?"x":"y").min = myChart.series[0]._axisBounds(i==0?"x":"y").min < s._axisBounds(i==0?"x":"y").min ? myChart.series[0]._axisBounds(i==0?"x":"y").min : s._axisBounds(i==0?"x":"y").min;
  189.       }
  190.       if (!myChart.axes[i].overrideMax) {  
  191.         myChart.series[0]._axisBounds(i==0?"x":"y")._max = myChart.series[0]._axisBounds(i==0?"x":"y").max > s._axisBounds(i==0?"x":"y").max ? myChart.series[0]._axisBounds(i==0?"x":"y").max : s._axisBounds(i==0?"x":"y").max;
  192.       }
  193.       myChart.axes[i]._update();
  194.     }
  195.     */
  196.      
  197.    
  198.     return s;
  199.   };
  200.  
  201.   buildSeries(opts, false);
  202.   if (opts.layers.length > 0) {
  203.     opts.layers.forEach(function(layer){
  204.       buildSeries(layer, true);
  205.     })
  206.   }
  207.   //unsure if this is best but if legend is provided (not empty) then evaluate
  208.   if(d3.keys(opts.legend).length > 0) {
  209.     var l =myChart.addLegend();
  210.     d3.keys(opts.legend).forEach(function(d){
  211.       l[d] = opts.legend[d];
  212.     });
  213.   }
  214.   //quick way to get this going but need to make this cleaner
  215.   if(opts.storyboard) {
  216.     myChart.setStoryboard(opts.storyboard);
  217.   };
  218.   myChart.draw();
  219.  
  220. </script>
  221.    
  222.     <script></script>    
  223.   </body>
  224. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top