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.


                footer a freeCodeCamp project by kbaig


	min-height: 80vh
	display: flex
	flex-direction: column
	justify-content: center
	align-items: center
	background: #eee
		position: absolute
		background: #eee
		border: 1px solid #aaa
		border-radius: 4px
		padding: 10px 15px
		display: flex
		flex-direction: column
				margin-bottom: 2px
				font-weight: 600
				font-size: 14px
		background: white
		border: 1px solid #aaa
		box-shadow: 1px 1px 10px 0 #aaa
			fill: #333
			font-size: 28px
			font-weight: 600
			fill: #333
			font-size: 18px
			font-size: 11px

			fill: #85bb65
				fill: #666
			font-size: 11px
			margin-bottom: 3px
			fill: #223318
		order: 2
		margin-top: 25px
		font-family: sans-serif
		font-size: 14px
		color: #222


	.then(res => res.json())
	.then(jsonResponse => plot(jsonResponse));

const plot = response => {
	const w = 850;
	const h = 500;
	const padding = 85;

	const dataset =;

	const monthNumToName = [

	const svg = d3
		.attr("width", w)
		.attr("height", h);

	// string to date helper
	const dateFromData = date => {
		const arr = date.split("-");
		return new Date(arr[0], arr[1], arr[2]);
	// x scale and axis
	const xScale = d3
			d3.min(dataset, d => dateFromData(d[0])),
			d3.max(dataset, d => dateFromData(d[0]))
		.range([padding, w - padding]);

	const xAxis = d3.axisBottom(xScale);
		.attr("transform", `translate(0, ${h - padding})`)
		.attr('class', 'axis')

		.attr("text-anchor", "middle")
		.attr("x", w / 2)
		.attr("y", h - padding / 2 - 5)
		.attr("class", "axis-title")
	// y scale and axis
	const yScale = d3
		.domain([0, d3.max(dataset, d => d[1])])
		.range([h - padding, padding]);

	const yAxis = d3.axisLeft(yScale).tickFormat(d => "$" + d3.format(",")(d));

		.attr("transform", `translate(${padding}, 0)`)
		.attr('class', 'axis')

		.attr("text-anchor", "middle")
		.attr("transform", `translate(${padding / 3}, ${h / 2})rotate(-90)`)
		.text("GDP (Billions)")
		.attr("class", "axis-title");

	// tooltip div
	const tooltip = d3
		.attr("class", "tooltip")
		.style("opacity", 0);

	// width of bars to produce continuous graph
	const barWidth = Math.ceil(xScale(dateFromData(dataset[1][0]))) - padding;

	// plot data and affix tooltip
		.attr("x", d => xScale(dateFromData(d[0])))
		.attr("y", d => yScale(d[1]))
		.attr("width", barWidth)
		.attr("height", d => h - padding - yScale(d[1]))
		.attr("class", "bar")
		.on("mouseover", d => {
				.style("opacity", 0.8);

			const date = dateFromData(d[0]);

						<span class="tooltip-row">$${d3.format(",.2f")(d[1])} Billion</span>
						<span class="tooltip-row">${monthNumToName[
						]} ${date.getFullYear()}</span>
				.style("left", d3.event.pageX + 8 + "px")
				.style("top", d3.event.pageY - 65 + "px");
		.on("mouseout", d => {
				.style("opacity", 0)

	// title
		.attr("text-anchor", "middle")
		.attr("x", w / 2)
		.attr("y", padding / 2)
		.text("US Gross Domestic Product Over Time")
		.attr("class", "title");
	// description
	const description = response.description.split('\n').slice(1);
		.attr('x', w / 2)
		.attr('y', h - padding / 4)
		.attr('class', 'description')
		.attr('text-anchor', 'middle')
		.attr('x', w / 2)
		.attr('y', (d, i) => h - padding / 2 + i * 12 + 15)
		.text(d => d);