philipsChart = {
let svg = d3.create("svg");
svg.attr("viewBox", [0, 0, width, height]);
let currentY = { cur: 80000 };
let currentYCont = [currentY];
let graphContainer = svg.append("g").attr("transform", element => {
let yTrans = 200;
let xTrans = 20;
return "translate(" + xTrans + "," + yTrans + ")";
});
let yMultiplesCopy = _.cloneDeep(yMultiples);
let slidingBar = svg
.append("line")
.attr("id", "slider")
.attr("y1", element => {
return 0;
})
.attr("x1", element => {
console.log(currentY);
return philipsIncomeXScale(currentY.cur);
})
.attr("y2", element => {
return height;
})
.attr("x2", element => {
return philipsIncomeXScale(currentY.cur);
})
.attr("style", "stroke:rgb(255,0,0);stroke-width:3");
let graphs = graphContainer
.selectAll("g.yMult")
.data(yMultiplesCopy)
.enter()
.append("g")
.attr("id", (element, index) => {
"ph" + index;
})
.attr("transform", (element, index) => {
let yTrans = index * (graphHeight + graphMargin.top);
let xTrans = 0;
return "translate(" + xTrans + "," + yTrans + ")";
})
.attr("class", "yMult");
graphs.append("text").text(element => {
return element.name;
});
graphs
.append("line")
.attr("y1", element => {
return element.scale(element.func(minY));
})
.attr("x1", element => {
return philipsIncomeXScale(minY);
})
.attr("y2", element => {
return element.scale(element.func(maxY));
})
.attr("x2", element => {
return philipsIncomeXScale(maxY);
})
.attr("style", "stroke:rgb(255,0,0);stroke-width:3");
graphs.append("text").attr("transform", (element, index) => {
let yTrans = 100;
let xTrans = 300;
return "translate(" + xTrans + "," + yTrans + ")";
}) /*
.text(element => {
return "is:" + element.func(currentY.cur);
})*/;
graphs
// .each(drawPhilipsYAxis);
.append("g")
.attr("transform", (element, index) => {
let yTrans = graphHeight;
let xTrans = 0;
return "translate(" + xTrans + "," + yTrans + ")";
})
.call(d3.axisBottom(philipsIncomeXScale));
graphContainer
.append("g")
.attr("transform", (element, index) => {
let yTrans = 0 * (graphHeight + graphMargin.top);
let xTrans = 0;
return "translate(" + xTrans + "," + yTrans + ")";
})
.call(d3.axisLeft(philipsRealInterestRateYScale));
graphContainer
.append("g")
.attr("transform", (element, index) => {
let yTrans = 1 * (graphHeight + graphMargin.top);
let xTrans = 0;
return "translate(" + xTrans + "," + yTrans + ")";
})
.call(d3.axisLeft(philipsUnemploymentYScale));
graphContainer
.append("g")
.attr("transform", (element, index) => {
let yTrans = 2 * (graphHeight + graphMargin.top);
let xTrans = 0;
return "translate(" + xTrans + "," + yTrans + ")";
})
.call(d3.axisLeft(philipsInflationYScale));
let titleDiv = svg
.append("g")
.attr("transform", "translate(" + width / 4 + ", " + 30 + ")")
.append("text")
.text("Philips curve");
svg.on("mouseover", function() {
currentY.cur = mousePositionToYPercentage(d3.mouse(this)[0]);
d3.select("line#slider")
.attr("x1", philipsIncomeXScale(currentY.cur))
.attr("x2", philipsIncomeXScale(currentY.cur));
/*yMultiplesCopy = yMultiples.map(element => {
element.yVal = currentY;
return element;
});*/
});
return svg.node();
}