Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="root"></div>
              
            
!

CSS

              
                body {
  background-image: url("https://i.pinimg.com/originals/6e/15/49/6e1549a23a5bade96933775ca76a280e.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
}

.pointContainer {
  transition: 0.15s linear;
}

.pointContainer text {
  transition: 0.15s linear;
}

.pointContainer.active text {
  fill: #297fb8;
}

.pointContainer ellipse {
  transition: 0.15s linear;
}

.pointContainer.active ellipse {
  fill: blue;
}

line {
  transition: 0.25s linear;
}

              
            
!

JS

              
                $(document).ready(function() {
  //d3.selectAll('h1').style("color", "red").style("display", "none");

  var url = "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/cyclist-data.json"
  var graphWidth  = 500,
      graphHeight = 300;

  var canvas = d3.select('.root')
                  .append('svg')
                  .attr("width", "calc(100vw - 20px)")
                  .attr("height", "calc(100vh - 20px)");
                  //.style("border", "1px solid black");

  var imgOne = canvas.append('image')
                      .attr("xlink:href", "https://oddert.github.io/img/sinbin_one.png")
                      .attr("width", "200px")
                      .attr("height", "200px")
                      .attr("x", "10")
                      .attr("y", "10");

  var imgTwo = canvas.append('image')
                      .attr("xlink:href", "https://oddert.github.io/img/sinbin_two.png")
                      .attr("width", "200px")
                      .attr("height", "200px")
                      .attr("x", "calc(100vw - 250)")
                      .attr("y", "50");

  var imgThree = canvas.append('image')
                      .attr("xlink:href", "https://oddert.github.io/img/sinbin_three.png")
                      .attr("width", "100px")
                      .attr("height", "100px")
                      .attr("x", "calc(100vw - 300)")
                      .attr("y", "400");

 $.getJSON(url, function (json) {

   var firstPosTime = json[0].Seconds,
       lastPosTime  = json[json.length-1].Seconds;

   var timeScale = d3.scaleLinear()
                      .domain([lastPosTime, firstPosTime])
                      .range([0, graphWidth])//this one take position

   var positionScale = d3.scaleLinear()
                      .domain([1, 35])
                      .range([0, graphHeight])//this one take time

   var graph = canvas.append('g')
                      .style("transform", "translate( calc(calc(50vw - 20px) - " + (graphWidth/2) + "px), calc(calc(50vh - 20px) - " + (graphHeight/2) + "px))")
                      .style("border", "10px solid blue");

   var graphBackground = graph.append('rect')
                              .attr("width", (graphWidth + 135))
                              .attr("height", (graphHeight + 135))
                              .attr("fill", "rgba(255, 255, 255, 0.8)")
                              .attr("x", "-65")
                              .attr("y", "-65")

   var pointContainer = graph.selectAll('ellipse')
                    .data(json)
                    .enter()
                    .append('g')
                    .attr("class", "pointContainer")
                    .on("mouseover", function(d) {
                      d3.select(this).attr("class", "pointContainer active");
                      infoBoxName.text(d.Name);
                      infoBoxTime.text("Lap Time: " + d.Time);
                      infoBoxPlace.text("Rank " + d.Place);
                      infoBoxYear.text(d.Year);
                      infoBoxDoping.text(d.Doping == "" ? "No doping allegations" : d.Doping);
                      targetLineContainer.style("display", null);
                      infoBoxContainer.style("display", null);
                      var xOffset = timeScale(d.Seconds);
                      var yOffset = positionScale(d.Place);
                      targetLineX.attr("x1", xOffset).attr("x2", xOffset).attr("y1", yOffset);
                      targetLineY.attr("y1", yOffset).attr("y2", yOffset).attr("x2", (xOffset));
                    })
                    .on("mouseout", function () {
                      d3.select(this).attr("class", "pointContainer");
                      targetLineContainer.style("display", "none");
                      infoBoxContainer.style("display", "none");
                    });

    var pointElipse = pointContainer.append('ellipse')
                     .attr("cy", function(d) {
                       return positionScale(d.Place);
                     })
                     .attr("cx", function (d) {
                       return timeScale(d.Seconds);
                     })
                     .attr("rx", "3")
                     .attr("ry", "3")
                     .attr("fill", function(d) {
                        return d.Doping == "" ? "#27ae61" : "#e84c3d"
                     });

    var pointTextWrap = pointContainer.append('a')
                                      .attr("target", "_blank")
                                      .attr("xlink:href", function (d) {
                                        return d.URL;
                                      });

    var pointText = pointTextWrap.append('text')
                                  .text(function(d) {
                                    return d.Name;
                                  })
                                  .attr("x", function (d) {
                                    return timeScale(d.Seconds);
                                  })
                                  .attr("y", function(d) {
                                    return positionScale(d.Place);
                                  })
                                  .attr("fill", "black")
                                  .attr("font-size", "0.6em")
                                  .attr("transform", "translate(6, 4)");

    var positionAxis = d3.axisLeft(positionScale)
                          .ticks(5);

                      graph.append('g')
                            .call(positionAxis)
                            .attr("transform", "translate(-10, 0)");

    var timeAxisScale = d3.scaleTime()
                          .domain([
                            new Date((firstPosTime * 1000)),
                            new Date((lastPosTime * 1000))
                          ])
                          .range([graphWidth, 0]);

    var timeAxis = d3.axisBottom(timeAxisScale)
                      .ticks(5)
                      .tickFormat(d3.timeFormat("%M:%S"));

                      graph.append('g')
                            .call(timeAxis)
                            .attr("transform", "translate(0, " + (graphHeight + 10) + ")");


    var infoBoxContainer = graph.append('g')
                                  .attr("transform", "translate(200, 200)")
                                  .style("display", "none");

    var infoBoxName = infoBoxContainer.append('text');
    var infoBoxTime = infoBoxContainer.append('text').attr("transform", "translate(0, 20)");
    var infoBoxPlace = infoBoxContainer.append('text').attr("transform", "translate(0, 40)");
    var infoBoxYear = infoBoxContainer.append('text').attr("transform", "translate(0, 60)");
    var infoBoxDoping = infoBoxContainer.append('text').attr("transform", "translate(0, 80)");

    var targetLineContainer = graph.append('g')
                                    .style("display", "none");

    var targetLineX = targetLineContainer.append('line')
                                          .attr("x1", "0")
                                          .attr("y1", "0")
                                          .attr("x2", "0")
                                          .attr("y2", "310")
                                          .style("stroke", "rgba(10,10,10,0.2)")
                                          .style("stroke-width", "1");

    var targetLineY = targetLineContainer.append('line')
                                          .attr("x1", "-10")
                                          .attr("y1", "0")
                                          .attr("x2", graphWidth)
                                          .attr("y2", "0")
                                          .style("stroke", "rgba(10,10,10,0.2)")
                                          .style("stroke-width", "1");

    var keyContainer = graph.append('g')
                            .attr("transform", "translate(15, 10)");

    var keyGuilty = keyContainer.append('g');
    var keyInnocent = keyContainer.append('g');

    var keyGuiltyCircle = keyGuilty.append('ellipse')
                                    .attr("cx", "0")
                                    .attr("cy", "0")
                                    .attr("rx", "3")
                                    .attr("ry", "3")
                                    .attr("fill", "#e84c3d");

    var keyGuiltyText = keyGuilty.append('text')
                                 .text("Doping Allegations")
                                 .style("font-size", "0.8em")
                                 .attr("x", "5")
                                 .attr("y", "4");

    var keyInnocentCircle = keyGuilty.append('ellipse')
                                   .attr("cx", "120")
                                   .attr("cy", "0")
                                   .attr("rx", "3")
                                   .attr("ry", "3")
                                   .attr("fill", "#27ae61");

    var keyInnocentText = keyGuilty.append('text')
                                  .text("No Doping Allegations")
                                  .style("font-size", "0.8em")
                                  .attr("x", "125")
                                  .attr("y", "4");

    var title = graph.append("text")
                      .text("Doping in Alpe d'Huez Fastest Race Times")
                      .attr("x", "100")
                      .attr("y", "-40")
                      .style("font-size", "1.25em");

    var timeAxisLabel = graph.append("text")
                              .text("Lap Time")
                              .attr("x", "200")
                              .attr("y", (graphHeight + 45))
                              .style("font-size", "0.7em");

    var timeAxisLabel = graph.append("text")
                              .text("Ranking")
                              .attr("x", "-50")
                              .attr("y", (graphHeight/2))
                              .attr("transform", "rotate(-90, -50, " + (graphHeight/2) + ")")
                              .style("font-size", "0.7em");



 });




});

              
            
!
999px

Console