Skip to content

Instantly share code, notes, and snippets.

@ptvans
Last active December 15, 2015 04:29
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 ptvans/5202432 to your computer and use it in GitHub Desktop.
Save ptvans/5202432 to your computer and use it in GitHub Desktop.
apple unit sales
{"description":"apple unit sales","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"freq.tsv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"freq2.tsv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"unit-sales.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"unitsales.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.6280948026772978,"thumbnail":"http://i.imgur.com/aMYXtI8.png","ajax-caching":true}
d3.select("#display").style("background-color","#3f3f3f")
var svg = d3.select("svg");
var data = tributary.unitsales;
var cw = 902;
var ch = 165;
var dw = 40;
var dh = 10;
var r = 3;
var offset = 105;
var dopq = 0.75;
var startdate = data[0].Date;
var enddate = data[54].Date;
console.log(startdate);
console.log(enddate);
var format = d3.time.format("%d-%m-%Y");
var parsed = format.parse(startdate);
console.log(parsed);
var timescale = d3.scale.linear()
.domain([format.parse(enddate), format.parse(startdate)])
.range([dw,dw + cw])
var unitsmax = 20000;
var unitscale = d3.scale.linear()
.domain([0,unitsmax])
.range([dh+ch,dh])
svg.append("g")
.attr("id", "desktops")
svg.append("g")
.attr("id", "portables")
.attr("transform", "translate("+ 0 +","+ offset * 1 +")")
svg.append("g")
.attr("id", "ipod")
.attr("transform", "translate("+ 0 +","+ offset * 2 +")")
svg.append("g")
.attr("id", "iphone")
.attr("transform", "translate("+ 0 +","+ offset * 3 +")")
svg.append("g")
.attr("id", "ipad")
.attr("transform", "translate("+ 0 +","+ offset * 4 +")")
var desktops = svg.select("#desktops")
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
"r":r,
"fill":"#207DB1",
"fill-opacity":dopq,
"cx":function(d) {
return timescale(format.parse(d.Date));},
"cy":function(d){
return unitscale(d.Desktops);}
})
var portables = svg.select("#portables")
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
"r":r,
"fill":"#AC2891",
"fill-opacity":dopq,
"cx":function(d) {
return timescale(format.parse(d.Date));},
"cy":function(d){
return unitscale(d.Portables);}
})
var ipod = svg.select("#ipod")
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
"r":r,
"fill":"#13A2DA",
"fill-opacity":dopq,
"cx":function(d) {
return timescale(format.parse(d.Date));},
"cy":function(d){
return unitscale(d.iPod);}
})
var iphone = svg.select("#iphone")
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
"r":r,
"fill":"#FC2D99",
"fill-opacity":dopq,
"cx":function(d) {
return timescale(format.parse(d.Date));},
"cy":function(d){
return unitscale(d.iPhone);}
})
var ipad = svg.select("#ipad")
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
"r":r,
"fill":"#6D5DC7",
"fill-opacity":dopq,
"cx":function(d) {
return timescale(format.parse(d.Date));},
"cy":function(d){
return unitscale(d.iPad);}
})
svg.append("text")
.text("desktops")
.attr("transform", "translate("+ dw +","+ offset * 1 +")")
svg.append("text")
.text("portables")
.attr("transform", "translate("+ dw +","+ offset * 2 +")")
svg.append("text")
.text("ipod")
.attr("transform", "translate("+ dw +","+ offset * 3 +")")
svg.append("text")
.text("iphone")
.attr("transform", "translate("+ dw +","+ offset * 4 +")")
svg.append("text")
.text("ipad")
.attr("transform", "translate("+ dw +","+ offset * 5 +")")
Date Desktops Portables iPod iPhone iPad
31-03-2012 0 0 0 0
31-12-2011 0 0 0 0 15434
30-09-2011 0 0 0 0 11123
30-06-2011 0 0 0 0 9246
31-03-2011 1009 2751 9017 18647 4694
31-12-2010 1227 2907 19446 16235 7331
30-09-2010 1242 2643 9051 14102 4188
30-06-2010 1004 2468 9406 8398 3270
31-03-2010 1147 1796 10885 8752 0
31-12-2009 1234 2128 20970 8737
30-09-2009 787 2266 10177 7367
30-06-2009 849 1754 10215 5208
31-03-2009 818 1398 11013 3793
31-12-2008 728 1796 22727 4363
30-09-2008 936 1675 11052 6892
30-06-2008 943 1553 11011 717
31-03-2008 856 1433 10644 1703
31-12-2007 977 1342 22121 2315
30-09-2007 817 1347 10200 1119
30-06-2007 634 1130 9815 270
31-03-2007 626 891 10549 0
31-12-2006 637 969 21066
30-09-2006 624 986 8729
30-06-2006 529 798 8111
31-03-2006 614 498 8526
31-12-2005 667 587 14043
30-09-2005 602 634 6451
30-06-2005 687 495 6155
31-03-2005 608 462 5311
31-12-2004 623 423 4580
30-09-2004 385 451 2016
30-06-2004 416 460 860
31-03-2004 391 358 807
31-12-2003 433 396 733
30-09-2003 473 314 338
30-06-2003 420 351 304
31-03-2003 412 299 78
31-12-2002 456 287 219
30-09-2002 494 240 270
30-06-2002 545 263 54
31-03-2002 583 230 57
31-12-2001 445 301 0
30-09-2001 542 308
30-06-2001 531 296
31-03-2001 562 189
31-12-2000 510 149
30-09-2000 947 175
30-06-2000 798 218
31-03-2000 828 215
31-12-1999 1057 320
30-09-1999 668 104
30-06-1999 833 72
31-03-1999 752 75
31-12-1998 845 99
30-09-1998 0 0 0 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment