src/hg/hgTracks/imageV2.c 1.4
1.4 2009/07/07 16:40:46 tdreszer
Very minor work towards making the imgBox portal. Mostly just want to check in some format changes before too much dust gathers
Index: src/hg/hgTracks/imageV2.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/imageV2.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 4 -r1.3 -r1.4
--- src/hg/hgTracks/imageV2.c 29 Jun 2009 18:15:03 -0000 1.3
+++ src/hg/hgTracks/imageV2.c 7 Jul 2009 16:40:46 -0000 1.4
@@ -1,49 +1,9 @@
-/* hgTracks - Human Genome browser main cgi script. */
+/* imageV2 - API for creating the image V2 features. */
#include "common.h"
-#include "hCommon.h"
-#include "linefile.h"
-#include "portable.h"
-#include "memalloc.h"
-#include "localmem.h"
-#include "obscure.h"
-#include "dystring.h"
-#include "hash.h"
-#include "jksql.h"
-#include "gfxPoly.h"
-#include "memgfx.h"
-#include "hvGfx.h"
-#include "psGfx.h"
-#include "cheapcgi.h"
#include "hPrint.h"
-#include "htmshell.h"
-#include "cart.h"
-#include "hdb.h"
#include "hui.h"
-#include "hgFind.h"
-#include "hgTracks.h"
-#include "trashDir.h"
-#include "grp.h"
-#include "versionInfo.h"
-#include "web.h"
-#include "cds.h"
-#include "cutterTrack.h"
-#include "wikiTrack.h"
-#include "ctgPos.h"
-#include "bed.h"
-#include "bigBed.h"
-#include "bedCart.h"
-#include "customTrack.h"
-#include "cytoBand.h"
-#include "ensFace.h"
-#include "liftOver.h"
-#include "pcrResult.h"
-#include "wikiLink.h"
#include "jsHelper.h"
-#include "mafTrack.h"
-#include "hgConfig.h"
-#include "encode.h"
-#include "agpFrag.h"
#include "imageV2.h"
static char const rcsid[] = "$Id$";
@@ -55,58 +15,17 @@
//struct mapItem *curMapItem = NULL; // Make this global for now to avoid huge rewrite
//#define IMAGEv2_UI
#ifdef IMAGEv2_UI
+/////////////////////////
// IMAGEv2
-// The new way to do images
-// Terms:
-// "image box": The new version of the image on the html page. It is a table with rows that contain tracks which are made up of parts of images.
-// "imgBox": The C struct that contains all information to render the image box on the html page.
-// "imgTbl": The HTML structure that contains individual track images. The javascript client controls the imgTbl.
-// Thus cgi knows imgBox while html/js knows imgTbl.
-// "image": A single gif. An image may contain mutilple tracks.
-// Even as a single track and image may contain a data image, sideLabel and centerLabel
-// "map" or "mapSet": The image map for providing links to items in a data image.
-// An image and map are a 1 to 1 pair and pixel coordinates are alway image relative.
-// "slice" or "imgSlice": The cgi concept of the portion of an image that is sent to the html/js side.
-// Thus, if we are sending a 3X sized image, the "slice" spans the entire 3X.
-// Frequently a subset of an image, but possibly the whole image.
-// Even if the image is of a single track, it might still be cut into data image, sideLabel and centerLabel slices.
-// "sliceMap": The portion of a map that belongs to a slice. The pixel coordinates are always image relative, not sice relative.
-// "portal" or "imgPortal": The html/js concept of the portion of a slice that is visible in the browser.
-// Thus, if we are sending a 3X sized data image slice, the "portal" seen in the browser spans only 1X.
-// Frequently a subset of a slice, but possibly the whole image slice.
-// "imgTrack" or track image: The cgi side whole shabang for rendering one track.
-// It contains track specific information and three slices: data, sideLabel and centerLabel
-// The imgBox contains N imgTracks. Typically an ajax/JSON request gets a single imgTrack returned.
-// image box support: This can contain all the support variables that are global to the image box (like font size, box width, etc.).
-// At this point, lets not talk structure or cgi vs. html/js but leave this container as a concept that we know needs filling.
-// imgBox is the top level and contains all info to draw the image in HTML
-// - contains slList of all imgTrack structs shown
-// imgTrack contains all info to display one track/subtrack in the imgBox
-// - contains 3 imgSlice structs (data, centerLabel, sideLabel
-// imgSlice contains all info to display a portion of an image file
-// - contains 1 image struct
-// image contains all information about an image file and associated map box
-//
-//////// Maps
-//struct mapItem // IMAGEv2: single map item in an image map.
-// {
-// struct mapItem *next; // slList
-// char *linkVar; // the get variables associated with the map link
-// char *title; // item title
-// int topLeftX; // in pixels relative to image
-// int topLeftY; // in pixels relative to image
-// int bottomRightX; // in pixels relative to image
-// int bottomRightY; // in pixels relative to image
-// };
-//struct mapSet // IMAGEv2: full map for image OR partial map for slice
-// {
-// char *name; // to point an image to a map in HTML
-// struct image *parentImg; // points to the image this map belongs to
-// char *linkRoot; // the common or static portion of the link for the entire image
-// struct mapItem *items; // list of items
-// };
+// The new way to do images: PLEASE REFER TO imageV2.h FOR A DETAILED DESCRIPTION
+/////////////////////////
+
+
+
+/////////////////////// Maps
+
struct mapSet *mapSetStart(char *name,struct image *img,char *linkRoot)
/* Starts a map (aka mapSet) which is the seet of links and image locations used in HTML.
Complete a map by adding items with mapItemAdd() */
{
@@ -225,9 +149,9 @@
}
}
return TRUE;
}
-/* Tests the completeness and consistency of this imgTrack (not including slices) */
+
void mapSetFree(struct mapSet **pMap)
/* frees all memory (including items) assocated with a single mapSet */
{
if(pMap != NULL && *pMap != NULL)
@@ -243,18 +167,12 @@
*pMap = NULL;
}
}
-//////// Images
-//struct image // IMAGEv2: single image which may have multiple imgSlices focused on it
-// {
-// struct image *next; // slList (Not yet used)
-// char *file; // name of file that hold the image
-// char *title; // image wide title
-// int width; // in pixels
-// int height; // in pixels
-// struct mapSet *map; // map assocated with this image (may be NULL)
-// };
+
+
+/////////////////////// Images
+
struct image *imgCreate(char *gif,char *title,int width,int height)
/* Creates a single image container.
A map map be added with imgMapStart(),mapSetItemAdd() */
{
@@ -298,21 +219,12 @@
*pImg = NULL;
}
}
-//////// Slices
-//struct imgSlice // IMAGEv2: the portion of an image that is displayable for one track
-// {
-// struct imgSlice *next; // slList
-// enum sliceType type; // Type of slice (currently only 3)
-// struct image *parentImg;// the actual image/gif
-// char *title; // slice wide title
-// struct mapSet *map; // A slice specific map. It contains a subset of the img->map. Coordinates must be img relative NOT slice relative!
-// int width; // in pixels (differs from img->width if img contains sideLabel)
-// int height; // in pixels (differs from img->height if img contains centerLabel and/or multiple tracks)
-// int offsetX; // offset from left (when img->width > slice->width)
-// int offsetY; // offset from top (when img->height > slice->height)
-// };
+
+
+/////////////////////// Slices
+
struct imgSlice *sliceCreate(enum sliceType type,struct image *img,char *title,int width,int height,int offsetX,int offsetY)
/* Creates of a slice which is a portion of an image.
A slice specific map map be added with sliceMapStart(),mapSetItemAdd() */
{
@@ -393,9 +311,9 @@
char qualifiedName[128];
safef(qualifiedName,sizeof(qualifiedName),"%s_%s",sliceTypeToString(slice->type),name);
return mapSetUpdate(map,qualifiedName,slice->parentImg,linkRoot);
}
-/* Adds a slice specific map to a slice of an image. Map items can then be added to the returned pointer with mapSetItemAdd()*/
+
boolean sliceIsConsistent(struct imgSlice *slice,boolean verbose)
/* Test whether the slice and it's associated image and map are consistent with each other */
{
if (slice == NULL)
@@ -416,9 +334,9 @@
warn("slice(%s) has an invalid width %d (image width %d)",
sliceTypeToString(slice->type),slice->width,slice->parentImg->width);
return FALSE;
}
-if (slice->height == 0)
+if (slice->height == 0) // FIXME: This may be a temporary solution to empty data slices
{
//if (verbose)
// warn("slice(%s) has an invalid height %d (image height %d)",
// sliceTypeToString(slice->type),slice->height,slice->parentImg->height);
@@ -476,23 +395,12 @@
*pSlice = NULL;
}
}
-//////// imgTracks
-//struct imgTrack // IMAGEv2: imageBox conatins list of displayed imageTracks
-// {
-// struct imgTrack *next; // slList
-// struct trackDb *tdb; // trackDb entry (should this be struct track* entry?)
-// char *name; // It is possible to have an imgTrack without a tdb, but then it mist have a name
-// char *db; // Image for db (species) (assert imgTrack matches imgBox)
-// char *chrom; // Image for chrom (assert imgTrack matches imgBox)
-// int chromStart; // Image start (absolute, not portal position)
-// int chromEnd; // Image end (absolute, not portal position)
-// boolean plusStrand; // Image covers plus strand, not minus strand
-// boolean showCenterLabel; // Initially display center label? TODO: Isn't this redundent with vis?
-// enum trackVisibility vis; // Current visibility of track image
-// struct imgSlice *slices; // Currently there should be three slices for every track: data, centerLabel, sideLabel
-// };
+
+
+/////////////////////// imgTracks
+
struct imgTrack *imgTrackStart(struct trackDb *tdb,char *name,char *db,char *chrom,int chromStart,int chromEnd,boolean plusStrand,boolean showCenterLabel,enum trackVisibility vis,int order)
/* Starts an image track which will contain all image slices needed to render one track
Must completed by adding slices with imgTrackAddSlice() */
{
@@ -586,9 +500,10 @@
struct mapSet *imgTrackGetMapByType(struct imgTrack *imgTrack,enum sliceType type)
/* Gets the map assocated with a specific slice belonging to the imgTrack */
{
-struct imgSlice *slice = imgTrackSliceGetByType(imgTrack,type); if(slice == NULL)
+struct imgSlice *slice = imgTrackSliceGetByType(imgTrack,type);
+if(slice == NULL)
return NULL;
return sliceGetMap(slice,FALSE); // Map could belong to image or could be slice specific
}
@@ -653,9 +568,9 @@
warn("imgTrack(%s) has bad slice",name);
return FALSE;
}
}
-// This is not a requirement as the data portion could be empty (height==0)
+// This is not a requirement as the data portion could be empty (height==0) FIXME This still needs to be properly resolved
//if(!found[isData])
// {
// if (verbose)
// warn("imgTrack(%s) has no DATA slice.",name);
@@ -679,26 +595,12 @@
}
}
-//////// Image Box
-//struct imgBox // IMAGEv2: imageBox conatins all the definitions to draw an image in hgTracks
-// {
-// char *db; // database (species)
-// char *chrom; // chrom
-// int chromStart; // imageBox displays this position (though images may cover more)
-// int chromEnd; // imageBox displays this position (though images may cover more)
-// boolean plusStrand; // imgBox currently shows plus strand, not minus strand
-// boolean showSideLabel; // Initially display side label? (use 'plusStrand' for left/right)
-// struct image *images; // Contains all images for the imgBox. TEMPORARY: hgTracks creates it's current one image and I'll store it here
-// struct image *bgImg; // When track images are transparent, bgImage contains blue lines that are db coordinate granularity.
-// int portalStart; // initial visible portal within html image table (db coodinates) [May be obsoleted by js client]
-// int portalEnd; // initial visible portal within html image table (db coodinates) [May be obsoleted by js client]
-// int portalWidth; // in pixels (note that width in visible position within image position (db coodinates)
-// // TODO: I am certain there are more details needed
-// struct imgTrack *imgTracks; // slList of all images to display
-// };
-struct imgBox *imgBoxStart(char *db,char *chrom,int chromStart,int chromEnd,boolean plusStrand,boolean showSideLabel,int portalWidth)
+
+/////////////////////// Image Box
+
+struct imgBox *imgBoxStart(char *db,char *chrom,int chromStart,int chromEnd,boolean plusStrand,boolean showSideLabel,int width)
/* Starts an imgBox which should contain all info needed to draw the hgTracks image with multiple tracks
The image box must be completed using imgBoxImageAdd() and imgBoxTrackAdd() */
{
struct imgBox * imgBox; // gifTn.forHtml, pixWidth, mapName
@@ -712,18 +614,35 @@
imgBox->plusStrand = plusStrand;
imgBox->showSideLabel = showSideLabel;
imgBox->images = NULL;
imgBox->bgImg = NULL;
-int oneThird = (chromEnd - chromStart)/3; // TODO: Currently defaulting to 1/3 of image width
-imgBox->portalStart = chromStart + oneThird;
-imgBox->portalEnd = chromEnd - oneThird;
-imgBox->portalWidth = portalWidth;
-// images are added with imgBoxImageAdd()
-// imgTracks are added with imgBoxTrackAdd()
-// Fill in imgTracks with slices as the map is created.
+imgBox->width = width;
+imgBox->showPortal = FALSE;
+//int oneThird = (chromEnd - chromStart)/3; // TODO: Currently defaulting to 1/3 of image width
+imgBox->portalStart = chromStart;// + oneThird;
+imgBox->portalEnd = chromEnd;// - oneThird;
+imgBox->portalWidth = chromEnd - chromStart;
+imgBox->basesPerPixel = ((double)imgBox->chromEnd - imgBox->chromStart)/imgBox->width; // FIXME: Shouldn't ignore sideLabel
return imgBox;
}
+boolean imgBoxDefinePortal(struct imgBox *imgBox,int portalStart,int portalEnd,int portalWidthInPixels)
+/* Defines the portal of the imgBox. The portal is the initial viewable region when dragScroll is being used.
+ returns TRUE if the portal is a proper subset of the imgBox as currently defined. */
+{
+if(portalStart < imgBox->chromStart || portalStart >= imgBox->chromEnd
+|| portalEnd <= imgBox->chromStart || portalEnd > imgBox->chromEnd)
+ return FALSE;
+if(portalWidthInPixels == 0 || portalWidthInPixels > imgBox->width)
+ return FALSE;
+imgBox->portalStart = portalStart;
+imgBox->portalEnd = portalEnd;
+imgBox->portalWidth = portalEnd - portalStart;
+imgBox->basesPerPixel = ((double)imgBox->chromEnd - imgBox->chromStart)/portalWidthInPixels;
+imgBox->showPortal = TRUE;
+return imgBox->showPortal;
+}
+
struct image *imgBoxImageAdd(struct imgBox *imgBox,char *gif,char *title,int width,int height,boolean backGround)
/* Adds an image to an imgBox. The image may be extended with imgMapStart(),mapSetItemAdd() */
{
struct image *img = imgCreate(gif,title,width,height);
@@ -750,8 +670,10 @@
return img;
}
return NULL;
}
+
+// TODO: Will we need this?
//boolean imgBoxImageRemove(struct imgBox *imgBox,struct image *img)
//{
//return slRemoveEl(&(imgBox->images),img);
//}
@@ -782,17 +706,21 @@
struct imgTrack *imgTrack = imgBoxTrackFind(imgBox,tdb,name);
if( imgTrack == NULL)
imgTrack = imgBoxTrackAdd(imgBox,tdb,name,vis,showCenterLabel,order);
return imgTrack;
-} struct imgTrack *imgBoxTrackUpdateOrAdd(struct imgBox *imgBox,struct trackDb *tdb,char *name,enum trackVisibility vis,boolean showCenterLabel,int order)
+}
+
+struct imgTrack *imgBoxTrackUpdateOrAdd(struct imgBox *imgBox,struct trackDb *tdb,char *name,enum trackVisibility vis,boolean showCenterLabel,int order)
/* Updates the imgTrack, or adds it if not found */
{
struct imgTrack *imgTrack = imgBoxTrackFind(imgBox,tdb,name);
if( imgTrack == NULL)
return imgBoxTrackAdd(imgBox,tdb,name,vis,showCenterLabel,order);
return imgTrackUpdate(imgTrack,tdb,name,imgBox->db,imgBox->chrom,imgBox->chromStart,imgBox->chromEnd,imgBox->plusStrand,showCenterLabel,vis,order);
}
+
+// TODO: Will we need this?
//boolean imgBoxTrackRemove(struct imgBox *imgBox,struct imgTrack *imgTrack)
//{
//return slRemoveEl(&(imgBox->imgTracks),imgTrack);
//}
@@ -935,9 +863,12 @@
*pImgBox = NULL;
}
}
-// Now the real work:
+
+
+/////////////////////// imageV2 UI API
+
void imageMapDraw(struct mapSet *map,char *name)
/* writes an image map as HTML */
{
//warn("Drawing map_%s %s",name,(map == NULL?"map is NULL":map->items == NULL?"map->items is NULL":"Should draw!"));
@@ -1016,17 +948,17 @@
hPrintf("<style type='text/css'>\n");
hPrintf(".trDrag {opacity:0.4; padding:1px; background-color:red;}\n");// outline:red solid thin;}\n"); // opacity for FF, padding/bg for IE
hPrintf(".dragHandle {cursor: s-resize;}\n");
hPrintf("div.dragZoom { cursor: text; }\n");
-//hPrintf("div.panDiv { width: %dpx; overflow: hidden; }\n",imgBox->portalWidth);
-//hPrintf("div.panDivScroller { width: %dpx; overflow: hidden; }\n",imgBox->portalWidth);
-//hPrintf("img.panImg { position: relative; left: -%dpx; top: 0px; border: 0; }\n",imgBox->portalWidth);
-//hPrintf("img.centerLab { position: relative; left: -%dpx; top: 0px; border: 0; }\n",imgBox->portalWidth);
+//hPrintf("div.panDiv { width: %dpx; overflow: hidden; }\n",imgBox->width);
+//hPrintf("div.panDivScroller { width: %dpx; overflow: hidden; }\n",imgBox->width);
+//hPrintf("img.panImg { position: relative; left: -%dpx; top: 0px; border: 0; }\n",imgBox->width);
+//hPrintf("img.centerLab { position: relative; left: -%dpx; top: 0px; border: 0; }\n",imgBox->width);
//hPrintf("img.sideLab { border: 0; }\n");
hPrintf("</style>\n");
hPrintf("<TABLE id='imgTbl' border=0 cellspacing=0 cellpadding=0");
-hPrintf(" width=%d",imgBox->portalWidth);
+hPrintf(" width=%d",imgBox->width);
hPrintf(" class='tableWithDragAndDrop' style='border:1px solid blue;border-collapse:separate'");
hPrintf(">\n");
struct imgTrack *imgTrack = imgBox->imgTracks;
@@ -1044,9 +976,9 @@
sliceAndMapDraw(imgTrackSliceGetByType(imgTrack,isSide), name);
hPrintf("</TD>");
}
// Main/Data image region
- hPrintf("<TD id='td_data_%s' width=%d>\n", trackName, imgBox->portalWidth);
+ hPrintf("<TD id='td_data_%s' width=%d>\n", trackName, imgBox->width);
hPrintf("<input TYPE=HIDDEN name='%s_%s' value='%d'>\n",trackName,IMG_ORDER_VAR,imgTrack->order);
// centerLabel
if(imgTrack->showCenterLabel)
{