wave icon indicating copy to clipboard operation
wave copied to clipboard

array buffer doesn't honor `size` property

Open zillionare opened this issue 2 years ago • 3 comments

Wave SDK Version, OS

0.22 ubuntu 20.04

Actual behavior

if you created a line plot with this:

    q.page["content"] = ui.plot_card(
        box="content",
        title="Line, groups",
        data=data("date series assets", 120),
        plot=ui.plot(
            [
                ui.mark(
                    type="line",
                    x="=date",
                    y="=assets",
                    color="=series",
                    y_min=0,
                    y_max=10,
                )
            ]
        ),
    )

then update data later:

q.page["content"].data[i] = [...]

this won't take effect since the original data buffer size is 0. if the buffer is defined as circular, then everything is fine.

Expected behavior

when data is defined as Array, as long as size is provided, it should:

  1. initially draw the plot with full x-axis (length is size), and draw dots, lines as many as which is provided initially
  2. upon update array, it's allowed to expand actual array, as long as the total size is not exceed.

zillionare avatar Jun 04 '22 02:06 zillionare

and if you have set data as circular one, pass rows is actually not allowed, this will result no any plot is drawing. you have to do like this:

async def render_content(q: Q, rows: List):
    q.page["content"] = ui.plot_card(
        box="content",
        title="Line, groups",
        data=data("date series assets", -120),
        plot=ui.plot(
            [
                ui.mark(
                    type="line",
                    x="=date",
                    y="=assets",
                    color="=series",
                    x_scale="time-category"
                )
            ]
        ),
    )

    # populate data one by one after it's constructured:
    if len(rows):
        for row in rows:
            q.page["content"].data[-1] = row

the behaviour is not intutive and not consistent.

zillionare avatar Jun 04 '22 03:06 zillionare

does this behaviour caused be plot_card (it use PackedRecord)? image

zillionare avatar Jun 04 '22 09:06 zillionare

@zillionare I already did some investigation and indeed there is some inconsistent behavior on how array and cyclic data buffers work with plot.

Could you clarify some points?

this won't take effect since the original data buffer size is 0

The declared size is 120 but the array is empty (0), is that what you meant?

initially draw the plot with full x-axis (length is size), and draw dots, lines as many as which is provided initially

It already draws the initially provided values. Do you want the axis to be drawn when there is no data provided initially as well?

upon update array, it's allowed to expand actual array, as long as the total size is not exceed.

I didn't get this one.

aalencar avatar Aug 08 '22 13:08 aalencar

Couldn't repro on either 0.22.0 or the latest main.

from h2o_wave import main, app, Q, ui, data


@app('/')
async def serve(q: Q):
    q.page['example'] = ui.plot_card(
        box='1 1 4 5',
        title='Line',
        data=data('year value', 9),
        plot=ui.plot([ui.mark(type='line', x_scale='time', x='=year', y='=value', y_min=0)])
    )
    d = [
        ('1991', 3),
        ('1992', 4),
        ('1993', 3.5),
        ('1994', 5),
        ('1995', 4.9),
        ('1996', 6),
        ('1997', 7),
        ('1998', 9),
        ('1999', 13),
    ]

    for idx, i in enumerate(d):
        q.page['example'].data[idx] = i

    await q.page.save()

Everything works as expected. @zillionare Feel free to reopen in case I missed something.

mturoci avatar Aug 23 '23 08:08 mturoci