observablehq / observablehq/plot
Weighted sum?
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- HTML
- Stars
- 5.4k
- Forks
- 244
- PR merge metrics
- No merged PRs in 30d
Description
It’d be nice to have a weighted sum reducer. This would require two channels as input (the values, and the weights), so I’m not sure how we would specify it. As a workaround, you can write a custom reducer, assuming that your data is indexable:
Plot.ruleX(
lockdown,
Plot.groupZ(
{
x: {
reduce(I, X) {
return (
d3.sum(I, (i) => lockdown[i].pop * X[i]) /
d3.sum(I, (i) => lockdown[i].pop)
);
}
}
},
{ x: "pct_change" }
)
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Plot.groupZ reducer API and the custom reduce workaround shown in the issue, including its use of d3.sum. Define how a weighted sum reducer would receive values and weights, then implement and document the chosen interface; done means weighted aggregation works without the custom reducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- d3js, javascript
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100