{{#each dishes}}
<li><strong>{{name}}</strong> costs {{price}}</li>
{{/each}}
</ol
'''
spec = '''
{
  "description": "A simple bar plot with embedded data.",
  "mark": "bar",
  "encoding": {
    "x": {"field": "a", "type": "ordinal"},
    "y": {"field": "b", "type": "quantitative"}
  }
}
'''
f = FakeCategoricalSeries()
n = 20


# Generate random datum between 1 and 100
def rnd(): return random.randint(1, 100)


@app('/demo')
async def serve(q: Q):
    q.page['example'] = ui.form_card(box='1 1 4 10', items=[
        ui.text_xl(content='Extra-large text, for headings.'),
        ui.text_l(content='Large text, for sub-headings.'),
        ui.text_m(content='Body text, for paragraphs and other content.'),
        ui.text_s(content='Small text, for small print.'),
        ui.text_xs(content='Extra-small text, for really small print.'),
Exemple #2
0
# Plot / Interval
# Make a column #plot. #interval
# ---
from synth import FakeCategoricalSeries
from h2o_wave import site, data, ui

page = site['/demo']

n = 20
f = FakeCategoricalSeries()
v = page.add(
    'example',
    ui.plot_card(box='1 1 4 5',
                 title='Interval',
                 data=data('product price', n),
                 plot=ui.plot([
                     ui.mark(type='interval',
                             x='=product',
                             y='=price',
                             y_min=0)
                 ])))
v.data = [(c, x) for c, x, dx in [f.next() for _ in range(n)]]

page.save()
Exemple #3
0
# Stat / Series / Small / Interval
# Create a small stat card displaying a primary value and a series plot.
# ---
import time

from faker import Faker

from synth import FakeCategoricalSeries
from h2o_wave import site, ui, data

page = site['/demo']

fake = Faker()
f = FakeCategoricalSeries()
cat, val, pc = f.next()
c = page.add(
    f'example',
    ui.small_series_stat_card(
        box='1 1 1 1',
        title=fake.cryptocurrency_name(),
        value=
        '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
        data=dict(qux=val, quux=pc),
        plot_category='foo',
        plot_type='interval',
        plot_value='qux',
        plot_color='$red',
        plot_data=data('foo qux', -20),
        plot_zero_value=0,
    ))
page.save()
Exemple #4
0
# Plot / Histogram
# Make a histogram.
# ---
from synth import FakeCategoricalSeries
from h2o_wave import site, data, ui

page = site['/demo']

n = 10
f = FakeCategoricalSeries()
v = page.add(
    'example',
    ui.plot_card(box='1 1 4 5',
                 title='Histogram',
                 data=data('lo hi price', n),
                 plot=ui.plot([
                     ui.mark(type='interval',
                             y='=price',
                             x1='=lo',
                             x2='=hi',
                             y_min=0)
                 ])))
v.data = [(i * 10, i * 10 + 10, x)
          for i, (c, x, dx) in enumerate([f.next() for _ in range(n)])]

page.save()
Exemple #5
0
# Plot / Interval / Range
# Make a column #plot with each bar representing high/low (or start/end) values.
# Transposing this produces a gantt plot. #interval #range
# ---
import random

from synth import FakeCategoricalSeries
from h2o_wave import site, data, ui

page = site['/demo']

n = 20
f = FakeCategoricalSeries()
v = page.add('example', ui.plot_card(
    box='1 1 4 5',
    title='Interval, range',
    data=data('product low high', n),
    plot=ui.plot([ui.mark(type='interval', x='=product', y0='=low', y='=high')])
))
v.data = [(c, x - random.randint(3, 10), x + random.randint(3, 10)) for c, x, dx in [f.next() for _ in range(n)]]

page.save()
Exemple #6
0
def create_dashboard(update_freq=0.0):
    page = site['/demo']

    simples = []
    for i in range(1, 7):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'a{i}',
            ui.small_stat_card(
                box=f'{i} 1 1 1',
                title=fake.cryptocurrency_name(),
                value=f'${val:.2f}',
            ))
        simples.append((f, c))

    simples_colored = []
    for i in range(1, 7):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'aa{i}',
            ui.small_series_stat_card(
                box=f'{6 + i} 1 1 1',
                title=fake.cryptocurrency_code(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                data=dict(qux=val, quux=pc / 100),
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        simples_colored.append((f, c))

    lines = []
    for i in range(1, 13, 2):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'b{i}',
            ui.wide_series_stat_card(
                box=f'{i} 2 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc / 100),
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        lines.append((f, c))

    bars = []
    for i in range(1, 13, 2):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'c{i}',
            ui.wide_series_stat_card(
                box=f'{i} 3 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc),
                plot_type='interval',
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -25),
                plot_zero_value=0))
        bars.append((f, c))

    large_pcs = []
    for i in range(1, 13):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'd{i}',
            ui.tall_gauge_stat_card(
                box=f'{i} 4 1 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        large_pcs.append((f, c))

    large_lines = []
    for i in range(1, 13):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'e{i}',
            ui.tall_series_stat_card(
                box=f'{i} 6 1 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc),
                plot_type='area',
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        large_lines.append((f, c))

    small_pcs = []
    for i in range(1, 7, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'f{i}',
            ui.wide_gauge_stat_card(
                box=f'{i} 8 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        small_pcs.append((f, c))

    small_pbs = []
    for i in range(7, 13, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'f{i}',
            ui.wide_bar_stat_card(
                box=f'{i} 8 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        small_pbs.append((f, c))

    large_cards = []
    for i in range(1, 7, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'g{i}',
            ui.large_stat_card(
                box=f'{i} 9 2 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc / 100),
                caption=' '.join(fake.sentences()),
            ))
        large_cards.append((f, c))

    large_pbs = []
    for i in range(7, 13, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'g{i}',
            ui.large_bar_stat_card(
                box=f'{i} 9 2 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                value_caption='This Month',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value_caption='Previous Month',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
                caption=' '.join(fake.sentences(2)),
            ))
        large_pbs.append((f, c))

    page.save()

    while update_freq > 0:
        time.sleep(update_freq)

        for f, c in simples:
            val, pc = f.next()
            c.value = f'${val:.2f}',

        for f, c in simples_colored:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in lines:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in bars:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in large_lines:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in large_pcs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in small_pcs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in small_pbs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in large_cards:
            val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc

        for f, c in large_pbs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        page.save()
Exemple #7
0
# Plot / Form
# Display a plot inside a form.
# ---
from synth import FakeCategoricalSeries
from h2o_wave import site, data, ui

page = site['/demo']

n = 20
f = FakeCategoricalSeries()
v = page.add(
    'example',
    ui.form_card(
        box='1 1 4 5',
        items=[
            ui.text_xl('Example 1'),
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='interval', x='=product', y='=price', y_min=0)
                ]),
                data=data(fields='product price',
                          rows=[(c, x)
                                for c, x, _ in [f.next() for _ in range(n)]],
                          pack=True),
            ),
            ui.text_xl('Example 2'),
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='interval', x='=product', y='=price', y_min=0)
                ]),
                data=data(fields='product price',