Skip to content

Conversation

@jesi-rgb
Copy link

@jesi-rgb jesi-rgb commented May 28, 2025

fixes #10

@netlify
Copy link

netlify bot commented May 28, 2025

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit 498bc38
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/69484062dc8a4400084c1c11
😎 Deploy Preview https://deploy-preview-70--svelteplot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jesi-rgb jesi-rgb changed the title first attempt at map docs Map Docs May 28, 2025
@jesi-rgb jesi-rgb marked this pull request as draft May 28, 2025 10:08
@jesi-rgb jesi-rgb marked this pull request as ready for review May 28, 2025 10:08
@jesi-rgb jesi-rgb marked this pull request as draft May 28, 2025 14:25
@Wolfr
Copy link
Contributor

Wolfr commented May 28, 2025

Awesome.

@jesi-rgb
Copy link
Author

As I'm writing this section, @gka, I find it weird that the current available transforms are inside a "Map" category. As per d3-array's documentation, this lies under "Summarizing Data".

I would expect a Map transformer to receive a callback function that transforms the data in some way. For example, taking all Athlete names and converting them to a smaller format:

"Michael Phelps" → "M. Phelps"
"Aaron Brown" → "A. Brown"

This is a small example but I think it gets the point across of what I'm trying to say.

Maybe the current "Map" section could be called "Summarize", a series of transformations to summarize the data, in which we can now include the rest of the available methods, like sum, min, max, and so on.

Maybe I'm understanding it wrong, though! Would love if you could shed some light on this topic!

@jamesscottbrown
Copy link
Contributor

Maybe the current "Map" section could be called "Summarize", a series of transformations to summarize the data, in which we can now include the rest of the available methods, like sum, min, max, and so on.

I'd expect a map function to transform a list of values to a list of the same length, but containing modified values.

I'd expect a summarize function to transform a list of values to a single value.

Cumsum, rank and quantile transform a list of values to another list of values, so I think they're more appropriately described as map than summarize.

However, I would generally expect a map function to act on each value individually. There might be an alternative name that is clearer, but Map is what Observable Plot uses and it woud be good to maintain API compatability.

@jesi-rgb
Copy link
Author

However, I would generally expect a map function to act on each value individually. There might be an alternative name that is clearer, but Map is what Observable Plot uses and it woud be good to maintain API compatability.

I guess this is the core issue: it's a cumsum is a Map because it receives an array and outputs an array of the same size, but output is dependent on all elements

GlobalMap, or something along those lines could work. I do agree, though, to stick to Observable's API naming. In fact, I was trying to stick with d3's!

@gka
Copy link
Contributor

gka commented Dec 21, 2025

Hi, apologies for my long silence here. Thanks a lot for taking on the map docs!

@jesi-rgb

I would expect a Map transformer to receive a callback function that transforms the data in some way. For example, taking all Athlete names and converting them to a smaller format

In SveltePlot this would just be a channel accessor. E.g. to lowercase athlete names you wouldn't use any transform but just a function accessor:

<Text data={athletes} text={d => d.name.toLowerCase()} />

I don't think we need to add a transform for these cases.

Maybe the current "Map" section could be called "Summarize", a series of transformations to summarize the data, in which we can now include the rest of the available methods, like sum, min, max, and so on.

I don't think map and summarize would be the same. Map always returns a list of values (just like the Array.map you mentioned). So it's not summarizing the values but transforming them.

(Also for actual summarizing you can use the group and bin transforms)

@jamesscottbrown

However, I would generally expect a map function to act on each value individually. There might be an alternative name that is clearer, but Map is what Observable Plot uses and it woud be good to maintain API compatability.

Well, the actual difference between using an accessor function and using a map transform is that the latter does give you access to the entire array while the former only operates on a single datum.

This is the reason why you can use the map transform to normalize data. Under the hood, the normalize transform is using the map transform.

But this discussion shows that these are useful things to clear up in the documentation of the map transform!

As for the examples included in the PR: I like the cumsum example, that's very clear, but I think the other examples are a bit too complicated. For instance, we could add an example using the quantile map for something more useful, like to compare distributions:

image

example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: Map transform docs need some 💙

4 participants