Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="content">
    <h1>Doping in Professional Bicycle Racing</h1>
    <div class="chart"></div>
    <div class="legend"></div>

</div>
<footer class="footer">
    <span>&copy; 2017 Developed with &nbsp;<i class="fa fa-heart" aria-hidden="true"></i> &nbsp;by Manish Giri using D3</span>
</footer>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Cinzel|Lora|Open+Sans|Patrick+Hand+SC|Playfair+Display');


$header-footer-color: #bdbdbd;
$bar-color: #212121;
$chart-background: #e0e0e0;
$rect-hover-color: #81c784;
$tooltip-background-color: #212121;


/*
  ---------------------------
    STICKY FOOTER
  ---------------------------

*/

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: url("https://www.dropbox.com/s/wqtbos5dw7zbwex/OSYEdQ%20%281%29.jpg?dl=1") no-repeat;
  background-size: cover;

}

.content {
  flex: 1 0 auto;
}



body {
  background-color: black;
}


/*
  ---------------------------
     HEADER
  ---------------------------

*/

h1 {
  font-family: 'Lora', serif;
  color: whitesmoke;
  text-align: center;
  font-size: 32px;
  text-transform: uppercase;
}



/*
  ---------------------------
     CHART
  ---------------------------

*/

svg {
  display: block;
  background-color: rgba(0,0,0,0.4);

  margin: 5px auto;
}


// axes color
.axisStyle {
  path, line, text {
    stroke: white;
    fill: none;
  }

}



/*
  ---------------------------
     TOOLTIP
  ---------------------------

*/

.tooltip {
  position: absolute;
  text-align: center;
  padding: 20px;
  background-color: $tooltip-background-color;
  color: whitesmoke;
  width: 260px;
  height: 130px;

  font-size: 12px;
  font-family:'Open Sans', sans-serif;
  border: 0px;
  border-radius: 8px;
  pointer-events: none;
}

.about {
  font-size: 14px;
  font-weight: bold;
  display: inline-block;
  margin-bottom: 5px;
}


.label {
  stroke: white;
  fill: none;
  shape-rendering: crispEdges;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;

}

/*
  ---------------------------
     FOOTER
  ---------------------------

*/

footer {
  text-align: center;
  color: white;
  text-transform: capitalize;

  span {
    font-family: 'Cinzel', serif;
    font-size: 16px;

    i {
      color: red;

    }
  }

}
              
            
!

JS

              
                /**
 * Created by manishgiri on 6/23/17.
 */


// margin
const margin = {top: 10, right: 60, bottom: 60, left: 60};

// SVG values
let width = 1060 - margin.left - margin.right;
let height = 500 - margin.top - margin.bottom;
let padding = 100;

// create div for tooltip
let div = d3.select("body")
    .append("div")
    .attr("class", "tooltip")
    .style("opacity", 0);


// create SVG element
let svg = d3.select(".chart")
    .append('svg')
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g")
    .attr("padding", 10)
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.json("https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/cyclist-data.json", function(result) {
    "use strict";
    let data = result;
    console.log(data);

    // create scales
    let xScale = d3.scaleTime()
        .domain([d3.max(data.map(row => d3.timeParse("%M:%S")(row.Time))), d3.min(data.map(row => d3.timeParse("%M:%S")(row.Time)))])
    .range([0, width])
        .nice();

    // use for axis
    let yScale = d3.scaleLinear()
        .domain(d3.extent(data, row => row.Place))
        .range([0, height])
        .nice();

    // use for plot
    let yScaleDup = d3.scaleLinear()
        .domain(d3.extent(data, row => row.Place))
        .range([0, height-3])
        .nice();

    // create scatter plot
    svg.selectAll("circle")
        .data(data)
        .enter()
        .append("circle")
        .attr("cx", d => xScale(d3.timeParse("%M:%S")(d.Time)))
        .attr("cy", d => yScaleDup(+d.Place))
        .attr("r", 6)
        .attr("fill", d => d.Doping ? "#f44336" : "#4caf50")
        .attr("stroke", "black")
        // create tooltips
        .on("mouseover", d => {
            div.transition()
                .duration(300)
                .style("opacity", 0.9)
            div.html(`<span class="about">${d.Name} - ${d.Nationality}</span><br> Time: ${d.Time}, Year: ${d.Year} <br> ${d.Doping}`)
                .style("left", (d3.event.pageX) - 60 + "px")
                .style("top", (d3.event.pageY) - 130 + "px")
        })
        .on("mouseout", d => {
            div.transition()
                .duration(500)
                .style("opacity", 0)
        });


    // create axes
    // x axis
    svg.append("g")
        .attr("class", "axisStyle")
        .attr("transform", "translate(0," + (height+2) + ")")
        .call(d3.axisBottom(xScale).tickFormat(d3.timeFormat("%M:%S")));

    // y axis
    svg.append("g")
        .attr("class", "axisStyle" )
        .call(d3.axisLeft(yScale));

    // create axes labels
    svg.append("text")
        .attr("transform", "rotate(-90)")
        .attr("x", 0 - (height/2))
        .attr("y", 0 - (margin.left) + 10)
        .attr("dy", "1em")
        .attr("class", "label")
        .style("color", "white")
        .style("text-anchor", "middle")
        .text("Rank")

    svg.append("text")
        .attr("transform", "translate(" + (width/2) + "," + (height + 50) + ")" )
        .style("text-anchor", "middle")
        .attr("class", "label")
        .text("Time")


});

              
            
!
999px

Console