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

should i be relative to the internal flattened array? #77

Closed
leeoniya opened this issue Dec 24, 2019 · 6 comments
Closed

should i be relative to the internal flattened array? #77

leeoniya opened this issue Dec 24, 2019 · 6 comments
Milestone

Comments

@leeoniya
Copy link
Owner

leeoniya commented Dec 24, 2019

right now the public API is split into x and y sections, but internally they're merged to keep the loops uniform, with just a sprinkling of if (i ==0) branching to split off x.

the public API accepts i that is against the internal flattened array, but this is not terribly intuitive, especially since uPlot goes to additional lengths to make it look like the internals match the externals, e.g.

self.series = splitXY(series);

this can probably be improved.

i've considered dropping the x/y and simply making the lists flat but it results in awkwardness elsewhere. e.g. x is required, but if nothing needs to be customized for the x axis, you need to provide options that start with null: axes: [null, {values}]. also, there can be multiple x axes (let's say different units), then what?

i guess one route can be to attach an extra required property to each option item in a flat list, eg. dir: 'x', but that's not great either.

considerations:

  • data[0] is always the x-series data and there can only be a single x series
  • there could be multiple x axes (alt units)

if we simply disallow multiple x axes, then this whole situation becomes easier. we can use flat lists and simply say that data[0], series[0] and axes[0] are all x, everything else is y, and then we just use a flat i as we do now and everything becomes logically aligned. yes, there will be axes: [null, {}, {}] but it's easy to reason about.

@leeoniya leeoniya mentioned this issue Dec 24, 2019
@leeoniya
Copy link
Owner Author

leeoniya commented Dec 24, 2019

...but multiple x axes can actually be quite useful, especially when comparing 2 time periods, or group-segmenting another axis:

XBDhQ
088297df-5acb-4974-872b-d3cc775a1be8_chart-legacy
36106056-4351e246-0fe4-11e8-95e9-970c904e9a57

@leeoniya leeoniya added this to the 1.0.0 milestone Dec 24, 2019
@leeoniya
Copy link
Owner Author

leeoniya commented Dec 24, 2019

here's what a flattened uniform structure would look like that allows i to be logically consistent (with multiple x axis support).

modifying the default y axis or y series would require null or {} placeholders for the skipped default x.

technically, the axes order doesnt matter s long and we can treat the first encountered side: 2 axis as the default x and side: 3 as the default y.

also, axis.side would become a required param, since no default could be assumed just from the position in the array.

there's no such option for series if we want to stay sane and follow the order of data.

{
  data: [
    [1,2,3,4],
    [47,22,13,4]
  ],
  series: [
    null,
    {},
  ],
  axes: [
   null,
   {values: () => {}, side: 3}
  ],
  scales: {
    x: {},
    y: {},
  }
}

there's no need for scales to be an object. we can move to scales being an array as well:

  scales: [
    null,
    {auto: false},
  ]

@thinhdev97
Copy link

Have you a sample demo for this? thanks.

@leeoniya
Copy link
Owner Author

a sample demo of what?

@thinhdev97
Copy link

thinhdev97 commented Jul 29, 2020

a sample demo of what?

multiple x-axes like image.
I want to render a time-series chart with 2 lines. But they have different x.

@leeoniya
Copy link
Owner Author

chart 2: https://leeoniya.github.io/uPlot/demos/time-periods.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants