Skip to content

pylib: add api support for grids #158

@sondove

Description

@sondove

Splitting this work out of #98

As we are nearing alpha release of novem grids it would make sense to add them to the python library.

I've outlined an api design below that is similar to how Mail is currently implemented and also stays close to existing paradigms and the cli.

from novem import Plot, Grid, Doc
from novem.grid import GridMap

# create grid
grd = Grid("r1_g1")

# define layout using novem ascii style
grd.layout = """
+-----------+
|   {a:-}   |
+-----------+
|   {b:-}   |
+-----+-----+
|{c:-}|{d:-}|
+-----+-----+
"""

# map existing visualisations to grid elements
grd.mapping = GridMap({
    'a':Plot("r1_p1_table_1"),
    'b':Plot("r1_p1_table_2"),
    'c':Plot("r1_p1_pie_1"),
    'd':Plot("r1_p1_pie_2"),
})

# get the url to the grid
print(grd.url)

The suggested GridMap resolves to a plain text file of the format

a => /u/:username/p/:plot_id
b => /u/:username/p/:plot_id

where the values before the => are based on the keys and the value after derived from the Plot.username and Plot.id

The grid follows the structure of existing novem plots with tags, shares, names etc

Below is a list of all the relevant endpoints

❯ novem -g test_grid --tree
[rwd] test_grid/
    ├── [r--] config/
    │   ├── [r--] borders/
    │   │   ├── [rw-] color
    │   │   ├── [rw-] corner
    │   │   ├── [rw-] label
    │   │   └── [rw-] style
    │   ├── [r--] colors/
    │   │   └── [rw-] theme
    │   ├── [r--] footer/
    │   │   ├── [rw-] footnote
    │   │   └── [rw-] pagenum
    │   ├── [r--] header/
    │   │   └── [rw-] title
    │   ├── [rw-] theme
    │   └── [rw-] type
    ├── [r--] files/
    │   ├── [r--] grid.ansi
    │   ├── [r--] grid.pdf
    │   ├── [r--] grid.png
    │   └── [r--] grid.txt
    ├── [rw-] shared/
    │   ├── [--d] public
    │   └── [--d] chat
    ├── [rw-] tags/
    ├── [rw-] description
    ├── [rw-] layout
    ├── [r--] log
    ├── [rw-] mapping
    ├── [rw-] name
    ├── [r--] shortname
    ├── [rw-] summary
    └── [r--] url

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions