leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.51k stars 371 forks source link

Create blank empty plot #217

Closed ghost closed 4 years ago

ghost commented 4 years ago

What's the best way to create a blank empty plot ready to call addSeries on? When I try to construct with an empty data array I get "Cannot read property '-1' of undefined". My use case is as a real-time graphing tool where users can add items to graph so I'd like to start out with a "blank" canvas.

leeoniya commented 4 years ago

hey @jasonatball

see https://github.com/leeoniya/uPlot/issues/162

probably worth starting a Recipes or FAQ wiki page instead of crawling through issues.

ghost commented 4 years ago

Thanks that's exactly what I was looking for. I had read the bottom of that issue but didn't see the note at the top. I ended up doing this which makes sense for my 1Hz data:

min: Math.round(new Date().getTime() / 1000),
max: Math.round(new Date().getTime() / 1000) + 1000
ghost commented 4 years ago

@leeoniya It appears that leaves a blank series since data is [[], []]. My workaround was to delSeries(1) and then addSeries({ ... }, 1). Is that the best solution?

leeoniya commented 4 years ago

yeah, that's not ideal. but omitting the seriers almost works. i think it's just a matter of not creating a default y series here:

https://github.com/leeoniya/uPlot/blob/b5fefa47977e79dd513009008e0ef62fc51411a3/src/uPlot.js#L208

this should be a pretty easy quality of life improvement.

leeoniya commented 4 years ago

625f6003a50c3f0c5caf2725061661aa0a3ef35f makes it possible to omit both series and data entirely:

https://jsfiddle.net/9twvyr2L/

ghost commented 4 years ago

Thanks for the excellent help. We maintain the COSMOS project so as a fellow maintainer I appreciate the help.

leeoniya commented 4 years ago

sure!

ghost commented 4 years ago

I was playing with your jsfiddle and tried this:

let u = new uPlot(opts, null, document.body);
u.addSeries({
  label: 'TEST',
  stroke: 'red'
})
u.setData([[1],[1]])

But nothing happens.

ghost commented 4 years ago

In my own application when I call addSeries I get the following stack:

TypeError: Cannot read property 'scale' of undefined
    at Xn (uPlot.iife.min.js:2)
    at Object.Bn.s.addSeries (uPlot.iife.min.js:2)
leeoniya commented 4 years ago

interesting. looks like some kind of bundling SNAFU:

where the hell did the splice() go?

https://github.com/leeoniya/uPlot/blob/625f6003a50c3f0c5caf2725061661aa0a3ef35f/src/uPlot.js#L379-L385

https://github.com/leeoniya/uPlot/blob/625f6003a50c3f0c5caf2725061661aa0a3ef35f/dist/uPlot.iife.js#L1112-L1117

something somewhere seems to think that splice has no side-effects and is getting removed.

time to open up a rollup bug perhaps. gonna try to isolate it in the REPL first.

leeoniya commented 4 years ago

could not get a simple repro in their REPL. opened https://github.com/rollup/rollup/issues/3555. hopefully some answers soon :\

leeoniya commented 4 years ago

https://github.com/leeoniya/uPlot/commit/abacd02d19403048dbfd30b2004238e203a25598 moves some code around to work around the bug.

ghost commented 4 years ago

I was able to link to your new release and it seems to be working great! I look forward to the next release. Thanks again!

leeoniya commented 3 years ago

v1.0.9 is out

sausin commented 3 years ago

Just wanted to drop by and say - Thank you! The whole experience with the package (including the way you're handling issues) is just awesome :+1:

One a side note - sorry, for the unnecessary pinging

leeoniya commented 3 years ago

@sausin thanks, happy to help! (most of the time)

sausin commented 3 years ago

Some friction will always exist!

What I saw as being important is that if any PR / issue is not taken forward, then the explanation is put in right there. It's good book keeping (for future self too), and a good place for people experiencing the same issue / planning to introduce a PR to check out before own/other's time is spent in vain.

Hoping the library will stick to the <30 kB mark that you've discussed. (As an aside, I'm kind of jealous that the hey.com bundle size is ~40 kB total - damn!).

leeoniya commented 3 years ago

(As an aside, I'm kind of jealous that the hey.com bundle size is ~40 kB total - damn!).

i'm getting around 35KB, and ~8KB of that is unused.

not sure what exactly is impressive about what could/should easily be a mostly-empty static page with 0 KB js, actually requiring 35KB of js?

my 9-5's heaviest interactive e-commerce page is ~65kb of js, which includes a ton of products pulled from a db, modals/lightboxes, nested tabs, pagination, gallery, shopping cart UI, is fully responsive and rehydrated on the client: https://us.thermosoft.com/floor-heating/systems/warmstep-mats?track=0

(?track=0 disables google & bing analytics, otherwise they add more js than the rest of our page).

sausin commented 3 years ago

The ~40 kB bundle size is for the actual application (not the current static page) that dhh has been discussing on twitter.

It was an observation that things are awesome with people trying to put in efforts minimizing their app footprint. uPlot is an effort in the same direction on the chart front :smiley:

EDIT:- That page has quite a bit going on. ~65 kB is great! :clap: