/* #ffbd00 - gold #0e1a36 - royal #008281 - teal #fafafa #c1c1c1 - line #f2f2f2; */ // set the dimensions and margins of the graph const margin = {top: 20, right: 20, bottom: 70, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; // parse the date / time const parseTime = d3.timeParse("%d-%b-%y"); //"%B %d, %Y" // set the ranges const x = d3.scaleTime().range([0, width]); const y = d3.scaleLinear().range([height, 0]); // define the line // line options https://bl.ocks.org/d3noob/ced1b9b18bd8192d2c898884033b5529 // http://bl.ocks.org/emmasaunders/c25a147970def2b02d8c7c2719dc7502 const valueline = d3.line() .curve(d3.curveLinear) .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.close); }); // append the svg obgect to the body of the page // appends a 'group' element to 'svg' // moves the 'group' element to the top left margin const svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // const drawChart = (data, chartMin = 0, chartMax = 100) => { data.forEach(function(d) { d.date = parseTime(d.date); d.close = +d.close; }); // Scale the range of the data x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([chartMin, d3.max(data, function(d) { return chartMax; })]); //d.close; // Add the X Axis svg.append("g") .attr("class", "axis") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x).ticks(20)) .selectAll("text") .style("text-anchor", "end") .attr("dx", "-.8em") .attr("dy", ".15em") .attr("transform", "rotate(-65)"); // Add the Y Axis svg.append("g") .attr("class", "axis") .call(d3.axisLeft(y).ticks(20)); } const handleMouseClick = (d) => { } const handleMouseOver = (d) => { } const handleMouseOut = (d) => { } const drawLine = (data, lineClass, bDrawPoints, bParseData = false) => { // format the data if (bParseData){ data.forEach(function(d) { d.date = parseTime(d.date); d.close = +d.close; }); } // Scale the range of the data x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([0, d3.max(data, function(d) { return 100; })]); //d.close; // Add the valueline path. const path = svg.append("path") .data([data]) .attr("class", lineClass) .attr("d", valueline); if (bDrawPoints) { svg.append('g').selectAll('circle') .data(data.reverse()) .enter().append('circle') .on("click", function(d) { return handleMouseClick(d)}) .on("mouseover", function(d) {return handleMouseOver(d)}) .on("mouseover", function(d) {return handleMouseOut(d)}) .attr("cx", function(d) { return x(d.date) }) .attr("cy", function(d) { return y(d.close) }) .attr("r", 0) .attr("class","datapoint") .style("opacity", function(d){ return (d.selected) ? 1 : 1}) .style("fill", "white") .style("stroke", function(d) { return "#000" }) .style("pointer-events", "all") .style("cursor", "pointer") .transition() .duration(1000) .delay( function(d,i){ return 250 + ( 750 * i) }) .attr("r", 10); } }