question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uPlot.Scatter

e.g. https://academy.datawrapper.de/article/65-how-to-create-a-scatter-plot

spatial index via e.g. https://github.com/mourner/kdbush or https://github.com/mourner/flatbush

data format e.g.:

[
  [x,y,v,l,x,y,v,l],  // series 1
  [x,y,v,l,x,y,v,l],  // series 2
  [x,y,v,l,x,y,v,l],  // series 3
]
  • v value (size of point/shape)
  • l label

should use a Path2D shape cache

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

14reactions
leeoniyacommented, Mar 22, 2020

sneak peek

30,000 scatter points (10k per series) in 100ms:

uplot-scatter

this is without building a spatial point index, which turns out to be a fairly expensive task (~40ms for kdbush).

if the points were square (instead of circles) and pixel-aligned, this would likely run 30-50% faster since there’d be no need for anti-aliasing.

10reactions
leeoniyacommented, Mar 25, 2020

ok, so i optimized point rendering in 12b6beb23d58bfab52c8af052c6e80cd23a267f7, to use a single Path2D.

since i had no baseline for whether 75ms was slow or fast for a 30k point scatter plot. i tried the same with the next-fastest lib (Chart.js 3.0 alpha). spoiler: it’s was never actually 75ms (that’s just JS exec time):

uPlot:

  • build: 450ms (75ms js + 375ms “system”)
  • toggle last series on/off: 625ms

Chart.js 3.0 alpha:

  • build: 900ms
  • toggle last series on/off: 3157ms

so about 2x as fast for init (but still without building a spatial index). and much faster for series toggle, even with rebuilding all paths. once i cache the Path2D objects, toggle will be faster still (by a lot).

another question is whether the design should accommodate multi-scale scatter plots. these are not very common, but they do exist:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Scatter Plots - Chartio
A scatter plot (aka scatter chart, scatter graph) uses dots to represent values for two different numeric variables. The position of each dot...
Read more >
Scatter (XY) Plots - Math is Fun
A Scatter (XY) Plot has points that show the relationship between two sets of data. In this example, each dot shows one person's...
Read more >
Scatter plot - Wikipedia
A scatter plot (also called a scatterplot, scatter graph, scatter chart, scattergram, or scatter diagram) is a type of plot or mathematical diagram...
Read more >
Example of direction in scatterplots (video) - Khan Academy
In accounting, scatterplots can be used to see if there is a relationship between to variables, such as money spent of advertising and...
Read more >
What is a Scatter Chart? - TIBCO Software
A scatter chart, also called a scatter plot, is a chart that shows the relationship between two variables. They are an incredibly powerful...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found