the-pudding / sleep-training

MIT License
0 stars 0 forks source link

Radius calculation #6

Closed tomvaillant closed 1 month ago

tomvaillant commented 1 month ago

In the Bubbles component I'm having trouble setting up my radiusScale (line 36) correctly so that the different datasets can all use the same scale. Two issues I'm seeing:

matthewfdaniels commented 1 month ago

i'm guessing it's because you're setting your radius scale in Bubbles. Every time you pass data to that component, it calculates the max and min radius value of that specific dataset you've passed.

what i would do is on this component, pass the max/min value as a prop

image

you could calculate the min/max value in Index.svelte where the data isn't filtered yet, and pass it to the Section component and then to Bubbles, or you could use stores but that's a new concept for you to learn potentially!

for your radius problems being negative, that's because it looks like the extent of your values are negative. here's what happened when i logged out this function

image image

So in theory, things should always be positive! one thing you can do keep things always in range is add this to the end of the radius function .clamp(true), which forces values to be within your output range

image

factoring your code this way also might easier to track

image

the $: will force anything to re-run in the statement if it changes. so in this example, xScaled will recalculate if innerWidth or positions change

image

In my example, $: data, runSimulation(); says, if data changes, run this function once

tomvaillant commented 1 month ago

Thanks Matt! Much prefer this syntax but I was having too many errors when I tried to implement it, will keep it for tomorrow.

The metrics used for radii are comparable within a dataset but not across datasets, so calculating it as a fixed overarching value wouldn't work (circles representing studies would be miniscule compared to reddit comments).

I was able to fix the negative values, when parsing CSVs I was importing the radius column values as strings rather than integers.