
Having a good environment is a step further into developing quality software. We will install Visual Studio Code with some essentials extensions + node.js + Github desktop + Angular cli
Our first project, DashboardOne, will be our support to start delving into svg and introduce d3.js to angular.
Having created our project we will now add the d3 and bootstrap npm dependencies.
We will be using bootstrap as a support library to simplify the html coding so we can focus more on d3.
In this lesson we will create the dashboard component. We will be adding our test charts to visualize our work while learning about d3
Why choosing the SVG format? What advantages does it bring to our charts?
Scale chart heights by mapping data values to pixels using a 250-pixel reference, compute the max with the spread operator, and update the rectangle heights and y positions.
Define left, right, top, and bottom margins; compute inner width and height from the SVG dimensions; update dimensions accordingly and reserve space for legends.
Explore svg path commands with d3 and Angular, including move, line, horizontal and vertical lines, cubic and quadratic bezier curves, and arc parameters with flags to generate figures.
Create an svg project to test svg path and add a grid. Add horizontal and vertical grid lines every 100 pixels, style with a dashed stroke, and control opacity.
Learn to make a chart input-driven using ngOnChanges, resize on data changes, and refactor to SetParams for API data and D3 integration.
The SVG specs. Basic elements: Rect, Circle, Line, Path, Polyline
To better understand how svg works, we will create a basic column chart by manually writing all the elements
In this lesson we will introduce d3 to angular and learn how to create the same column chart by using d3.
D3 keywords: select, selectAll, enter, append
Bind data to rectangles with d3, use enter to set height 10,20,30 by index, position with i times width and padding, then style with blue fill using .style() and .attr().
Explore the D3 update pattern to handle changing data by updating existing elements, appending new ones with enter, and managing removals with exit to reflect data changes in a chart.
Learn how the D3 update pattern handles exit selections by removing elements, updating remaining rectangles’ heights with accessor functions, and properly clearing attributes using null.
Recreate chart two using D3 by importing input data from Angular core, wiring data into rectangles based on employee age, and handling undefined data with ngOnChanges and a draw method.
Apply scaleLinear to map employee age and salary to chart coordinates, fix variable usage for height and y, and use max salary to scale rectangles for consistent visuals.
Discover the d3 axis, its four position types, and how to customize styling by selecting elements, applying properties, and appending axes to containers using scales.
Practice adding a vertical y axis to the chart in d3 by creating a y axis container and a left-positioned y axis, then adjust the left margin for proper fit.
Learn to customize D3 axes beyond default styles by using axis methods and post-selection, controlling tick counts, formats, and custom tick values mapped from the scale’s max.
Style D3 axis grids and ticks, apply selective styling to lines only, and add a rotated y-axis label by wrapping text in a container and positioning it with margins.
Replace axis ids with employee names by binding names to tick elements, rotate labels 45 degrees, adjust margins and translation, and implement set labels to organize chart for future data.
This lecture demonstrates the d3 update pattern to toggle between full and filtered data using a getter and a data state, updating enter, update, and exit to redraw the chart.
Implement in-chart dropdowns for a D3 and Angular chart, managing two selects (x and y) inside the chart via a short form component, with responsive styling.
Create empty methods for set dimensions, set elements, set params, set labels, set axis, and draw to structure the svg chart before adding data.
Implement the scatterData getter to produce numeric x and y points from the selected sepal length and sepal width, returning an empty array until both values are chosen.
Define x and y linear scales with domains and inverted ranges using inner width and height, compute max values from data with the D3 math function, and finalize parameters.
The src for the angular initial setup, already with chart 5, is available here in the src.zip
Add a chart component in Angular by generating a new charts component, wiring input data from Angular core, and embedding the Covid data dashboard in the app HTML.
Explain d3 time concepts by converting strings to dates with timeParse and formatting them with timeFormat, while configuring x time scales, y linear scales, and color scales.
Bind data to legend items, create entering elements, append circles and text, and position with padding and radius; merge updates colors and labels for all legend items.
Reposition the legend in an interactive D3 and Angular chart by recalculating item widths, padding, and centering the legend for accurate alignment.
Implement mouse over and click events to manage default, over, and inactive states, highlighting hovered legend lines and toggling visibility based on selected data and active status.
Bind the legend onClick to receive the event and item name, toggle the corresponding active line by index, and redraw the chart after each toggle in d3 and angular.
Add a chart component to an Angular app by creating an SVG with class short six, importing ElementRef, configuring view encapsulation none, binding input data, and rendering with D3.
Define the config interface for a donut chart by outlining inner radius coefficient, hidden opacity, legend item properties, transition timing, and arc attributes, then move margins into the config.
Compute chart dimensions using the SVG's bounding client rect to derive inner width and height after margins, then calculate radius and inner radius, and position chart containers.
Define setParams to initialize an arc generator with inner and outer radii, a pie generator with a value, and a category ten ordinal color scale with IDs.
Implement mouse enter, mouse leave, and click interactions on the legend to highlight the corresponding arc, fade others, and redraw the chart.
Learn how arcTween: enter animates new edges by binding previous and current data, extending previous data with the enter selection, and interpolating start and end angles for new elements.
Convert the chart configuration into an input, enabling two charts with distinct configurations (donut and pie), and implement a default and private config with deep copying to preserve styling.
We will create the method UpdateObjectWithPartialValues which allow us to set only some properties of an object, while keeping all the other properties unchanged
Create chart component with ng generate component, define input data and config, switch to string template with inline styling for svg class, and wire data into app component HTML.
Define interfaces for group stack data and stack config, then use the stack helper to set stacks with population data by year, gender, and age group in millions.
Explore the anatomy of a d3 chart by structuring dimensions, margins, and inner dimensions with reusable helpers, then assemble axes, svg containers, legend, tooltip, and color scales.
Define chart structure by setting dimensions, elements, parameters, labels, axes, legend, and the draw method, with tooltip and highlight methods driven by events to update chart on init.
Define a default group stack config with opacity, transition, and margins, importing the correct interfaces. Implement a getter that returns the default when config is missing.
Setting a helper to calculate the most common points used in the chart
Implement the set elements by creating and positioning the x axis container, y axis container, data container, legend, tooltip, title, and y label, using margins and transforms.
For this lecture we will visit the d3-scale-chromatic github page to understand how to use the d3 color library
Learn to stack data with d3.stack in practice using a year-based dataset with apples, bananas, cherries, and dates, converting data to stack arrays and rendering rectangles with scales and colors.
Add a legend to the chart by creating legend item containers with rectangles and labels, then add the rectangles and text elements and finally reposition the items.
Configure tooltips by setting x and y padding, background color, and label properties like font size, height, and text separator to position and style svg tooltips.
Improve bar transitions on toggle in an interactive D3 and Angular chart by adding enter transitions for new rectangles with zero height and millisecond durations for smooth visual cues.
Improve interactive charts by ensuring disabled elements do not highlight or fade others, and apply the same fade to legend labels and legend items.
Add a transition to the y scale and y axis so removal animates the chart, using the slow duration to match the short duration.
Create a map helper to convert covid data, including deaths, into map-ready format by mapping locations to iso3 codes and grouping data by date, with a title showing current date.
Set the dimensions on a dimension surface, define elements, parameters, labels, and legend, then draw the method and highlights using a non-linear scale and a map tooltip event emitter.
We are moving the DimensionHelper class into an angular service that can be injected into the charts
Install topojson and import it into an angular chart; convert topojson to geojson with feature method and bind features to a path to render a map, addressing data loading timing.
Bind threshold data to legend items, create and position legend item containers with rectangles and text, and wire mouse and click interactions.
Highlight legend items and features on mouse enter, reset on mouse leave, using data-driven highlighting with a highlighted class and a black stroke for rectangles.
Set up a timeline tooltip component in Angular by configuring inputs, host access, SVG dimensions, and margins.
Define the interfaces for the timeline tooltip, including tooltip state, timeline data, and timeline config, with properties for visibility, position, title, active time, margins, dimensions, and typography.
Implement a timeline tooltip in a D3 and angular map by defining tooltip state, mapping country IDs to names, and wiring tooltip data to the map display.
Fix the tooltip overflow by adjusting the app component: set the width to the max content and add a z-index of ten, removing overflow hidden from the short styling.
Explore implementing d3 timeline visuals using setArea and setLine, defining y zero and y one with a date domain, and handling null values to skip drawing.
Update the timeline tooltip configuration by adding line stroke, area fill, and opacity, and extend the axis with color and optional dasharray for customizable tooltips.
Install and add the play slider component to the app HTML before the map tooltip, and style the short body and controller for a 250-pixel height.
Create a play slider component with a play/pause toggle, a range input, and custom slider styling, wired to change events in an Angular D3 project.
Fixes the timeline tooltip by anchoring the date text to start on the left and to end on the right, ensuring the current date stays visible.
Enable strict mode, install d3 and topojson types, and update the config with required properties; then adjust code to fix typing errors and initialize variables in components.
Set up tsconfig and angular compiler options, install the type files for these three and topojson, and fix implicit typing and missing initializers when serving the app.
Fix the timeline tooltip error in the interactive charts with D3 and Angular by marking the max value as optional with a question mark, preventing undefined data from breaking computations.
The source code for the strict mode can be found here in the resources. However, You'll need to add the missing packages and change the tsconfig.json in order for the application to work.
Create a swarm chart from demographics data by continent and year using force simulation and Voronoi partitions, then build reusable base charts, legend and tooltip services, and optimize performance.
Set up an Angular app component to fetch demographics from the API, subscribe to the demographics swarm observable, and convert data to the final format using a swarm helper.
Extend the chart by subclassing the base chart into a swarm short component, wiring input data, config, and output events, and calling the superclass constructor to demonstrate inheritance.
Continue building the short chart component by handling init, resize, and chart updates with RxJS subscriptions, setting SVG, dimensions, and elements, then updating the chart on resize.
Define base SVG dimensions from the node and update the surface with config margins, then set the viewBox; make set elements, set params, set labels, set legend, and draw abstract.
Define a linear y scale with a domain (min to max) and a range from inner height to zero, using extent and accessors, while handling empty data and undefined values.
Define margins to fit the axis, set up x and y axes, adjust scales and padding, remove last tick, apply grid lines with styled ticks, and refine for readable charts.
Discover the abstract legend service for interactive charts with d3 and angular, defining data and config, and implementing generate, update, and set legend items with repositioning and highlighting.
Define legend interfaces for the legend service, including a legend item with id, label, color, and a legend data list of items; set default data to an empty items array.
Implement the click event in the legend to toggle visibility and styling of chart items, fading inactive items to 0.3 opacity and restoring them on re-click.
Highlight methods identify a group by id via the legend, fade other items with opacity, and reset highlights when the legend interaction ends.
Improve styling of interactive charts by applying a black stroke to highlighted elements and increasing their radius to three, while inactive ones stay at radius two.
Create a new tooltip service, export the class, decorate it with Angular core's injectable, and inject it via the constructor so it is available in the chart.
Learn to build and customize a tooltip service for D3 charts in Angular, using setElements to update data, styling via font size and weight, and accurately positioning the tooltip.
Determine tooltip alignment in D3 and Angular interactive charts by comparing the x coordinate to the chart center and returning left or right positions.
Explore Delaunay triangulation and Voronoi partitions to simplify pointer navigation and tooltips in interactive charts. Learn to compute triangle circumcenters and map regions to circles for responsive highlighting.
Fix a legend onMouseClick bug by syncing legend clicks with item resets, updating highlights and IDs so Europe and Asia render immediately, then proceed with Voronoi development.
Update the voronoi to reflect filtered data by removing hidden legend items and resetting the voronoi on legend clicks, drawing updated partitions for regions like North America and Europe.
Finish the swarm chart by adapting chart seven to the new tooltip service, implement the changes, and return after completing the update.
Add an onMouseLeave handler in the draw rectangles method to reset highlights and apply a 300 millisecond opacity transition for smooth fading.
D3 is such a powerful language, however it can be difficult to start with.
Angular is an amazing framework but it lacks in data visualizations.
We will connect both worlds and create together amazing interactive charts that will bring your pages to another level.
For the absolute beginners, we will start from zero, understanding the d3 library, how it works, and how to use it. We will go into a depth analysis of the d3 update pattern so you can master the library and avoid the most common mistakes beginners do.
You will connect to api services and transform your data into the right format for each chart.
You will learn the SVG format and standards and how you can use it to create your own customized data visualizations.
We will use angular services and asynchronous data flows to inject data on the charts,
If you already know d3, you will learn about more advanced concepts, using the different d3 libraries, like the d3-array, the d3-force, voronoi partitions and others.
We will create legend and tooltip services, sending and receiving actions to charts and reacting to user inputs.
We will move into reusable charts by creating basic charts and extending them using inheritance.
Finally, you will end the course with a solid base to create your own reusable charts building upon the foundations of what you study here.
Welcome to the world of d3 and angular!