Pen Settings



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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.




                html { height: 100%; }
body {
  align-items: center;
  background-color: #1D1E22;
  display: flex;
  justify-content: center;
  height: 100%;

svg {
  background-color: #fff;
  margin: 20px;
  padding: 60px 0 40px 50px;

.title {
  font-size: 24px;

.subtitle {
  font-size: 20px;

.dot {
  stroke: #000;
  fill-opacity: 0.7;
  stroke-opacity: 0.7;

div.tooltip {
  background: rgba(112, 127, 140, .85);
  border: none;
  border-radius: 2px;
  color: #fff;
  font-size: 18px;
  padding: 10px 20px;
  pointer-events: none;
  position: absolute;
  text-align: left;
  width: 250px;


                // store data in variable
const dataURI = ''

// set up svg
const w = 1120
const h = 500
const padding = 60
const svg ='body')
              .attr('width', w)
              .attr('height', h)

// set up chart title
   .attr('transform', `translate(${w/2}, ${padding - 60})`)
   .attr('class', 'title')
   .attr('id', 'title')
   .style('text-anchor', 'middle')
   .text('Doping in Professional Bicycle Racing')

// set up chart subtitle
   .attr('transform', `translate(${w/2}, ${padding - 30})`)
   .attr('class', 'subtitle')
   .attr('id', 'subtitle')
   .style('text-anchor', 'middle')
   .text('35 Fastest times up Alpe d\'Huez')

// read in data
d3.json(dataURI, {crossOrigin: "anonymous"}).then(data => {
  // set up min and max for data points
  const minSeconds = d3.min(data, d => d.Seconds - 10)
  const maxSeconds = d3.max(data, d => d.Seconds + 5)
  const minYears = d3.min(data, d => d.Year - 1)
  const maxYears = d3.max(data, d => d.Year + 1)
  // set up time format function
  const formatSeconds = seconds => {
    let duration = moment.duration(seconds, 'seconds')
    return moment(duration.asMilliseconds()).format('mm:ss')
  // set up date object for test requirement
  const secondsToDate = seconds => {
    let t = new Date(1970, 0, 1)
    return t
  // set up x scale
  const xScale = d3.scaleLinear()
                   .domain([minYears, maxYears])
                   .range([padding, w - padding])
  // set up y scale
  const yScale = d3.scaleLinear()
                   .domain([minSeconds, maxSeconds])
                   .range([padding, h - padding])
  // set up color scale
  const colorScale = d3.scaleOrdinal(d3.schemeAccent)
  // append div for use as tooltip
  const tooltip ='body')
                    .attr('class', 'tooltip')
                    .attr('id', 'tooltip')
                    .style('opacity', 0)
  // set up scatter plot
  const dot = svg.selectAll('circle')
                 .attr('cx', d => xScale(d.Year))
                 .attr('cy', d => yScale(d.Seconds))
                 .attr('r', d => 8)
                 .attr('class', 'dot')
                 .attr('data-xvalue', d => d.Year)
                 .attr('data-yvalue', d => secondsToDate(d.Seconds))
                 .style('fill', d => colorScale(d.Doping !== ''))
                 // set up mouseover to modify tooltip div
                 .on('mouseover', (d, i) => {
                          .style('opacity', 0.9)
                            <br />
                            <br />
                            Year: ${d.Year}, Time: ${d.Time}
                                  ? `
                                    <br />
                                    <br />
                                  : ''
                          .attr('data-year', d.Year)
                          .style('left', (d3.event.pageX) + 20 + 'px')
                          .style('top', (d3.event.pageY) + 'px')
                 // set up mouseout to modify tooltip div
                 .on('mouseout', d => {
                          .style('opacity', 0)
  // set up x axis
  const xAxis = d3.axisBottom()
  // use call to create x axis
     .attr('transform', `translate(0, ${h - padding})`)
     .attr('id', 'x-axis')
  // set up x axis label
   .attr('transform', `translate(${w/2}, ${h - 10})`)
   .style('text-anchor', 'middle')
  // set up y axis
  const yAxis = d3.axisLeft(yScale).tickFormat(formatSeconds)
  // use call to create y axis
     .attr('transform', `translate(${padding}, 0)`)
     .attr('id', 'y-axis')
  // set up y axis label
     .attr('transform', `translate(10, ${h/2})rotate(-90)`)
     .style('text-anchor', 'middle')
     .text('Time in Minutes')
  // set up legend
  const legend = svg.selectAll('.legend')
                    .attr('class', 'legend')
                    .attr('id', 'legend')
                    .attr('transform', (d, i) => `translate(0, ${h/2 - i * 25})`)
  // add proper text to legend
        .attr('x', w - 70)
        .attr('y', 15)
        .style('text-anchor', 'end')
        .text(d => {
          if (d) {
            return "Riders with doping allegations"
          } else {
            return "No doping allegations"
  // add color keys to legend
        .attr('x', w - padding)
        .attr('width', 20)
        .attr('height', 20)
        .style('fill', colorScale)