Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Jan 8, 2023
1 parent 7e18d7e commit 1be017b
Show file tree
Hide file tree
Showing 25 changed files with 384 additions and 159 deletions.
37 changes: 10 additions & 27 deletions image/generate_figs.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
from typing import Callable
from functools import wraps
from pathlib import Path
import numpy as np
from magicgui import magicgui
from magicgui.widgets import TextEdit

from tabulous import TableViewer, commands as cmds

_ALL_FUNCTIONS = []
_DIR_PATH = Path(__file__).parent
from tabulous_doc import FunctionRegistry

REG = FunctionRegistry(Path(__file__).parent)

def register(f: Callable[[], TableViewer]):
@wraps(f)
def wrapped():
viewer = f()
viewer.save_screenshot(_DIR_PATH / f"{f.__name__}.png")
viewer.close()

_ALL_FUNCTIONS.append(wrapped)
return wrapped


def main():
for f in _ALL_FUNCTIONS:
f()


@register
@REG.register
def viewer_example():
viewer = TableViewer()
sheet = viewer.open_sample("iris", type="spreadsheet")
Expand All @@ -40,7 +23,7 @@ def viewer_example():
return viewer


@register
@REG.register
def filter_example():
viewer = TableViewer()
rng = np.random.default_rng(1234)
Expand All @@ -52,7 +35,7 @@ def filter_example():
return viewer


@register
@REG.register
def sort_example():
viewer = TableViewer()
rng = np.random.default_rng(1234)
Expand All @@ -67,7 +50,7 @@ def sort_example():
return viewer


@register
@REG.register
def colormap_example():
viewer = TableViewer()
sheet = viewer.open_sample("iris", type="spreadsheet")
Expand All @@ -82,7 +65,7 @@ def colormap_example():
return viewer


@register
@REG.register
def eval_example():
viewer = TableViewer()
sheet = viewer.add_spreadsheet(np.arange(100))
Expand All @@ -96,7 +79,7 @@ def eval_example():
return viewer


@register
@REG.register
def command_palette_example():
viewer = TableViewer()
viewer.add_spreadsheet()
Expand All @@ -105,7 +88,7 @@ def command_palette_example():
return viewer


@register
@REG.register
def custom_widget_example():
viewer = TableViewer()
sheet = viewer.add_spreadsheet()
Expand Down Expand Up @@ -133,4 +116,4 @@ def read_csv(save_path: Path):


if __name__ == "__main__":
main()
REG.run_all()
33 changes: 33 additions & 0 deletions rst/_static/font.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.gray {color: gray;}

.grey {color: gray;}

.silver {color: silver;}

.white {color: white;}

.red {color: red;}

.magenta {color: magenta;}

.pink {color: pink;}

.orange {color: orange;}

.yellow {color: yellow;}

.lime {color: lime;}

.green {color: green;}

.teal {color: teal;}

.cyan {color: cyan;}

.aqua {color: aqua;}

.blue {color: blue;}

.navy {color: navy;}

.purple {color: purple;}
1 change: 1 addition & 0 deletions rst/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_css_files = ["font.css"]

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
Binary file modified rst/fig/cell_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rst/fig/colormap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rst/fig/colormap_interpolate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rst/fig/column_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rst/fig/dock_with_table_data_annotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rst/fig/edit_cell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed rst/fig/filter.gif
Binary file not shown.
82 changes: 56 additions & 26 deletions rst/fig/generate_figs.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
from __future__ import annotations

from typing import Callable
from functools import wraps
from pathlib import Path
import numpy as np

from tabulous import TableViewer, commands as cmds
from tabulous.widgets import TableBase

_ALL_FUNCTIONS = []
_DIR_PATH = Path(__file__).parent

from tabulous_doc import FunctionRegistry

def register(f: Callable[[], TableViewer | TableBase]):
@wraps(f)
def wrapped():
if out := f():
out.save_screenshot(_DIR_PATH / f"{f.__name__}.png")
if isinstance(out, TableViewer):
out.close()
REG = FunctionRegistry(Path(__file__).parent)

_ALL_FUNCTIONS.append(wrapped)
return wrapped

@REG.register
def edit_cell():
viewer = TableViewer()
sheet = viewer.add_spreadsheet({"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"]})
viewer.resize(100, 100)
sheet.move_iloc(2, 2)
cmds.selection.edit_current(viewer)
return viewer

def main():
for f in _ALL_FUNCTIONS:
f()

@register
@REG.register
def colormap():
viewer = TableViewer()
table = viewer.open_sample("iris")
Expand All @@ -53,7 +41,15 @@ def _(x: float):
table.move_iloc(57, 2)
return viewer

@register
@REG.register
def colormap_interpolate():
viewer = TableViewer()
table = viewer.add_table({"value": [-3, -2, -1, 0, 1, 2, 3]})
table.text_color.set("value", interp_from=["blue", "gray", "red"])
viewer.resize(100, 100)
return viewer

@REG.register
def cell_labels():
viewer = TableViewer()
sheet = viewer.add_spreadsheet(np.arange(4))
Expand All @@ -63,7 +59,7 @@ def cell_labels():
viewer.resize(120, 180)
return sheet

@register
@REG.register
def tile_tables():
viewer = TableViewer()
sheet0 = viewer.add_spreadsheet(name="A")
Expand All @@ -74,6 +70,40 @@ def tile_tables():
viewer.resize(100, 100)
return viewer

@REG.register
def dock_with_table_data_annotation():
from tabulous.types import TableData
from magicgui import magicgui

viewer = TableViewer()
rng = np.random.default_rng(0)
viewer.add_table(
{"value_0": rng.normal(size=20), "value_1": rng.random(20)}
)
@magicgui
def f(table: TableData, mean: bool, std: bool, max: bool, min: bool) -> TableData:
funcs = []
for checked, f in [(mean, np.mean), (std, np.std), (max, np.max), (min, np.min)]:
if checked:
funcs.append(f)
return table.apply(funcs)

viewer.add_dock_widget(f)
viewer.resize(120, 180)
return viewer

@REG.register
def column_filter():
viewer = TableViewer()
rng = np.random.default_rng(0)
sheet = viewer.add_spreadsheet(
{"A": rng.integers(0, 10, size=20),
"B": rng.random(20).round(2)}
)
viewer.resize(120, 180)
sheet.proxy.filter("A > 5")
return viewer


if __name__ == "__main__":
main()
REG.run_all()
Binary file removed rst/fig/table_interface_0.gif
Binary file not shown.
Binary file removed rst/fig/table_interface_1.gif
Binary file not shown.
Binary file modified rst/fig/tile_tables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions rst/font.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. role:: black
.. role:: gray
.. role:: white
.. role:: red
.. role:: magenta
.. role:: pink
.. role:: orange
.. role:: yellow
.. role:: lime
.. role:: green
.. role:: teal
.. role:: cyan
.. role:: aqua
.. role:: blue
.. role:: purple
2 changes: 1 addition & 1 deletion rst/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Cooperate with Other Widgets
.. toctree::
:maxdepth: 2

./main/dock_widget
./main/integrate_custom_widgets
./main/non_mainwindow


Expand Down
Loading

0 comments on commit 1be017b

Please sign in to comment.