@@ -1266,16 +1266,9 @@ static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData]
12661266 if ( WaveExists ( wvXRef))
12671267 if ( numResultsX == 1 )
12681268 WAVE /Z wvXdata = wvXRef[ 0 ]
1269- if ( WaveExists ( wvXdata) && DimSize ( wvXdata, ROWS) == numResultsY && numpnts ( wvYdata) == 1 )
1270- if ( IsTextWave ( wvXdata))
1271- WAVE /T wT = wvXdata
1272- Make / FREE/ T wvXnewDataT = { wT[ i ]}
1273- formulaResults[ i ][ % FORMULAX] = wvXnewDataT
1274- else
1275- WAVE wv = wvXdata
1276- Make / FREE/ D wvXnewDataD = { wv[ i ]}
1277- formulaResults[ i ][ % FORMULAX] = wvXnewDataD
1278- endif
1269+ if ( WaveExists ( wvXdata) && DimSize ( wvXdata, ROWS) == numResultsY && numpnts ( wvYdata) == 1 && numpnts ( wvXdata) != 1 )
1270+ Duplicate / FREE/ T/ RMD= [ i ] wvXdata, wvXnewData
1271+ formulaResults[ i ][ % FORMULAX] = wvXnewData
12791272 else
12801273 formulaResults[ i ][ % FORMULAX] = wvXRef[ 0 ]
12811274 endif
@@ -1302,7 +1295,7 @@ static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData]
13021295
13031296 dataUnits = ""
13041297 if ( ! IsNull ( dataUnitCheck))
1305- dataUnits = SelectString ( addDataUnitsInAnnotation && ! IsEmpty ( dataUnitCheck) , "" , "(" + dataUnitCheck + ")" )
1298+ dataUnits = SelectString ( addDataUnitsInAnnotation && ! IsEmpty ( dataUnitCheck) , "" , SF_FormatUnit ( dataUnitCheck) )
13061299 endif
13071300
13081301 plotMetaData. dataType = JWN_GetStringFromWaveNote ( wvYRef, SF_META_DATATYPE)
@@ -1314,6 +1307,11 @@ static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData]
13141307 return [ formulaResults, plotMetaData]
13151308End
13161309
1310+ static Function/S SF_FormatUnit ( string unit)
1311+
1312+ return "(" + unit + ")"
1313+ End
1314+
13171315static Function/S SF_GetAnnotationPrefix ( string dataType)
13181316
13191317 strswitch ( dataType)
@@ -1749,48 +1747,59 @@ static Function SF_CommonWindowSetup(string win, string graph)
17491747 DoWindow / T $ win, newTitle
17501748End
17511749
1752- static Function/WAVE SF_GatherYUnits ( WAVE /WAVE formulaResults, string explicitLbl, WAVE /Z /T yUnits )
1750+ static Function SF_GatherAxisLabels ( WAVE /WAVE formulaResults, string explicitLbl, string formulaLabel, WAVE /T axisLabels )
17531751
17541752 variable i , size, numData
1753+ string unit
17551754
1756- if ( ! WaveExists ( yUnits))
1757- Make / FREE/ T/ N=0 yUnits
1758- endif
1759-
1760- size = DimSize ( yUnits, ROWS)
1755+ size = DimSize ( axisLabels, ROWS)
17611756 if ( ! isEmpty ( explicitLbl))
1762- Redimension / N= ( size + 1 ) yUnits
1763- yUnits [ size] = explicitLbl
1764- return yUnits
1757+ Redimension / N= ( size + 1 ) axisLabels
1758+ axisLabels [ size] = explicitLbl
1759+ return NaN
17651760 endif
17661761
17671762 numData = DimSize ( formulaResults, ROWS)
1768- Redimension / N= ( size + numData) yUnits
1763+ Redimension / N= ( size + numData) axisLabels
17691764
17701765 for ( i = 0; i < numData; i += 1 )
17711766 WAVE /Z wvResultY = formulaResults[ i ][ % FORMULAY]
17721767 if ( ! WaveExists ( wvResultY))
17731768 continue
17741769 endif
1775- yUnits[ size] = WaveUnits ( wvResultY, COLS)
1776- size += 1
1770+
1771+ strswitch ( formulaLabel)
1772+ case "FORMULAY" :
1773+ unit = WaveUnits ( wvResultY, COLS)
1774+ break
1775+ case "FORMULAX" :
1776+ WAVE /Z wvResultX = formulaResults[ i ][ % FORMULAX]
1777+ if ( WaveExists ( wvResultX))
1778+ unit = WaveUnits ( wvResultX, ROWS)
1779+ else
1780+ unit = WaveUnits ( wvResultY, ROWS)
1781+ endif
1782+ break
1783+ default :
1784+ ASSERT ( 0, "Unsupported formulaLabel: " + formulaLabel)
1785+ break
1786+ endswitch
1787+
1788+ // fallback to the unit if present
1789+ if ( ! IsEmpty ( unit))
1790+ axisLabels[ size] = SF_FormatUnit ( unit)
1791+ size += 1
1792+ endif
17771793 endfor
1778- Redimension / N= ( size) yUnits
17791794
1780- return yUnits
1795+ Redimension / N = ( size ) axisLabels
17811796End
17821797
1783- static Function/S SF_CombineYUnits ( WAVE /T units)
1784-
1785- string separator = " / "
1786- string result = ""
1798+ static Function/S SF_CombineAxisLabels ( WAVE /T axisLabels)
17871799
1788- WAVE /T unique = GetUniqueEntries ( units, dontDuplicate = 1 )
1789- for ( unit : unique)
1790- result += unit + separator
1791- endfor
1800+ WAVE /T unique = GetUniqueEntries ( axisLabels, dontDuplicate = 1 )
17921801
1793- return RemoveEndingRegExp ( result , separator )
1802+ return TextWaveToList ( unique , " / " , trailSep = 0 )
17941803End
17951804
17961805static Function SF_CheckNumTraces ( string graph, variable numTraces)
@@ -1874,7 +1883,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
18741883 variable winDisplayMode, showLegend, tagCounter, overrideMarker
18751884 variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
18761885 variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis
1877- string win, wList, winNameTemplate, exWList, wName, annotation, yAxisLabel, wvName, info, xAxis
1886+ string win, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel , yAxisLabel, wvName, info, xAxis
18781887 string formulasRemain, yAndXFormula, xFormula, yFormula, tagText, name, winHook
18791888 STRUCT SF_PlotMetaData plotMetaData
18801889 STRUCT RGBColor color
@@ -1902,8 +1911,9 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
19021911 postPlotPSX = 0
19031912 showLegend = 1
19041913 formulaCounter = 0
1905- WAVE /Z wvX = $ ""
1906- WAVE /Z/ T yUnits = $ ""
1914+ WAVE /Z wvX = $ ""
1915+
1916+ Make / FREE/ T/ N=0 xAxisLabels, yAxisLabels
19071917
19081918 formulasRemain = graphCode[ j]
19091919
@@ -1935,8 +1945,8 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
19351945 Abort
19361946 endtry
19371947
1938- WAVE /T yUnitsResult = SF_GatherYUnits ( formulaResults, plotMetaData. yAxisLabel , yUnits )
1939- WAVE /T yUnits = yUnitsResult
1948+ SF_GatherAxisLabels ( formulaResults, plotMetaData. xAxisLabel , "FORMULAX" , xAxisLabels )
1949+ SF_GatherAxisLabels ( formulaResults , plotMetaData . yAxisLabel , "FORMULAY" , yAxisLabels )
19401950
19411951 if ( ! cmpstr ( plotMetaData. dataType, SF_DATATYPE_PSX))
19421952 PSX_Plot ( win, graph, formulaResults, plotMetaData)
@@ -2127,8 +2137,6 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
21272137 formulaCounter += 1
21282138 while ( 1 )
21292139
2130- yAxisLabel = SF_CombineYUnits ( yUnits)
2131-
21322140 if ( showLegend)
21332141 customLegend = JWN_GetStringFromWaveNote ( formulaResults, SF_META_CUSTOM_LEGEND)
21342142
@@ -2268,15 +2276,19 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
22682276 endfor
22692277 endfor
22702278
2271- if ( ! IsEmpty ( plotMetaData. xAxisLabel) && traceCnt > 0 )
2272- Label / W=$ win bottom, plotMetaData. xAxisLabel
2273- ModifyGraph / W=$ win tickUnit ( bottom) =1
2274- endif
2275- if ( ! IsEmpty ( yAxisLabel) && traceCnt > 0 )
2276- Label / W=$ win left, yAxisLabel
2277- ModifyGraph / W=$ win tickUnit ( left) =1
2278- endif
22792279 if ( traceCnt > 0 )
2280+ xAxisLabel = SF_CombineAxisLabels ( xAxisLabels)
2281+ if ( ! IsEmpty ( xAxisLabel))
2282+ Label / W=$ win bottom, xAxisLabel
2283+ ModifyGraph / W=$ win tickUnit ( bottom) =1
2284+ endif
2285+
2286+ yAxisLabel = SF_CombineAxisLabels ( yAxisLabels)
2287+ if ( ! IsEmpty ( yAxisLabel))
2288+ Label / W=$ win left, yAxisLabel
2289+ ModifyGraph / W=$ win tickUnit ( left) =1
2290+ endif
2291+
22802292 ModifyGraph / W=$ win zapTZ ( bottom) =1
22812293 endif
22822294
0 commit comments