Built with blockbuilder.org
Last active
October 7, 2018 18:51
-
-
Save headwinds/0d4cd73a04c6f3984aae052980582ff6 to your computer and use it in GitHub Desktop.
rivalry performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| date | close | |
|---|---|---|
| 5-Apr-12 | 45.51 | |
| 4-Apr-12 | 39.51 | |
| 3-Apr-12 | 23.51 | |
| 2-Apr-12 | 47.51 | |
| 30-Mar-12 | 50.51 | |
| 29-Mar-12 | 65.51 | |
| 28-Mar-12 | 81.51 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| date | close | |
|---|---|---|
| 1-May-12 | 58.13 | |
| 30-Apr-12 | 53.98 | |
| 27-Apr-12 | 67.00 | |
| 26-Apr-12 | 89.70 | |
| 25-Apr-12 | 99.00 | |
| 24-Apr-12 | 130.28 | |
| 23-Apr-12 | 166.70 | |
| 20-Apr-12 | 234.98 | |
| 19-Apr-12 | 345.44 | |
| 18-Apr-12 | 443.34 | |
| 17-Apr-12 | 543.70 | |
| 16-Apr-12 | 580.13 | |
| 13-Apr-12 | 605.23 | |
| 12-Apr-12 | 622.77 | |
| 11-Apr-12 | 626.20 | |
| 10-Apr-12 | 628.44 | |
| 9-Apr-12 | 636.23 | |
| 5-Apr-12 | 633.68 | |
| 4-Apr-12 | 624.31 | |
| 3-Apr-12 | 629.32 | |
| 2-Apr-12 | 618.63 | |
| 30-Mar-12 | 599.55 | |
| 29-Mar-12 | 609.86 | |
| 28-Mar-12 | 617.62 | |
| 27-Mar-12 | 614.48 | |
| 26-Mar-12 | 606.98 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| date | close | |
|---|---|---|
| 5-Apr-12 | 45.51 | |
| 4-Apr-12 | 40.51 | |
| 3-Apr-12 | 43.51 | |
| 2-Apr-12 | 47.51 | |
| 30-Mar-12 | 60.51 | |
| 29-Mar-12 | 55.51 | |
| 28-Mar-12 | 61.51 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| body { | |
| font: 12px sans-serif; | |
| } | |
| .axis path, | |
| .axis line { | |
| fill: none; | |
| stroke: #ddd; | |
| shape-rendering: crispEdges; | |
| } | |
| .x.axis path { | |
| //fill: #ddd; | |
| stroke: #ddd; | |
| } | |
| .tick { | |
| fill: #999; | |
| } | |
| .rivarly-line { | |
| fill: none; | |
| stroke: #ddd; | |
| stroke-width: 4px; | |
| } | |
| .expected-line { | |
| fill: none; | |
| stroke: #008281; | |
| stroke-width: 4px; | |
| } | |
| .actual-line { | |
| fill: none; | |
| stroke: #0e1a36; | |
| stroke-width: 4px; | |
| } | |
| .line { | |
| fill: none; | |
| stroke: steelblue; | |
| stroke-width: 4px; | |
| } | |
| .selectedline { | |
| fill: none; | |
| stroke: steelblue; | |
| stroke-width: 8px; | |
| } | |
| .lineSelected { | |
| } | |
| circle { | |
| pointer-events: all; | |
| cursor: points; | |
| } | |
| .datapoint { | |
| pointer-events: "all"; | |
| cursor: "pointer" !imporantant; | |
| stroke-width: 2px; | |
| } | |
| </style> | |
| <body> | |
| <!-- load the d3.js library --> | |
| <script src="https://d3js.org/d3.v5.min.js"></script> | |
| <script> | |
| /* | |
| #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"); | |
| // 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.curveCardinal) | |
| .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) => { | |
| 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 X Axis | |
| svg.append("g") | |
| .attr("class", "axis") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(d3.axisBottom(x).ticks(10)) | |
| .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)); | |
| } | |
| const handleMouseClick = (d) => { | |
| } | |
| const handleMouseOver = (d) => { | |
| } | |
| const handleMouseOut = (d) => { | |
| } | |
| const drawLine = (data, lineClass, bDrawPoints) => { | |
| // format the data | |
| 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); | |
| } | |
| } | |
| // Get the data | |
| d3.csv("actual.csv").then( data => { | |
| drawChart(data); | |
| }, | |
| error => { | |
| // handle the error | |
| }); | |
| d3.csv("rivalry.csv").then( data => { | |
| drawLine(data, "rivarly-line"); | |
| }, | |
| error => { | |
| // handle the error | |
| }); | |
| d3.csv("expected.csv").then( data => { | |
| drawLine(data, "expected-line"); | |
| }, | |
| error => { | |
| // handle the error | |
| }); | |
| // Get the data | |
| d3.csv("actual.csv").then( data => { | |
| drawLine(data, "actual-line", true); | |
| }, | |
| error => { | |
| // handle the error | |
| }); | |
| </script> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| date | close | |
|---|---|---|
| 5-Apr-12 | 45.51 | |
| 4-Apr-12 | 42.51 | |
| 3-Apr-12 | 43.51 | |
| 2-Apr-12 | 42.51 | |
| 30-Mar-12 | 25.51 | |
| 29-Mar-12 | 35.51 | |
| 28-Mar-12 | 65.51 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment