#pragma rtGlobals=1 // Use modern global access method. #pragma moduleName=KBColorizeTraces #pragma version=9.02 // shipped with Igor 9.02 // Written by Kevin Boyce with tweaks by Howard Rodstein and Jim Prouty. // // Version 6.03, JP: Added Markers and Line Styles Quick Sets // Added image plots and value readouts for the Color Wheel sliders. // Added Linear Hue checkbox. // Now Desaturated colors no longer tend towards pink. // Made most functions static. // // Version 6.04, JP: Restored KBColorizeTraces to lightness, saturation, startingHue parameters only (as per Igor 6.02A and earlier), // and added KBColorizeTracesLinearHue() with same parameters, // and KBColorizeTracesOptLinear(lightness, saturation, startingHue,[useLinearHue]). // // Version 6.041, JP: Works correctly if the current data folder isn't root. Fixes thanks to "Marcel Graf" // Version 6.1, JP: Slider pointers don't overlap the image plots on Windows. // Version 6.22, JP: Fixed lstyle wrapping to not skip style 17 // Version 6.34, JP: Fixed bug in KBColorTablePopMenuProc(). // Version 6.38, JP: A focused Color Wheel graph no longer prevents the graph traces from updating. // // The color wheels colorize the waves in the top graph, // with given lightness and saturation starting hue. // Lightness, saturation and starting hue vary between 0 and 1. // // NOTE: lightness and saturation are really cheap approximations. // For that matter, so is hue, which is simply an rgb circle. // Colors appear evenly distributed in "hue", except around green-blue, // where they move more quickly, since color perception isn't as good there. // I generally call it with lightness=0.9 and saturation=1. // // Version 9.02, JP: Added a way to colorize traces using color table WAVEs (which are different from Igor's built-in color tables). //------------- Public Routines ---------------------------- Menu "Graph" "Make Traces Different", /Q, ShowKBColorizePanel() End Function ShowKBColorizePanel() DoWindow/F KBColorizePanel if (V_Flag == 0) CreateKBColorizePanel() endif End Function CreateKBColorizePanel() DoWindow/K KBColorizePanel NewPanel /W=(412,64,715,647)/N=KBColorizePanel/K=1 as "Make Traces Different" ModifyPanel/W=KBColorizePanel noEdit=1, fixedSize=1 DefaultGuiFont/W=#/Mac popup={"_IgorMedium",12,0},all={"_IgorMedium",12,0} DefaultGuiFont/W=#/Win popup={"_IgorMedium",0,0},all={"_IgorMedium",0,0} String topGraphHost=KBActiveGraphHost() if( strlen(topGraphHost) ) AutoPositionWindow/M=0/R=$topGraphHost KBColorizePanel endif GroupBox markersGroup,pos={10,9},size={280,78},title="Markers Quick Set" PopupMenu allMarkers,pos={23,33},size={152,20},proc=KBColorizeTraces#AllMarkersPopMenuProc,title="Reset All Traces To:" PopupMenu allMarkers,mode=20,popvalue="",value= #"\"*MARKERPOP*\"" PopupMenu markersSeries,pos={34,60},size={183,20},proc=KBColorizeTraces#UniqueMarkersPopMenuProc,title="Unique Markers:" PopupMenu markersSeries,mode=1,popvalue="All Sequential",value= #"\"All Sequential;All Random;Only Filled;Only Outlined;Only Lines;Only Round;Only Square;Only Diamond;Only Triangle;Only Crosses;\"" GroupBox lineStylesGroup,pos={10,99},size={280,78},title="Line Styles Quick Set" PopupMenu allLineStyles,pos={23,122},size={232,20},proc=KBColorizeTraces#AllLineStylesPopMenuProc,title="Reset All Traces To:" PopupMenu allLineStyles,mode=1,bodyWidth= 130,popvalue="",value= #"\"*LINESTYLEPOP*\"" Button uniqueLineStyles,pos={124,150},size={130,20},proc=KBColorizeTraces#UniqueLineStylesButtonProc,title="Sequential Line Styles" GroupBox colorsQuickSetGroup,pos={10,185},size={280,147},title="Colors Quick Set" PopupMenu ColorPop,pos={23,210},size={152,20},proc=KBColorizeTraces#ColorizePopMenuProc,title="Reset All Traces To:" PopupMenu ColorPop,help={"Sets all traces in the active graph to the color you choose."} PopupMenu ColorPop,mode=1,popColor= (0,0,0),value= #"\"*COLORPOP*\"" PopupMenu ColorTablePop,pos={52,238},size={223,20},proc=KBColorizeTraces#KBColorTablePopMenuProc,title="Set Traces To:" PopupMenu ColorTablePop,help={"Sets all traces in the active graph using the entire range of the color table you choose."} PopupMenu ColorTablePop,mode=56,bodyWidth= 150,popvalue="",value= #"\"*COLORTABLEPOP*\"" Button colorTableWaves,pos={124,270},size={150,20} Button colorTableWaves,title="Color Table Waves ...", proc=ColorTableWavesButtonProc Button commonColorsButton,pos={124,301},size={150,20},proc=CommonColorsButtonProc,title="Commonly-Used Colors" Button commonColorsButton,help={"Sets all traces in the active graph to a range of commonly-used colors. The colors repeat every 10 traces."} GroupBox colorWheelGroup,pos={10,337},size={280,220},title="Color Wheel" TitleBox hueTitle,pos={26,358},size={66,16},title="Starting Hue",frame=0 TitleBox saturationTitle,pos={123,358},size={54,16},title="Saturation",frame=0 TitleBox lightnessTitle,pos={210,358},size={50,16},title="Lightness",frame=0 // the global variables don't exist until RestoreKBColorizePanelSettings is called, so they're set there, not here Slider hueSlider,pos={24,378},size={19,123},proc=KBColorizeTraces#KBJPColorizeSliderProc Slider hueSlider,help={"Sets the hue for the first trace. Other trace colors are distributed around the color wheel."} Slider hueSlider,limits={0,0.99,0.01},ticks= 0 // ,variable= root:Packages:KBColorize:gStartingHue Slider satSlider,pos={120,378},size={19,123},proc=KBColorizeTraces#KBJPColorizeSliderProc Slider satSlider,help={"Sets the hue for the first trace. Other trace colors are distributed around the color wheel."} Slider satSlider,limits={0.2,1,0.01},ticks= 0 // ,variable= root:Packages:KBColorize:gSaturation Slider lightSlider,pos={207,378},size={19,123},proc=KBColorizeTraces#KBJPColorizeSliderProc Slider lightSlider,help={"Sets the hue for the first trace. Other trace colors are distributed around the color wheel."} Slider lightSlider,limits={0.2,0.9,0.01},ticks= 0 // ,variable= root:Packages:KBColorize:gLightness CheckBox linearHue,pos={31,532},size={76,16},proc=KBColorizeTraces#LinearCheckProc,title="Linear Hue " //CheckBox linearHue,variable= root:Packages:KBColorize:gLinearHue // restore control settings and create globals // RestoreKBColorizePanelSettings needs controls, creates the global variables RestoreKBColorizePanelSettings() ValDisplay hueReadout,pos={46,506},size={33,18},format="%.2f",frame=5 ValDisplay hueReadout,limits={0,0,0},barmisc={0,1000} ValDisplay hueReadout,value= #"root:Packages:KBColorize:gStartingHue" ValDisplay hueReadout1,pos={144,506},size={33,18},format="%.2f",frame=5 ValDisplay hueReadout1,limits={0,0,0},barmisc={0,1000} ValDisplay hueReadout1,value= #"root:Packages:KBColorize:gSaturation" ValDisplay hueReadout2,pos={232,506},size={33,18},format="%.2f",frame=5 ValDisplay hueReadout2,limits={0,0,0},barmisc={0,1000} ValDisplay hueReadout2,value= #"root:Packages:KBColorize:gLightness" // UpdateHueTicks needs globals, creates images UpdateHueTicks() // Create image subwindows DefineGuide UGH0={FT,383},UGH1={FT,494} Display/W=(52,170,82,295)/FG=(,UGH0,,UGH1)/HOST=KBColorizePanel AppendImage/T root:Packages:KBColorize:hueRGBImage ModifyImage hueRGBImage ctab= {*,*,Grays,0} ModifyGraph userticks(left)={root:Packages:KBColorize:hueTicks,root:Packages:KBColorize:hueTickLabels} ModifyGraph userticks(top)={root:Packages:KBColorize:hueTicks,root:Packages:KBColorize:hueTickLabels} ModifyGraph margin(left)=-1,margin(bottom)=-1,margin(top)=-1,margin(right)=-1 ModifyGraph tick=2 ModifyGraph mirror=0 ModifyGraph nticks=10 ModifyGraph noLabel=2 ModifyGraph standoff=0 ModifyGraph axThick(left)=0 SetAxis/A/R left ModifyGraph swapXY=1 RenameWindow #,G0 SetActiveSubwindow ## Display/W=(147,172,177,293)/FG=(,UGH0,,UGH1)/HOST=# AppendImage/T root:Packages:KBColorize:satRGBImage ModifyImage satRGBImage ctab= {*,*,Grays,0} ModifyGraph margin(left)=-1,margin(bottom)=-1,margin(top)=-1,margin(right)=-1 ModifyGraph mirror=0 ModifyGraph nticks=0 ModifyGraph noLabel=2 ModifyGraph standoff=0 ModifyGraph axThick=0 SetAxis/A/R left ModifyGraph swapXY=1 RenameWindow #,G1 SetActiveSubwindow ## Display/W=(233,173,261,295)/FG=(,UGH0,,UGH1)/HOST=# AppendImage/T root:Packages:KBColorize:lightRGBImage ModifyImage lightRGBImage ctab= {*,*,Grays,0} ModifyGraph margin(left)=-1,margin(bottom)=-1,margin(top)=-1,margin(right)=-1 ModifyGraph mirror=0 ModifyGraph nticks=0 ModifyGraph noLabel=2 ModifyGraph standoff=0 ModifyGraph axThick=0 SetAxis/A/R left ModifyGraph swapXY=1 RenameWindow #,G2 SetActiveSubwindow ## SetWindow kwTopWin,hook(KBColorize)=KBColorizeTraces#KBColorizePanelHook End //-------------- Private (static) Routines --------------------------- static Function KBColorizePanelHook(s) STRUCT WMWinHookStruct &s Variable statusCode= 0 strswitch(s.eventName) case "kill": StoreKBColorizeSettings() DoWindow KBColorTableWave if( V_Flag == 0 ) Execute/P "DELETEINCLUDE " Execute/P "COMPILEPROCEDURES " endif break case "activate": UpdateHueTicks() break endswitch return statusCode // 0 if nothing done, else 1 End Function KBColorizeTracesOptLinear(lightness, saturation, startingHue,[useLinearHue]) Variable lightness, saturation, startingHue // 0-1 Variable useLinearHue // optional boolean. If false, use "warped" hue, new parameter for 6.03 if( ParamIsDefault(useLinearHue) ) useLinearHue= 0 endif Variable traceIndex, numTraces String graphName= KBActiveGraph() numTraces = KBTracesInGraph(graphName) if (numTraces <= 0) return 0 endif string vtrl=tracenamelist(graphName,";",1+4) //list of visible traces on graph string Vtracename for( traceIndex= 0; traceIndex < numTraces; traceIndex += 1 ) Variable hue= mod(startingHue + traceIndex/numTraces, 1) // 0-1 if( !useLinearHue ) hue= GetKBHueFromLinearHue(hue) // 0-1 endif Variable red, green, blue KBHSLToRGB(hue*65535, saturation*65535, lightness*65535, red, green, blue) Vtracename = stringfromlist(traceIndex,Vtrl) ModifyGraph/W=$graphName/Z rgb($Vtracename)=(red, green, blue) endfor return numTraces End Function KBColorizeTraces(lightness, saturation, startingHue) Variable lightness, saturation, startingHue // 0-1 return KBColorizeTracesOptLinear(lightness, saturation, startingHue) End Function KBColorizeTracesLinearHue(lightness, saturation, startingHue) Variable lightness, saturation, startingHue // 0-1 return KBColorizeTracesOptLinear(lightness, saturation, startingHue, useLinearHue=1) End static Constant ksNumDemoColors= 100 static Function CreateHSLImages(useLinearHue, startHue, sat, light) Variable useLinearHue // boolean. If false, use "warped" hue Variable startHue, sat, light // 0...1, startHue is a linear index into the HSL space NewDataFolder/O root:Packages NewDataFolder/O root:Packages:KBColorize // make hue image Make/O/N=(ksNumDemoColors,1,3)/U/W root:Packages:KBColorize:hueRGBImage WAVE/U/W hueRGBImage= root:Packages:KBColorize:hueRGBImage SetScale x, 0, 1, "", hueRGBImage if( useLinearHue ) hueRGBImage[][][0] = mod(0+p*65535/ksNumDemoColors, 65535) // varying hues. since we distribute them differently, we should modify this as per KB else // Colors are evenly distributed in "hue", except around // green-blue, where they move more quickly, since color perception isn't as good there. // those colors are centered at Hue = 0.7 and Hue=0.35 hueRGBImage[][][0] = limit(GetKBHueFromLinearHue(p/ksNumDemoColors)*65535,0,65535)// varying hues. since we distribute them differently, we should modify this as per KB endif hueRGBImage[][][1] = limit(sat*65535,0,65535) // constant saturation hueRGBImage[][][2] = limit(light*65535,0,65535) // constant lightness ImageTransform/O hsl2rgb hueRGBImage // converts 0...65535 HSL values to 0...65535 /U/W RGB values // NOTE: ONLY the Hue image is capable of showing the colors of all the traces // (since only that image has both saturation and lightness held constant). // Add user-defined ticks to the image plot #G0 right axis (remember the X and Y axes are swapped) // to indicate the chosen colors. Variable numTraces = KBTracesInGraph("") Make/O/N=(numTraces) root:Packages:KBColorize:hueTicks= mod(startHue+p/numTraces,1) Make/O/N=(numTraces)/T root:Packages:KBColorize:hueTickLabels= "" // to make user ticks happy if( !useLinearHue ) startHue= GetKBHueFromLinearHue(startHue) endif // make saturation image from 0.2 to 1 Make/O/N=(ksNumDemoColors,1,3)/U/W root:Packages:KBColorize:satRGBImage WAVE/U/W satRGBImage= root:Packages:KBColorize:satRGBImage satRGBImage[][][0] = mod(startHue*65535, 65535) // constant hue satRGBImage[][][1] = (0.2 + 0.8*p/ksNumDemoColors)*65535 // increasing saturation satRGBImage[][][2] = limit(light*65535,0,65535) // constant lightness ImageTransform/O hsl2rgb satRGBImage // make lightness image range from 0.2 to 0.9 Make/O/N=(ksNumDemoColors,1,3)/U/W root:Packages:KBColorize:lightRGBImage WAVE/U/W lightRGBImage= root:Packages:KBColorize:lightRGBImage lightRGBImage[][][0] = mod(startHue*65535, 65535) // constant hue lightRGBImage[][][1] = limit(sat*65535,0,65535) // constant saturation lightRGBImage[][][2] = (0.2 +0.7*p/ksNumDemoColors)*65535 // increasing lightness ImageTransform/O hsl2rgb lightRGBImage End // Find the number of traces on the top graph static Function KBTracesInGraph(win) // "" for top graph String win if( strlen(win) == 0 ) win= KBActiveGraph() if( strlen(win) == 0 ) return 0 endif endif return ItemsInList(TraceNameList(win,";",1+4)) End // GetKBHueFromLinearHue warps the hue space to accomplish this goal: // Colors are evenly distributed in "hue", except around // green-blue, where they move more quickly, since color perception isn't as good there. // those colors are centered at Hue = 0.7 and Hue=0.35 static Function GetKBHueFromLinearHue(linearHue) Variable linearHue // 0-1 Variable red, green, blue KBGetColorRGB( 0.5, 1, linearHue, red, green, blue) Variable warpedHue, sat, light KBRGBToHSL(red, green, blue, warpedHue, sat, light) return warpedHue/65535 // 0-1 End // convert RGB to HSL static Function KBRGBToHSL(red, green, blue, hue, sat, light) Variable red, green, blue // inputs, 0-65535 Variable &hue, &sat, &light // outputs, 0-65535 NewDataFolder/O root:Packages NewDataFolder/O root:Packages:KBColorize Make/O/N=(1,1,3)/U/W root:Packages:KBColorize:rgbhsl WAVE rgbhsl=root:Packages:KBColorize:rgbhsl rgbhsl[0][0][0]= round(red) rgbhsl[0][0][1]= round(green) rgbhsl[0][0][2]= round(blue) ImageTransform/O rgb2hsl rgbhsl hue=rgbhsl[0][0][0]*257 // 0-65535 sat=rgbhsl[0][0][1]*257 // 0-65535 light= rgbhsl[0][0][2]*257 // 0-65535 End // convert HSL to RGB: static Function KBHSLToRGB(hue, sat, light, red, green, blue) Variable hue, sat, light // inputs, 0-65535 Variable &red, &green, &blue // outputs, 0-65535 NewDataFolder/O root:Packages NewDataFolder/O root:Packages:KBColorize Make/O/N=(1,1,3)/U/W root:Packages:KBColorize:rgbhsl WAVE rgbhsl= root:Packages:KBColorize:rgbhsl rgbhsl[0][0][0]= hue rgbhsl[0][0][1]= sat rgbhsl[0][0][2]= light ImageTransform/O hsl2rgb rgbhsl red=rgbhsl[0][0][0] // 0-65535 green=rgbhsl[0][0][1] // 0-65535 blue= rgbhsl[0][0][2] // 0-65535 End static Function KBGetColorRGB( lightness, saturation, ratio, red, green, blue ) Variable lightness, saturation // 0-1 Variable ratio // 0-1, really a hue Variable &red, &green, &blue // outputs, 0-65535 Variable rmin, rmax, gmin, gmax, bmin,bmax, phi, r,g,b bmax = 65535*lightness bmin = 65535*max(min((lightness-saturation), 1), 0) // Reduce red and green maximum values, since red is brighter // than blue, and green is brighter still. This started out using // CIE values, but that didn't look good, so it's just empirical now. rmin = bmin/1; rmax = bmax/1 gmin = bmin/1.5; gmax = bmax/1.5 phi= ratio * ((2*PI)-1) // phi will determine the "hue". // Make phi move faster between 1.5 and 2.5, since color // sensitivity is less in that region. if( phi > 2.5 ) phi += 1 else if( phi > 1.5 ) phi += (phi-1.5) endif endif // Calculate r, g, and b if( phi < 2*PI/3 ) red= rmin + (rmax-rmin)*(1+cos(phi))/2 green= gmin + (gmax-gmin)*(1+cos(phi-2*PI/3))/2 blue= bmin else if( phi < 4*PI/3 ) red= rmin green= gmin + (gmax-gmin)*(1+cos(phi-2*PI/3))/2 blue= bmin + (bmax-bmin)*(1+cos(phi-4*PI/3))/2 else red= rmin + (rmax-rmin)*(1+cos(phi))/2 green= gmin blue= bmin + (bmax-bmin)*(1+cos(phi-4*PI/3))/2 endif endif End static Function UpdateColors() UpdateHueTicks() String graphName = KBActiveGraph() if ( strlen(graphName)) NVAR saturation = root:Packages:KBColorize:gSaturation NVAR lightness = root:Packages:KBColorize:gLightness NVAR startingHue = root:Packages:KBColorize:gStartingHue NVAR linearHue = root:Packages:KBColorize:gLinearHue KBColorizeTracesOptLinear(lightness, saturation, startingHue,useLinearHue=linearHue) endif End Static Function UpdateHueTicks() NVAR saturation = root:Packages:KBColorize:gSaturation NVAR lightness = root:Packages:KBColorize:gLightness NVAR startingHue = root:Packages:KBColorize:gStartingHue NVAR linearHue = root:Packages:KBColorize:gLinearHue CreateHSLImages(linearHue, startingHue, saturation, lightness) End static Function KBJPColorizeSliderProc(name, value, event) : SliderControl String name Variable value Variable event UpdateColors() End static Function LinearCheckProc(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked UpdateColors() End // StoreKBColorizeSettings() // Stores the state of the control panel settings in global variables in the // KBColorizePanel data folder. static Function StoreKBColorizeSettings() String savedDataFolder = GetDataFolder(1) NewDataFolder/O/S root:Packages NewDataFolder/O/S :KBColorize // Markers Quick Set ControlInfo/W=KBColorizePanel allMarkers Variable/G gAllMarkersMenuItem= V_Value ControlInfo/W=KBColorizePanel markersSeries Variable/G gUniqueMarkersMenuItem= V_Value // Line Styles Quick Set ControlInfo/W=KBColorizePanel allLineStyles Variable/G gAllLineStylesMenuItem= V_Value // Colors Quick Set ControlInfo/W=KBColorizePanel ColorPop Variable/G gPopRed = V_red Variable/G gPopGreen = V_green Variable/G gPopBlue = V_blue ControlInfo/W=KBColorizePanel ColorTablePop String/G gColorTableName= S_value // Color Wheel // gStartingHue, gSaturation, gLightness and gLinearHue // global variables are set directly by their controls. SetDataFolder savedDataFolder End static Function RestoreKBColorizePanelSettings() String savedDataFolder = GetDataFolder(1) NewDataFolder/O/S root:Packages NewDataFolder/O/S :KBColorize // Markers Quick Set NVAR/Z menuItem = gAllMarkersMenuItem if (NVAR_Exists(menuItem)) PopupMenu allMarkers,win=KBColorizePanel, mode=menuItem endif NVAR/Z menuItem = gUniqueMarkersMenuItem if (NVAR_Exists(menuItem)) PopupMenu markersSeries,win=KBColorizePanel, mode=menuItem endif // Line Styles Quick Set NVAR/Z menuItem = gAllLineStylesMenuItem if (NVAR_Exists(menuItem)) PopupMenu allLineStyles,win=KBColorizePanel, mode=menuItem endif // Colors Quick Set NVAR/Z popRed = gPopRed NVAR/Z popGreen = gPopGreen NVAR/Z popBlue = gPopBlue if (NVAR_Exists(popRed)) PopupMenu colorPop,win=KBColorizePanel, popColor=(popRed,popGreen,popBlue) endif SVAR/Z colorTableName = gColorTableName if (SVAR_Exists(colorTableName)) Variable ctableMenuItem= 1+WhichListItem(colorTableName, CTabList()) PopupMenu colorTablePop,win=KBColorizePanel, mode=ctableMenuItem endif // Color Wheel NVAR/Z startingHue = gStartingHue if (!NVAR_Exists(startingHue)) Variable/G gStartingHue= 0 endif Slider hueSlider,win=KBColorizePanel,variable= root:Packages:KBColorize:gStartingHue NVAR/Z linearHue= gLinearHue if (!NVAR_Exists(linearHue)) Variable/G gLinearHue= 0 endif CheckBox linearHue,win=KBColorizePanel,variable= root:Packages:KBColorize:gLinearHue NVAR/Z saturation = gSaturation if (!NVAR_Exists(saturation)) Variable/G gSaturation= 1 endif Slider satSlider,win=KBColorizePanel,variable= root:Packages:KBColorize:gSaturation NVAR/Z lightness = gLightness if (!NVAR_Exists(lightness)) Variable/G gLightness= 0.5 endif Slider lightSlider,win=KBColorizePanel,variable= root:Packages:KBColorize:gLightness ControlUpdate/W=KBColorizePanel/A SetDataFolder savedDataFolder End Static Function ColorizePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl String ctrlName Variable popNum String popStr String graphName = KBActiveGraph() if (strlen(graphName) == 0) return -1 endif StoreKBColorizeSettings() ControlInfo $ctrlName // Another way: sets V_Red, V_Green, V_Blue ModifyGraph/W=$KBActiveGraph() rgb=(V_Red, V_Green, V_Blue) End Function ColorTableWavesButtonProc(ctrlName) : ButtonControl String ctrlName KBShowColorTableWavePanel() End Function CommonColorsButtonProc(ctrlName) : ButtonControl String ctrlName String graphName = KBActiveGraph() if (strlen(graphName) == 0) return -1 endif Variable numTraces = KBTracesInGraph(graphName) if (numTraces <= 0) return -1 endif string vtrl=tracenamelist(graphName,";",1+4) //list of visible traces on graph string Vtracename Variable red, green, blue Variable i, index for(i=0; i 4 ) // some color table waves might have col[3] = alpha return 0 endif return 1 End static Function/S KBRecurseColorTablesFolder(String listSoFar, DFREF dfr) if( !DataFolderRefStatus(dfr) ) return listSoFar endif // list all of the waves in the folder Variable haveOneWave= 0 // if a folder has at least one color table wave, list disabled folder name in front of it. Variable index = 0 do Wave/Z w = WaveRefIndexedDFR(dfr, index) if (!WaveExists(w)) break // no more waves endif // see if it is a color table wave if( KBIsColorTableWave(w) ) if( haveOneWave == 0 ) DFREF dfSav = GetDataFolderDFR() SetDataFolder dfr String dataFolderName = GetDataFolder(0) SetDataFolder dfSav listSoFar += "\M0:(:" + dataFolderName+";" // append disabled folder name haveOneWave=1 endif listSoFar += NameOfWave(w)+";" endif index += 1 while(1) // then recurse into all subfolders Variable numChildDataFolders = CountObjectsDFR(dfr, 4) Variable i for(i=0; i= 2 ) // if we have loaded color table waves PopupMenu ColorTableWaveNames,mode=2 endif endif KBUpdateCTabDemo() break case "kill": DoWindow KBColorizePanel if( V_Flag == 0 ) Execute/P "DELETEINCLUDE " Execute/P "COMPILEPROCEDURES " endif break endswitch return hookResult // 0 if nothing done, else 1 End static Function ShowKBColorTableWave() DoWindow/K KBColorTableWave NewPanel/K=1/W=(581,56,973,219)/N=KBColorTableWave as "Trace Colors from Color Table Wave" ModifyPanel fixedSize=1, noEdit=1 NewDataFolder/O root:Packages NewDataFolder/O root:Packages:KBColorize String list = KBColorTableWaveNames() Variable mode = 1 Variable items= ItemsInList(list) if( items >= 2 ) mode= 2 String name= StrVarOrDefault("root:Packages:KBColorize:gColorTableWaveName","") if( strlen(name) ) // find matching item in popup list Variable itemNo = WhichListItem(name, list) if( itemNo != -1 ) mode= 1+itemNo endif endif endif PopupMenu ColorTableWaveNames,pos={21.00,23.00},size={150.00,20.00},proc=KBColorizeTraces#KBColorTableWavesPopMenuProc PopupMenu ColorTableWaveNames,title="Color Table Wave:" PopupMenu ColorTableWaveNames,mode=mode,value=#"KBColorizeTraces#KBColorTableWaveNames()" Variable checked = NumVarOrDefault("root:Packages:KBColorize:gColorTableWaveReversed",0) Variable/G root:Packages:KBColorize:gColorTableWaveReversed = checked CheckBox reverse,pos={23.00,69.00},size={57.00,16.00},proc=KBColorizeTraces#KBReverseCheckProc CheckBox reverse,title="Reverse",variable=root:Packages:KBColorize:gColorTableWaveReversed Button close,pos={322.00,132.00},size={50.00,20.00},proc=KBColorizeTraces#KBCloseColorTableWavePanel Button close,title="Close" Button getColorTableWaves,pos={21.00,132.00},size={140.00,20.00},proc=KBColorizeTraces#KBLoadColorTableWaves Button getColorTableWaves,title="Load Color Table Waves" KBUpdateCTabDemo() // forcibly builds the demo wave Display/W=(117,61,371,95)/HOST=# AppendImage/T :Packages:KBColorize:demoColorTableWave ModifyImage demoColorTableWave ctab= {*,*,Grays,0} ModifyGraph margin(left)=-1,margin(bottom)=-1,margin(top)=-1,margin(right)=-1,frameStyle=1 ModifyGraph mirror=2 ModifyGraph nticks=0 ModifyGraph noLabel=2 ModifyGraph fSize=8 ModifyGraph standoff=0 ModifyGraph tkLblRot(left)=90 ModifyGraph btLen=3 ModifyGraph tlOffset=-2 SetAxis/A/R left RenameWindow #,G0 SetActiveSubwindow ## End static Function/WAVE KBDemoColorTableWave(WAVE/Z w, Variable reversed) String ctabName DFREF dfSav = GetDataFolderDFR() NewDataFolder/O/S root:Packages NewDataFolder/O/S :KBColorize if( !WaveExists(w) ) // make a dummy image Make/O/U/I/N=(10,3)/FREE grey = 60000 WAVE w= grey endif Variable rows= DimSize(w,0) Make/O/N=(rows,2,3) demoColorTableWave if( reversed ) demoColorTableWave = w[(rows-1)-p][r] else demoColorTableWave = w[p][r] endif SetDataFolder dfSav return demoColorTableWave End