{"version":3,"file":"diversification-risk-C0VvA-qk.js","sources":["../../../app/javascript/components/viz/diversification/diversification-risk-graph.js","../../../app/javascript/components/viz/diversification/diversification-risk.vue"],"sourcesContent":["import * as d3 from '~/app/custom-d3'\nimport numeral from 'numeral'\n\nexport default class RiskGraph {\n constructor(el, funds) {\n this.el = el\n this.margin = {\n top: 20,\n left: 50,\n right: 10,\n bottom: 20\n }\n\n this.funds = funds\n this.options = this.generateBounds()\n this.setup(d3.entries(funds))\n\n this.callbacks = {};\n }\n\n on(event, callback) {\n this.callbacks[event] = callback\n }\n\n generateBounds() {\n var bounds = this.el.getBoundingClientRect(),\n height = 300,\n width = 1100\n if(height > bounds.width) {\n height = bounds.width * 0.8\n }\n if(width > bounds.width) {\n width = bounds.width\n }\n return {\n height: height,\n width: width\n }\n }\n\n setup(funds) {\n this.svg = d3.select(this.el).append(\"svg\")\n .attr('class', 'graph')\n .attr(\"width\", this.options.width)\n .attr(\"height\", this.options.height);\n\n // X-axis\n this.xAxisEl = this.svg.append(\"g\")\n .attr(\"class\", \"x axis\")\n .attr(\"transform\", \"translate(\"+this.margin.left+\",\" + (this.options.height-this.margin.top-10) + \")\");\n this.xAxisEl.append(\"text\")\n .attr(\"class\", \"text-end text-lg\")\n .attr(\"y\", -18)\n .attr(\"x\", this.options.width-100)\n .attr(\"dy\", \".71em\")\n .text(\"Historical Risk\");\n\n // Y-axis\n this.yAxisEl = this.svg.append(\"g\")\n .attr(\"class\", \"y axis\")\n .attr(\"transform\", \"translate(\"+this.margin.left+\",\"+this.margin.top+\")\");\n this.yAxisEl.append(\"text\")\n .attr(\"class\", \"text-end text-lg rotate--90\")\n .attr(\"y\", 6)\n .attr(\"x\", this.margin.top*-1)\n .attr(\"dy\", \".71em\")\n .text(\"Historical Returns\");\n\n\n // Risk/Reward path\n var g = this.svg.append('g')\n .attr('transform', \"translate(\" + this.margin.left + \",\" + this.margin.top + \")\");\n this.path = g.append('path')\n .attr('class', 'line stroke-grey-700 stroke-width-base stroke-dasharray-dashed-lg');\n\n\n\n // Tooltips\n this.tip = d3.tip().attr('class', 'd3-tip rounded').html(function(fund) {\n return `
${fund.label}
Avg gain: ${numeral(fund.computed.avg).format('0.0%')}
Risk: ${numeral(fund.computed.risk).format('0.0')}