LM18
LM18
ii. HTML:
o Hypertext Markup Language is used to structure content for web browsers.
o HTMLis stored in plain text files with the .html suffix.
o A simple HTMLdocument looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Page Title</h1>
<p>This is a really interesting paragraph.</p>
</body>
</html>
iii. DOM:
o The term Document Object Model refers to the hierarchical structure of HTML.
o Each pair of bracketed tags (or, in some cases, a single tag) is an element, and we
refer to elements’ relationships to each other in human terms: parent, child, sibling,
ancestor, and descendant.
Fig 1.1 Chrome’s web inspector
iv. CSS:
o Cascading Style Sheets are used to style the visual presentation of DOM elements.
CSS looks like the following:
body
{
background-color: white;
color: black;
}
o CSS styles consist of selectors and properties. Selectors are followed by properties,
grouped in curly brackets.
o A property and its value are separated by a colon, and the line is terminated with a
semicolon, like the following:
selector {
property: value;
property: value;
property: value;
}
o You can apply the same properties to multiple selectors at once by separating the
selectors with a comma, as in the following:
selectorA,
selectorB,
selectorC {
property: value;
property: value;
property: value;
}
o For example, you might want to specify that both p paragraphs and li list items
should use the same font size, line height, and color.
p,
li {
font-size: 12px;
line-height: 14px;
color: orange;
}
v. Java Script:
o JavaScript is the scripting language that can make pages dynamic by manipulating
the DOM after a page has already loaded in the browser.
vi. SVG:
o D3 is most useful when used to generate and manipulate visuals as Scalable Vector
Graphics (SVG).
o Drawing with divs and other native HTML elements is possible, but a bit clunky and
subject to the usual inconsistencies across different browsers.
o Using SVG is more reliable, visually consistent, and faster.
2. Setting up D3:
o A simple matter of downloading the latest version, creating an empty page in which to
write your code, and, finally, setting up a local web server.
1. Downloading D3:
Start by creating a new folder for your project. Call it whatever you like, but
maybe something like project-folder.
Then place the latest version of D3 into that folder. Go to https://d3js.org, click
the link to download the latest version of D3 as a ZIP file, and then decompress
the ZIP file.
As of this writing, the current version of D3 is 4.5.0. Move the file d3.js into
your new project folder.
In that folder, you’ll also see d3.min.js, a “minified” version from which
whitespace has been removed for smaller file sizes and faster load times.
2. Referencing D3:
Now create a simple HTML page within your project folder named
index.html.
Your folder structure should now look something like this:
project-folder/
d3.js
d3.min.js (optional)
index.html
Paste the following into your new HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Page Template</title>
<script type="text/javascript" src="d3.js"></script>
</head>
<body>
<script type="text/javascript">
// Your beautiful D3 code will go here
</script>
</body>
</html>
3. Setting Up a Web Server:
o In some cases, you can view local HTML files directly in your web browser.
o However, some browsers have restrictions that prevent them from loading local
files via JavaScript, for security reasons.