From f9a0b84254fb29bb71030f69cb688f70daf7e282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Enrique=20Rasc=C3=B3n?= Date: Wed, 28 May 2025 12:06:31 +0200 Subject: [PATCH 1/4] first attempt at map docs --- src/routes/transforms/map/+page.md | 98 ++++++++++++++++++++++++------ src/routes/transforms/map/+page.ts | 8 +++ 2 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 src/routes/transforms/map/+page.ts diff --git a/src/routes/transforms/map/+page.md b/src/routes/transforms/map/+page.md index 74bfb0eb..529387e6 100644 --- a/src/routes/transforms/map/+page.md +++ b/src/routes/transforms/map/+page.md @@ -2,26 +2,90 @@ title: Map transform --- +Mapping transformations apply a given function to every element in the input +data. + +Currently, there are 3 mapping transforms available: cumsum, rank, and quantile. + + +## Cumsum + +```svelte live + + + + + + +``` + + +## Rank + ```svelte live + + + + +``` + +## Quantile + +```svelte live + - - + + ``` + + +## Map Reference diff --git a/src/routes/transforms/map/+page.ts b/src/routes/transforms/map/+page.ts new file mode 100644 index 00000000..b3941759 --- /dev/null +++ b/src/routes/transforms/map/+page.ts @@ -0,0 +1,8 @@ +import { loadDatasets } from '$lib/helpers/data.js'; +import type { PageLoad } from './$types.js'; + +export const load: PageLoad = async ({ fetch }) => { + return { + data: await loadDatasets(['aapl', 'olympians'], fetch) + }; +}; From e67134a65e4f82036c85ad5c8f0bd697314a6a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Enrique=20Rasc=C3=B3n?= Date: Wed, 28 May 2025 20:52:58 +0200 Subject: [PATCH 2/4] more explainers --- src/routes/transforms/map/+page.md | 95 ++++++++++++++++++++++++++---- src/routes/transforms/map/+page.ts | 2 +- 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/routes/transforms/map/+page.md b/src/routes/transforms/map/+page.md index 529387e6..67e229df 100644 --- a/src/routes/transforms/map/+page.md +++ b/src/routes/transforms/map/+page.md @@ -10,7 +10,11 @@ Currently, there are 3 mapping transforms available: cumsum, rank, and quantile. ## Cumsum -```svelte live +The `cumsum` expression stands for Cumulative Sum. It represents how your data +stacks up and changes. At any given point, you get the total sum of all previous +data points. + +```svelte - + + ``` +```svelte + + + + + + +``` + + +Here, we are visualizing the top 10 fastest cars, and their ranking. As you can +see, the Y axis does not output the actual seconds to reach 60mph, but rather answers the question "in what +position does each car end up?". + +Sorting the cars before passing them to Plot is important. It's not necessary. +The rank function just assigns a number to each datapoint based on the position +it would occupy with the property provided (in this case, `"0-60 mph (s)"`). Had +we not sorted the array, the visualization would look like this: + + +```svelte live + + + + + + +``` + +As we can see, here we don't sort the array. We are still taking just 10 cars. +In this case, we see the ordering that was implicit from the dataset, which +appears to be in alphabetical order (though it may not be). + +Now the line is jagged, showing what each car's position is with respect to this +subset of 10 cars. + + ## Quantile ```svelte live diff --git a/src/routes/transforms/map/+page.ts b/src/routes/transforms/map/+page.ts index b3941759..a75ea383 100644 --- a/src/routes/transforms/map/+page.ts +++ b/src/routes/transforms/map/+page.ts @@ -3,6 +3,6 @@ import type { PageLoad } from './$types.js'; export const load: PageLoad = async ({ fetch }) => { return { - data: await loadDatasets(['aapl', 'olympians'], fetch) + data: await loadDatasets(['aapl', 'cars', 'olympians'], fetch) }; }; From 568e7c92ef0f02f4cb0f256eae2573fec5618b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Enrique=20Rasc=C3=B3n?= Date: Thu, 29 May 2025 10:31:04 +0200 Subject: [PATCH 3/4] fix wording and add live example --- src/routes/transforms/map/+page.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/routes/transforms/map/+page.md b/src/routes/transforms/map/+page.md index 67e229df..0d275e86 100644 --- a/src/routes/transforms/map/+page.md +++ b/src/routes/transforms/map/+page.md @@ -14,6 +14,26 @@ The `cumsum` expression stands for Cumulative Sum. It represents how your data stacks up and changes. At any given point, you get the total sum of all previous data points. +```svelte live + + + + + + +``` + ```svelte - + + + +``` + +```svelte + + + + + ```