observablehq / observablehq/plot

Auto mark isMonotonic should distinguish sorted within series

Open
#1,763 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

If data is monotonic in X or Y, the auto mark may draw a line. But we have a longstanding TODO in isMonotonic:

https://github.com/observablehq/plot/blob/ee5eff7844a48453a4c6239d9f11363edc0879c6/src/marks/auto.js#L246-L263

For example, this data:

const data = [
    {date: new Date(2020, 0, 1), value: 5, series: 1},
    {date: new Date(2020, 0, 1), value: 50, series: 2},
    {date: new Date(2020, 0, 1), value: 500, series: 3},
    {date: new Date(2020, 0, 2), value: 6, series: 1},
    {date: new Date(2020, 0, 2), value: 60, series: 2},
    {date: new Date(2020, 0, 2), value: 600, series: 3},
    {date: new Date(2020, 0, 3), value: 7, series: 1},
    {date: new Date(2020, 0, 3), value: 70, series: 2},
    {date: new Date(2020, 0, 3), value: 700, series: 3}
  ]
  return Plot.auto(data, {x: "date", y: "value"}).plot();

Produces a weird line:

image

If two points have the same value (so order === 0), should isMonotonic be false? There are fancier things we could do, like trying to infer a z channel, but…

(Idk if this is a bug or enhancement!)

Contributor guide

Open the contributing guide

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.

Research direction

Read src/marks/auto.js at lines 246-263, then reproduce the issue with the supplied Plot.auto data containing three series. Determine how equal or interleaved values should affect isMonotonic, and verify that the example no longer produces a misleading line when the behavior is corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
d3, javascript
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.