Built with blockbuilder.org
forked from BenHeubl's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
forked from BenHeubl's block: final_bw_projection_chart
forked from anonymous's block: final_bw_projection_chart
xxxxxxxxxx
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="style3.css" type="text/css" media="screen"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script type="text/javascript" src="https://infographics.economist.com/js_libraries/infographic_mobile.js"></script>
<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> -->
<link rel="stylesheet" href="https://cdn.static-economist.com/sites/all/themes/econfinal/styles/reset.css">
<link type="text/css" rel="stylesheet" media="all" href="https://cdn.static-economist.com/sites/all/themes/econfinal/styles/ec-custom-fonts.css">
<script src="d3.slider.js"></script>
<script src="variables.js"></script>
<link rel="stylesheet" href="style2.css">
<style>
#update {
margin-bottom: 20px;
padding-left: 30px;
}
#update #buttons {
width: 230px;
margin: 0 auto 0px auto;
}
.button1 {
width: 100px;
padding: 10px 5px;
cursor: pointer;
text-align: center;
font-size: 16px;
border: 1px solid #e0e0e0;
float: left;
}
.button1:hover {
background: #e0e0e0;
}
.button1.current1 {
background: #000;
color: #fff;
}
.it {
font-style: italic;
}
.overlay {
fill: none;
pointer-events: all;
}
.focus circle {
fill: #ffbcbc;
stroke: #ff0000;
}
</style>
</head>
<body>
<div id="header">
<div id="block"></div>
<h1>Broadway prediction model</h1>
<h2>The success of Hamilton compared to your own show</h2>
</div>
</div>
<div id="content">
<div id="main-wrapper">
<div id="controls">
<div class="sentence">Highest actor Ulmer score? </div>
<div id="ULM" class="dropdown-wrapper", tabindex="0" style="float:left;z-index:20">
<span>kind</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">2nd highest actor Ulmer score </div>
<div id="ULM2" class="dropdown-wrapper", tabindex="1" style="float:left;z-index:20">
<span>type</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Seats? </div>
<div id="SEATS" class="dropdown-wrapper", tabindex="2" style="float:left;z-index:20">
<span>Genre</span>
<ul class="dropdown"></ul>
</div>
<!-- 2nd line -->
<div class="sentence">Original work? </div>
<div id="OR" class="dropdown-wrapper", tabindex="0" style="float:left;z-index:10">
<span>Yes</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Musical? </div>
<div id="MUS" class="dropdown-wrapper", tabindex="1" style="float:left;z-index:10">
<span>MUS</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Cast size? </div>
<div id="CASTSIZE" class="dropdown-wrapper", tabindex="2" style="float:left;z-index:10">
<span>Yes</span>
<ul class="dropdown"></ul>
</div>
<!-- 3rd line -->
<div class="sentence">Disney? </div>
<div id="DIS" class="dropdown-wrapper", tabindex="0" style="float:left;z-index:10">
<span>No</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Based on a movie? </div>
<div id="MOV" class="dropdown-wrapper", tabindex="1" style="float:left;z-index:10">
<span>MOV</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">NYT Review? </div>
<div id="NYT" class="dropdown-wrapper", tabindex="2" style="float:left;z-index:10">
<span>Fill</span>
<ul class="dropdown"></ul>
</div>
<!-- 4nd line -->
<div class="sentence">USA Today review? </div>
<div id="USAT" class="dropdown-wrapper", tabindex="0" style="float:left;z-index:10">
<span>#</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Tony awards? </div>
<div id="TONY" class="dropdown-wrapper", tabindex="1" style="float:left;z-index:10">
<span>#</span>
<ul class="dropdown"></ul>
</div>
<!-- 5nd line -->
<div class="sentence">Is drama? </div>
<div id="DRAMA" class="dropdown-wrapper", tabindex="0" style="float:left;z-index:10">
<span>#</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Past max gross of show's author? </div>
<div id="SHOW" class="dropdown-wrapper", tabindex="1" style="float:left;z-index:10">
<span>#</span>
<ul class="dropdown"></ul>
</div>
<div class="sentence">Is comedy? </div>
<div id="COMEDY" class="dropdown-wrapper", tabindex="2" style="float:left;z-index:10">
<span>Fill</span>
<ul class="dropdown"></ul>
</div>
<!-- Cast -->
<!-- <div class="sentence"> Cast-size</div>
<div id="cast">
<div id="ageslider" class="sliderholder"></div>
<div id="agevalue"></div>
</div>
</div> -->
<!-- end Controls -->
</div><!-- @end #main-wrapper -->
</div>
<div id="content">
<div id="main-wrapper">
<div id="footer">
<!-- results -->
<h1 width="500px" id="resultheading">Weekly revenue prediction:</h1>
<h2 width="500px" id="resultVal">100,000 $</h2>
</div>
<div id="container">
<div id="chart"></div>
<div id="update">
<div id="buttons">
<div class="button1 current1" data-val="A">Accumulative</div>
<div class="button1" data-val="W">Per week</div>
<div class="clr"></div>
</div>
</div>
<p id="source">Sources:<span class="it"> Economist</span></p>
</div>
</div><!-- @end #main-wrapper -->
</div>
<script>
var margin = {top: 20, right: 80, bottom: 50, left: 90},
width = 595 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var Stack = "A";
// var barChartHeight = 130;
var areaChartHeight = 500;
var tagColour = "#e11b17";
var colHighlighted = "#FD9D28";
var colUnhighlighted = "#dddddd";
var colourButtonOff = "#ffffff"; // white
var colourButtonOn = "#00699f"; // blue
var highlightColour = "#9a404f";
var colourTint = "#7fc9c7";
var p99Colour = "#3dbbd1";
var kind = {
"play": "Play",
"musical": "Musical",
}
var actor = { // 1
"AActor": "A-Actor",
"bActor": "B-Actor",
"cActor": "C-Actor",
};
var genre = { // 2
"comedy": "Comedy",
"drama": "Drama",
"other": "Other",
};
// var age_slider = d3.slider().min(0).max(100).ticks(0).stepValues(d3.range(0,100)).value(currentCastSize)
// .callback(brushed);
// d3.select("#ageslider").call(age_slider);
// d3.select("#agevalue").text(currentCastSize);
var bisectDate = d3.bisector(function(d) { return d.date; }).left,
formatValue = d3.format(",.2f"),
formatCurrency = function(d) { return "$" + formatValue(d); };
d3.selectAll(".button1").on("click", function() {
Stack = d3.select(this).attr("data-val");
d3.select(".current1").classed("current1", false);
d3.select(this).classed("current1", true);
makeChartsPerWeek(Stack);
return Stack;
});
// // setting up variables
// var D2 = 0 ; === WEEK
var D2 = 0;
// var A2 = 200 ;
// var B2 = 100 ;
// var C2 = 1500 ;
// var D2 = 0 ;
// var E2 = 1;
// var F2 = 1 ;
// var G2 = 45 ;
// var H2 = 0 ;
// var I2 = 0 ;
// var J2 = 1 ;
// var K2 = 4 ;
// var L2 = 3 ;
// var M2 = 0 ;
// var N2 = 0 ;
// var O2 = 1 ;
var ULM = {
"A_200": 200,
"A_0" : 0,
"A_50" : 50,
"A_125" : 125,
"A_175" : 175,
"A_225" : 225,
"A_270" : 270,
"A_295" : 295,
}
var current_ULM = "A_200";
var A2 = ULM[current_ULM];
var ULM2 = {
"A_100": 100,
"A_0" : 0,
"A_50" : 50,
"A_125" : 125,
"A_175" : 175,
"A_225" : 225,
"A_270" : 270,
"A_295" : 295,
}
var current_ULM2 = "A_100";
var B2 = ULM2[current_ULM2];
var SEATS = {
"A_1500": 1500,
"A_500" : 500,
"A_750" : 750,
"A_1000" : 1000,
"A_1250" : 1250,
"A_1500" : 1500,
"A_1700" : 1700,
"A_2000" : 2000,
}
var current_SEATS = "A_1500";
var C2 = SEATS[current_SEATS];
var OR = {
"Yes": 1,
"No" : 0,
}
var current_OR = "Yes";
var E2 = OR[current_OR];
var MUS = {
"Yes": 1,
"No" : 0,
}
var current_MUS = "Yes";
var F2 = MUS[current_MUS];
var CASTSIZE = {
"A_45": 45,
"A_0" : 0,
"A_10" : 10,
"A_20" : 20,
"A_30" : 30,
"A_40" : 40,
"A_50" : 50,
"A_60" : 60,
"A_70" : 70,
"A_80" : 80,
"A_90" : 90,
}
var current_CASTSIZE = "A_45";
var G2 = CASTSIZE[current_CASTSIZE];
var DIS = {
"Yes": 1,
"No" : 0,
}
var current_DIS = "No";
var H2 = DIS[current_DIS];
var MOV = {
"Yes": 1,
"No" : 0,
}
var current_MOV = "No";
var I2 = MOV[current_MOV];
var NYT = {
"Good": 1,
"Bad" : 0,
}
var current_NYT = "Good";
var J2 = NYT[current_NYT];
var USAT = {
"A_1": 1,
"A_2" : 2,
"A_3" : 3,
"A_4" : 4,
"A_5" : 5,
}
var current_USAT = "A_4";
var K2 = USAT[current_USAT];
var TONY = {
"A_0": 0,
"A_1": 1,
"A_2" : 2,
"A_3" : 3,
"A_4" : 4,
"A_5" : 5,
"A_6" : 6,
}
var current_TONY = "A_3";
var L2 = TONY[current_TONY];
var COMEDY = {
"Yes": 1,
"No" : 0,
}
var current_COMEDY = "No";
var M2 = COMEDY[current_COMEDY];
var DRAMA = {
"Yes": 1,
"No" : 0,
}
var current_DRAMA = "No";
var N2 = DRAMA[current_DRAMA];
var SHOW = {
"A_1": 1,
"A_2" : 2,
"A_3" : 3,
"A_4" : 4,
"A_5" : 5,
}
var current_SHOW = "A_1";
var O2 = SHOW[current_SHOW];
// a Highest actor Ulmer score 200 0 50 125 175 225 270 295 DONE
// b 2nd highest actor Ulmer score 100 0 50 125 175 225 270 295 DONE
// c Seats in theater 1500 500 750 1000 1250 1500 1750 2000
// d Week of year (1-53) 30
// e Original work? 1 0 1
// f Musical? 1 0 1
// g Cast size 45 1 10 20 30 40 50 60 70 80 90
// h Disney? 0 0 1
// i Based on a movie? 0 0 1
// j NYT Review (1=good, 0=bad) 1
// k USA Today review (1=bad, 5=good) 4
// l major Tony awards 3
// m Is comedy? 0
// n Is drama? 0
// o Past max gross of show's author 1
// currentCastSize // 3
var currentKind = "play";
var currentActor = "AActor";
var currentGenre = "comedy";
var currentCastSize = 50;
// var currentKindID = 0,
// currentActorID = 0,
// currentGenreID = 0;
var result;
// ULM dropdown menu
var dropdown_actor = d3.select("#controls #ULM");
dropdown_actor.select("span").text(ULM[current_ULM]);
dropdown_actor.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_actor_li = dropdown_actor.select(".dropdown").selectAll("li")
.data(d3.keys(ULM))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_ULM ? true : false; }).text(function(d) { return ULM[d]; });
dropdown_actor_li.on("click", function(d, i) {
d3.select("#ULM span").text(ULM[d]);
d3.select(this).classed("current", true);
d3.select("#ULM #" + current_ULM).classed("current", false);
current_ULM = d;
A2 = ULM[current_ULM];
// current_ULM_Result = parseInt(current_ULM.split("_")[1])
update();
return A2;
});
// ULM2 dropdown menu
var dropdown_ULM2 = d3.select("#controls #ULM2");
dropdown_ULM2.select("span").text(ULM2[current_ULM2]);
dropdown_ULM2.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_ULM2_li = dropdown_ULM2.select(".dropdown").selectAll("li")
.data(d3.keys(ULM2))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_ULM2 ? true : false; }).text(function(d) { return ULM2[d]; });
dropdown_ULM2_li.on("click", function(d, i) {
d3.select("#ULM2 span").text(ULM2[d]);
d3.select(this).classed("current", true);
d3.select("#ULM2 #" + current_ULM2).classed("current", false);
current_ULM2 = d;
B2 = ULM2[current_ULM2];
update();
return B2;
});
// SEATS dropdown menu
var dropdown_SEATS = d3.select("#controls #SEATS");
dropdown_SEATS.select("span").text(SEATS[current_SEATS]);
dropdown_SEATS.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_SEATS_li = dropdown_SEATS.select(".dropdown").selectAll("li")
.data(d3.keys(SEATS))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_SEATS ? true : false; }).text(function(d) { return SEATS[d]; });
dropdown_SEATS_li.on("click", function(d, i) {
d3.select("#SEATS span").text(SEATS[d]);
d3.select(this).classed("current", true);
d3.select("#SEATS #" + current_SEATS).classed("current", false);
current_SEATS = d;
C2 = SEATS[current_SEATS];
update();
return C2;
});
// OR dropdown menu
var dropdown_OR = d3.select("#controls #OR");
dropdown_OR.select("span").text(current_OR);
dropdown_OR.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_OR_li = dropdown_OR.select(".dropdown").selectAll("li")
.data(d3.keys(OR))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_OR ? true : false; }).text(function(d) { return d; });
dropdown_OR_li.on("click", function(d, i) {
d3.select("#OR span").text(d);
d3.select(this).classed("current", true);
d3.select("#OR #" + current_OR).classed("current", false);
current_OR = d;
E2 = OR[current_OR];
update();
return E2;
});
// MUS dropdown menu
var dropdown_MUS = d3.select("#controls #MUS");
dropdown_MUS.select("span").text(current_MUS);
dropdown_MUS.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_MUS_li = dropdown_MUS.select(".dropdown").selectAll("li")
.data(d3.keys(MUS))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_MUS ? true : false; }).text(function(d) { return d; });
dropdown_MUS_li.on("click", function(d, i) {
d3.select("#MUS span").text(d);
d3.select(this).classed("current", true);
d3.select("#MUS #" + current_MUS).classed("current", false);
current_MUS = d;
F2 = MUS[current_MUS];
update();
return F2;
});
// CASTSIZE dropdown menu
var dropdown_CASTSIZE = d3.select("#controls #CASTSIZE");
dropdown_CASTSIZE.select("span").text(CASTSIZE[current_CASTSIZE]);
dropdown_CASTSIZE.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_CASTSIZE_li = dropdown_CASTSIZE.select(".dropdown").selectAll("li")
.data(d3.keys(CASTSIZE))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_CASTSIZE ? true : false; }).text(function(d) { return CASTSIZE[d]; });
dropdown_CASTSIZE_li.on("click", function(d, i) {
d3.select("#CASTSIZE span").text(CASTSIZE[d]);
d3.select(this).classed("current", true);
d3.select("#CASTSIZE #" + current_CASTSIZE).classed("current", false);
current_CASTSIZE = d;
G2 = CASTSIZE[current_CASTSIZE];
update();
return G2;
});
// DIS dropdown menu
var dropdown_DIS = d3.select("#controls #DIS");
dropdown_DIS.select("span").text(current_DIS);
dropdown_DIS.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_DIS_li = dropdown_DIS.select(".dropdown").selectAll("li")
.data(d3.keys(DIS))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_DIS ? true : false; }).text(function(d) { return d; });
dropdown_DIS_li.on("click", function(d, i) {
d3.select("#DIS span").text(d);
d3.select(this).classed("current", true);
d3.select("#DIS #" + current_DIS).classed("current", false);
current_DIS = d;
H2 = DIS[current_DIS];
update();
return H2;
});
// MOV dropdown menu
var dropdown_MOV = d3.select("#controls #MOV");
dropdown_MOV.select("span").text(current_MOV);
dropdown_MOV.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_MOV_li = dropdown_MOV.select(".dropdown").selectAll("li")
.data(d3.keys(MOV))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_MOV ? true : false; }).text(function(d) { return d; });
dropdown_MOV_li.on("click", function(d, i) {
d3.select("#MOV span").text(d);
d3.select(this).classed("current", true);
d3.select("#MOV #" + current_MOV).classed("current", false);
current_MOV = d;
I2 = MOV[current_MOV];
update();
return I2;
});
// NYT dropdown menu
var dropdown_NYT = d3.select("#controls #NYT");
dropdown_NYT.select("span").text(current_NYT);
dropdown_NYT.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_NYT_li = dropdown_NYT.select(".dropdown").selectAll("li")
.data(d3.keys(NYT))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_NYT ? true : false; }).text(function(d) { return d; });
dropdown_NYT_li.on("click", function(d, i) {
d3.select("#NYT span").text(d);
d3.select(this).classed("current", true);
d3.select("#NYT #" + current_NYT).classed("current", false);
current_NYT = d;
J2 = NYT[current_NYT];
update();
return J2;
});
// USAT dropdown menu
var dropdown_USAT = d3.select("#controls #USAT");
dropdown_USAT.select("span").text(USAT[current_USAT]);
dropdown_USAT.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_USAT_li = dropdown_USAT.select(".dropdown").selectAll("li")
.data(d3.keys(USAT))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_USAT ? true : false; }).text(function(d) { return USAT[d]; });
dropdown_USAT_li.on("click", function(d, i) {
d3.select("#USAT span").text(USAT[d]);
d3.select(this).classed("current", true);
d3.select("#USAT #" + current_USAT).classed("current", false);
current_USAT = d;
K2 = USAT[current_USAT];
update();
return K2;
});
// TONY dropdown menu
var dropdown_TONY = d3.select("#controls #TONY");
dropdown_TONY.select("span").text(TONY[current_TONY]);
dropdown_TONY.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_TONY_li = dropdown_TONY.select(".dropdown").selectAll("li")
.data(d3.keys(TONY))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_TONY ? true : false; }).text(function(d) { return TONY[d]; });
dropdown_TONY_li.on("click", function(d, i) {
d3.select("#TONY span").text(TONY[d]);
d3.select(this).classed("current", true);
d3.select("#TONY #" + current_TONY).classed("current", false);
current_TONY = d;
L2 = TONY[current_TONY];
update();
return L2;
});
// COMEDY dropdown menu
var dropdown_COMEDY = d3.select("#controls #COMEDY");
dropdown_COMEDY.select("span").text(current_COMEDY);
dropdown_COMEDY.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_COMEDY_li = dropdown_COMEDY.select(".dropdown").selectAll("li")
.data(d3.keys(COMEDY))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_COMEDY ? true : false; }).text(function(d) { return d; });
dropdown_COMEDY_li.on("click", function(d, i) {
d3.select("#COMEDY span").text(d);
d3.select(this).classed("current", true);
d3.select("#COMEDY #" + current_COMEDY).classed("current", false);
current_COMEDY = d;
M2 = COMEDY[current_COMEDY];
update();
return M2;
});
// DRAMA dropdown menu
var dropdown_DRAMA = d3.select("#controls #DRAMA");
dropdown_DRAMA.select("span").text(current_DRAMA);
dropdown_DRAMA.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_DRAMA_li = dropdown_DRAMA.select(".dropdown").selectAll("li")
.data(d3.keys(DRAMA))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_DRAMA ? true : false; }).text(function(d) { return d; });
dropdown_DRAMA_li.on("click", function(d, i) {
d3.select("#DRAMA span").text(d);
d3.select(this).classed("current", true);
d3.select("#DRAMA #" + current_DRAMA).classed("current", false);
current_DRAMA = d;
N2 = DRAMA[current_DRAMA];
update();
return N2;
});
// SHOW dropdown menu
var dropdown_SHOW = d3.select("#controls #SHOW");
dropdown_SHOW.select("span").text(SHOW[current_SHOW]);
dropdown_SHOW.on("click", function() {
d3.select(this).classed("active", !d3.select(this).classed("active"));
});
var dropdown_SHOW_li = dropdown_SHOW.select(".dropdown").selectAll("li")
.data(d3.keys(SHOW))
.enter().append("li")
.attr("id", function(d) { return d; })
.classed("current", function(d) { return d == current_SHOW ? true : false; }).text(function(d) { return SHOW[d]; });
dropdown_SHOW_li.on("click", function(d, i) {
d3.select("#SHOW span").text(SHOW[d]);
d3.select(this).classed("current", true);
d3.select("#SHOW #" + current_SHOW).classed("current", false);
current_SHOW = d;
O2 = SHOW[current_SHOW];
update();
return O2;
});
/////////////////// /////////////////// /////////////////// ///////////////////
/////////////////// /////////////////// /////////////////// ///////////////////
var parseDate = d3.time.format("%m/%d/%Y").parse;
var x = d3.time.scale()
.range([0, width]);
var xA = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var yA = d3.scale.linear()
.domain([0, 1])
.range([height, 0]);
var color = d3.scale.ordinal().range(["#70C7DB", "#A15F7F"]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(6)
.tickFormat(d3.time.format("%m"))
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickSize(-width)
.ticks(7);
var line = d3.svg.line()
.interpolate("step")
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.temperature); });
var svg = d3.select("#chart").append("svg").classed("wrapper2", true)
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
ageAnnotate(1.1,100, "Hamilton's success sticks out");
ageAnnotate(1.3,371, "Average gross revenue is 907,573 USD");
d3.csv("dataBW4.csv", function(error, data) {
if (error) throw error;
color.domain(d3.keys(data[0]).filter(function(key) { return key !== "date"; }));
data.forEach(function(d) {
d.date = parseDate(d.date);
});
var cities = color.domain().map(function(name) {
return {
name: name,
values: data.map(function(d) {
return {date: d.date, temperature: +d[name]};
})
};
});
var Weeks = color.domain().map(function(name) {
return {
name: name,
values: data.map(function(d) {
return {date: d.date, temperature: +d[name]};
})
};
});
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([
d3.min(cities, function(c) { return 0}),
d3.max(cities, function(c) { return d3.max(c.values, function(v) { return v.temperature; }); })
]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("x", 428)
.attr("y", -15)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Months, 2015/2016");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Cumulative revenue, in $");
var city = svg.selectAll(".city")
.data(cities)
.enter().append("g")
.attr("class", "city");
console.log(cities)
city.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); })
.style("stroke-opacity", 0.7);
city.append("text")
.datum(function(d) { return {name: d.name, value: d.values[d.values.length - 1]}; })
.attr("transform", function(d) { return "translate(" + x(d.value.date) + "," + y(d.value.temperature) + ")"; })
.attr("x", 3)
.attr("dy", ".35em")
.text(function(d) { return d.name; })
.style("fill", function(d) { return color(d.name); })
svg.append("g")
.attr("class", "baseline")
.attr("transform", "translate(0, "+ height +")")
.append("line")
.attr("x1", -20)
.attr("x2", width)
.attr("y2", 0)
});
var parseDate2 = d3.time.format("%m/%d/%Y").parse;
var dataNew = [];
var datafinal;
d3.csv("dateModel.csv", function (error, dataWeeks, results) {
var results = 0;
dataWeeks.forEach(function(d, i) {
d.x2 = parseDate2(d.dateModel);
d.y2 = (results*i);
// dataNew.push({x2: parseDate2(d.dateModel),
// y2: (results*i)})
}); // end for map function
// console.log(dataWeeks)
// var line3 = d3.svg.line()
// .interpolate("step")
// .x(function(d) { return x(d.x2); })
// .y(function(d) { return y(d.y2); });
// var linegraph3 = svg.append("path")
// .attr("class", "line3")
// .attr('d', function(d){return line3(dataWeeks)})
// .style("stroke", "#0C6290")
// .style("fill", "none")
// .style("stroke-width", 4)
// .style("stroke-opacity", 0.7)
// .attr("transform", "translate(0, -5)");
// update(dataWeeks, line3)
})
// function brushed () {
// update();
// currentCastSize = age_slider.value();
// d3.select("#agevalue").text(currentCastSize)
// return currentCastSize;
// }
function ageAnnotate(year, Ypos, text) {
svg.append("line")
.attr("class", "annotation")
.attr("x1", 259)
.attr("x2", 259)
.attr("stroke-dasharray", "3,3")
.attr("y1", yA(0))
.attr("y2", yA(1));
svg.append("text")
.attr("class", "annotation")
.attr("transform", "translate("+xA((year-0.8))+","+Ypos+")rotate(-0)")
.text(text);
}
var focus = svg.append("g")
.attr("class", "focus")
.style("display", "none");
focus.append("circle")
.attr("r", 4.5);
focus.append("text")
.attr("x", 9)
.attr("dy", ".35em");
var weekly_av_2015_16 = 907573.9;
var weeklystde_2015_16 = 479660.8;
var finalNum;
function predictor (A2 ,B2 ,C2 ,D2 ,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2 , weekly_av_2015_16, weeklystde_2015_16) {
ProbSellout = 1/
(
1+
(
Math.exp(
-(
-(0.0042183*A2)
+(0.0039907*B2)
+(0.0000626*(Math.pow(A2, 2)))
+(0.00000812*(Math.pow(B2, 2)))
-(0.0007982*C2)
+(0.0419669*((D2==47?1:0)))
+(1.041139*(Math.pow(((D2==52?(6/7):(D2==53?3/7:0))), 2)))
-(0.1213413*D2)
+(0.0129541*(Math.pow(D2, 2)))
-(0.0003998*(Math.pow(D2, 3)))
+(0.00000373*(Math.pow(D2, 4)))
-(0.4756087*E2)
-(3.885171*F2)
-(0.092289*G2*F2)
+(1.883142*H2)
-(0.0162975*I2)
+(0.0839098*G2)
+(0.1854669*J2)
-(0.8336684*(1-J2))
+(0.2028874*F2*K2)
+(0.1258541*J2*F2)
+(0.3561441*F2*(1-J2))
-(0.470837*(Math.log(G2)))
+(1.802581*F2*(Math.log(G2)))
+(1.217256*(Math.log(L2)))
-(0.5184693*F2*(Math.log(L2+1)))
-(0.1466195*M2)
-(0.157074*N2)
+(0.0150286*(Math.log(O2+1)))
-1.9122703
)
)
)
)
// console.log(ProbSellout)
var ZIfSellout = ((-0.0016507*A2)
+(0.0052863*B2)
+(0.0000186*(Math.pow(A2, 2)))
-(0.0000205*(Math.pow(B2, 2)))
+(0.0015585*C2)
+(0.2960315*E2)
-(0.5571162*F2)
-(0.0105103*F2*G2)
+(0.0739237*H2)
-(0.100593*I2)
+(0.0156484*G2)
+(0.1381832*K2)
+(0.3338621*F2*(Math.log(G2)))
+(0.1955426*F2*(Math.log(L2+1)))
+(0.0734202*M2)
-(0.1991816*N2)-2.682552)
// console.log(ZIfSellout)
var ZIfNoSellout = (
(0.0011112*B2)
+(0.0000139*(Math.pow(A2, 2)))
-(0.0007004*A2)
-(0.000000678*(Math.pow(B2, 2)))
+(0.2004303*E2)
-(1.477247*F2)
-(0.006352*F2*G2)
+(0.38273282*H2)
+(0.0155657*G2)
+(0.1257408*F2*K2)
+(0.5647975*F2*(Math.log(G2)))
+(0.1675119*(Math.log(L2+1)))
+(0.1041002*M2)
+(0.0932572*N2)
-1.186324)
var projZ =(ProbSellout*ZIfSellout)+((1-ProbSellout)*ZIfNoSellout)
// console.log(projZ)
var WeekAvRatio = (
(0.1219971*((D2==47?1:0)))
+(0.3760431*(Math.pow(((D2==52?(6/7):(D2==53?3/7:0))), 2)))
-(0.0392583*D2)
+(0.0030492*(Math.pow(D2, 2)))
-(0.0000761*(Math.pow(D2, 3)))
+(0.000000606*(Math.pow(D2, 4)))
+1.052012
)
// console.log(WeekAvRatio)
var WeekStdevRatio = (
(0.040333*((D2==47?1:0)))
+(0.4126905*(((D2==52?(6/7):(D2==53?3/7:0)))))
-(0.5734843*(Math.pow(((D2==52?(6/7):(D2==53?3/7:0))), 2)))
+(0.0358187*D2)
-(0.0022887*(Math.pow(D2, 2)))
+(0.0000488*(Math.pow(D2, 3)))
-(0.000000324*(Math.pow(D2, 4)))
+0.8853995
)
// console.log("projZ " + projZ + ", " +
// "WeekStdevRatio " + WeekStdevRatio + ", " +
// "weeklystde_2015_16 " + weeklystde_2015_16 + ", " +
// "WeekAvRatio " + WeekAvRatio + ", " +
// "weekly_av_2015_16 " + weekly_av_2015_16 + ", "
// )
var ProjGross =(projZ*WeekStdevRatio*weeklystde_2015_16)+(WeekAvRatio*weekly_av_2015_16)
finalNum = ProjGross.toFixed();
// var Revenue = d3.select("#result").append("text")
// .text(finalNum + "$ USD").style("font-size", 30)
// console.log(finalNum)
return finalNum;
} // end of predictor function
/// Calculate the x and y, and path for the projection line:
var datas = [];
// var array = d3.range(1, 53);
var array2015 = d3.range(29, 54)
var array2016 = d3.range(1, 28)
array = array2015.concat(array2016)
// predictor function call
predictor(A2,B2 ,C2 ,D2, E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)
var x33 = d3.time.scale()
.range([0, width]);
var y33 = d3.scale.linear()
.range([height, 0]);
var arr = [];
array.forEach(function(d, i) {
D2 = d;
arr.push(+(predictor(A2,B2,C2,D2,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)))
})
var new_array = arr.concat();
for (var i = 1; i < arr.length; i++) {
new_array[i] = new_array[i-1] + arr[i];
}
var new_array = [];
arr.reduce(function(a,b,i) { return new_array[i] = a+b; },0);
// console.log(new_array)
array.forEach(function(d, i) {
datas.push({x3: i, y3: new_array[i]})
})
x33.domain([0,52]);
y33.domain([0, 100000000]);
var line4 = d3.svg.line()
.interpolate("step")
.x(function(d) { return x33(d.x3); })
.y(function(d) { return y33(d.y3); });
var area = d3.svg.area()
.x(function(d) { return x33(d.x3); })
.y0(height)
.y1(function(d) { return y33(d.y3); });
var linegraph4 = svg.append("path")
.attr("class", "line4")
.attr('d', function(d){return line4(datas)})
.style("stroke", "#ed113a")
.style("fill", "none")
.style("stroke-width", 2)
.style("stroke-opacity", 1)
.attr("transform", "translate(0, 0)");
// function mouseover:
function mousemove() {
var x0 = x.invert(d3.mouse(this)[0]),
i = bisectDate(datas, x0, 1),
d0 = datas[i - 1],
d1 = datas[i],
d = x0 - d0.x3 > d1.x3 - x0 ? d1 : d0;
console.log(d1)
focus.attr("transform", "translate(" + x33(d.x3) + "," + y33(d.y3) + ")");
focus.select("text").text(formatCurrency(d.y3));
}
// var area4 = svg.append("path")
// .attr("class", "area")
// .datum(datas)
// .attr("d", area)
// .style("fill", "#edfbd5")
// .style("fill-opacity", 0.1)
// .attr("transform", "translate(0, 0)");
// Mouseover Overlay:
svg.append("rect")
.attr("class", "overlay")
.attr("width", width)
.attr("height", height)
.on("mouseover", function() { focus.style("display", null); })
.on("mouseout", function() { focus.style("display", "none"); })
.on("mousemove", mousemove);
function update () {
datas = [];
arr = [];
predictor(A2,B2 ,C2 ,D2, E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)
array.forEach(function(d, i) {
D2 = d;
arr.push(+(predictor(A2,B2,C2,D2,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)))
})
new_array = arr.concat();
for (var i = 1; i < arr.length; i++) {
new_array[i] = new_array[i-1] + arr[i];
}
x33.domain([0,52]);
y33.domain([0, 100000000]);
new_array = [];
arr.reduce(function(a,b,i) { return new_array[i] = a+b; },0);
// console.log(new_array)
array.forEach(function(d, i) {
datas.push({x3: i, y3: new_array[i]})
})
var line4 = d3.svg.line()
.interpolate("step")
.x(function(d) { return x33(d.x3); })
.y(function(d) { return y33(d.y3); });
d3.select(".line4").transition().duration(1000)
.attr('d', function(d){return line4(datas)})
} // update function end
function makeChartsPerWeek(Stack) {
if (Stack == "W") {
datas = [];
arr = [];
predictor(A2,B2 ,C2 ,D2, E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)
array.forEach(function(d, i) {
D2 = d;
arr.push(+(predictor(A2,B2,C2,D2,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)))
})
array.forEach(function(d, i) {
D2 = d;
datas.push({x3: i, y3: +(predictor(A2,B2,C2,D2,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16))})
})
x.domain([0,52]);
y.domain([0, 3000000]);
x33.domain([0,52]);
y33.domain([0, 3000000]);
var line4 = d3.svg.line()
.interpolate("step")
.x(function(d) { return x33(d.x3); })
.y(function(d) { return y33(d.y3); });
d3.select(".line4").transition().duration(1000)
.attr('d', function(d){return line4(datas)})
svg.select(".y.axis")
.transition()
.duration(600)
.call(yAxis);
} else {
datas = [];
arr = [];
predictor(A2,B2 ,C2 ,D2, E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)
array.forEach(function(d, i) {
D2 = d;
arr.push(+(predictor(A2,B2,C2,D2,E2 ,F2 ,G2 ,H2 ,I2 ,J2 ,K2 ,L2 ,M2 ,N2 ,O2,weekly_av_2015_16,weeklystde_2015_16)))
})
new_array = arr.concat();
for (var i = 1; i < arr.length; i++) {
new_array[i] = new_array[i-1] + arr[i];
}
new_array = [];
arr.reduce(function(a,b,i) { return new_array[i] = a+b; },0);
// console.log(new_array)
array.forEach(function(d, i) {
datas.push({x3: i, y3: new_array[i]})
})
x.domain([0,52]);
y.domain([0, 100000000]);
x33.domain([0,52]);
y33.domain([0, 100000000]);
var line4 = d3.svg.line()
.interpolate("step")
.x(function(d) { return x33(d.x3); })
.y(function(d) { return y33(d.y3); });
d3.select(".line4").transition().duration(1000)
.attr('d', function(d){return line4(datas)})
svg.select(".y.axis")
.transition()
.duration(600)
.call(yAxis);
}
};
</script>
</body>
Modified http://infographics.economist.com/js_libraries/infographic_mobile.js to a secure url
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js
https://infographics.economist.com/js_libraries/infographic_mobile.js
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js