D3 Principles D3 is Data Driven Library written in JavaScript for Dynamically manipulating the Document Object Model DOM Working with data and shapes Providing effective and efficient user interactions Enabling smooth transitions between user interfaces UIs Layering managing visual elements in linear hierarchical network and geographical forms Standards Key Terms There are a number of standards definitions that are important when using D3 as these terms words are common heavily used in web development circles This includes HyperText Markup Language HTML Document Object Model DOM Cascading Style Sheets CSS Scalable Vector Graphics SVG JavaScript If you re already familiar with these concepts then you may skip ahead however to be complete we ll explain each of them in detail HyperText Markup Language HTML As you have have realised by now HTML is the language used to structure the contents of a web page HTML is a text based language with the extension html A minimum bare bone example of what a HTML file looks like DOCTYPE html html lang en head meta charset utf8 title Your Title title head body comment body htm You should notice the essential tags which are common to nearly all web pages html meta title head body In addition you can add comments to html files which are not displayed on screen these are between the tags Document Object Model DOM After the web page is loaded the structured HTML tags are parsed and allow the web browser to build a hierarchical structure of the page Every tag in the HTML file is converted to an element object in the DOM in a parent child hierarchy This makes your HTML form a logical structure that is easy to navigate and manage Once the DOM is formed you re ready to add modify or remove any elements on the page using JavaScript and D3 Example of a simple DOM given the following HTML DOCTYPE html html lang en head meta charset utf8 title Your Title title head body div h1 Hello Sweet World h1 p Would the code taste sweeter in any other language p div body htm Note when you write your html it s usually cleaner and easier to read if you indent the tags based on their depth i e parent child dependency The document object model for the above HTML would be Document HTML head title Your Title body div h1 Hello sw p Would the Cascade Style Sheets CSS HTML gives your web page content and structure but no styling visual information This is where CSS comes in CSS styles makes your web page more attractive visually nicer to look at sexy CSS is a Style Sheet Language and is used to describe the visual aspects of your document page Each of the elements and objects visual presentation details are defined using CSS e g color margins position and so on Scalable Vector Graphics SVG SVG allows you to create bespoke detailed graphical effects Importantly SVG is not a direct image i e doesn t generate pixels Instead as the name suggests it generates vector art The scalable word in SVG means the graphic is able to resize to the necessary dimensions without distortion Nearly all browsers support SVG graphics SVG is important as it s a crucial tool for creating powerful data visualizations using D3 You create and use SVG graphics as you would any other element You use the svg tag to specify a region area that you ll drawn on vector lines and shapes For example svg width 500 height 500 svg The default measurement of SVG height width is in pixels so you do not need to specify any units Now if you wan tot draw a rectangle in your svg region you d type the following svg width 400 height 300 rect x 0 y 0 width 300 height 200 rect svg svg width 400 height 250 rect x 0 y 0 width 300 height 200 rect svg You can draw other shapes in the SVG element area as well not just rectangles Range of shapes and drawing styles including lines circles ellipses text and paths Similar to HTML elements the SVG elements also have styling options For example to set the background color using the fill keyword inside the rect tag You can even specify the border line color using the stroke keyword as shown below svg width 400 height 250 rect x 0 y 0 width 300 height 200 fill blue stroke width 10 stroke pink rect svg JavaScript JavaScript is a powerful scripting language that you use to execute custom commands to your browser JavaScript is a loosly typed language that interactives with the HTML elements DOM and styles to ame the web user interface for interactive and dynamic A loosely typed language is a programming language that does not require a variable to be defined To ensure consistency between browsers the JavaScript language must conform to a set of standards ECMAScript standards These standards help ensure core features and funcitonality work the same for all of your programs and your D3 library
tyle Sheets CSS HTML gives your web page content and structure but no styling visual information This is where CSS comes in CSS styles makes your web page more attractive visually nicer to look at sexy CSS is a Style Sheet Language and is used to describe the visual aspects of your document page Each of the elements and objects visual presentation details are defined using CSS e g color margins position and so on Scalable Vector Graphics SVG SVG allows you to create bespoke detailed graphical effects Importantly SVG is not a direct image i e doesn t generate pixels Instead as the name suggests it generates vector art The scalable word in SVG means the graphic is able to resize to the necessary dimensions without distortion Nearly all browsers support SVG graphics SVG is important as it s a crucial tool for creating powerful data visualizations using D3 You create and use SVG graphics as you would any other element You use the svg tag to specify a region area that you ll drawn on vector lines and shapes For example svg width 500 height 500 svg The default measurement of SVG height width is in pixels so you do not need to specify any units Now if you wan tot draw a rectangle in your svg region you d type the following svg width 400 height 300 rect x 0 y 0 width 300 height 200 rect svg svg width 400 height 250 rect x 0 y 0 width 300 height 200 rect svg You can draw other shapes in the SVG element area as well not just rectangles Range of shapes and drawing styles including lines circles ellipses text and paths Similar to HTML elements the SVG elements also have styling options For example to set the background color using the fill keyword inside the rect tag You can even specify the border line color using the stroke keyword as shown below svg width 400 height 250 rect x 0 y 0 width 300 height 200 fill blue stroke width 10 stroke pink rect svg JavaScript JavaScript is a powerful scripting language that you use to execute custom commands to your browser JavaScript is a loosly typed language that interactives with the HTML elements DOM and styles to ame the web user interface for interactive and dynamic A loosely typed language is a programming language that does not require a variable to be defined To ensure consistency between browsers the JavaScript language must conform to a set of standards ECMAScript standards These standards help ensure core features and funcitonality work the same for all of your programs and your D3 library