diff --git a/pages/course/tooltip/introduction.tsx b/pages/course/tooltip/introduction.tsx new file mode 100644 index 00000000..bfedc931 --- /dev/null +++ b/pages/course/tooltip/introduction.tsx @@ -0,0 +1,185 @@ +import React from 'react'; +import TitleAndDescription from '@/component/TitleAndDescription'; +import { LayoutCourse } from '@/component/LayoutCourse'; +import { lessonList } from '@/util/lessonList'; +import { CodeSandbox } from '@/component/CodeSandbox'; +import Link from 'next/link'; +import { Badge } from '@/component/UI/badge'; +import { ExerciseAccordion } from '@/component/ExerciseAccordion'; +import { + Exercise, + ExerciseDoubleSandbox, +} from '@/component/ExerciseDoubleSandbox'; +import { Caption } from '@/component/UI/Caption'; +import { Sidenote } from '@/component/SideNote'; +import { ScatterplotBasicDemo } from '@/viz/ScatterplotBasic/ScatterplotBasicDemo'; +import { ScatterplotClimateCrisisDemo } from '@/viz/ScatterplotClimateCrisis/ScatterplotClimateCrisisDemo'; +import { ChartOrSandbox } from '@/component/ChartOrSandbox'; +import { TakeHome } from '@/component/TakeHome'; + +const previousURL = '/course/hover-effect/internal-state'; +const currentURL = '/course/tooltip/introduction'; +const nextURL = '/course/tooltip/tooltip-component'; +const seoDescription = ''; + +export default function Home() { + const currentLesson = lessonList.find((l) => l.link === currentURL); + + if (!currentLesson) { + return null; + } + + return ( + l.link === nextURL)} + previousTocItem={lessonList.find((l) => l.link === previousURL)} + > + +

+ One of the most frustrating experiences in visual design is seeing + a graph element on the screen but missing crucial details{' '} + about it—even though that information exists! +

+

+ This module will end that frustration by showing you how to create{' '} + reusable tooltip components. Let’s dive in. +

+ + } + /> +

🤔 Tooltip: Why?

+

+ The graph below is a scatterplot{' '} + originally published by Datawrapper. It shows a strong{' '} + negative correlation between vulnerability to climate change and + CO₂ emissions 😔. +

+

The graph looks good, and the message is clear.

+

+ But while a few countries are labeled on the chart,{' '} + + isn’t it frustrating not to know which country each data point + represents + + ? +

+

+
+

+

In my opinion, it definitely is!

+

+ This is where tooltips come into play. Try hovering over a square: an + informative tooltip with everything you need to know will appear. +

+ + Reproduction of a chart originally published by{' '} + + Data Wrapper + {' '} + using react and d3.js. + + } + /> + {/* - +- +- +- +- +- +- +- +- +- */} +

Design consideration

+

A few stuff to keep in mind to create a good tooltip:

+

⚡️ Fast, but not too fast

+

+ Tooltips should appear quickly upon hovering, but not so fast + that they flicker with small mouse movements +

+

💧 Show only crucial information

+

+ Do not overwhelm the user with a ton of information. Pick only + what's truly informative. Tooltip are not always necessary, if it's just + to remind the marker value, do not build a tooltip. +

+

📍 Positionning

+

+ Tooltips should appear near the cursor without obstructing the + view of other data points. They should reposition based on + available screen space. +

+

👨‍🦽 Accessibility

+

+ Tooltips should be accessible for all users, including those navigating + via keyboard. +

+

👯 Consistency

+

+ consistent formatting and style across all tooltips within the chart and + within the application. Make tooltip style fits marker style. +

+ {/* - +- +- +- +- +- +- +- +- +- */} +

Tooltip: How?

+

The tooltip isn’t built in SVG, but in HTML.

+

+ Formatting text in SVG can be cumbersome, and HTML offers useful CSS + features like borders and shadows that are perfect for tooltips. +

+

+ The strategy is straightforward: place a div on top of the + SVG area with matching dimensions. This div will host the + tooltip React component, rendering HTML directly inside it. +

+

+
+

+
+ Anatomy of a graph with separate layers for SVG and tooltips + + Anatomy of a Graph with an SVG area and an overlaying tooltip layer + +
{' '} +

+
+

+

Now, we have two tasks ahead:

+

1️⃣ Create a Tooltip component that displays the information.

+

+ 2️⃣ Ensure the tooltip appears only when the user hovers over a graph + element. +

{' '} +

+
+

+

That’s the plan for the next two lessons!

+
+ ); +} diff --git a/pages/example/timeseries-moving-average.tsx b/pages/example/timeseries-moving-average.tsx index a8718f92..da9b3df3 100644 --- a/pages/example/timeseries-moving-average.tsx +++ b/pages/example/timeseries-moving-average.tsx @@ -166,7 +166,7 @@ export default function Home() {
  • Use{' '} - + Voronoi {' '} for closest point detection to trigger the hover effect diff --git a/public/excalidraw/tooltip-layer.png b/public/excalidraw/tooltip-layer.png new file mode 100644 index 00000000..6da74210 Binary files /dev/null and b/public/excalidraw/tooltip-layer.png differ diff --git a/util/lessonList.tsx b/util/lessonList.tsx index 76fb7bc6..4a9c07b6 100644 --- a/util/lessonList.tsx +++ b/util/lessonList.tsx @@ -477,7 +477,7 @@ export const lessonList: Lesson[] = [ // // { - name: 'Design consideration', + name: 'Introduction', description: ( <>

    @@ -486,9 +486,9 @@ export const lessonList: Lesson[] = [

    ), - readTime: 4, - link: '/course/responsiveness/introduction', - status: 'not available', + readTime: 3, + link: '/course/tooltip/introduction', + status: 'free', moduleId: 'tooltip', }, { @@ -499,8 +499,8 @@ export const lessonList: Lesson[] = [ ), readTime: 4, - link: '', - status: 'not available', + link: '/course/tooltip/tooltip-component', + status: 'free', moduleId: 'tooltip', }, { @@ -513,8 +513,8 @@ export const lessonList: Lesson[] = [ ), readTime: 4, - link: '', - status: 'not available', + link: '/course/tooltip/display-on-hover', + status: 'free', moduleId: 'tooltip', }, { @@ -527,8 +527,23 @@ export const lessonList: Lesson[] = [ ), readTime: 4, - link: '', - status: 'not available', + link: '/course/tooltip/templates', + status: 'free', + moduleId: 'tooltip', + }, + { + name: 'Project', + description: ( + <> +

    + Let's create a stunning heatmap with good tooltips to apply everything + we learnt so far. +

    + + ), + readTime: 4, + link: '/course/tooltip/project', + status: 'free', moduleId: 'tooltip', },