Skip to content

Commit

Permalink
API docs for table subcomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Feb 10, 2023
1 parent fbcc2bf commit 58d64a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion jdaviz/components/plugin_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
display: inline-block;
}
.row-select {
width: 100%;
}
Expand Down
35 changes: 35 additions & 0 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,16 @@ def show(self, loc="inline", title=None): # pragma: no cover

class Table(PluginSubcomponent):
"""
Table subcomponent. For most cases where a plugin only requires a single table, use the mixin
instead.
To use in a plugin, define ``plugin.table = Table(plugin)``, create a ``table_widget`` Unicode
traitlet, and set ``plugin.table_widget = 'IPY_MODEL_'+self.table.model_id``.
To render in the plugin's vue file::
<jupyter-widget :widget="table_widget"></jupyter-widget>
"""
template_file = __file__, "../components/plugin_table.vue"

Expand All @@ -2198,6 +2208,13 @@ def __init__(self, plugin, *args, **kwargs):
super().__init__(plugin, 'Table', *args, **kwargs)

def add_item(self, item):
"""
Add an item/row to the table.
Parameters
----------
item : QTable, QTableRow, or dictionary of row-name, value pairs
"""
def json_safe(item):
if hasattr(item, 'to_string'):
return item.to_string()
Expand Down Expand Up @@ -2236,13 +2253,25 @@ def vue_clear_table(self, data=None):

def export_table(self):
"""
Export the QTable representation of the table.
"""
# TODO: default to only showing selected columns?
return self._qtable


class TableMixin(VuetifyTemplate, HubListener):
"""
Table subcomponent mixin.
In addition to ``table``, this provides the following methods at the plugin-level:
* :meth:`clear_table`
* :meth:`export_table`
To render in the plugin's vue file::
<jupyter-widget :widget="table_widget"></jupyter-widget>
"""
table_widget = Unicode().tag(sync=True)

Expand All @@ -2252,6 +2281,9 @@ def __init__(self, *args, **kwargs):
self.table_widget = 'IPY_MODEL_'+self.table.model_id

def clear_table(self):
"""
Clear all entries/markers from the current table.
"""
self.table.clear_table()

def vue_clear_table(self, data=None):
Expand All @@ -2260,4 +2292,7 @@ def vue_clear_table(self, data=None):
self.clear_table()

def export_table(self):
"""
Export the QTable representation of the table.
"""
return self.table.export_table()

0 comments on commit 58d64a0

Please # to comment.