#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access. Menu "Graph" "Make Angle Color Legend" End Menu "Panel" "Make Angle Color Legend" End Menu "Layout" "Make Angle Color Legend" End Proc MakeAngleColorLegend(colorTableName, repeatColorTable, x0Points, y0Points, radiusPoints, startAngleDegrees, ccw, surroundThicknessPoints, directionsThicknessPoints, arrowOptions) String colorTableName= StrVarOrDefault(PackageDFVar("colorTableName"), "SpectrumBlack") Variable repeatColorTable = NumVarOrDefault(PackageDFVar("repeatColorTable"), 1) // 0 is no repeat, 1 is repeat once (2 color tables), etc. Variable x0Points = NumVarOrDefault(PackageDFVar("x0Points"), NaN) // default is center of window Variable y0Points = NumVarOrDefault(PackageDFVar("y0Points"), NaN) // default is center of window Variable radiusPoints = NumVarOrDefault(PackageDFVar("radiusPoints"), 36) // default is 0.5 inch Variable startAngleDegrees= NumVarOrDefault(PackageDFVar("startAngleDegrees"), 90) Variable ccw=NumVarOrDefault(PackageDFVar("ccw"), 1) ? 2 : 1 // 1 = "Clockwise", 2 = "Counter-Clockwise" Variable surroundThicknessPoints=NumVarOrDefault(PackageDFVar("surroundThicknessPoints"), 1) Variable directionsThicknessPoints= NumVarOrDefault(PackageDFVar("directionsThicknessPoints"), 1) Variable arrowOptions= 1+NumVarOrDefault(PackageDFVar("arrowOptions"), 1) // 0 is none, 1 is black arrows, 2 is white arrows, 3 is white arrows with black "outline", 4 is black arrows with white "outline" Prompt colorTableName, "color table", popup, CTabList() Prompt repeatColorTable, "# of color table repeats" Prompt x0Points, "x origin (points) or NaN for center" Prompt y0Points, "y origin (points) or NaN for center" Prompt ccw, "Angle", popup, "Clockwise;Counter-Clockwise;" // 1,2 Prompt arrowOptions, "arrow options", popup, "None;Black;White;White on Black;Black on White;" ccw = ccw == 2 // convert popup item numbers to boolean arrowOptions= arrowOptions - 1 // convert popup item numbers to option // remember choices for next time String/G root:Packages:AngleColorLegend:colorTableName = colorTableName Variable/G root:Packages:AngleColorLegend:repeatColorTable = repeatColorTable Variable/G root:Packages:AngleColorLegend:x0Points = x0Points Variable/G root:Packages:AngleColorLegend:y0Points = y0Points Variable/G root:Packages:AngleColorLegend:radiusPoints = radiusPoints Variable/G root:Packages:AngleColorLegend:startAngleDegrees = startAngleDegrees Variable/G root:Packages:AngleColorLegend:ccw = ccw Variable/G root:Packages:AngleColorLegend:surroundThicknessPoints = surroundThicknessPoints Variable/G root:Packages:AngleColorLegend:directionsThicknessPoints = directionsThicknessPoints Variable/G root:Packages:AngleColorLegend:arrowOptions = arrowOptions Variable okay = fMakeAngleColorLegend(colorTableName, repeatColorTable, x0Points, y0Points, radiusPoints, startAngleDegrees, ccw, surroundThicknessPoints, directionsThicknessPoints, arrowOptions) if( okay ) HideTools/A // work around for Igor 8 bug ShowTools/A arrow endif End static Constant kDebugging = 0 Function fMakeAngleColorLegend(colorTableName, repeatColorTable, x0Points, y0Points, radiusPoints, startAngleDegrees, ccw, surroundThicknessPoints, directionsThicknessPoints, arrowOptions) String colorTableName Variable repeatColorTable // 0 is no repeats, 1 is one repeat, etc Variable x0Points, y0Points, radiusPoints Variable startAngleDegrees // 0, 90, 180, or 270 corresponds to Right, Bottom, Left, or Top. Default is 0 (Right) Variable ccw // 0 for clockwise, else counter-clockwise. Variable surroundThicknessPoints Variable directionsThicknessPoints // 0 for no, 1 for yes Variable arrowOptions // 0 is none, 1 is black arrows, 2 is white arrows, 3 is white arrows with black "outline", 4 is black arrows with white "outline" WAVE ctab = ReplicatedColorTable(colorTableName, repeatColorTable, 360) if( kDebugging > 1 ) DemoColorTable(ctab) DoWindow/F scratchGraph if( V_Flag == 0 ) Display/N=scratchGraph/K=1 endif endif String win = ActiveWin() // if "", we don't have a suitable window topmost if( strlen(win) == 0 ) DoAlert 0, "Expected the Active Window to be a graph, panel, or layout." return 0 endif #if IgorVersion() >= 7 if( kDebugging ) // DANGER: Clears Layer currently in use GetWindow $win drawLayer SetDrawLayer/W=$win/K $S_Value endif #endif GetWindow $win wsize // screen corners in points if( numtype(x0Points) != 0 ) x0Points = floor((V_Right-V_Left)/2) endif if( numtype(y0Points) != 0 ) y0Points = round((V_Bottom-V_Top)/2) endif SetDrawEnv/W=$win push SetDrawEnv/W=$win gstart, gname=AngleColorScale // Marks the start of a named group of objects. SetDrawEnv/W=$win xcoord=abs, ycoord=abs, linethick= 0, save // absolute coords, no line thickness for wedges Variable numWedges = DimSize(ctab,0) // one wedge per color Variable deltaRadians = 2 * pi / numWedges // radians/wedge, full circle assumed Variable angle0 = startAngleDegrees * pi / 180 // radians Variable i for(i= 0; i maxRows) ) Variable replicatedRows = colorTableRows * (1+repeatColorTable) replicatedRows = min(replicatedRows, maxRows) // avoid creating needlessly complex drawing Variable rowsPerRepeat = floor(replicatedRows / (1+repeatColorTable)) Variable totalRows = rowsPerRepeat*(1+repeatColorTable) Redimension/N=(totalRows,-1) replicated // Extract rowsPerRepeat from ctab Variable i for(i=0;i<=repeatColorTable;i+=1) Variable firstRow= i*rowsPerRepeat replicated[firstRow, firstRow+rowsPerRepeat-1][] = ctab[(p-firstRow) * (colorTableRows-1) / (rowsPerRepeat-1)][q] endfor endif return replicated End // This is where the packages's globals are stored. Function/S PackageDF() return "root:Packages:AngleColorLegend" End Function/S SetPackageDF() String oldDF = GetDataFolder(1) SetDataFolder PackageDF() return oldDF End Function/S PackageDFVar(varName) String varName String df= PackageDF() if( !DataFolderExists(df) ) NewDataFolder/O root:Packages NewDataFolder/O $df endif return df+":"+PossiblyQuoteName(varName) End static Function/S ActiveWinInWin(win) String win String active="" if( strlen(win) ) Variable type= WinType(win) if( type != 0 ) GetWindow $win activeSW // Stores the window "path" of currently active subwindow in S_Value. See Subwindow Syntax for details on the window hierarchy. Variable activeType= WinType(S_Value) if( activeType == 1 || activeType == 3 || activeType == 7 ) // window or subwindow, graph, layout, or panel active= S_Value endif endif endif return active End static Function/S ActiveWin() String win= WinName(0,1+4+64,1) // topmost graph, layout, or panel win = ActiveWinInWin(win) // a graph can be a subwindow in a panel or in another graph return win End // ----- DEBUGGING Function DemoColorTable(ctab) WAVE ctab Variable rows = DimSize(ctab,0) Make/O/N=(rows,10) ramp = p DoWindow/K DemoColorTableGraph NewImage/K=1/N=DemoColorTableGraph ramp ModifyImage/W=$S_Name ramp ctab={*,*,ctab,0} End