diff --git a/src/routes/transforms/map/+page.md b/src/routes/transforms/map/+page.md index 74bfb0eb..a2eba5ac 100644 --- a/src/routes/transforms/map/+page.md +++ b/src/routes/transforms/map/+page.md @@ -2,26 +2,211 @@ 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 + +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 + + + + + + +``` + +Here we have the stocks data for Apple, plotted over time, with the cumulative +sum mapping of the Volume. We can see how the volume increases overtime. Any +sudden jumps in the Volume of Apple stocks would be very clear and visible in +this kind of chart. + +## Rank + +The `rank` function assigns a 0-based index to each datapoint had the data been +sorted. Essentially it tells you where the datapoint lies within your whole +dataset, for the provided property. + + ```svelte live - - + + + ``` + +```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, though not strictly 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 + +The `quantile` function effectively works the same as the `rank` function, but +instead of being 0-based index, it outputs a number between 0 and 1, basically +giving the proportion in which each element lies within the whole dataset. + +The calculation is whatever each element rank has, divided by the total number +of elements. + +```svelte live + + + + + + +``` + +```svelte + + + + + + +``` + + +## Map Reference diff --git a/src/routes/transforms/map/+page.ts b/src/routes/transforms/map/+page.ts new file mode 100644 index 00000000..a75ea383 --- /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', 'cars', 'olympians'], fetch) + }; +};