Skip to content

Commit

Permalink
Merge pull request #351 from pl0xz0rz/bokeh3_migration
Browse files Browse the repository at this point in the history
Workaround to force bokeh to import mathjax when using bokehInteractiveTemplate getDefaultVars
  • Loading branch information
miranov25 authored Mar 1, 2024
2 parents 8a59e1c + 967ff7f commit aa560f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def getDefaultVars(normalization=None, variables=None, defaultVariables={}, weig
#
['descriptionTable', {"name":"description"}],
['selectionTable', {"name":"selection"}],
[['bin_center_0'], ['bin_count'], {"source":"histoXYData", "name":"tex_hack", "xAxisTitle": "$$X_0$$"}],
figureGlobalOption
]
figureLayoutDesc={
Expand All @@ -281,6 +282,7 @@ def getDefaultVars(normalization=None, variables=None, defaultVariables={}, weig
}
figureLayoutDesc["selection"] = ["selection", {'plot_height': 200, 'sizing_mode': 'scale_width'}]
figureLayoutDesc["description"] = ["description", {'plot_height': 200, 'sizing_mode': 'scale_width'}]
figureLayoutDesc["ignoreme"] = ["tex_hack", {'plot_height': 200, 'sizing_mode': 'scale_width'}]

print("Default RootInteractive variables are defined.")
return aliasArray, variables, parameterArray, widgetParams, widgetLayoutDesc, histoArray, figureArray, figureLayoutDesc
Expand Down Expand Up @@ -570,6 +572,7 @@ def getDefaultVarsNormAll(variables=None, defaultVariables={}, weights=None, mul
#
['descriptionTable', {"name":"description"}],
['selectionTable', {"name":"selection"}],
[['bin_center_0'], ['bin_count'], {"source":"histoXYData", "name":"tex_hack", "xAxisTitle": "$$X_0$$"}],
figureGlobalOption
]
figureLayoutDesc={
Expand All @@ -582,6 +585,7 @@ def getDefaultVarsNormAll(variables=None, defaultVariables={}, weights=None, mul
}
figureLayoutDesc["selection"] = ["selection", {'plot_height': 200, 'sizing_mode': 'scale_width'}]
figureLayoutDesc["description"] = ["description", {'plot_height': 200, 'sizing_mode': 'scale_width'}]
figureLayoutDesc["ignoreme"] = ["tex_hack", {'plot_height': 200, 'sizing_mode': 'scale_width'}]

print("Default RootInteractive variables are defined.")
return aliasArray, transformArray, variables, parameterArray, widgetParams, widgetLayoutDesc, histoArray, figureArray, figureLayoutDesc
Expand Down
10 changes: 5 additions & 5 deletions RootInteractive/InteractiveDrawing/bokeh/bokehTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def bokehDrawArray(dataFrame, query, figureArray, histogramArray=[], parameterAr
TableColumn(title="Value", field="value"),
TableColumn(title="Is active", field="active"),
]
widget = DataTable(columns=columns)
widget = DataTable(columns=columns, sizing_mode=optionLocal.get("sizing_mode", "inherit"))
selectionTables.append(widget)
plotArray.append(widget)
if "name" in optionLocal:
Expand Down Expand Up @@ -741,7 +741,7 @@ def bokehDrawArray(dataFrame, query, figureArray, histogramArray=[], parameterAr
filter.active = !this.active
filter.change.emit()
"""))
widgetFull = row([widgetFull, widgetToggle])
widgetFull = row([widgetFull, widgetToggle], sizing_mode=optionLocal.get("sizing_mode", "inherit"))
plotArray.append(widgetFull)
if "name" in optionWidget:
plotDict[optionWidget["name"]] = widgetFull
Expand Down Expand Up @@ -1291,7 +1291,7 @@ def bokehDrawArray(dataFrame, query, figureArray, histogramArray=[], parameterAr
selectionCDS.data = selectionTableData
for i in selectionTables:
i.source = selectionCDS
i.view = CDSView(source=selectionCDS)
i.view = CDSView()
if isinstance(options['layout'], list) or isinstance(options['layout'], dict):
pAll = processBokehLayoutArray(options['layout'], plotArray, plotDict)
if options['doDraw']:
Expand Down Expand Up @@ -2254,7 +2254,7 @@ def makeCdsSel(cdsDict, paramDict, key):
cds_used["cdsSel"] = cdsSel
return cdsSel

def makeDescriptionTable(cdsDict, cdsName, fields, meta_fields):
def makeDescriptionTable(cdsDict, cdsName, fields, meta_fields, **kwargs):
cds = ColumnDataSource()
new_dict = {}
columns = []
Expand All @@ -2270,4 +2270,4 @@ def makeDescriptionTable(cdsDict, cdsName, fields, meta_fields):
new_dict[i] = column
columns.append(TableColumn(field=i, title=i))
cds.data = new_dict
return DataTable(source=cds, columns=columns)
return DataTable(source=cds, columns=columns, sizing_mode=kwargs.get("sizing_mode", "inherit"))
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
df['errY']=df.A*0.02+0.02
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"}
'D.AxisTitle': r"\[x\pi\]", 'Bool.AxisTitle': "A>half"}

#widgets="slider.A(0,1,0.05,0,1), slider.B(0,1,0.05,0,1), slider.C(0,1,0.01,0.1,1), slider.D(0,1,0.01,0,1), checkbox.Bool(1), multiselect.E(0,1,2,3,4)"
widgets="slider.A(0,1,0.05,0,1), slider.B(0,1,0.05,0,1), slider.C(0,1,0.01,0.1,1), slider.D(0,1,0.01,0,1), checkbox.Bool(1)"
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_interactiveTemplateMultiDiff():
jsFunctionArray=jsFunctionArray)

def test_interactiveTemplateMultiYDiff():
output_file("test_histogramTemplateMultiY.html")
output_file("test_histogramTemplateMultiYDiff.html")
aliasArray, jsFunctionArray, variables, parameterArray, widgetParams, widgetLayoutDesc, histoArray, figureArray, figureLayoutDesc = getDefaultVarsNormAll(variables=["A", "B", "C", "D"], multiAxis="varY")
widgetsSelect = [
['range', ['A'], {"name":"A"}],
Expand All @@ -472,3 +472,4 @@ def test_interactiveTemplateMultiYDiff():
widgetLayout=widgetLayoutDesc, sizing_mode="scale_width", histogramArray=histoArray, aliasArray=aliasArray, arrayCompression=arrayCompressionRelative16,
jsFunctionArray=jsFunctionArray)

test_interactiveTemplateMultiY()
4 changes: 2 additions & 2 deletions RootInteractive/InteractiveDrawing/bokeh/test_bokehDrawSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
df['maskAC']=2*(df['A']>.5)|1*(df['C']>.5)
df['ones']=1
df.head(10)
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"}
df.meta.metaData = {'A.AxisTitle': r"\[x\pi\]", '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 All @@ -73,7 +73,7 @@
figureArray = [
# ['A'], ['C-A'], {"color": "red", "size": 7, "colorZvar":"C", "filter": "A<0.5"}],
[['A'], ['A*A-C*C'], {"color": "red", "size": 2, "colorZvar": "A", "varZ": "C", "errY": "errY", "errX":"0.01"}],
[['X'], ['C+A', 'C-A', 'A/A'], {"name": "fig1"}],
[['X'], ['C+A', 'C-A', 'A/A'], {"name": "fig1", "xAxisTitle":r"\[x\pi\]", "plotTitle":"C+A, C-A vs {X}" }],
[['B'], ['C+B', 'C-B'], { "colorZvar": "B", "errY": "errY", "rescaleColorMapper": True, "colorAxisLabel": "B (cm/s)"}],
[['D'], ['(A+B+C)*DD'], {"colorZvar": "colorZ", "size": 10, "errY": "errY"} ],
# [['D'], ['D*10'], {"size": 10, "errY": "errY","markers":markerFactor, "color":colorFactor,"legend_field":"DDC"}],
Expand Down

0 comments on commit aa560f2

Please sign in to comment.