Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Div widget and table to describe data (parsing user input metadata) - for #309 #311

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions RootInteractive/InteractiveDrawing/bokeh/bokehTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from bokeh.models.transforms import CustomJSTransform
from bokeh.models.mappers import LinearColorMapper
from bokeh.models.widgets.tables import ScientificFormatter, DataTable
from bokeh.models.widgets.markups import Div
from bokeh.models.plots import Plot
from bokeh.transform import *
from RootInteractive.InteractiveDrawing.bokeh.ConcatenatedString import ConcatenatedString
Expand Down Expand Up @@ -509,6 +510,33 @@ def bokehDrawArray(dataFrame, query, figureArray, histogramArray=[], parameterAr
else:
optionGroup = options
continue
optionLocal = optionGroup.copy()
nvars = len(variables)
if isinstance(variables[-1], dict):
logging.info("Option %s", variables[-1])
optionLocal.update(variables[-1])
nvars -= 1
if variables[0] == 'div':
text_content = optionLocal.get("text", variables[1])
widget = Div(text=text_content)
plotArray.append(widget)
if "name" in optionLocal:
plotDict[optionLocal["name"]] = widget
continue
if variables[0] == 'descriptionTable':
data_source = optionLocal.get("source", None)
meta_fields = optionLocal.get("meta_fields", ["AxisTitle", "Description"])
if "variables" in optionLocal:
used_variables = optionLocal["variables"]
else:
meta = cdsDict[data_source]["meta"]
used_variables = [*{i.split(".")[0] for i in meta.keys()}]
text_content = makeDescriptionTable(cdsDict, data_source, used_variables, meta_fields)
widget = Div(text=text_content)
plotArray.append(widget)
if "name" in optionLocal:
plotDict[optionLocal["name"]] = widget
continue
if variables[0] == 'table':
TOptions = {
'include': '',
Expand Down Expand Up @@ -708,13 +736,6 @@ def bokehDrawArray(dataFrame, query, figureArray, histogramArray=[], parameterAr
widgetParams.append(variables)
continue

optionLocal = optionGroup.copy()
nvars = len(variables)
if isinstance(variables[-1], dict):
logging.info("Option %s", variables[-1])
optionLocal.update(variables[-1])
nvars -= 1

x_transform = optionLocal.get("x_transform", None)
x_transform_parsed, x_transform_customjs = make_transform(x_transform, paramDict, aliasDict, cdsDict, jsFunctionDict)
y_transform = optionLocal.get("y_transform", None)
Expand Down Expand Up @@ -1608,6 +1629,7 @@ def makeCDSDict(sourceArray, paramDict, options={}):
if cds_name in cdsDict:
raise ValueError("Column data source IDs must be unique. Multiple data sources with name: "+ str(cds_name)+ " detected.")
cdsDict[cds_name] = iSource
iSource["meta"] = {}

# Detect the type
if "type" not in iSource:
Expand Down Expand Up @@ -1638,6 +1660,7 @@ def makeCDSDict(sourceArray, paramDict, options={}):

# Create cdsOrig
if cdsType == "source":
iSource["meta"] = iSource["data"].meta.metaData.copy()
if "arrayCompression" in iSource and iSource["arrayCompression"] is not None:
iSource["cdsOrig"] = CDSCompress(name=name_orig)
else:
Expand Down Expand Up @@ -1884,4 +1907,18 @@ def makeCdsSel(cdsDict, paramDict, key):
downsampler.update()
""")])
cds_used["cdsSel"] = cdsSel
return cdsSel
return cdsSel

def makeDescriptionTable(cdsDict, cdsName, fields, meta_fields):
th = '</td>\n<td>'.join(meta_fields)
rows = []
for i in fields:
current_row = []
for j in meta_fields:
value = cdsDict[cdsName]["meta"].get(f"{i}.{j}", "")
current_row.append(f"<td>{value}</td>")
current_row = '\t'.join(current_row)
rows.append(f"<tr><th>{i}</th>{current_row}</tr>")
rows = '\n'.join(rows)
text = f"<table><tr><th></th><td>{th}</td></tr> { rows} </table>"
return text
12 changes: 8 additions & 4 deletions RootInteractive/InteractiveDrawing/bokeh/test_bokehDrawSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
AddMetadata(tree, "B.AxisTitle", "B (cm/s)")
AddMetadata(tree, "C.AxisTitle", "B (s)")
AddMetadata(tree, "D.AxisTitle", "D (a.u.)")
AddMetadata(tree, "A.Description", "Lorem ipsum")
AddMetadata(tree, "B.Description", "The velocity B")
except:
pass

Expand Down Expand Up @@ -52,7 +54,7 @@
df['errY']=df.A*0.02+0.02
df['maskAC']=2*(df['A']>.5)|1*(df['C']>.5)
df.head(10)
df.meta.metaData = {'A.AxisTitle': "A (cm)", 'B.AxisTitle': "B (cm/s)", 'C.AxisTitle': "C (s)", 'D.AxisTitle': "D (a.u.)", 'Bool.AxisTitle': "A>half", 'E.AxisTitle': "Category"}
df.meta.metaData = {'A.AxisTitle': "A (cm)", 'B.AxisTitle': "B (cm/s)", 'C.AxisTitle': "C (s)", 'D.AxisTitle': "D (a.u.)", 'E.AxisTitle': "Category", "A.Description": "The distance A"}

parameterArray = [
{"name": "colorZ", "value":"A", "options":["A", "B", "EE"]},
Expand Down Expand Up @@ -91,7 +93,7 @@
['slider', ['AA'], {'bins': 10, "toggleable":True, "name": "widgetAA"}],
['multiSelect', ["DDC", "A2", "A3", "A4", "A0", "A1"]],
['multiSelectBitmask', ["maskAC"], {"mapping": {"A": 2, "C": 1}, "how":"all", "title": "maskAC(all)"}],
['select',["CC", 0, 1, 2, 3], {"default": 1, "toggleable":True}],
['select',["CC", 0, 1, 2, 3], {"default": 1}],
['multiSelect',["BoolB"]],
['textQuery', {"title": "selection", "name":"selectionText"}],
#['slider','F', ['@min()','@max()','@med','@min()','@median()+3*#tlm()']], # to be implmneted
Expand All @@ -103,7 +105,8 @@
['spinner', ['nPoints'], {"name": "nPointsRender"}],
['select', ['transformX'], {"name": "transformX"}],
['select', ['transformY'], {"name": "transformY"}],
['slider', ['paramX'], {"name":"paramX"}]
['slider', ['paramX'], {"name":"paramX"}],
['descriptionTable', {"name":"description"}]
]

widgetLayoutDesc={
Expand All @@ -119,7 +122,8 @@
"B": [
[3, 4, {'commonX': 1, 'y_visible': 3, 'x_visible':1, 'plot_height': 100}],
{'plot_height': 100, 'sizing_mode': 'scale_width', 'y_visible' : 2}
]
],
"Description": ["description"]
}

def test_record(record_property: ty.Callable[[str, ty.Any], None]):
Expand Down