Latest / CyberSecurity Summary / Data Visualization with JavaScript
Transcript
- 0:00Speaker 1: Imagine you just pulled up to a gas station. You
- 0:03Speaker 1: put the nozzle in your car, you squeeze the handle,
- 0:06Speaker 1: and you pump twenty gallons of fuel. But like there's
- 0:10Speaker 1: this massive leak in the hose. Oh no, yeah, so
- 0:14Speaker 1: out of those twenty gallons, nineteen point nine gallons just
- 0:18Speaker 1: drip directly onto the concrete highway.
- 0:21Speaker 2: That's terrible, right, you.
- 0:22Speaker 1: Only actually get a few drops into your engine. I
- 0:24Speaker 1: mean that sounds completely.
- 0:25Speaker 2: Absurd, right, it really does. But you know that is
- 0:27Speaker 2: exactly what is happening to our information right now.
- 0:30Speaker 1: Exactly.
- 0:30Speaker 2: We hear constantly about how much data we are generating
- 0:33Speaker 2: as a society, but the reality of how little we
- 0:37Speaker 2: actually use is staggering.
- 0:40Speaker 1: It's crazy. One widely cited estimate suggests that ninety nine
- 0:44Speaker 1: point five percent of the data our systems collect just
- 0:47Speaker 1: goes to waste.
- 0:48Speaker 2: Wow.
- 0:49Speaker 1: Yeah, it just sits on servers, completely ignored. And the
- 0:51Speaker 1: reason for that massive waste is what we are tackling
- 0:54Speaker 1: in today's.
- 0:55Speaker 2: Deep dive, which is such an important topic.
- 0:57Speaker 1: It is our mission today is short cutting your path
- 1:00Speaker 1: to becoming a master of visual communication, because raw data,
- 1:05Speaker 1: by its very nature, is just an abstract headache for
- 1:09Speaker 1: the human brain.
- 1:10Speaker 2: Right, Our brains aren't built for raw spreadsheets, No.
- 1:13Speaker 1: They aren't. So we are pulling some incredible insights today
- 1:17Speaker 1: from a book by Stephen A. Thomas called Data Visualization
- 1:20Speaker 1: with JavaScript.
- 1:21Speaker 2: And you know what I love about this specific book
- 1:23Speaker 2: is that it doesn't just treat charts like magic tricks, right.
- 1:27Speaker 2: It acknowledges that effective visualizations are really the only way
- 1:31Speaker 2: to transform those abstract, raw numbers into a shape that
- 1:35Speaker 2: the human brain can actually process, yeah, making it digestible exactly.
- 1:40Speaker 2: When a chart is built perfectly, you free the viewer
- 1:43Speaker 2: like they don't have to decisive the math, they just
- 1:45Speaker 2: get it. Yeah, they can just focus entirely on the
- 1:47Speaker 2: store that the data is trying to tell. But you
- 1:50Speaker 2: cannot build that kind of seamless experience unless you understand
- 1:54Speaker 2: the mechanics happening under the hood, Which means.
- 1:56Speaker 1: We aren't just going to sit here and talk about,
- 1:58Speaker 1: you know, what makes a good chart on a theory
- 2:00Speaker 1: medical level.
- 2:00Speaker 2: No, we're getting into the weeds.
- 2:03Speaker 1: We really are. We are actually going to look at
- 2:06Speaker 1: how they are built. We're going to explore the underlying
- 2:08Speaker 1: logic of open source tools, specifically focusing on a JavaScript
- 2:13Speaker 1: library called flat ru two.
- 2:15Speaker 2: It's a great tool.
- 2:16Speaker 1: It is we are getting into the nuts and bolts
- 2:18Speaker 1: of how a computer draws a story. But before we
- 2:22Speaker 1: can start building complex, dazzling interactive graphics, we have to
- 2:26Speaker 1: master the absolute workhorse, the foundation, right, and I'm talking
- 2:31Speaker 1: about the simple bar chart.
- 2:32Speaker 2: It really is the foundation of everything. I mean, you
- 2:34Speaker 2: have seen thousands of bar charts in your life, which
- 2:38Speaker 2: means there is zero learning curve for the viewer.
- 2:40Speaker 1: Yeah, totally intuitive.
- 2:42Speaker 2: The convention is so baked into our psychology that you
- 2:44Speaker 2: just absorb the information. But actually building one from scratch
- 2:48Speaker 2: reveals some really fascinating mechanics about how computers and humans, well,
- 2:52Speaker 2: they disagree on what makes sense?
- 2:54Speaker 1: Yes, and the book walks us through a brilliant example
- 2:56Speaker 1: of this. Okay, let's unpack this. Let's do We look
- 2:58Speaker 1: at the English Mere League wins for the soccer team
- 3:02Speaker 1: Manchester City. This is from two thousand and six to
- 3:05Speaker 1: twenty twelve, and the data points show their performance shifting
- 3:08Speaker 1: pretty dramatically. They started thirteen wins in two thousand and six,
- 3:12Speaker 1: they drop to eleven wins in two thousand and seven,
- 3:14Speaker 1: and eventually they climb all the way up to twenty
- 3:16Speaker 1: eight wins by twenty twelve.
- 3:18Speaker 2: Quite a jump.
- 3:19Speaker 1: Yeah. Now, to get this data onto a web page
- 3:22Speaker 1: using that flow year two library, you can't just type
- 3:25Speaker 1: the numbers onto the screen. You have to use an
- 3:27Speaker 1: HTML canvas.
- 3:28Speaker 2: Element right, And for anyone who hasn't built a web page,
- 3:32Speaker 2: think of an HTML canvas exactly like it sounds. It
- 3:35Speaker 2: is a literal, blank, invisible rectangle that the browser sets
- 3:38Speaker 2: aside on your screen, like a literal canvas exactly. It
- 3:42Speaker 2: doesn't process texts like a normal web page. It's a
- 3:45Speaker 2: dedicated sandbox specifically for a JavaScript library. To draw raw pixels.
- 3:50Speaker 1: And to tell the library what to draw in that sandbox,
- 3:53Speaker 1: you have to feed it nested to raise a data
- 3:55Speaker 1: so you package the year and the wins together as coordinates.
- 3:58Speaker 2: Sounds straightforward enough.
- 3:59Speaker 1: It does, But here's the catch. If you just feed
- 4:02Speaker 1: those coordinates in and let the library use its default
- 4:04Speaker 1: mathematical settings, you run into a massive problem. The default
- 4:08Speaker 1: algorithm automatically calculates the vertical axis the y axis based
- 4:13Speaker 1: purely on your lowest and highest data points, so it
- 4:15Speaker 1: zooms in. Yes, because Manchester City's lowest number of wins
- 4:20Speaker 1: was eleven, the bottom of the chart starts.
- 4:23Speaker 2: At eleven, which is an issue.
- 4:25Speaker 1: Well, wait a minute, let me push back on this
- 4:26Speaker 1: for a second.
- 4:27Speaker 2: Okay, go ahead.
- 4:28Speaker 1: If I am a computer programmer, I might argue that
- 4:31Speaker 1: the computer is doing exactly what it should if the
- 4:34Speaker 1: data only exists between the numbers eleven and twenty eight.
- 4:38Speaker 1: Isn't starting the axis at eleven mathematically the most precise
- 4:42Speaker 1: way to show that specific variance? Technically, yes, right, So
- 4:47Speaker 1: why are we overwriting the computer when its math is
- 4:49Speaker 1: technically correct?
- 4:50Speaker 2: That is the perfect question because it highlights the fundamental
- 4:52Speaker 2: difference between mathematical precision and human visual processing.
- 4:57Speaker 1: Okay, how so.
- 4:58Speaker 2: Well the math is correct visually, it is a total disaster.
- 5:02Speaker 2: When we look at a bar chart, our brains don't
- 5:04Speaker 2: just read the numbers on the side. We process the
- 5:07Speaker 2: proportion of the shapes. Oh, I see, We inherently believe
- 5:10Speaker 2: that if one bar is twice as tall as another,
- 5:12Speaker 2: the underlying value must be twice as large.
- 5:15Speaker 1: That makes total sense. It's like cropping a photograph so
- 5:18Speaker 1: tightly that you lose all the background context.
- 5:21Speaker 2: That's a perfect analogy. So if the bottom of your
- 5:23Speaker 2: chart is set to eleven, the bar for the year
- 5:26Speaker 2: two thousand and seven, where they won exactly eleven games,
- 5:29Speaker 2: completely disappears.
- 5:31Speaker 1: Oh wow, because it's at the absolute bottom exactly.
- 5:33Speaker 2: It has zero height. It's just a flat line on
- 5:36Speaker 2: the floor of the chart. To anyone quickly glancing at it,
- 5:39Speaker 2: it visually implies that Manchester City won absolutely zero games
- 5:43Speaker 2: that year.
- 5:44Speaker 1: Right. Think about the last stock chart you looked at
- 5:47Speaker 1: on your phone. Did you actually check where the y
- 5:49Speaker 1: axis started? Probably not, because if it didn't start at zero,
- 5:52Speaker 1: you might have panicked over a visual drop that was
- 5:55Speaker 1: actually minuscule. In reality, it's a huge blind spot.
- 5:57Speaker 2: Exactly. You end up manipulating the viewers perception of reality,
- 6:01Speaker 2: even if you did it completely by accident.
- 6:03Speaker 1: Yeah, the visual.
- 6:04Speaker 2: Distance between eleven wins and twenty eight wins looks like
- 6:07Speaker 2: a catastrophic chasm if eleven is.
- 6:09Speaker 1: The floor, right, But when you go into the code
- 6:11Speaker 1: and manually force the y axis minimum to zero, the
- 6:15Speaker 1: eleven wind bar suddenly has weight.
- 6:17Speaker 2: It changes everything the viewer sees.
- 6:19Speaker 1: The true proportional difference. It was a bad year, sure,
- 6:23Speaker 1: but it wasn't a total failure.
- 6:25Speaker 2: And while you are in the code fixing the axis,
- 6:28Speaker 2: you also have to fix the computer's assumptions about the
- 6:30Speaker 2: numbers themselves.
- 6:31Speaker 1: Oh right.
- 6:32Speaker 2: Because the computer algorithm assumes all data could potentially be fractions,
- 6:35Speaker 2: it helpfully adds decimal points to the labels. On the side.
- 6:38Speaker 1: You cannot have fifteen point zero soccer.
- 6:41Speaker 2: Wins exactly, so you pass a quick option in the code.
- 6:44Speaker 2: It's tick decimals zero. It cleans up the labels.
- 6:49Speaker 1: It really proves that the code might be mathematically sound,
- 6:52Speaker 1: but you constantly have to manually adjust it for human reality.
- 6:55Speaker 2: It is a constant translation between machine logic and human intuition.
- 6:59Speaker 1: Okay, so forcing a zero baseline fixes a static bar chart,
- 7:04Speaker 1: but that really only works for discrete, separated moments in time.
- 7:07Speaker 1: What if we're tracking something massive and continuous, like say
- 7:10Speaker 1: climate change over fifty years.
- 7:12Speaker 2: That gets tricky.
- 7:13Speaker 1: Yeah, a bar chart with fifty individual pillars would just
- 7:15Speaker 1: look like a crowded fence.
- 7:17Speaker 2: The trend gets lost. How does the code handle decades
- 7:20Speaker 2: of continuous movement? That is where you have to transition
- 7:23Speaker 2: to line charts. They really excel at revealing the overall
- 7:27Speaker 2: narrative in massive data sets without bogging the viewers bring
- 7:31Speaker 2: down in the individual year by year data.
- 7:33Speaker 1: Points, and the book uses this incredible data set from NOAA,
- 7:38Speaker 1: the National Oceanic and Atmospheric Administration. It's a great example.
- 7:41Speaker 1: It spans over fifty years tracking the carbon dioxide concentration
- 7:45Speaker 1: in the atmosphere from Manola, Hawaii alongside the global surface
- 7:50Speaker 1: temperature deviations for that exact same time period.
- 7:53Speaker 2: Which presents a notoriously difficult challenge for a developer. You
- 7:56Speaker 2: are trying to plot two very critical but very different,
- 8:00Speaker 2: currently measured metrics on the exact same piece of digital paper.
- 8:03Speaker 1: Here's where it gets really interesting. We are talking about
- 8:06Speaker 1: putting two completely different scales on the same.
- 8:09Speaker 2: Chart, the double access dilemmas exactly.
- 8:11Speaker 1: You have CO two, which is measured in parts per million.
- 8:13Speaker 1: Those are large absolute numbers in the three hundreds and
- 8:16Speaker 1: four hundreds, right, and then you have temperature deviations which
- 8:18Speaker 1: are measured in tiny fractions of a single degree celsi's
- 8:22Speaker 1: numbers like zero point zero seven or point one.
- 8:24Speaker 2: Two, So completely different scales.
- 8:27Speaker 1: If you just overlay them, the grid lines clash, the
- 8:29Speaker 1: values don't align, and the viewer just gives up. But
- 8:33Speaker 1: beyond the formatting, the whole concept of a deviation metric
- 8:36Speaker 1: is confusing. It really is the temperature values aren't absolute temperatures,
- 8:41Speaker 1: they are deviations from the twentieth century historical average. So
- 8:46Speaker 1: how on earth does a developer make that historical average
- 8:49Speaker 1: clear to the end user without just slapping a giant
- 8:52Speaker 1: paragraph of explanatory text onto the screen.
- 8:55Speaker 2: What's fascinating here is one of my favorite techniques in
- 8:57Speaker 2: the book. The author uses a brilliant yet incredibly simple
- 9:01Speaker 2: coding trick.
- 9:02Speaker 1: I love this part.
- 9:03Speaker 2: To represent that twentieth century average baseline, the coder literally
- 9:08Speaker 2: injects a completely fake dummy data set into the JavaScript array.
- 9:13Speaker 1: Wait fake data.
- 9:14Speaker 2: Yes, for every single year from nineteen fifteen nine to
- 9:17Speaker 2: twenty twelve, they add a corresponding data point of exactly zero.
- 9:20Speaker 1: Oh, it's like drawing a firm line in the sand,
- 9:23Speaker 1: so you can accurately measure exactly how far the tide
- 9:25Speaker 1: is coming in.
- 9:26Speaker 2: That's a great way to think about it. And they
- 9:27Speaker 2: don't just leave it looking like a normal line of data.
- 9:30Speaker 2: What do they do in the code? They style this
- 9:32Speaker 2: specific zero line to be only one pixel wide. They
- 9:36Speaker 2: color it a dark, subtle gray, and they completely disable
- 9:39Speaker 2: its drop shadow, so it blends in exactly. By changing
- 9:43Speaker 2: those visual properties, it stops looking like a data set
- 9:46Speaker 2: to the human eye and starts looking like a piece
- 9:48Speaker 2: of the charts structural framework.
- 9:50Speaker 1: It creates an instant visual anchor. You don't have to
- 9:53Speaker 1: read an explanation. Your brain immediately understands that anything above
- 9:56Speaker 1: that gray line is warmer than the historical average, and
- 10:00Speaker 1: anything below it is cooler. It's so intuitive, And the
- 10:03Speaker 1: author does one more subtle thing in the code that
- 10:05Speaker 1: I found so clever. When you have multiple lines, you
- 10:09Speaker 1: obviously need a legend so the user knows what they're looking.
- 10:11Speaker 2: At, right a key.
- 10:13Speaker 1: By default, the computer will just list the legend items
- 10:15Speaker 1: in whatever random order you fed the arrays into the code.
- 10:18Speaker 2: Which again is the computer just doing what it's told,
- 10:21Speaker 2: but completely ignoring human logic.
- 10:24Speaker 1: Right. But if you intentionally swamp the order of the
- 10:27Speaker 1: data series in your code, specifically putting the temperature deviation
- 10:31Speaker 1: data right next to that dummy baseline zero data, they
- 10:35Speaker 1: get grouped together visually in the little legend box.
- 10:38Speaker 2: Oh that's smart.
- 10:38Speaker 1: It intuitively links the concept of the temperature with the
- 10:41Speaker 1: baseline for the viewer before their eyes even move over
- 10:45Speaker 1: to analyze the graph itself. To tiny psychological match.
- 10:48Speaker 2: It proves that building these things isn't just about plotting points.
- 10:52Speaker 2: You are designing a cognitive experience. You are quietly guiding
- 10:55Speaker 2: the user's eye to make the right connections.
- 10:58Speaker 1: So we've solved tracking things over continuous time. But what
- 11:02Speaker 1: if time isn't the factor at all? Okay, what if
- 11:04Speaker 1: you want to take a snapshot of the world right
- 11:06Speaker 1: now and figure out if two entirely different variables actually
- 11:10Speaker 1: cause each other, or at least correlate.
- 11:12Speaker 2: That is the perfect scenario for a scatter chart. You
- 11:15Speaker 2: aren't looking at trends over time. You are looking for
- 11:17Speaker 2: relationships between disparate things.
- 11:19Speaker 1: The Deep Dive moves into this fascinating twenty ten OECD
- 11:23Speaker 1: data set. It compares healthcare spending as a percentage of
- 11:27Speaker 1: a country's GDP against the average life expectancy of its citizens.
- 11:31Speaker 2: A classic comparison.
- 11:33Speaker 1: Yeah, the fundamental question is does spending a higher percentage
- 11:37Speaker 1: of your national wealth on healthcare actually equal a longer
- 11:41Speaker 1: life for your people?
- 11:42Speaker 2: It is a very complex question. You are plotting dozens
- 11:46Speaker 2: of individual countries as floating dots based on those two
- 11:49Speaker 2: independent variables.
- 11:50Speaker 1: But once again, if you just hand this raw data
- 11:52Speaker 1: to the flat er two library, the default output is
- 11:56Speaker 1: pretty claustrophobic, very crammed. The library tries to maximize the space,
- 12:00Speaker 1: so the points get crammed right against the very edges
- 12:02Speaker 1: of the chart box. The dot for the country with
- 12:04Speaker 1: the lowest spending physically touches the left wall, and the
- 12:08Speaker 1: highest bending touches the right wall.
- 12:09Speaker 2: That's hard to read.
- 12:11Speaker 1: It just like framing a beautiful painting but letting the
- 12:13Speaker 1: picture frame cover up the outer two inches of the canvas.
- 12:16Speaker 1: Your eyes need margins to comfortably process the words, and
- 12:20Speaker 1: data points need margins to be compared accurately.
- 12:22Speaker 2: And while visualization libraries almost always have an autoscale feature
- 12:26Speaker 2: that tries to fix this mathematically, they often fall short
- 12:29Speaker 2: of what the human eye actually needs.
- 12:31Speaker 1: So it's the fix.
- 12:32Speaker 2: A skilled visualizer will look at that cramped box and
- 12:35Speaker 2: manually override the defaults. You explicitly tell the code set
- 12:40Speaker 2: the x axis minimum to five and the maximum to twenty.
- 12:43Speaker 2: You intentionally pad the axes to give the data breathing room.
- 12:47Speaker 1: It separates the cluster of information from the boundaries of
- 12:50Speaker 1: the chart, but the breathing room isn't the only thing
- 12:53Speaker 1: the user needs. The x axis represents a percentage, bending
- 12:56Speaker 1: as a percentage GDP. But the raw data in the array,
- 13:00Speaker 1: it's just the integers five, ten, fifteen, extrail numbers. Yeah.
- 13:04Speaker 1: If you leave it like that, the user has to
- 13:06Speaker 1: look at the number fifteen, scan their eyes over to
- 13:09Speaker 1: the access title, read percentage of GDP, and then remind
- 13:12Speaker 1: themselves right that number fifteen means fifteen percent.
- 13:15Speaker 2: Which sounds incredibly minor, but in the world of data consumption,
- 13:18Speaker 2: that is cognitive friction. It slows down comprehension, and as.
- 13:21Speaker 1: A developer, you have the power to just remove that friction.
- 13:24Speaker 1: Flutoo allows you to write a custom formatting function for
- 13:27Speaker 1: the axis labels. That's really handy.
- 13:29Speaker 2: So instead of just accepting the default integers, you write
- 13:32Speaker 2: a tiny piece of logic that intercepts the label right
- 13:36Speaker 2: before the browser draws it on the canvas, and simply
- 13:38Speaker 2: a pens a percentage signed to it. Oh nice. The
- 13:41Speaker 2: user just sees fifteen percent and instantly understands the value,
- 13:44Speaker 2: and you really want them to understand it quickly, because
- 13:47Speaker 2: the payoff of this specific data set is amazing. When
- 13:51Speaker 2: you step back and look at the scatterplot, you don't
- 13:54Speaker 2: see a perfect diagonal line going up.
- 13:56Speaker 1: No, you don't, and that is exactly why you need
- 13:59Speaker 1: a scatterplot instead of a bar chart. If you just
- 14:02Speaker 1: average the data out into bars, you would miss the reality.
- 14:05Speaker 1: You miss the whole point exactly. The scatter reveals a
- 14:08Speaker 1: messy cluster. It visually proves that simply spending more money
- 14:12Speaker 1: on healthcare does not guarantee a linear, straight line increase
- 14:16Speaker 1: in life expectancy.
- 14:17Speaker 2: Right, they are country spending less that are achieving longer
- 14:19Speaker 2: life stands.
- 14:20Speaker 1: The spread is the story.
- 14:21Speaker 2: It's brilliant. But speaking of cognitive friction, well, we have
- 14:25Speaker 2: to talk about the most controversial chart in the entire
- 14:28Speaker 2: corporate world, and frankly.
- 14:30Speaker 1: The messy reality of the code that builds them. I
- 14:33Speaker 1: am talking, of course, about the notorious pie chart.
- 14:35Speaker 2: The chart that data scientists absolutely love to hate.
- 14:39Speaker 1: Okay, I have to play devil's advocate here. Wait, everyone
- 14:41Speaker 1: loves a colorful pie chart. They're in literally every boardroom
- 14:45Speaker 1: presentation and every quarterly report ever made. Why do developers
- 14:49Speaker 1: usually hate them?
- 14:50Speaker 2: Well, if we connect this to the bigger picture, it
- 14:53Speaker 2: comes down to a fundamental biological flaw in how the
- 14:57Speaker 2: human brain processes geometry. Really biology, Yeah, we are actually
- 15:02Speaker 2: terrible at judging the relative size of areas. We are
- 15:04Speaker 2: very good at comparing lengths, like the height of vertical
- 15:08Speaker 2: bars in a bar chart.
- 15:09Speaker 1: Sure, and that's easy.
- 15:10Speaker 2: If one bar is just a few pixels taller than another,
- 15:13Speaker 2: your eye catches it instantly. But when you take a circle,
- 15:16Speaker 2: slice it into five or six irregularly sized wedges, and
- 15:19Speaker 2: then ask the human eye to rank them.
- 15:21Speaker 1: By size to a guessing game.
- 15:23Speaker 2: We fail miserably. Unless the difference is drastic. We just
- 15:27Speaker 2: cannot accurately compare those non rectangular areas. If you're comparing
- 15:31Speaker 2: multiple values against each other, a bar chart is almost
- 15:34Speaker 2: always better.
- 15:35Speaker 1: Okay, fair enough, But the book actually defends them in
- 15:38Speaker 1: one very specific scenario.
- 15:40Speaker 2: Yes it does. They are highly effective for one task
- 15:44Speaker 2: emphasizing a single fraction against a hole.
- 15:47Speaker 1: Ooh.
- 15:47Speaker 2: If you only have two slices and you want to
- 15:49Speaker 2: show the sheer proportion of one piece relative to everything else,
- 15:53Speaker 2: it is incredibly powerful.
- 15:55Speaker 1: The example in the book is striking. It uses World
- 15:58Speaker 1: Bank data from two thousand and eight to visualize extreme
- 16:01Speaker 1: global poverty.
- 16:02Speaker 2: It's a sobering visual, it really is.
- 16:04Speaker 1: It highlights that twenty two point four percent of the
- 16:06Speaker 1: world's population was living on less than a dollar and
- 16:09Speaker 1: twenty five cents a day. Wow. When you put that
- 16:11Speaker 1: single red wedge of twenty two point four percent against
- 16:15Speaker 1: a solid, massive circle representing the rest of humanity, you
- 16:18Speaker 1: don't need to compare multiple variables. The impact is visceral
- 16:21Speaker 1: and instant.
- 16:22Speaker 2: In that context, the pie chart strips away everything extraneous
- 16:25Speaker 2: and forces you to confront that single massive proportion.
- 16:28Speaker 1: But actually getting that pie chart to render brings us
- 16:31Speaker 1: to my absolute favorite part of this deep dive. It
- 16:33Speaker 1: is the reality versus ideal world philosophy of the book,
- 16:37Speaker 1: which is so relatable because we tend to think of
- 16:39Speaker 1: computer programming as this pristine, perfect science where everything is logical.
- 16:44Speaker 1: But the reality is that even great widely used open
- 16:47Speaker 1: source cools have hilarious, messy corps.
- 16:51Speaker 2: Software is written by humans, and humans use tape and
- 16:54Speaker 2: glue to hold things together.
- 16:56Speaker 1: Exactly so the author details this known deliberate and the
- 17:00Speaker 1: Flatschow Library. When the library is trying to calculate how
- 17:04Speaker 1: big to draw the charts, the size the text, the
- 17:06Speaker 1: width of labels, everything, it has to physically create dummy
- 17:10Speaker 1: HTML elements in the background of your web browser to
- 17:13Speaker 1: measure them.
- 17:14Speaker 2: It has to generate them to size them up right.
- 17:16Speaker 1: But obviously it doesn't want the user to see these
- 17:19Speaker 1: weird dummy text elements popping up on the web page
- 17:22Speaker 1: while it does the mask.
- 17:23Speaker 2: They need to exist on the page to be measured,
- 17:25Speaker 2: but they need to be invisible to the user.
- 17:27Speaker 1: So what does this all mean? How do the developers
- 17:29Speaker 1: hide them? Well, every web page is structured using something
- 17:33Speaker 1: called the DOM, the document object model, the blueprint. It's
- 17:36Speaker 1: basically the blueprint of the page, and you style that
- 17:39Speaker 1: blueprint using CSS. The developers of this library wrote a
- 17:44Speaker 1: CSS rule using absolute positioning. They told these dummy text
- 17:48Speaker 1: elements to be placed exactly ten thousand pixels above the
- 17:51Speaker 1: top of the.
- 17:52Speaker 2: User's screen using a negative value.
- 17:54Speaker 1: Yes, they use a top margin of negative ten thousand
- 17:56Speaker 1: picks on.
- 17:57Speaker 2: The logic being just throw it so far off the
- 18:00Speaker 2: screen that no one will ever see it out of sight,
- 18:02Speaker 2: out of mind exactly.
- 18:04Speaker 1: But here is the catch. CSS absolute positioning is tricking.
- 18:08Speaker 1: It is like telling someone go stand one hundred feet north,
- 18:12Speaker 1: but north of what the center of the earth, the
- 18:15Speaker 1: room you were currently standing in.
- 18:16Speaker 2: It's relative.
- 18:17Speaker 1: That is what happens to the browser. Sometimes, depending on
- 18:20Speaker 1: how your specific web page is built, that negative ten
- 18:23Speaker 1: thousand pixels is calculated relative to a container inside your page,
- 18:28Speaker 1: not the absolute top of the browser.
- 18:29Speaker 2: Window, which becomes a massive problem if the user's document
- 18:32Speaker 2: is extremely long.
- 18:34Speaker 1: Yes, if you are building a massive, long, scrolling dashboard
- 18:37Speaker 1: full of charts, that negative ten thousand pisel trick completely backfires.
- 18:41Speaker 1: The browser's positioning gets confused.
- 18:43Speaker 2: Oh, I can picture it now.
- 18:44Speaker 1: Suddenly the user is scrolling down your beautiful dashboard and
- 18:48Speaker 1: they start seeing random pieces of invisible chart text scattering
- 18:52Speaker 1: like confetti across your website.
- 18:54Speaker 2: It is the perfect encapsulation of how coding in the
- 18:56Speaker 2: real world actually works. You can have the most elegant
- 19:00Speaker 2: data structures, but you are still at the mercy of
- 19:03Speaker 2: a web browser misinterpreting a CSS hack from a third
- 19:07Speaker 2: party library.
- 19:09Speaker 1: And I absolutely love the book's practical takeaway for this.
- 19:12Speaker 1: The author basically says, Look, you could theoretically go into
- 19:14Speaker 1: the open source library, dig through thousands of lines of
- 19:17Speaker 1: source code and rewrite their positioning logic to be perfect.
- 19:21Speaker 1: Or you can just be a pragmatic developer.
- 19:23Speaker 2: Sometimes you just need a quick fix.
- 19:25Speaker 1: He suggests just writing a single line of jQuery to
- 19:28Speaker 1: find and hide the library's messy invisible.
- 19:31Speaker 2: Elements for those unfamiliar. jQuery is just a shortcut language
- 19:35Speaker 2: for web developers. It allows you to quickly find elements
- 19:38Speaker 2: on a web page after it has loaded and manipulate them.
- 19:40Speaker 1: Right so, the author says, just write a quick jQuery
- 19:43Speaker 1: script that targets the specific class name of those messy
- 19:46Speaker 1: invisible elements, the dot, float, dummy div class and just
- 19:51Speaker 1: brutally forces them to hide once the chart is done drawing.
- 19:55Speaker 2: It's a band aid, but sometimes the best solution is
- 19:57Speaker 2: the pragmatic one. It saves you hours of de and
- 20:00Speaker 2: it gets the visualization working for the user, which is
- 20:02Speaker 2: the ultimate goal.
- 20:03Speaker 1: It is such a wonderfully messy reality check. Yeah, which
- 20:06Speaker 1: actually brings us to the most important question for you,
- 20:09Speaker 1: the listener. We've spent this time talking about arrays, HTML canvases,
- 20:14Speaker 1: y axis minimums, and CSS bugs. Why does knowing the
- 20:17Speaker 1: JavaScript logic behind these charts actually matter to you?
- 20:20Speaker 2: It matters deeply because visual communication is a language, and
- 20:24Speaker 2: right now in the modern world, data is being spoken
- 20:27Speaker 2: at you constantly all day long.
- 20:29Speaker 1: Exactly think about it. Whether you are actively trying to
- 20:32Speaker 1: program a dashboard at your job, prepping a slide deck
- 20:35Speaker 1: for a board meeting, or simply just sitting on your
- 20:38Speaker 1: couch trying to consume your daily news on your phone
- 20:40Speaker 1: without being misled.
- 20:41Speaker 2: It's everywhere.
- 20:42Speaker 1: Understanding how axes are manipulated, why data points, meat, breathing room,
- 20:46Speaker 1: and when a pie chart is actually useful makes you
- 20:49Speaker 1: a vastly sharper, more critical consumer of information.
- 20:53Speaker 2: You stop just looking at the geometric shapes and you
- 20:55Speaker 2: start seeing the underlying structure.
- 20:58Speaker 1: You start to recognize the choices the creator made, and.
- 21:00Speaker 2: Even more importantly, you start to recognize the choices they
- 21:03Speaker 2: decided not to make.
- 21:04Speaker 1: Absolutely. Yeah, so we want to leave you with this thought.
- 21:07Speaker 1: Tom all over today. Now that you know exactly how
- 21:10Speaker 1: easily a chart's entire narrative can be radically altered just
- 21:14Speaker 1: by tweaking the minimum value of a y axis in
- 21:17Speaker 1: the code, or switching from comparative bars to an unreadable
- 21:20Speaker 1: pie slice.
- 21:21Speaker 2: Yeah, think about that.
- 21:23Speaker 1: How much the data you scrolled past today was intentionally
- 21:25Speaker 1: designed to manipulate your perception rather than actually inform you