Skip to content

Commit

Permalink
TraceValueDisplayHook: Add it
Browse files Browse the repository at this point in the history
For plots like the labnotebook or the analysis function parameters it is
easily possible that one has multiple traces with more or less the same
x and y values. And for these cases it is difficult to distinguish the
entries.

We now have a custom window hook which creates a tooltip with the names
and values of the labnotebook/analysis function parameter.
  • Loading branch information
t-b committed Oct 16, 2024
1 parent 1c2527d commit aab7df3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,7 @@ StrConstant SF_META_LINESTYLE = "/LineStyle" // number
StrConstant SF_META_TRACE_MODE = "/TraceMode" // number
StrConstant SF_META_TRACETOFRONT = "/TraceToFront" // number, boolean, defaults to false (0)
StrConstant SF_META_DONOTPLOT = "/DoNotPlot" // number, boolean, defaults to false (0)
StrConstant SF_META_WINDOW_HOOK = "/WindowHook" // string

/// A color group allows to have matching colors for sweep data with the same channel type/number and sweep.
/// It is applied before the matching headstage/average colors in #SF_GetTraceColor().
Expand Down
69 changes: 68 additions & 1 deletion Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis
string win, wList, winNameTemplate, exWList, wName, annotation, yAxisLabel, wvName, info, xAxis
string formulasRemain, yAndXFormula, xFormula, yFormula, tagText, name
string formulasRemain, yAndXFormula, xFormula, yFormula, tagText, name, winHook
STRUCT SF_PlotMetaData plotMetaData
STRUCT RGBColor color

Expand Down Expand Up @@ -2159,6 +2159,11 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
endif
endif

winHook = JWN_GetStringFromWaveNote(formulaResults, SF_META_WINDOW_HOOK)
if(!IsEmpty(winHook))
SetWindow $win, tooltipHook(SweepFormulaTraceValue)=$winHook
endif

for(k = 0; k < formulaCounter; k += 1)
WAVE/WAVE plotFormData = collPlotFormData[k]
WAVE/T tracesInGraph = plotFormData[0]
Expand Down Expand Up @@ -5814,6 +5819,7 @@ static Function/WAVE SF_OperationAnaFuncParam(variable jsonId, string jsonPath,
WAVE/WAVE output = SF_OperationAnaFuncParamIterate(graph, names, selectData, SF_OP_ANAFUNCPARAM)

JWN_SetStringInWaveNote(output, SF_META_OPSTACK, AddListItem(SF_OP_ANAFUNCPARAM, ""))
JWN_SetStringInWaveNote(output, SF_META_WINDOW_HOOK, "TraceValueDisplayHook")

SF_SetSweepXAxisTickLabels(output, selectData)

Expand Down Expand Up @@ -6002,6 +6008,7 @@ static Function/WAVE SF_OperationLabnotebook(variable jsonId, string jsonPath, s
endif

JWN_SetStringInWaveNote(output, SF_META_OPSTACK, AddListItem(SF_OP_LABNOTEBOOK, ""))
JWN_SetStringInWaveNote(output, SF_META_WINDOW_HOOK, "TraceValueDisplayHook")

SF_SetSweepXAxisTickLabels(output, selectData)

Expand Down Expand Up @@ -7469,3 +7476,63 @@ static Function/S SF_MatchSweepMapColumn(string graph, string match, string colL

return uniqueEntries[0]
End

Function TraceValueDisplayHook(STRUCT WMTooltipHookStruct &s)

string name, msg, allTraces, trace, tooltip, match, options, win, valueStr, tagText
variable numTraces, i

// traceName is set only for graphs and only if the mouse hovered near a trace
if(IsEmpty(s.traceName))
return 0
endif

win = s.winName

tooltip = ""
allTraces = TraceNameList(win, ";", 1 + 2)

numTraces = ItemsInList(allTraces)
for(i = 0; i < numTraces; i += 1)
trace = StringFromList(i, allTraces)

sprintf options, "WINDOW:%s;ONLY:%s;DELTAX:24;DELTAY:24", win, trace
match = TraceFromPixel(s.mouseLoc.h, s.mouseLoc.v, options)

if(IsEmpty(match))
continue
endif

WAVE wv = TraceNameToWaveRef(win, trace)

name = JWN_GetStringFromWaveNote(wv, SF_META_LEGEND_LINE_PREFIX)

if(IsEmpty(name))
// not a labnotebook/analysis function parameter
continue
endif

if(IsNumericWave(wv))
tagText = JWN_GetStringFromWaveNote(wv, SF_META_TAG_TEXT)
if(IsEmpty(tagText))
valueStr = num2str(wv[s.row][s.column][s.layer][s.chunk])
else
valueStr = ReplaceString("\r", tagText, "\r" + ReplicateString(" ", strlen(name) + 2))
endif
elseif(IsTextWave(wv))
WAVE/T wvText = wv
valueStr = wvText[s.row][s.column][s.layer][s.chunk]
endif

sprintf msg, "%s: %s\r", name, valueStr
tooltip += msg
endfor

if(!IsEmpty(tooltip))
s.tooltip = "<pre>" + RemoveEnding(tooltip, "\r") + "</pre>"
s.isHtml = 1
return 1
endif

return 0
End

0 comments on commit aab7df3

Please sign in to comment.