Skip to content

Commit 86a73e9

Browse files
committed
SF_GatherAxisLabels: Also gather the x-labels
1 parent 0b7355d commit 86a73e9

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,9 +1742,11 @@ static Function SF_CommonWindowSetup(string win, string graph)
17421742
DoWindow/T $win, newTitle
17431743
End
17441744

1745-
static Function SF_GatherAxisLabels(WAVE/WAVE formulaResults, string explicitLbl, WAVE/T axisLabels)
1745+
static Function SF_GatherAxisLabels(WAVE/WAVE formulaResults, string explicitLbl, string formulaLabel, WAVE/T axisLabels)
17461746

17471747
variable i, size, numData
1748+
string unit
1749+
17481750
size = DimSize(axisLabels, ROWS)
17491751
if(!isEmpty(explicitLbl))
17501752
Redimension/N=(size + 1) axisLabels
@@ -1760,9 +1762,29 @@ static Function SF_GatherAxisLabels(WAVE/WAVE formulaResults, string explicitLbl
17601762
if(!WaveExists(wvResultY))
17611763
continue
17621764
endif
1763-
// fallback to the y data unit
1764-
axisLabels[size] = WaveUnits(wvResultY, COLS)
1765-
size += 1
1765+
1766+
strswitch(formulaLabel)
1767+
case "FORMULAY":
1768+
unit = WaveUnits(wvResultY, COLS)
1769+
break
1770+
case "FORMULAX":
1771+
WAVE/Z wvResultX = formulaResults[i][%FORMULAX]
1772+
if(WaveExists(wvResultX))
1773+
unit = WaveUnits(wvResultX, ROWS)
1774+
else
1775+
unit = WaveUnits(wvResultY, ROWS)
1776+
endif
1777+
break
1778+
default:
1779+
ASSERT(0, "Unsupported formulaLabel: " + formulaLabel)
1780+
break
1781+
endswitch
1782+
1783+
// fallback to the unit if present
1784+
if(!IsEmpty(unit))
1785+
axisLabels[size] = SF_FormatUnit(unit)
1786+
size += 1
1787+
endif
17661788
endfor
17671789

17681790
Redimension/N=(size) axisLabels
@@ -1856,7 +1878,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
18561878
variable winDisplayMode, showLegend, tagCounter, overrideMarker
18571879
variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
18581880
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis
1859-
string win, wList, winNameTemplate, exWList, wName, annotation, yAxisLabel, wvName, info, xAxis
1881+
string win, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
18601882
string formulasRemain, yAndXFormula, xFormula, yFormula, tagText, name, winHook
18611883
STRUCT SF_PlotMetaData plotMetaData
18621884
STRUCT RGBColor color
@@ -1886,7 +1908,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
18861908
formulaCounter = 0
18871909
WAVE/Z wvX = $""
18881910

1889-
Make/FREE/T/N=0 yAxisLabels
1911+
Make/FREE/T/N=0 xAxisLabels, yAxisLabels
18901912

18911913
formulasRemain = graphCode[j]
18921914

@@ -1918,7 +1940,8 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
19181940
Abort
19191941
endtry
19201942

1921-
SF_GatherAxisLabels(formulaResults, plotMetaData.yAxisLabel, yAxisLabels)
1943+
SF_GatherAxisLabels(formulaResults, plotMetaData.xAxisLabel, "FORMULAX", xAxisLabels)
1944+
SF_GatherAxisLabels(formulaResults, plotMetaData.yAxisLabel, "FORMULAY", yAxisLabels)
19221945

19231946
if(!cmpstr(plotMetaData.dataType, SF_DATATYPE_PSX))
19241947
PSX_Plot(win, graph, formulaResults, plotMetaData)
@@ -2249,8 +2272,9 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
22492272
endfor
22502273

22512274
if(traceCnt > 0)
2252-
if(!IsEmpty(plotMetaData.xAxisLabel))
2253-
Label/W=$win bottom, plotMetaData.xAxisLabel
2275+
xAxisLabel = SF_CombineAxisLabels(xAxisLabels)
2276+
if(!IsEmpty(xAxisLabel))
2277+
Label/W=$win bottom, xAxisLabel
22542278
ModifyGraph/W=$win tickUnit(bottom)=1
22552279
endif
22562280

Packages/tests/Basic/UTF_SweepFormula.ipf

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,23 +2150,31 @@ End
21502150

21512151
static Function TestAxisLabelGathering()
21522152

2153-
string win, graph, yAxis, code
2153+
string win, graph, xAxis, yAxis, code
21542154

21552155
win = GetDataBrowserWithData()
21562156
graph = SFH_GetFormulaGraphForBrowser(win)
21572157

21582158
Make/O data1 = {1}
2159+
SetScale/P x, 0, 1, "x1", data1
21592160
SetScale/P y, 0, 1, "y1", data1
21602161

21612162
Make/O data2 = {2}
2163+
SetScale/P x, 0, 1, "x2", data2
21622164
SetScale/P y, 0, 1, "y2", data2
21632165

2164-
code = "wave(root:data1)\r" + \
2165-
"with \r" + \
2166-
"wave(root:data2)\r"
2166+
Make/O data3 = {3}
2167+
SetScale/P x, 0, 1, "x3", data3
2168+
SetScale/P y, 0, 1, "y3", data3
2169+
2170+
code = "wave(data1)\r" + \
2171+
"with \r" + \
2172+
"wave(data2) vs wave(data3)\r"
21672173
ExecuteSweepFormulaInDB(code, win)
21682174
yAxis = AxisLabel(graph, "left")
21692175
CHECK_EQUAL_STR(yAxis, "(y1) / (y2)")
2176+
xAxis = AxisLabel(graph, "bottom")
2177+
CHECK_EQUAL_STR(xAxis, "(x1) / (x3)")
21702178

2171-
KillWaves/Z data1, data2
2179+
KillWaves/Z data1, data2, data3
21722180
End

0 commit comments

Comments
 (0)