Skip to content

Commit

Permalink
Merge pull request #2147 from AllenInstitute/feature/2147-minor-sweep…
Browse files Browse the repository at this point in the history
…-formula-additions

Minor SF enhancements
  • Loading branch information
t-b authored Jun 14, 2024
2 parents 5c9352e + 1deb4b3 commit 58beeb2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
1 change: 1 addition & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ StrConstant SF_META_XTICKLABELS = "/XTickLabels" // text wave
StrConstant SF_META_XTICKPOSITIONS = "/XTickPositions" // numeric wave
StrConstant SF_META_XAXISLABEL = "/XAxisLabel" // string
StrConstant SF_META_YAXISLABEL = "/YAxisLabel" // string
StrConstant SF_META_LEGEND_LINE_PREFIX = "/LegendLinePrefix" // string
StrConstant SF_META_OPSTACK = "/OperationStack" // string
StrConstant SF_META_MOD_MARKER = "/Marker" // numeric wave
StrConstant SF_META_SHOW_LEGEND = "/ShowLegend" // numeric, boolean, defaults to true (1)
Expand Down
65 changes: 47 additions & 18 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ End
static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData, WAVE data)

variable channelNumber, channelType, sweepNo, isAveraged
string channelId, prefix
string channelId, prefix, legendPrefix
string traceAnnotation, annotationPrefix

prefix = RemoveEnding(ReplaceString(";", plotMetaData.opStack, " "), " ")
Expand All @@ -1248,8 +1248,15 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
case SF_DATATYPE_SWEEP: // fallthrough
case SF_DATATYPE_LABNOTEBOOK: // fallthrough
case SF_DATATYPE_TP:
sweepNo = JWN_GetNumberFromWaveNote(data, SF_META_SWEEPNO)
annotationPrefix = SF_GetAnnotationPrefix(plotMetaData.dataType)
sweepNo = JWN_GetNumberFromWaveNote(data, SF_META_SWEEPNO)
legendPrefix = JWN_GetStringFromWaveNote(data, SF_META_LEGEND_LINE_PREFIX)

if(!IsEmpty(legendPrefix))
legendPrefix = " " + legendPrefix + " "
endif

sprintf annotationPrefix, "%s%s", SF_GetAnnotationPrefix(plotMetaData.dataType), legendPrefix

if(IsValidSweepNumber(sweepNo))
channelNumber = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELNUMBER)
channelType = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELTYPE)
Expand Down Expand Up @@ -1375,9 +1382,9 @@ End
static Function/S SF_ShrinkLegend(string annotation)

string str, tracePrefix, opPrefix, sweepNum, suffix
string opPrefixOld, suffixOld
string sweepList = ""
variable firstRun = 1
string opPrefixOld, suffixOld, tracePrefixOld, shrunkAnnotation
string sweepList
variable multipleSweeps

string expr = "(\\\\s\\([\\s\\S]+\\)) ([\\s\\S]*Sweep) (\\d+) ([\\s\\S]*)"

Expand All @@ -1386,29 +1393,51 @@ static Function/S SF_ShrinkLegend(string annotation)
return annotation
endif

SplitString/E=expr lines[0], tracePrefix, opPrefixOld, sweepNum, suffixOld
if(V_flag != 4)
return annotation
endif
sweepList = AddListItem(sweepNum, sweepList, ",")
shrunkAnnotation = ""

tracePrefixOld = ""
suffixOld = ""
opPrefixOld = ""
sweepList = ""

for(line : lines)
if(firstRun)
firstRun = 0
continue
SplitString/E=expr line, tracePrefix, opPrefix, sweepNum, suffix
if(V_flag != 4)
return annotation
endif

if(IsEmpty(tracePrefixOld) && IsEmpty(opPrefixOld) && IsEmpty(suffixOld))
tracePrefixOld = tracePrefix
opPrefixOld = opPrefix
suffixOld = suffix
sweepList = ""
endif

SplitString/E=expr line, str, opPrefix, sweepNum, suffix
if(V_flag != 4 || CmpStr(opPrefixOld, opPrefix, 2) || CmpStr(suffixOld, suffix, 2))
if(CmpStr(suffixOld, suffix, 2))
return annotation
endif

if(CmpStr(opPrefixOld, opPrefix, 2))
multipleSweeps = ItemsInList(sweepList, ",") > 1
sweepList = CompressNumericalList(sweepList, ",")
shrunkAnnotation += tracePrefixOld + opPrefixOld + SelectString(multipleSweeps, "", "s") + " " + sweepList + " " + suffixOld + "\r"

tracePrefixOld = tracePrefix
opPrefixOld = opPrefix
suffixOld = suffix
sweepList = ""
endif

sweepList = AddListItem(sweepNum, sweepList, ",", Inf)
endfor

sweepList = CompressNumericalList(sweepList, ",")
if(!IsEmpty(sweepList))
multipleSweeps = ItemsInList(sweepList, ",") > 1
sweepList = CompressNumericalList(sweepList, ",")
shrunkAnnotation += tracePrefixOld + opPrefixOld + SelectString(multipleSweeps, "", "s") + " " + sweepList + " " + suffixOld
endif

return tracePrefix + opPrefixOld + "s " + sweepList + " " + suffixOld
return shrunkAnnotation
End

static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string winNameTemplate, string graph, variable winDisplayMode, variable numGraphs)
Expand Down
2 changes: 1 addition & 1 deletion Packages/tests/Basic/UTF_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3526,7 +3526,7 @@ static Function TestLegendShrink()
CHECK_EQUAL_STR(strRef, result)

str = "\s(T000000d0_Sweep_0_AD1) Sweep 0 AD1\r\s(T000000d1_Sweep_1_AD1) Sweep 1 AD1\r\s(T000000d2_Sweep_2_AD1) operation Sweep 2 AD1"
strref = str
strref = "\s(T000000d0_Sweep_0_AD1)Sweeps 0-1 AD1\r\s(T000000d2_Sweep_2_AD1)operation Sweep 2 AD1"
result = MIES_SF#SF_ShrinkLegend(str)
CHECK_EQUAL_STR(strRef, result)

Expand Down

0 comments on commit 58beeb2

Please sign in to comment.