BCDA-APS / gemviz

Data visualization for tiled
https://bcda-aps.github.io/gemviz/
Other
4 stars 0 forks source link

Generalize how to get column data, labels, and even which columns to use. #61

Closed prjemian closed 1 year ago

prjemian commented 1 year ago
          The new `_getKey()` method ...

can lead to some generalized specification of each of the data table items. A few items (time, detectors, motors) would need special handling. There's a pattern here...

Originally posted by @prjemian in https://github.com/BCDA-APS/tiled-viz2023/issues/52#issuecomment-1642577741

prjemian commented 1 year ago

Since the column labels are specified as a list of strings, it might be easier to specify the columns with a dictionary where the keys are the labels to be used and the values are the list of parameters for the _getKey() method. In the special cases, such as start/time, where custom handling is required, a custom method could be used in place of the list. The column number would be used to pick the information from the dictionary. Here is some prototype code:

column = index.column()
label = self.labelDict.keys()[column]
specification = self.labelDict[label]
if isinstance(specification, list):
    cell_value = self._getKey(run, *specification)
else:
    cell_value = specification(run)
return cell_value

and this code is added to the __init__() method:

self.labelDict = {
    "Scan ID" : ["start", "scan_id"],
    "Plan Name" : ["start", "plan_name"],
    "Motors" : self._get_run_motors,
    "Detectors" : self._get_run_detectors,
    "Date" : self._get_run_start_date,
    "Status" : ["stop", "exit_status"],
}
self.columnLabels = list(self.labelDict.keys())

By this technique, it would easy to re-order the columns and to add additional columns.