Skip to content

Commit 650ba95

Browse files
committed
SF: Add support to plotter to display data in tables
Tables introduce a second type of displaying data (after plots) to the plotter. Tables are displayed in a separate panel. Therefore in SF_PreparePlotter the plotGraphs wave that lists all window names is extended with a new row for the names of the table subwindows. The creation of plotGraphs is moved to an own getter function. The panel or window creation for SF_DM_NORMAL mode is moved to an own function SF_NewSweepFormulaBaseWindow For the equivalent of RemoveTracesFromGraph the function RemoveAllColumnsFromTable is used for tables. Since not all SubWindows prepared by SF_PreparePlotter might be used in plotting the subWindows (SF_DM_SUBWINDOWS mode) are tiled only between the windows that actually contain data after all data was plotted in SF_TileExistingData.
1 parent fc06f2d commit 650ba95

File tree

2 files changed

+165
-44
lines changed

2 files changed

+165
-44
lines changed

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 155 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Menu "GraphPopup"
4141
"Bring browser to front", /Q, SF_BringBrowserToFront()
4242
End
4343

44+
Menu "TablePopup"
45+
"Bring browser to front", /Q, SF_BringBrowserToFront()
46+
End
47+
4448
Function SF_BringBrowserToFront()
4549

4650
string browser, graph
@@ -544,14 +548,73 @@ static Function/S SF_ShrinkLegend(string annotation)
544548
return shrunkAnnotation
545549
End
546550

551+
static Function SF_ClearPlotPanel(string win)
552+
553+
string subWindow
554+
variable wType
555+
556+
TUD_Clear(win, recursive = 1)
557+
558+
WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";")
559+
560+
for(subWindow : allWindows)
561+
if(IsSubwindow(subWindow))
562+
// in complex hierarchies we might kill more outer subwindows first
563+
// so the inner ones might later not exist anymore
564+
KillWindow/Z $subWindow
565+
endif
566+
endfor
567+
568+
RemoveAllControls(win)
569+
wType = WinType(win)
570+
if(wType == WINTYPE_PANEL || wType == WINTYPE_GRAPH)
571+
RemoveAllDrawLayers(win)
572+
endif
573+
End
574+
575+
/// @brief Creates a new panel for sweepformula display of graph or table and returns the actual window name
576+
///
577+
/// @param[in] templateName base name of new window
578+
/// @param[in] graph name of sweepbrowser/databrowser window
579+
/// @param[in] winType [optional, default WINTYPE_PANEL] specifies window type
580+
/// @returns name of created window
581+
static Function/S SF_NewSweepFormulaBaseWindow(string templateName, string graph, [variable winType])
582+
583+
string win
584+
585+
winType = ParamIsDefault(winType) ? WINTYPE_PANEL : winType
586+
587+
win = templateName
588+
if(WindowExists(win))
589+
SF_ClearPlotPanel(win)
590+
else
591+
if(winType == WINTYPE_GRAPH)
592+
Display/N=$win/K=1/W=(150, 400, 1000, 700)
593+
elseif(winType == WINTYPE_PANEL)
594+
NewPanel/N=$win/K=1/W=(150, 400, 1000, 700)
595+
elseif(winType == WINTYPE_TABLE)
596+
Edit/N=$win/K=1/W=(150, 400, 1000, 700)
597+
else
598+
FATAL_ERROR("Unsupported window type")
599+
endif
600+
win = S_name
601+
602+
SF_CommonWindowSetup(win, graph)
603+
endif
604+
605+
return win
606+
End
607+
547608
static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string winNameTemplate, string graph, variable winDisplayMode, variable numGraphs)
548609

549610
variable i, guidePos, restoreCursorInfo
550-
string panelName, guideName1, guideName2, win
611+
string panelName, guideName1, guideName2, win, winTable, winNameTemplateTable
551612

552613
ASSERT(numGraphs > 0, "Can not prepare plotter window for zero graphs")
553614

554-
Make/FREE/T/N=(numGraphs) plotGraphs
615+
winNameTemplateTable = winNameTemplate + "table"
616+
617+
WAVE/T plotGraphs = GetPlotGraphNames(numGraphs)
555618
Make/FREE/WAVE/N=(numGraphs, 3) infos
556619
SetDimensionLabels(infos, "axes;cursors;annotations", COLS)
557620

@@ -580,41 +643,15 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi
580643

581644
if(winDisplayMode == SF_DM_NORMAL)
582645
for(i = 0; i < numGraphs; i += 1)
583-
win = winNameTemplate + num2istr(i)
584-
585-
if(!WindowExists(win))
586-
Display/N=$win/K=1/W=(150, 400, 1000, 700) as win
587-
win = S_name
588-
endif
589-
590-
SF_CommonWindowSetup(win, graph)
591-
592-
plotGraphs[i] = win
646+
win = winNameTemplate + num2istr(i)
647+
plotGraphs[i][%GRAPH] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_GRAPH)
648+
win = winNameTemplateTable + num2istr(i)
649+
plotGraphs[i][%TABLE] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_TABLE)
593650
endfor
594651
elseif(winDisplayMode == SF_DM_SUBWINDOWS)
595652

596-
win = winNameTemplate
597-
if(WindowExists(win))
598-
TUD_Clear(win, recursive = 1)
599-
600-
WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";")
601-
602-
for(subWindow : allWindows)
603-
if(IsSubwindow(subWindow))
604-
// in complex hierarchies we might kill more outer subwindows first
605-
// so the inner ones might later not exist anymore
606-
KillWindow/Z $subWindow
607-
endif
608-
endfor
609-
610-
RemoveAllControls(win)
611-
RemoveAllDrawLayers(win)
612-
else
613-
NewPanel/N=$win/K=1/W=(150, 400, 1000, 700)
614-
win = S_name
615-
616-
SF_CommonWindowSetup(win, graph)
617-
endif
653+
win = SF_NewSweepFormulaBaseWindow(winNameTemplate, graph)
654+
winTable = SF_NewSweepFormulaBaseWindow(winNameTemplateTable, graph)
618655

619656
// now we have an open panel without any subwindows
620657

@@ -627,23 +664,32 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi
627664
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
628665
guidePos = i / numGraphs
629666
DefineGuide/W=$win $guideName1={FT, guidePos, FB}
667+
DefineGuide/W=$winTable $guideName1={FT, guidePos, FB}
630668
endfor
631669

632670
DefineGuide/W=$win customLeft={FL, 0.0, FR}
633671
DefineGuide/W=$win customRight={FL, 1.0, FR}
672+
DefineGuide/W=$winTable customLeft={FL, 0.0, FR}
673+
DefineGuide/W=$winTable customRight={FL, 1.0, FR}
634674

635675
// and now the subwindow graphs
636676
for(i = 0; i < numGraphs; i += 1)
637677
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
638678
guideName2 = SF_PLOTTER_GUIDENAME + num2istr(i + 1)
639679
Display/HOST=$win/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Graph" + num2str(i))
640-
plotGraphs[i] = winNameTemplate + "#" + S_name
680+
plotGraphs[i][%GRAPH] = win + "#" + S_name
681+
Edit/HOST=$winTable/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Table" + num2str(i))
682+
plotGraphs[i][%TABLE] = winTable + "#" + S_name
641683
endfor
642684
endif
643685

644-
for(win : plotGraphs)
686+
for(i = 0; i < numGraphs; i += 1)
687+
win = plotGraphs[i][%GRAPH]
645688
RemoveTracesFromGraph(win)
646689
ModifyGraph/W=$win swapXY=0
690+
691+
win = plotGraphs[i][%TABLE]
692+
RemoveAllColumnsFromTable(win)
647693
endfor
648694

649695
return [plotGraphs, infos]
@@ -740,13 +786,52 @@ static Function SF_CheckNumTraces(string graph, variable numTraces)
740786
endif
741787
End
742788

743-
static Function SF_CleanUpPlotWindowsOnFail(WAVE/T plotGraphs)
789+
static Function SF_KillEmptyDataWindows(WAVE/T plotGraphs)
744790

745791
for(str : plotGraphs)
746-
WAVE/Z wv = WaveRefIndexed(str, 0, 1)
747-
if(!WaveExists(wv))
748-
KillWindow/Z $str
792+
if(WindowExists(str))
793+
WAVE/Z wv = WaveRefIndexed(str, 0, 1)
794+
if(!WaveExists(wv))
795+
KillWindow/Z $str
796+
endif
797+
endif
798+
endfor
799+
End
800+
801+
/// @brief Tiles the subwindows in the panels acording to existing data, requires SF_DM_SUBWINDOWS mode
802+
static Function SF_TileExistingData(WAVE/T plotGraphs)
803+
804+
variable numSubWins, numData, guidePos, i, j, col, numCols
805+
string guideName1, guideName2, win
806+
807+
numCols = DimSize(plotGraphs, COLS)
808+
for(col = 0; col < numCols; col += 1)
809+
win = plotGraphs[0][col]
810+
win = RemoveEnding(win, "#" + StringFromList(ItemsInList(win, "#") - 1, win, "#"))
811+
812+
numSubWins = DimSize(plotGraphs, ROWS)
813+
Make/FREE/N=(numSubWins) hasData
814+
hasData[] = WaveExists(WaveRefIndexed(plotGraphs[p][col], 0, 1))
815+
816+
WAVE/Z idx = FindIndizes(hasData, var = 1)
817+
if(!WaveExists(idx))
818+
KillWindow/Z $win
819+
return NaN
749820
endif
821+
822+
numData = DimSize(idx, ROWS)
823+
j = 0
824+
for(i : idx)
825+
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
826+
guidePos = j / numData
827+
DefineGuide/W=$win $guideName1={FT, guidePos, FB}
828+
829+
guideName2 = SF_PLOTTER_GUIDENAME + num2istr(i + 1)
830+
guidePos = (j + 1) / numData
831+
DefineGuide/W=$win $guideName2={FT, guidePos, FB}
832+
833+
j += 1
834+
endfor
750835
endfor
751836
End
752837

@@ -788,6 +873,15 @@ static Function/WAVE SF_PrepareResultWaveForPlotting(DFREF dfr, WAVE wvResult, v
788873
return plotWave
789874
End
790875

876+
static Function SF_IsDataForTableDisplay(WAVE wvY)
877+
878+
variable useTable
879+
880+
useTable = JWN_GetNumberFromWaveNote(wvY, SF_PROPERTY_TABLE)
881+
882+
return IsNaN(useTable) ? 0 : !!useTable
883+
End
884+
791885
/// @brief Plot the formula using the data from graph
792886
///
793887
/// @param graph graph to pass to SF_FormulaExecutor
@@ -801,7 +895,8 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
801895
variable winDisplayMode, showLegend, tagCounter, overrideMarker, line, lineGraph, lineGraphFormula
802896
variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
803897
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis, xFormulaOffset
804-
string win, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
898+
variable showInTable
899+
string win, winTable, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
805900
string formulasRemain, moreFormulas, yAndXFormula, xFormula, yFormula, tagText, name, winHook
806901
STRUCT SF_PlotMetaData plotMetaData
807902
STRUCT RGBColor color
@@ -838,8 +933,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
838933
formulasRemain = graphCode[j][%GRAPHCODE]
839934
lineGraph = str2num(graphCode[j][%LINE])
840935

841-
win = plotGraphs[j]
842-
wList = AddListItem(win, wList)
936+
win = plotGraphs[j][%GRAPH]
937+
winTable = plotGraphs[j][%TABLE]
938+
if(winDisplayMode == SF_DM_NORMAL)
939+
wList = AddListItem(win, wList)
940+
wList = AddListItem(winTable, wList)
941+
endif
843942

844943
Make/FREE=1/T/N=(MINIMUM_WAVE_SIZE) wAnnotations, formulaArgSetup
845944
Make/FREE=1/WAVE/N=(MINIMUM_WAVE_SIZE) collPlotFormData
@@ -865,7 +964,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
865964
try
866965
[formulaResults, plotMetaData] = SF_GatherFormulaResults(xFormula, yFormula, graph, line, xFormulaOffset)
867966
catch
868-
SF_CleanUpPlotWindowsOnFail(plotGraphs)
967+
SF_KillEmptyDataWindows(plotGraphs)
869968
Abort
870969
endtry
871970

@@ -886,6 +985,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
886985
WAVE/ZZ previousColorGroups
887986
endif
888987
WAVE/Z colorGroups = SF_GetColorGroups(formulaResults, previousColorGroups)
988+
showInTable = SF_IsDataForTableDisplay(formulaResults)
889989

890990
numData = DimSize(formulaResults, ROWS)
891991
for(k = 0; k < numData; k += 1)
@@ -924,6 +1024,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
9241024

9251025
SFH_ASSERT(!(IsTextWave(wvY) && (WaveExists(wvX) && IsTextWave(wvX))), "One wave needs to be numeric for plotting")
9261026

1027+
if(showIntable)
1028+
AppendToTable/W=$winTable wvY.ld
1029+
dataCnt += 1
1030+
continue
1031+
endif
1032+
9271033
if(IsTextWave(wvY))
9281034
SFH_ASSERT(WaveExists(wvX), "Cannot plot a single text wave")
9291035
ModifyGraph/W=$win swapXY=1
@@ -1245,6 +1351,11 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
12451351
endif
12461352
endfor
12471353

1354+
if(winDisplayMode == SF_DM_SUBWINDOWS)
1355+
SF_TileExistingData(plotGraphs)
1356+
endif
1357+
SF_KillEmptyDataWindows(plotGraphs)
1358+
12481359
if(winDisplayMode == SF_DM_NORMAL)
12491360
exWList = WinList(winNameTemplate + "*", ";", "WIN:1")
12501361
numWins = ItemsInList(exWList)

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9213,3 +9213,13 @@ Function/WAVE GetSFAssertData()
92139213

92149214
return wv
92159215
End
9216+
9217+
/// @brief Used for preparing graph and table window names for the SF plotter
9218+
Function/WAVE GetPlotGraphNames(variable numGraphs)
9219+
9220+
Make/FREE/T/N=(numGraphs, 2) plotGraphs
9221+
SetDimlabel COLS, 0, GRAPH, plotGraphs
9222+
SetDimlabel COLS, 1, TABLE, plotGraphs
9223+
9224+
return plotGraphs
9225+
End

0 commit comments

Comments
 (0)