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. 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

JavaScript

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

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 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

              
                
              
            
!

CSS

              
                @import "https://fonts.googleapis.com/css?family=Open+Sans&display=swap";

:root {
	box-sizing: border-box;
	font-family: "Open Sans", sans-serif;
}

body {
	background-color: SteelBlue;
	padding-top: 5em;
}

#chart {
	border: thin outset gray;
	background-color: ghostwhite;
	box-shadow: 1px 1px 10px 1px black;
	width: 970px;
	margin: auto;
	padding: 1em;
	display: block;
}

#title {
	font-size: 200%;
	font-weight: bold;
	font-variant: small-caps;	
}

#sub-title {
	font-size: 150%;
}

.dot {
	opacity: 0.7;
	fill: #00ff00;
	border: thick solid black;
	stroke: #000;
	stroke-width: 3;
}

[doped^="http"] {
	fill: #ff8000;
}

#tooltip {
	position: absolute;
	color: ghostwhite;
	border: thin solid black;
	background-color: #0080ff;
	font-size: small;
	padding: 0 1em 0 1em;
}
.label {
	font-weight: bolder;
	font-size: 150%;
	font-variant: small-caps;
}

              
            
!

JS

              
                const DATA_API =
	"https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/cyclist-data.json";

const HEIGHT = 470,
	WIDTH = 840,
	PADDING = { top: 80, right: 60, bottom: 60, left: 80 };

const tooltip = d3
	.select("body")
	.append("div")
	.attr("id", "tooltip")
	.style("visibility", "hidden");

const colours = d3.scaleOrdinal(
	[`#00FF00`, `#FF8000`],
	[`No doping allegations`, `Riders with doping allegations`]
);

d3.json(DATA_API).then(data => {
	console.clear();
	//convert data to Date format
	data.forEach(d => {
		d.Seconds = new Date(d.Seconds * 1000);
	});
	//render SVG area for chart
	const chartSVG = d3
		.select("body")
		.append("svg")
		.attr("width", WIDTH + PADDING.left + PADDING.right)
		.attr("height", HEIGHT + PADDING.top + PADDING.bottom)
		.attr("id", "chart");
	//initialise x-Axis
	const xScale = d3.scaleLinear();
	const minYear = d3.min(data, d => d.Year) - 1;
	const maxYear = d3.max(data, d => d.Year) + 1;
	xScale.domain([minYear, maxYear]);
	xScale.range([PADDING.left, WIDTH]);
	const xAxis = d3.axisBottom(xScale).tickFormat(d3.format("d"));
	//initialise y-Axis
	const yScale = d3.scaleTime();
	yScale.domain(d3.extent(data, d => d.Seconds));
	yScale.range([PADDING.top, HEIGHT + PADDING.top]);
	const yAxis = d3.axisLeft(yScale);
	yAxis.tickFormat(d3.timeFormat("%M:%S"));
	//render title
	chartSVG
		.append("text")
		.attr("id", "title")
		.attr("x", (WIDTH + PADDING.left + PADDING.right) / 2)
		.attr("y", PADDING.top / 2 - 10)
		.attr("text-anchor", "middle")
		.text("Doping in Professional Bicycle Racing");
	//render subtitle
	chartSVG
		.append("text")
		.attr("id", "sub-title")
		.attr("x", (WIDTH + PADDING.left + PADDING.right) / 2)
		.attr("y", PADDING.top / 2 + 25)
		.attr("text-anchor", "middle")
		.text("35 Fastest times up Alpe d'Huez");
	//render x-axis
	chartSVG
		.append("g")
		.call(xAxis)
		.attr("id", "x-axis")
		.attr("transform", `translate(0,${HEIGHT + PADDING.top})`);
	chartSVG
		.append("text")
		.attr("class", "x label")
		.attr("text-anchor", "end")
		.attr("x", (WIDTH + PADDING.left + PADDING.right) / 2)
		.attr("y", HEIGHT + PADDING.top + PADDING.bottom - 10)
		.text("Year Set");
	//render y-axis
	chartSVG
		.append("g")
		.call(yAxis)
		.attr("id", "y-axis")
		.attr("transform", `translate(${PADDING.left},0)`);
	chartSVG
		.append("text")
		.attr("class", "y label")
		.attr("text-anchor", "end")
		.attr("x", PADDING.bottom + PADDING.top - HEIGHT / 2)
		.attr("y", 30)
		.attr("transform", "rotate(-90)")
		.text("Time in Minutes:Seconds");
	//render points and add 0.5 to co-ordinates to fix calculation errors in scales
	chartSVG
		.selectAll("circle")
		.data(data)
		.enter()
		.append("circle")
		.attr("class", "dot")
		.attr("data-xvalue", d => d.Year)
		.attr("data-yvalue", d => d.Seconds)
		.attr("cx", d => xScale(d.Year) + 0.5)
		.attr("cy", d => yScale(d.Seconds) + 0.5)
		.attr("r", 5)
		.attr("doped", d => d.URL)
		.on("mouseover", d => {
			tooltip
				.attr("data-year", d.Year)
				.html(
					`<p><strong>Name</strong>: ${d.Name}<br/>
					<strong>Nationality:</strong> ${d.Nationality}<br/>
					<strong>Year:</strong> ${d.Year}<br/>
					<strong>Time (mm:ss) :</strong> ${d.Time}<br/>
					${d.Doping ? `<strong>Doping:</strong> ${d.Doping}` : ""} </p>`
				)
				.style("visibility", "visible")
				.style("left", d3.event.pageX + 5 + "px")
				.style("top", d3.event.pageY - 55 + "px");
		})
		.on("mouseout", () => {
			tooltip.style("visibility", "hidden");
		});
	//render legend
	const legend = chartSVG
		.selectAll(".legend")
		.data(colours.domain())
		.enter()
		.append("g")
		.attr("id", "legend")
		.attr(
			"transform",
			(d, i) =>
				"translate(0," +
				((HEIGHT + PADDING.top + PADDING.bottom) / 2 - i * 25) +
				")"
		);

	legend
		.append("circle")
		.attr("cx", WIDTH)
		.attr("cy", 11)
		.attr("r", 5)
		.style("fill", d => d)
		.style("stroke", "#000")
		.style("stroke-width", 3);

	legend
		.append("text")
		.attr("x", WIDTH - 10)
		.attr("y", 10)
		.attr("dy", ".35em")
		.style("text-anchor", "end")
		.text(d => colours(d));
});

              
            
!
999px

Console