HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Quote Machine">
<meta name="keywords" content="HTML,CSS,XML,JavaScript,JQuery,Bootstrap,Ajax">
<meta name="author" content="Cesar Gomez">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:400,600,700" rel="stylesheet"><script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</head>
<body>
<div class="text-center">
<h1 id="title">DATA CHART</h1>
</div>
<div class="row">
<div class="col">
<div id="graph"> </div>
<div class="freeIcon text-center">
<i class="fab fa-free-code-camp"></i>
</div>
</div>
<div class="col">
<div class="text-center" id="userTitle">
<h3>User Stories to Complete</h3>
</div>
<ul>
<li>My chart should have a title with a corresponding id="title"</li>
<li>My chart should have a g element x-axis with a corresponding id="x-axis".</li>
<li>My chart should have a g element y-axis with a corresponding id="y-axis"</li>
<li>Both axes should contain multiple tick labels, each with the corresponding class="tick"</li>
<li>My chart should have a rect element for each data point with a corresponding class="bar" displaying the data</li>
<li> Each bar should have the properties data-date and data-gdp containing date and GDP values</li>
<li>The bar elements' data-date properties should match the order of the provided data</li>
<li>The bar elements' data-gdp properties should match the order of the provided data</li>
<li>Each bar element's height should accurately represent the data's corresponding GDP</li>
<li>The data-date attribute and its corresponding bar element should align with the corresponding value on the x-axis</li>
<li>The data-gdp attribute and its corresponding bar element should align with the corresponding value on the y-axis</li>
<li>I can mouse over an area and see a tooltip with a corresponding id="tooltip" which displays more information about the area</li>
<li>My tooltip should have a data-date property that corresponds to the data-date of the active area</li>
</ul>
</div>
</body>
body{
background-color: #2f2fa2;
position:relative;
}
#graph {
margin-top: 40px;
text-align:center;
}
#title{
color: #fff;
margin-bottom:50px;
border-bottom: 5px;
}
.bar {
fill: #f64c72;
}
.active{
fill:red;
}
div.tooltip {
position:absolute;
text-align: center;
width: 60px;
height: 48px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
fill:red;
}
ul {
color: #fff;
font-weight:600;
}
li{
padding: 5px;
}
.freeIcon{
font-size: 95px;
color: #fff;
}
#userTitle{
margin-bottom: 10px;
color: #99738e;
}
let value = [];
let dates = []
const width = 700;
const height = 530;
d3.json("https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json").then((data) => {
let datas = data.data;
datas.forEach(function(setData){
dates.push(new Date (setData[0]))
value.push((setData[1]))
// value.splice(55, value.length)
})
console.log(value)
const svg = d3.select("#graph")
.append("svg")
.attr("width",width)
.attr("height", height);
const sameDate = d3.timeFormat("%Y-%m-%d")
const xScale = d3.scaleTime()
.domain([d3.min(dates), d3.max(dates)])
.range([0 , width - 80]);
const x_axis = d3.axisBottom()
.scale(xScale)
const yAxis = d3.scaleLinear()
.domain([0, d3.max(value)])
.range([height , 0])
const y_axis = d3.axisLeft()
.scale(yAxis)
const scaleGross = d3.scaleLinear()
.domain([0, d3.max(value)])
.range([0, height])
const gdp = value.map(function(item){
return scaleGross(item)
})
let xAxisTranslate = height - 30;
const yAxisTranslate = 0 - 30;
svg.append("g")
.attr("transform", "translate(50, " + xAxisTranslate +")")
.attr("id","x-axis")
.call(x_axis)
.style("color","white")
svg.append("g")
.attr("transform","translate(50,"+ yAxisTranslate +")")
.attr("id","y-axis")
.call(y_axis)
.style("color","white")
let div = d3.select("body").append("div")
.attr("class", "tooltip")
.attr("id", "tooltip")
.style("opacity", 0);
svg.selectAll("rect")
.data(gdp)
.enter()
.append("rect")
.attr("data-date", function(d,i) {
return datas[i][0]
})
.attr("data-gdp", function(d,i) {
return datas[i][1]
})
.attr('x', function(d, i) {
return xScale(dates[i]);
})
.attr("y", (d,i) =>{
return height - d
})
.classed("bar", true)
.on("mouseover", function(d,i) {
let coordinates = d3.mouse(this)
const formYear = d3.timeFormat("%b %Y")
d3.select(this)
.classed("active", true)
div.transition()
.duration(200)
.style("opacity", .9)
div.attr("data-date", datas[i][0])
.html("Date " + "</br>" + formYear(dates[i]) + "</br>" + "$" + d3.select(this).attr("data-gdp"))
.style("left", event.clientX + "px")
.style("top", (coordinates[1]) + "px")
})
.on("mouseout", function(d) {
d3.select(this)
.classed("active", false)
div.transition()
.duration(100)
.style("opacity", 0);
})
.attr("width", width/275)
.attr("height", (d) => {
return d;
})
.attr("transform","translate(51,-30)")
})
Also see: Tab Triggers