Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype HTML>
- <meta charset = 'utf-8'>
- <html>
- <head>
- <script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script>
- <script src='//dimplejs.org/dist/dimple.v2.1.0.min.js' type='text/javascript'></script>
- <style>
- .rChart {
- display: block;
- margin-left: auto;
- margin-right: auto;
- width: 520px;
- height: 480px;
- }
- </style>
- </head>
- <body >
- <div id = 'chart1b143e7e815' class = 'rChart dimple'></div>
- <script type="text/javascript">
- var opts = {
- "dom": "chart1b143e7e815",
- "width": 520,
- "height": 480,
- "xAxis": {
- "type": "addLogAxis",
- "showPercent": false,
- "overrideMin": 10
- },
- "yAxis": {
- "type": "addLogAxis",
- "showPercent": false,
- "overrideMin": 10000
- },
- "zAxis": [],
- "colorAxis": [],
- "defaultColors": [],
- "layers": [],
- "legend": [],
- "x": "Citations",
- "y": "Followers",
- "type": "bubble",
- "groups": "Name",
- "id": "chart1b143e7e815"
- },
- 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"}];
- var svg = dimple.newSvg("#" + opts.id, opts.width, opts.height);
- var myChart = new dimple.chart(svg, data);
- if (opts.bounds) {
- myChart.setBounds(opts.bounds.x, opts.bounds.y, opts.bounds.width, opts.bounds.height);//myChart.setBounds(80, 30, 480, 330);
- }
- //dimple allows use of custom CSS with noFormats
- if(opts.noFormats) { myChart.noFormats = opts.noFormats; };
- //for markimekko and addAxis also have third parameter measure
- //so need to evaluate if measure provided
- //function to build axes
- function buildAxis(position,layer){
- var axis;
- var axisopts;
- if (!layer[position+"Axis"]){
- axisopts = opts[position+"Axis"];
- } else axisopts = layer[position+"Axis"];
- if(axisopts.measure) {
- axis = myChart[axisopts.type](position,layer[position],axisopts.measure);
- } else {
- axis = myChart[axisopts.type](position, layer[position]);
- };
- if(!(axisopts.type === "addPctAxis")) axis.showPercent = axisopts.showPercent;
- if (axisopts.orderRule) axis.addOrderRule(axisopts.orderRule);
- if (axisopts.grouporderRule) axis.addGroupOrderRule(axisopts.grouporderRule);
- if (axisopts.overrideMin) axis.overrideMin = axisopts.overrideMin;
- if (axisopts.overrideMax) axis.overrideMax = axisopts.overrideMax;
- if (axisopts.inputFormat) axis.dateParseFormat = axisopts.inputFormat;
- if (axisopts.outputFormat) axis.tickFormat = axisopts.outputFormat;
- return axis;
- };
- var c = null;
- if(d3.keys(opts.colorAxis).length > 0) {
- c = myChart[opts.colorAxis.type](opts.colorAxis.colorSeries,opts.colorAxis.palette) ;
- }
- //allow manipulation of default colors to use with dimple
- if(opts.defaultColors.length) {
- opts.defaultColors = opts.defaultColors[0];
- if (typeof(opts.defaultColors) == "function") {
- //assume this is a d3 scale
- //for now loop through first 20 but need a better way to handle
- defaultColorsArray = [];
- for (var n=0;n<20;n++) {
- defaultColorsArray.push(opts.defaultColors(n));
- };
- opts.defaultColors = defaultColorsArray;
- }
- opts.defaultColors.forEach(function(d,i) {
- opts.defaultColors[i] = new dimple.color(d);
- })
- myChart.defaultColors = opts.defaultColors;
- }
- //do series
- //set up a function since same for each
- //as of now we have x,y,groups,data,type in opts for primary layer
- //and other layers reside in opts.layers
- function buildSeries(layer, hidden){
- //inherit from primary layer if not intentionally changed or xAxis, yAxis, zAxis null
- if (!layer.xAxis) layer.xAxis = opts.xAxis;
- if (!layer.yAxis) layer.yAxis = opts.yAxis;
- if (!layer.zAxis) layer.zAxis = opts.zAxis;
- var x = buildAxis("x", layer);
- x.hidden = hidden;
- var y = buildAxis("y", layer);
- y.hidden = hidden;
- //z for bubbles
- var z = null;
- if (!(typeof(layer.zAxis) === 'undefined') && layer.zAxis.type){
- z = buildAxis("z", layer);
- };
- //here think I need to evaluate group and if missing do null
- //as the group argument
- //if provided need to use groups from layer
- var s = new dimple.series(myChart, null, x, y, z, c, null, dimple.plot[layer.type], dimple.aggregateMethod.avg, dimple.plot[layer.type].stacked);
- //as of v1.1.4 dimple can use different dataset for each series
- if(layer.data){
- //convert to an array of objects
- //avoid lodash for now
- datakeys = d3.keys(layer.data)
- layer.dataarray = layer.data[datakeys[1]].map(function(d,i){
- var tempobj = {}
- datakeys.forEach(function(key){
- tempobj[key] = layer.data[key][i]
- })
- return tempobj
- })
- s.data = layer.dataarray;
- }
- //for measure axis dimple sorts at the series level not at axis level
- ['x','y'].map(function(ax){
- if( layer[ax + 'Axis'].type=="addMeasureAxis" && layer[ax + 'Axis'].orderRule ){
- if( typeof layer[ax + 'Axis'].orderRule == "string" ){
- s.addOrderRule( layer[ax + 'Axis'].orderRule );
- } else if ( typeof layer[ax + 'Axis'].orderRule == "object" ) {
- s._orderRules = layer[ax + 'Axis'].orderRule;
- }
- }
- })
- if(layer.hasOwnProperty("groups")) {
- s.categoryFields = (typeof layer.groups === "object") ? layer.groups : [layer.groups];
- //series offers an aggregate method that we will also need to check if available
- //options available are avg, count, max, min, sum
- }
- if (!(typeof(layer.aggregate) === 'undefined')) {
- s.aggregate = eval(layer.aggregate);
- }
- if (!(typeof(layer.lineWeight) === 'undefined')) {
- s.lineWeight = layer.lineWeight;
- }
- if (!(typeof(layer.lineMarkers) === 'undefined')) {
- s.lineMarkers = layer.lineMarkers;
- }
- if (!(typeof(layer.barGap) === 'undefined')) {
- s.barGap = layer.barGap;
- }
- if (!(typeof(layer.interpolation) === 'undefined')) {
- s.interpolation = layer.interpolation;
- }
- myChart.series.push(s);
- /*placeholder fix domain of primary scale for new series data
- //not working right now but something like this
- //for now just use overrideMin and overrideMax from rCharts
- for( var i = 0; i<2; i++) {
- if (!myChart.axes[i].overrideMin) {
- 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;
- }
- if (!myChart.axes[i].overrideMax) {
- 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;
- }
- myChart.axes[i]._update();
- }
- */
- return s;
- };
- buildSeries(opts, false);
- if (opts.layers.length > 0) {
- opts.layers.forEach(function(layer){
- buildSeries(layer, true);
- })
- }
- //unsure if this is best but if legend is provided (not empty) then evaluate
- if(d3.keys(opts.legend).length > 0) {
- var l =myChart.addLegend();
- d3.keys(opts.legend).forEach(function(d){
- l[d] = opts.legend[d];
- });
- }
- //quick way to get this going but need to make this cleaner
- if(opts.storyboard) {
- myChart.setStoryboard(opts.storyboard);
- };
- myChart.draw();
- </script>
- <script></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement