bb7c285d51eabd45fe7fbb3ae297acd0324915b7
kent
  Tue Apr 19 15:09:50 2011 -0700
Refactoring in hopes of making auto-scale work as you'd hope with multiwigs.  That still isn't there, this is just preliminaries.
diff --git src/hg/lib/wiggleCart.c src/hg/lib/wiggleCart.c
index 1ed4540..2459adf 100644
--- src/hg/lib/wiggleCart.c
+++ src/hg/lib/wiggleCart.c
@@ -125,41 +125,41 @@
             if(setting != NULL)
                 {
                 parseColonRange(setting, absMin, absMax);
                 }
             }
         }
 
     setting = trackDbSettingByView(tdb, VIEWLIMITS);
     if(setting != NULL)
         {
         parseColonRange(setting, retMin, retMax);
         }
     }
 }
 
+void wigFetchMinMaxYWithCart(struct cart *theCart, struct trackDb *tdb, char *name,
+			     double *retMin, double *retMax, double *retAbsMin, double *retAbsMax,
+			     int wordCount, char **words)
 /*****************************************************************************
  *	Min, Max Y viewing limits
  *	Absolute limits are defined on the trackDb type line for wiggle,
  *	or MIN_LIMIT / MAX_LIMIT trackDb settings for bedGraph
  *	User requested limits are defined in the cart
  *	Default opening display limits are optionally defined with the
  *		defaultViewLimits or viewLimits declaration from trackDb
  *****************************************************************************/
-void wigFetchMinMaxYWithCart(struct cart *theCart, struct trackDb *tdb, char *name,
-			     double *retMin, double *retMax, double *retAbsMin, double *retAbsMax,
-			     int wordCount, char **words)
 {
 boolean isBedGraph = (wordCount == 0 || sameString(words[0],"bedGraph"));
 // Determine absolute min and max.  Someday hgTrackDb will enforce inclusion of data
 // range settings, but until then, there is some circular logic where either one
 // can provide a default for the other if the other is missing.
 double absMax = 0.0, absMin = 0.0;
 boolean missingAbsMin = FALSE, missingAbsMax = FALSE;
 if (isBedGraph)
     {
     char *tdbMin = trackDbSettingClosestToHomeOrDefault(tdb, MIN_LIMIT, NULL);
     char *tdbMax = trackDbSettingClosestToHomeOrDefault(tdb, MAX_LIMIT, NULL);
     if (tdbMin == NULL)
 	missingAbsMin = TRUE;
     else
 	absMin = sqlDouble(tdbMin);
@@ -249,37 +249,37 @@
     *retAbsMin = absMin;
 if (retAbsMax)
     *retAbsMax = absMax;
 // After the dust settles from tdb's trackDb settings, now see if composite view
 // settings from tdb's parents override that stuff anyway:
 viewLimitsCompositeOverride(tdb, name, retMin, retMax, retAbsMin, retAbsMax);
 
 // And as the final word after composite override, reset retMin and retMax if from cart:
 if (cartMinStr && cartMaxStr)
     {
     *retMin = cartMin;
     *retMax = cartMax;
     }
 }	/*	void wigFetchMinMaxYWithCart()	*/
 
+void wigFetchMinMaxPixelsWithCart(struct cart *theCart, struct trackDb *tdb, char *name,int *Min, int *Max, int *Default)
 /*	Min, Max, Default Pixel height of track
  *	Limits may be defined in trackDb with the maxHeightPixels string,
  *	Or user requested limits are defined in the cart.
  *	And default opening display limits may optionally be defined with the
  *		maxHeightPixels declaration from trackDb
  *****************************************************************************/
-void wigFetchMinMaxPixelsWithCart(struct cart *theCart, struct trackDb *tdb, char *name,int *Min, int *Max, int *Default)
 {
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *heightPer = NULL; /*	string from cart	*/
 int maxHeightPixels = atoi(DEFAULT_HEIGHT_PER);
 int defaultHeightPixels = maxHeightPixels;
 int defaultHeight;      /*      truncated by limits     */
 int minHeightPixels = MIN_HEIGHT_PER;
 char * tdbDefault = cloneString(
     trackDbSettingClosestToHomeOrDefault(tdb, MAXHEIGHTPIXELS, DEFAULT_HEIGHT_PER) );
 
 if (sameWord(DEFAULT_HEIGHT_PER,tdbDefault))
     {
     struct hashEl *hel;
     /*	no maxHeightPixels from trackDb, maybe it is in tdb->settings
      *	(custom tracks keep settings here)
@@ -343,39 +343,39 @@
 	}
     }
 heightPer = cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, HEIGHTPER);
 /*      Clip the cart value to range [minHeightPixels:maxHeightPixels] */
 if (heightPer) defaultHeight = min( maxHeightPixels, atoi(heightPer));
 else defaultHeight = defaultHeightPixels;
 defaultHeight = max(minHeightPixels, defaultHeight);
 
 *Max = maxHeightPixels;
 *Default = defaultHeight;
 *Min = minHeightPixels;
 
 freeMem(tdbDefault);
 }	/* void wigFetchMinMaxPixelsWithCart()	*/
 
+static char *wigCheckBinaryOption(struct trackDb *tdb, char *Default,
+    char *notDefault, char *tdbString, char *secondTdbString)
 /*	A common operation for binary options (two values possible)
  *	check for trackDb.ra, then tdb->settings values
  *	return one of the two possibilities if found
  *	(the tdbString and secondTdbString are a result of
  *		early naming conventions changing over time resulting in
  *		two possible names for the same thing ...)
  */
-static char *wigCheckBinaryOption(struct trackDb *tdb, char *Default,
-    char *notDefault, char *tdbString, char *secondTdbString)
 {
 char *tdbDefault = trackDbSettingClosestToHomeOrDefault(tdb, tdbString, "NONE");
 char *ret;
 
 ret = Default;	/* the answer, unless found to be otherwise	*/
 
 if (sameWord("NONE",tdbDefault) && (secondTdbString != (char *)NULL))
     tdbDefault = trackDbSettingClosestToHomeOrDefault(tdb, secondTdbString, "NONE");
 
 if (differentWord("NONE",tdbDefault))
     {
     if (differentWord(Default,tdbDefault))
     	ret = notDefault;
     }
 else
@@ -394,107 +394,107 @@
 		ret = notDefault;
 	    }
 	else if (secondTdbString != (char *)NULL)
 	    {
 	    if ((hel = hashLookup(tdb->settingsHash, secondTdbString)) != NULL)
 		{
 		if (differentWord(Default,(char *)hel->val))
 		    ret = notDefault;
 		}
 	    }
 	}
     }
 return(cloneString(ret));
 }
 
-/*	transformFunc - none by default **********************************/
 enum wiggleGridOptEnum wigFetchTransformFuncWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name,char **optString)
+/*	transformFunc - none by default **********************************/
 {
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *transformFunc;
 enum wiggleTransformFuncEnum ret = wiggleTransformFuncNone;
 char * tdbDefault = trackDbSettingClosestToHome(tdb, TRANSFORMFUNC);
 
 transformFunc = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, TRANSFORMFUNC));
 
 if ((transformFunc == NULL) && (tdbDefault != NULL))
     transformFunc = cloneString(tdbDefault);
 
 if (optString && transformFunc)
     *optString = cloneString(transformFunc);
 
 if (transformFunc)
     {
     ret = wiggleTransformFuncToEnum(transformFunc);
     freeMem(transformFunc);
     }
 return(ret);
 }
 
-/*	alwaysZero - off by default **********************************/
 enum wiggleGridOptEnum wigFetchAlwaysZeroWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name,char **optString)
+/*	alwaysZero - off by default **********************************/
 {
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *alwaysZero;
 enum wiggleAlwaysZeroEnum ret = wiggleAlwaysZeroOff;
 char * tdbDefault = trackDbSettingClosestToHome(tdb, ALWAYSZERO);
 
 alwaysZero = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, ALWAYSZERO));
 
 if ((alwaysZero == NULL) && (tdbDefault != NULL))
     alwaysZero = cloneString(tdbDefault);
 
 if (optString && alwaysZero)
     *optString = cloneString(alwaysZero);
 
 if (alwaysZero)
     {
     ret = wiggleAlwaysZeroToEnum(alwaysZero);
     freeMem(alwaysZero);
     }
 return(ret);
 }
 
-/*	horizontalGrid - off by default **********************************/
 enum wiggleGridOptEnum wigFetchHorizontalGridWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name,char **optString)
+/*	horizontalGrid - off by default **********************************/
 {
 char *Default = wiggleGridEnumToString(wiggleHorizontalGridOff);
 char *notDefault = wiggleGridEnumToString(wiggleHorizontalGridOn);
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *horizontalGrid = NULL;
 enum wiggleGridOptEnum ret;
 
 horizontalGrid = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, HORIZGRID));
 
 if (!horizontalGrid)	/*	if it is NULL	*/
     horizontalGrid = wigCheckBinaryOption(tdb,Default,notDefault,GRIDDEFAULT,
 	HORIZGRID);
 
 if (optString)
     *optString = cloneString(horizontalGrid);
 
 ret = wiggleGridStringToEnum(horizontalGrid);
 freeMem(horizontalGrid);
 return(ret);
 }	/*	enum wiggleGridOptEnum wigFetchHorizontalGridWithCart()	*/
 
-/******	autoScale - off by default ***************************************/
 enum wiggleScaleOptEnum wigFetchAutoScaleWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name, char **optString)
+/******	autoScale - off by default ***************************************/
 {
 char *autoString = wiggleScaleEnumToString(wiggleScaleAuto);
 char *manualString = wiggleScaleEnumToString(wiggleScaleManual);
 char *Default = manualString;
 char *notDefault = autoString;
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *autoScale = NULL;
 enum wiggleScaleOptEnum ret;
 
 
 autoScale = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, AUTOSCALE));
 
 if (!autoScale)	/*	if nothing from the Cart, check trackDb/settings */
     {
     /*	It may be the autoScale=on/off situation from custom tracks */
@@ -511,57 +511,57 @@
 		AUTOSCALEDEFAULT, AUTOSCALE);
 	else
 	    autoScale = wigCheckBinaryOption(tdb,Default,notDefault,
 		AUTOSCALEDEFAULT, AUTOSCALE);
 	}
     }
 
 if (optString)
     *optString = cloneString(autoScale);
 
 ret = wiggleScaleStringToEnum(autoScale);
 freeMem(autoScale);
 return(ret);
 }	/*	enum wiggleScaleOptEnum wigFetchAutoScaleWithCart()	*/
 
-/******	graphType - line(points) or bar graph *****************************/
 enum wiggleGraphOptEnum wigFetchGraphTypeWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name, char **optString)
+/******	graphType - line(points) or bar graph *****************************/
 {
 char *Default = wiggleGraphEnumToString(wiggleGraphBar);
 char *notDefault = wiggleGraphEnumToString(wiggleGraphPoints);
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *graphType = NULL;
 enum wiggleGraphOptEnum ret;
 
 graphType = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, LINEBAR));
 
 if (!graphType)	/*	if nothing from the Cart, check trackDb/settings */
     graphType = wigCheckBinaryOption(tdb,Default,notDefault,GRAPHTYPEDEFAULT,
 	GRAPHTYPE);
 
 if (optString)
     *optString = cloneString(graphType);
 
 ret = wiggleGraphStringToEnum(graphType);
 freeMem(graphType);
 return(ret);
 }	/*	enum wiggleGraphOptEnum wigFetchGraphTypeWithCart()	*/
 
-/******	windowingFunction - Whiskers by default **************************/
 enum wiggleWindowingEnum wigFetchWindowingFunctionWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name, char **optString)
+/******	windowingFunction - Whiskers by default **************************/
 {
 char *Default = wiggleWindowingEnumToString(wiggleWindowingWhiskers);
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *windowingFunction = NULL;
 enum wiggleWindowingEnum ret;
 
 windowingFunction = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, WINDOWINGFUNCTION));
 
 /*	If windowingFunction is a string, it came from the cart, otherwise
  *	see if it is specified in the trackDb option, finally
  *	return the default.
  */
 if (!windowingFunction)
     {
     char * tdbDefault =
@@ -586,33 +586,33 @@
 		    freeMem(windowingFunction);
 		    windowingFunction = cloneString((char *)hel->val);
 		    }
 	    }
 	}
     }
 
 if (optString)
     *optString = cloneString(windowingFunction);
 
 ret = wiggleWindowingStringToEnum(windowingFunction);
 freeMem(windowingFunction);
 return(ret);
 }	/*	enum wiggleWindowingEnum wigFetchWindowingFunctionWithCart() */
 
-/******	smoothingWindow - OFF by default **************************/
 enum wiggleSmoothingEnum wigFetchSmoothingWindowWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name, char **optString)
+/******	smoothingWindow - OFF by default **************************/
 {
 char * Default = wiggleSmoothingEnumToString(wiggleSmoothingOff);
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char * smoothingWindow = NULL;
 enum wiggleSmoothingEnum ret;
 
 smoothingWindow = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, SMOOTHINGWINDOW));
 
 if (!smoothingWindow) /* if nothing from the Cart, check trackDb/settings */
     {
     char * tdbDefault =
 	trackDbSettingClosestToHomeOrDefault(tdb, SMOOTHINGWINDOW, Default);
 
 
     if (differentWord(Default,tdbDefault))
@@ -633,60 +633,60 @@
 		    freeMem(smoothingWindow);
 		    smoothingWindow = cloneString((char *)hel->val);
 		    }
 	    }
 	}
     }
 
 if (optString)
     *optString = cloneString(smoothingWindow);
 
 ret = wiggleSmoothingStringToEnum(smoothingWindow);
 freeMem(smoothingWindow);
 return(ret);
 }	/*	enum wiggleSmoothingEnum wigFetchSmoothingWindowWithCart()	*/
 
-/*	yLineMark - off by default **********************************/
 enum wiggleYLineMarkEnum wigFetchYLineMarkWithCart(struct cart *theCart,
     struct trackDb *tdb, char *name, char **optString)
+/*	yLineMark - off by default **********************************/
 {
 char *Default = wiggleYLineMarkEnumToString(wiggleYLineMarkOff);
 char *notDefault = wiggleYLineMarkEnumToString(wiggleYLineMarkOn);
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *yLineMark = NULL;
 enum wiggleYLineMarkEnum ret;
 
 yLineMark = cloneString(cartOptionalStringClosestToHome(theCart, tdb, compositeLevel, YLINEONOFF));
 
 if (!yLineMark)	/*	if nothing from the Cart, check trackDb/settings */
     yLineMark = wigCheckBinaryOption(tdb,Default,notDefault,YLINEONOFF,
 	(char *)NULL);
 
 if (optString)
     *optString = cloneString(yLineMark);
 
 ret = wiggleYLineMarkStringToEnum(yLineMark);
 freeMem(yLineMark);
 return(ret);
 }	/*	enum wiggleYLineMarkEnum wigFetchYLineMarkWithCart()	*/
 
+void wigFetchYLineMarkValueWithCart(struct cart *theCart,struct trackDb *tdb, char *name, double *tDbYMark )
 /*	y= marker line value
  *	User requested value is defined in the cart
  *	A Default value can be defined as
  *		yLineMark declaration from trackDb
  *****************************************************************************/
-void wigFetchYLineMarkValueWithCart(struct cart *theCart,struct trackDb *tdb, char *name, double *tDbYMark )
 {
 boolean compositeLevel = isNameAtCompositeLevel(tdb,name);
 char *yLineMarkValue = NULL;  /*	string from cart	*/
 double yLineValue;   /*	value from cart or trackDb */
 char * tdbDefault = cloneString(
     trackDbSettingClosestToHomeOrDefault(tdb, YLINEMARK, "NONE") );
 
 if (sameWord("NONE",tdbDefault))
     {
     struct hashEl *hel;
     /*	no yLineMark from trackDb, maybe it is in tdb->settings
      *	(custom tracks keep settings here)
      */
     if ((tdb->settings != (char *)NULL) &&
 	(tdb->settingsHash != (struct hash *)NULL))
@@ -707,30 +707,45 @@
 
 /*	if yLineMarkValue is non-Null, it is the requested value 	*/
 if (yLineMarkValue)
     yLineValue = atof(yLineMarkValue);
 else /*    See if a default line is specified in the trackDb.ra file */
     if (differentWord("NONE",tdbDefault))
 	yLineValue = atof(tdbDefault);
 
 /*	If possible to return	*/
 if (tDbYMark)
 	*tDbYMark = yLineValue;
 
 freeMem(tdbDefault);
 }	/*	void wigFetchYLineMarkValueWithCart()	*/
 
+void wigFetchMinMaxLimitsWithCart(struct cart *theCart, struct trackDb *tdb, char *name,
+    double *min, double *max,double *tDbMin, double *tDbMax)
 /*****************************************************************************
  *	Min, Max Y viewing limits
  *	Absolute limits are defined by minLimit, maxLimit in the trackDb
  *		default to 0 and 1000 if not present
  *	User requested limits are defined in the cart
  *	Default opening display limits are optionally defined with the
  *		defaultViewLimits declaration from trackDb
  *		or viewLimits from custom tracks
  *		(both identifiers work from either custom or trackDb)
  *****************************************************************************/
-void wigFetchMinMaxLimitsWithCart(struct cart *theCart, struct trackDb *tdb, char *name,
-    double *min, double *max,double *tDbMin, double *tDbMax)
 {
 wigFetchMinMaxYWithCart(theCart,tdb,name,min,max,tDbMin,tDbMax,0,NULL);
 }	/*	void wigFetchMinMaxYWithCart()	*/
+
+char *wigFetchAggregateValWithCart(struct cart *cart, struct trackDb *tdb)
+/* Return aggregate value for track. */
+{
+return cartOrTdbString(cart, tdb, "aggregate", WIG_AGGREGATE_TRANSPARENT);
+}
+
+boolean wigIsOverlayTypeAggregate(char *aggregate)
+/* Return TRUE if aggregater type is one of the overlay ones. */
+{
+if (aggregate == NULL)
+    return FALSE;
+return differentString(aggregate, WIG_AGGREGATE_NONE);
+}
+