Explore non-additive flow metrics and weighted aggregation

Open
#125 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
typescript

Research direction

This is exploratory design work, not a ready task. Start by reading PR #22 and its weighted aggregation discussion to see why its weights are lost and why location aggregation uses the computed metric. Then review the data aggregation layer, covering the local and worker data providers, to see where sum-based combining happens. Done means agreed semantics for weighted means, location summaries, and time aggregation, not a patch.

Written by the indexing model from the issue text.

Description

Flowmap.gl currently sums flow magnitudes when combining flows. This is appropriate for trips, people, goods, or money, but produces misleading results for non-additive metrics such as average journey time, average cost per trip, or a performance score weighted by trip volume.

This issue preserves the use case explored by @arashkav in #22 and its weighted aggregation example. The contribution identified a useful limitation. A future implementation should start from an active application's requirements and a representative dataset; this issue is exploratory, rather than a commitment to a general aggregation framework.

Example use case

A flow represents an average travel time plus the number of trips underlying that average. When locations merge into clusters, the resulting flow should show the trip-weighted average, and location summaries should remain consistent.

For example, 10 minutes across 100 trips and 20 minutes across one trip combine to (10 * 100 + 20 * 1) / 101 ≈ 10.10 minutes. Summing the averages, averaging them equally, or using the averages themselves as weights gives the wrong result.

Proposed direction

  • Keep sum as the default and preserve existing API behavior and the efficient summation path.
  • Initially support only operations justified by the concrete use case, likely sum and weighted mean, with ordinary mean if needed. Avoid exposing arbitrary reducers before their semantics and maintenance cost are understood.
  • Retain sufficient aggregation state: {sum, count} for a mean, or {weightedSum, weightSum} for a weighted mean. Combine that state and finalize to a display value only when needed. A finalized average alone cannot be correctly aggregated again.
  • Define how the metric affects flow thickness, ranking, legends, and tooltips. Decide separately what location summaries represent and what weights determine cluster positions; an average delay need not determine a location's geographic influence.
  • Apply the chosen semantics consistently to clustered flows, duplicate origin–destination rows without clustering, location summaries, time aggregation, and filtered/global summaries. If a summary is not meaningful for a metric, define that explicitly.
  • Keep the implementation in the data aggregation layer and account for local and worker data providers. Preserve numeric and string location IDs without coercing one into the other.

The public API should follow from those decisions; the accessor names and callback signature proposed in #22 are not requirements.

Lessons from #22

The existing PR needs redesign rather than a rebase. In particular, aggregation weights are lost when flows become aggregate records, and subsequent location aggregation uses the computed metric as its weight. The non-clustered and time aggregation paths also continue to sum. These are mathematical and behavioral consistency issues, beyond the age of the branch.

The PR's move to temporary accumulators and one final aggregation call per group is useful. For means, compact sufficient state can avoid retaining all source values.

Validation for a future implementation

  • Unequal group sizes and weights produce the same result when combined directly or in stages.
  • Clustering, zoom changes, filtering, and time aggregation follow the documented semantics.
  • Numeric and string IDs retain their identity.
  • Empty groups, missing/non-finite values, zero total weight, and any restrictions on weights have explicit behavior and tests.
  • Existing sum behavior and API compatibility remain intact, with representative checks for memory use and calculation cost.

For fixed-resolution applications, preprocessing one value per origin–destination pair and disabling clustering can cover part of the need today. Interactive reclustering is the stronger motivation for core support.

Contributions of concrete datasets and desired visual behavior would help determine the smallest useful scope.

Dominant language
TypeScript
Stars
143
Forks
24
Avg merge
1d 4h
Merged PRs (30d)
18

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from visgl/flowmap.gl

All issues in visgl/flowmap.gl

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.