Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scale.range of default x/y scales should be initialized without series #309

Closed
NoahBres opened this issue Sep 20, 2020 · 10 comments
Closed
Labels
bug Something isn't working

Comments

@NoahBres
Copy link

I get the following error when upgrading to uPlot 1.2.1:

Screen Shot 2020-09-19 at 10 14 49 PM

Line in question:

Screen Shot 2020-09-19 at 10 15 07 PM

Honestly not sure if this error is due to 1.2.1 specifically. I upgraded directly from 1.1.2 so I will roll back and see which versions causes the issue.

@NoahBres
Copy link
Author

Might actually be something wrong with my build configuration. Please disregard until I figure it out.

@leeoniya
Copy link
Owner

leeoniya commented Sep 20, 2020

it's almost certainly the next commit following 1.2.1: fe5fac7

that code runs for y scales of empty charts (without data).

the default scale ranging functions get initialized as part of iterating the series arrays (since series can implicitly initialize new scales simply by specifying a unique key):

https://github.com/leeoniya/uPlot/blob/master/src/uPlot.js#L535

however, there are always default x and y scales created on init. so i'm guessing you are initializing a data-less plot with no y series? (i'm on a phone but i think those are the necessary conditions here).

a repro would obviously help.

@NoahBres
Copy link
Author

NoahBres commented Sep 20, 2020

however, there are always default x and y scales created on init. so i'm guessing you are initializing a data-less plot with no y series?

I believe I was doing this but I switched some code around and generated data before the graph is initialized (it's a live visualization so data is streaming) and it does not seem to change anything.

I am hoping to get a live reproduction up but that is having it's own different issue :P

I'll get back to you once I figure it out.

@NoahBres
Copy link
Author

NoahBres commented Sep 20, 2020

Ah. It was an empty y series. My apologies. It was due to some async problems.
Thank you so much for your patience and your amazing support!

@leeoniya
Copy link
Owner

no problem. i still think this is an issue, though.

the solution is most likely to also init scale.range for the default scales here:

https://github.com/leeoniya/uPlot/blob/master/src/uPlot.js#L246

@leeoniya leeoniya reopened this Sep 20, 2020
@leeoniya leeoniya changed the title "wsc.range is not a function" - uPlot 1.2.1 scale.range of default x/y scales should be initialized without series Sep 20, 2020
@ghost
Copy link

ghost commented Sep 23, 2020

I'm seeing the same issue since 1.2.1:

TypeError: wsc.range is not a function
    at setScales (webpack-internal:///./node_modules/uplot/dist/uPlot.esm.js:1624)
    at setScale (webpack-internal:///./node_modules/uplot/dist/uPlot.esm.js:2320)
    at _setScale (webpack-internal:///./node_modules/uplot/dist/uPlot.esm.js:2403)
    at _setSize (webpack-internal:///./node_modules/uplot/dist/uPlot.esm.js:1306)
    at Object.setSize (webpack-internal:///./node_modules/uplot/dist/uPlot.esm.js:1312)
    at VueComponent.resize

Is there an easy workaround? I display my empty chart and then dynamically add items to it.

@leeoniya
Copy link
Owner

Is there an easy workaround? I display my empty chart and then dynamically add items to it.

i think the recommendation going forward if you want to handle a data-less (or series-less) case will be to explcitly provide scale.range which handles the null case when there is no data from which to autoscale. this will be better than relying on uPlot to do some sort of ambiguous "right thing" magic.

see the first example here:

https://github.com/leeoniya/uPlot/blob/master/demos/no-data.html

@leeoniya leeoniya added the bug Something isn't working label Sep 24, 2020
@ghost
Copy link

ghost commented Sep 24, 2020

Interesting. Before I was just doing this in my scales:

        scales: {
          x: {
            min: Math.round(new Date().getTime() / 1000),
            max: Math.round(new Date().getTime() / 1000) + 1000
          },
          y: {
            min: -100,
            max: 100
          }
        }

Your example has me doing this now which works:

        scales: {
          x: {
            range(u, dataMin, dataMax) {
              if (dataMin == null) return [1566453600, 1566497660]
              return [dataMin, dataMax]
            }
          },
          y: {
            range(u, dataMin, dataMax) {
              if (dataMin == null) return [-100, 100]
              return uPlot.rangeNum(dataMin, dataMax, 0.1, true)
            }
          }
        }

@leeoniya
Copy link
Owner

leeoniya commented Sep 24, 2020

yeah, that method turned out to be tricky to support in the case when you go from data to no-data but the original min/max setting is now gone (since those actually become mutable min/max values). also in combo with range it becomes very inconsistent to explain or reason about, so using only range handles all cases clearly.

@NoahBres
Copy link
Author

I'm late but thank you so much! You're awesome <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants