D3 Flashcards
D3
= Data-Driven Documents
A library that provides a mechanism for connecting arbitrary data to documents (DOM elements), allowing the appearance and behaviour of the documents. to be driven by the data.
VISUALISATION is provided by HTML, CSS, or SVG, D3 focuses on the DATA. It is actually a collection of integrated JS tools for manipulating data structures necessary to create data visualisations.
How does D3 work?
DATA drives documents that display D3 visualisations. By ADDING, CHANGING, or REMOVING data, you directly affect the way your chart appears on the screen.
Typical D3 Script
- selects HTML or SVG elements
- binds them to individual data items
- removes, updates, or appends graphical elements automatically, when necessary.
* individual data items can be accessed in callbacks in the methods that set values for styles, attributes, and transforms.
D3’s actual data visualisation part
Contains tools that are applied to previously selected DOM nodes and data:
- layout generators
- scales
- axis generators
- map projections
- shape generators
- colour scemes
What does d3’s .data() do?
Sets the data to drive creation of the elements.
What does d3’s .enter() do?
Creates a selection to add elements per data item.
It binds the data to the selection of elements creating the array of placeholders of the same size as the data array.
When is d3’s .transition() called?
Before the attributes and styles that are to be changed.
Which d3 modules are enough to create an animated interactive bar chart?
- selection
- transition
What categories of d3 modules exist?
Modules for:
- data manipulation
- document manipulation
- interactivity and animation
- colours
- asynchronous operation and packaging
- 2D geometry
- spherical geometry and geographic maps
- layouts
When to use canvas in D3?
Use it in all or part of your app
-> if you have memory problems due to excessive objects created in the DOM
HTML canvas how to
- setup the graphic context (practically all the canvas API consists of methods and properties called from the graphic context.
const ctx = canvas.getContext(‘2d’)
- before drawing, you set properties such as font, fillStyle, strokeStyle
ctx. fillStyle = ‘red’;
ctx. lineWidth=’10’;
- then you fill or stroke rectangles and add arbitrary paths.
ctx. fillRect(50,50,50,50);
ctx. strokeRect(50,50,50,50):