59c4b5446987113a20a88c2860c469ae14dcc0b9 larrym Thu Jul 28 21:39:44 2011 -0700 switch to using in-memory json; refactor trackDbJson so it is part of hgTracks global in the client (redmine #4550) diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c index 1e972b0..ad8784e 100644 --- src/hg/hgTracks/hgTracks.c +++ src/hg/hgTracks/hgTracks.c @@ -92,31 +92,31 @@ "hide", "dense", "full" }; char *protDbName; /* Name of proteome database for this genome. */ #define MAX_CONTROL_COLUMNS 6 #define LOW 1 #define MEDIUM 2 #define BRIGHT 3 #define MAXCHAINS 50000000 boolean hgDebug = FALSE; /* Activate debugging code. Set to true by hgDebug=on in command line*/ int imagePixelHeight = 0; boolean dragZooming = TRUE; struct hash *oldVars = NULL; -struct hash *jsVarsHash = NULL; +struct jsonHashElement *jsonForClient = NULL; boolean hideControls = FALSE; /* Hide all controls? */ boolean trackImgOnly = FALSE; /* caller wants just the track image and track table html */ boolean ideogramToo = FALSE; /* caller wants the ideoGram (when requesting just one track) */ /* Structure returned from findGenomePos. * We use this to to expand any tracks to full * that were found to contain the searched-upon * position string */ struct hgPositions *hgp = NULL; /* Other global variables. */ struct trackHub *hubList = NULL; /* List of all relevant hubs. */ struct group *groupList = NULL; /* List of all tracks. */ char *browserName; /* Test, preview, or public browser */ @@ -2456,40 +2456,40 @@ { if(theImgBox) { // Set imgTrack in case any map items will be set sliceHeight = trackPlusLabelHeight(track, fontHeight); sliceOffsetY = y; curImgTrack = imgBoxTrackFind(theImgBox,track->tdb,NULL); } y = doTrackMap(track, hvg, y, fontHeight, trackPastTabX, trackPastTabWidth); } } /* Finish map. */ hPrintf("</MAP>\n"); -jsAddBoolean(jsVarsHash, "dragSelection", dragZooming); -jsAddBoolean(jsVarsHash, "inPlaceUpdate", IN_PLACE_UPDATE); +jsonHashAddBoolean(jsonForClient, "dragSelection", dragZooming); +jsonHashAddBoolean(jsonForClient, "inPlaceUpdate", IN_PLACE_UPDATE); if(rulerClickHeight) { - jsAddNumber(jsVarsHash, "rulerClickHeight", rulerClickHeight); + jsonHashAddNumber(jsonForClient, "rulerClickHeight", rulerClickHeight); } if(newWinWidth) { - jsAddNumber(jsVarsHash, "newWinWidth", newWinWidth); + jsonHashAddNumber(jsonForClient, "newWinWidth", newWinWidth); } /* Save out picture and tell html file about it. */ if(hvgSide != hvg) hvGfxClose(&hvgSide); hvGfxClose(&hvg); if(theImgBox) { imageBoxDraw(theImgBox); #ifdef IMAGEv2_DRAG_SCROLL // If a portal was established, then set the global dimensions back to the portal size if(imgBoxPortalDimensions(theImgBox,NULL,NULL,NULL,NULL,&winStart,&winEnd,&(tl.picWidth),NULL)) { pixWidth = tl.picWidth; winBaseCount = winEnd - winStart; @@ -4567,32 +4567,32 @@ zoomedToBaseLevel = (winBaseCount <= insideWidth / tl.mWidth); zoomedToCodonLevel = (ceil(winBaseCount/3) * tl.mWidth) <= insideWidth; zoomedToCdsColorLevel = (winBaseCount <= insideWidth*3); if (psOutput != NULL) { hPrintDisable(); hideControls = TRUE; withNextItemArrows = FALSE; withNextExonArrows = FALSE; hgFindMatches = NULL; } /* Tell browser where to go when they click on image. */ hPrintf("<FORM ACTION=\"%s\" NAME=\"TrackHeaderForm\" id=\"TrackHeaderForm\" METHOD=\"GET\">\n\n", hgTracksName()); -jsAddNumber(jsVarsHash, "insideX", insideX); -jsAddBoolean(jsVarsHash, "revCmplDisp", revCmplDisp); +jsonHashAddNumber(jsonForClient, "insideX", insideX); +jsonHashAddBoolean(jsonForClient, "revCmplDisp", revCmplDisp); #ifdef NEW_JQUERY hPrintf("<script type='text/javascript'>var newJQuery=true;</script>\n"); #else///ifndef NEW_JQUERY hPrintf("<script type='text/javascript'>var newJQuery=false;</script>\n"); #endif///ndef NEW_JQUERY if (!psOutput) cartSaveSession(cart); clearButtonJavascript = "document.TrackHeaderForm.position.value=''; document.getElementById('suggest').value='';"; /* See if want to include sequence search results. */ userSeqString = cartOptionalString(cart, "ss"); if (userSeqString && !ssFilesExist(userSeqString)) { userSeqString = NULL; cartRemove(cart, "ss"); @@ -4751,33 +4751,33 @@ #ifdef IMAGEv2_DRAG_SCROLL if(theImgBox) { // If a portal was established, then set the global dimensions back to the portal size if(imgBoxPortalDimensions(theImgBox,NULL,NULL,NULL,NULL,&winStart,&winEnd,&(tl.picWidth),NULL)) { winBaseCount = winEnd - winStart; insideWidth = tl.picWidth-gfxBorder-insideX; } } #endif//def IMAGEv2_DRAG_SCROLL /* Center everything from now on. */ hPrintf("<CENTER>\n"); // info for drag selection javascript -jsAddNumber(jsVarsHash, "winStart", winStart); -jsAddNumber(jsVarsHash, "winEnd", winEnd); -jsAddString(jsVarsHash, "chromName", chromName); +jsonHashAddNumber(jsonForClient, "winStart", winStart); +jsonHashAddNumber(jsonForClient, "winEnd", winEnd); +jsonHashAddString(jsonForClient, "chromName", chromName); if(trackImgOnly && !ideogramToo) { struct track *ideoTrack = chromIdeoTrack(trackList); if (ideoTrack) { ideoTrack->limitedVisSet = TRUE; ideoTrack->limitedVis = tvHide; /* Don't draw in main gif. */ } makeActiveImage(trackList, psOutput); fflush(stdout); return; // bail out b/c we are done } @@ -5863,31 +5863,31 @@ dragZooming = advancedJavascriptFeaturesEnabled(cart); /* Do main display. */ if (cartUsualBoolean(cart, "hgt.trackImgOnly", FALSE)) { trackImgOnly = TRUE; ideogramToo = cartUsualBoolean(cart, "hgt.ideogramToo", FALSE); hideControls = TRUE; withNextItemArrows = FALSE; withNextExonArrows = FALSE; hgFindMatches = NULL; // XXXX necessary ??? } hWrites(commonCssStyles()); -jsVarsHash = newHash(8); +jsonForClient = newJsonHash(newHash(8)); jsIncludeFile("jquery.js", NULL); jsIncludeFile("jquery-ui.js", NULL); jsIncludeFile("utils.js", NULL); jsIncludeFile("ajax.js", NULL); boolean searching = differentString(cartUsualString(cart, TRACK_SEARCH,"0"),"0"); if(dragZooming && !searching) { jsIncludeFile("jquery.imgareaselect.js", NULL); #ifndef NEW_JQUERY webIncludeResourceFile("autocomplete.css"); jsIncludeFile("jquery.autocomplete.js", NULL); #endif///ndef NEW_JQUERY } jsIncludeFile("autocomplete.js", NULL); jsIncludeFile("hgTracks.js", NULL); @@ -5982,22 +5982,28 @@ } else if (cartVarExists(cart, configShowEncodeGroups)) { /* currently not used */ cartRemove(cart, configShowEncodeGroups); struct grp *grp = NULL, *grps = hLoadGrps(database); for (grp = grps; grp != NULL; grp = grp->next) if (startsWith("encode", grp->name)) collapseGroup(grp->name, FALSE); configPageSetTrackVis(-2); } else { tracksDisplay(); } -if(hashNumEntries(jsVarsHash)) - { + +// XXXX debugging stuff +struct slRef *list = NULL; +jsonListAddNumber(&list, 666); +jsonListAddString(&list, "1,2,3"); +jsonHashAdd(jsonForClient, "testing", (struct jsonElement *) newJsonList(list)); +jsonHashAddDouble(jsonForClient, "float", expf(1)); + hPrintf("<script type='text/javascript'>\n"); - jsPrintHash(jsVarsHash, "hgTracks", 0); +jsonPrint((struct jsonElement *) jsonForClient, "hgTracks", 0); hPrintf("</script>\n"); - } + }