Changeset 4908


Ignore:
Timestamp:
Apr 28, 2009, 2:47:33 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1302: Overview plots and correction factor plots as extension

Location:
trunk
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/extensions/ExtensionsInvoker.java

    r4870 r4908  
    8080  }
    8181
     82  /**
     83    Get the number of enabled extensions in this invokation.
     84    Note that this number doesn't have to correspond to the actual
     85    number of actions since an extension may choose to create 0, 1 or
     86    more actions.
     87    @return The number of enabled extensions
     88    @since 2.12
     89  */
     90  public int getNumExtensions()
     91  {
     92    return contexts.size();
     93  }
     94 
    8295  /**
    8396    Create an iterator that iterates over all {@link Action}:s created
  • trunk/www/WEB-INF/extensions/core-extensions.xml

    r4870 r4908  
    6060    </description>
    6161  </extension-point>
     62
     63  <extension-point
     64    id="net.sf.basedb.clients.web.bioassayset.overviewplots"
     65    >
     66    <action-class>net.sf.basedb.clients.web.extensions.plot.OverviewPlotAction</action-class>
     67    <name>Bioassay set: Overview plots</name>
     68    <description>
     69      Extension point for overview plots for a bioassay set. The overview
     70      plots are usually one pre-defined plot per bioassay. For example,
     71      MA plots for 2-channel data. Extensions should provide OverviewPlotAction
     72      instances. The rendering is internal and generates one &lt;img&gt; tag
     73      for each plot. An extension is supposed to generate the image URL that
     74      leads to a servlet that creates the actual image. We recommend that
     75      images are cached. See the core plot servlet for details.
     76    </description>
     77  </extension-point>
    6278 
    6379  <extension-point
     
    88104  -->
    89105 
     106  <extension
     107    id="net.sf.basedb.clients.web.bioassayset.overviewplots.maplot"
     108    extends="net.sf.basedb.clients.web.bioassayset.overviewplots"
     109    >
     110    <index>1</index>
     111    <about>
     112      <name>MA/Correction factor plots</name>
     113      <description>
     114        Generates MA and correction factor plots for
     115        2-channel data.
     116      </description>
     117    </about>
     118    <action-factory>
     119      <factory-class>
     120        net.sf.basedb.clients.web.extensions.plot.MAPlotFactory
     121      </factory-class>
     122      <parameters>
     123        <width>400</width>
     124        <height>300</height>
     125        <plotServlet>/views/experiments/plotter/plot</plotServlet>
     126      </parameters>
     127    </action-factory>
     128  </extension>
     129 
    90130</extensions>
  • trunk/www/include/scripts/tabcontrol.js

    r4889 r4908  
    4141    if (checkRemembered)
    4242    {
    43       // TODO - this implementation only works well if there is a single tabcontrol per page
    44       // and if the page is in a frameset or was opened as a popup
    45       var theWindow = window.opener ? window.opener : window.top;
    46       var lastLocation = theWindow.lastRememberedTabLocation;
    47       var lastTabId = theWindow.lastRememberedTabId;
    48       var thisLocation = location.pathname;
    4943      var tabControl = document.getElementById(tabControlId);
    50       if ((lastLocation == thisLocation) && lastTabId && !tabControl.activeTab)
    51       {
    52         tabId = lastTabId;
     44      if (!tabControl.activeTab)
     45      {
     46        var theWindow = window.opener ? window.opener : window.top;
     47        var rememberedTabId = this.getRememberedTabId(theWindow, tabControlId);
     48        if (rememberedTabId) tabId = rememberedTabId
    5349      }
    5450    }
     
    112108    }
    113109    tabControl.activeTab = tab;
    114     theWindow.lastRememberedTabLocation = location.pathname;
    115     theWindow.lastRememberedTabId = tabId;
    116  
     110    this.rememberActiveTab(theWindow, tabControlId, tabId);
    117111    if (tabControl.activeContent != null)
    118112    {
     
    128122  }
    129123
     124  this.rememberActiveTab = function(window, tabControlId, tabId)
     125  {
     126    if (!window.rememberedTabs) window.rememberedTabs = new Array();
     127    var rememberedTabs = window.rememberedTabs;
     128    var thisLocation = location.pathname;
     129    if (!rememberedTabs[thisLocation]) rememberedTabs[thisLocation] = new Array();
     130    rememberedTabs[thisLocation][tabControlId] = tabId;
     131  }
     132 
     133  this.getRememberedTabId = function(window, tabControlId)
     134  {
     135    if (!window.rememberedTabs) return null;
     136    var rememberedTabs = window.rememberedTabs;
     137    var thisLocation = location.pathname;
     138    if (!rememberedTabs[thisLocation]) return null;
     139    return rememberedTabs[thisLocation][tabControlId];
     140  }
     141 
    130142  this.getActiveTabId = function(tabControlId)
    131143  {
  • trunk/www/views/experiments/bioassays/list_bioassays.jsp

    r4889 r4908  
    135135      guiContext, bioAssaySet);
    136136  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
     137  ExtensionsInvoker overviewPlotInvoker = ExtensionsControl.useExtensions(jspContext,
     138      "net.sf.basedb.clients.web.bioassayset.overviewplots");
    137139  %>
    138140  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
     
    174176    function switchTab(tabControlId, tabId)
    175177    {
    176       if (tabId == 'properties' || tabId == 'overviewplots' || tabId == 'cfplots' || tabId == 'annotations')
     178      if (tabId == 'properties' || tabId == 'overviewplots' || tabId == 'annotations')
    177179      {
    178180        location.href = '../bioassaysets/index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experiment.getId()%>&item_id=<%=bioAssaySetId%>&tab='+tabId;
     
    630632   
    631633    <t:tab id="overviewplots" title="Overview plots"
    632       visible="<%=hasDbSpots && rawDataType.getChannels() == 2%>" />
    633      
    634     <t:tab id="cfplots" title="Correction factor plots"
    635       visible="<%=hasDbSpots && rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>" />
     634      visible="<%=overviewPlotInvoker.getNumExtensions() > 0%>" />
    636635   
    637636    </t:tabcontrol>
  • trunk/www/views/experiments/bioassaysets/view_bioassayset.jsp

    r4889 r4908  
    6363  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
    6464  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
     65  import="net.sf.basedb.clients.web.extensions.plot.OverviewPlotAction"
     66  import="net.sf.basedb.clients.web.extensions.plot.PlotGenerator"
    6567  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     68  import="net.sf.basedb.util.extensions.ActionIterator"
    6669  import="java.util.Date"
    6770  import="java.util.Map"
    6871  import="java.util.Set"
    6972  import="java.util.List"
     73  import="java.util.Iterator"
    7074%>
    7175<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    143147  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
    144148  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, bioAssaySet);
    145   ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
     149  ExtensionsInvoker toolbarInvoker = ToolbarUtil.useExtensions(jspContext);
     150  ExtensionsInvoker overviewPlotInvoker = ExtensionsControl.useExtensions(jspContext,
     151      "net.sf.basedb.clients.web.bioassayset.overviewplots");
    146152  %>
    147153  <base:page title="<%=title%>">
     
    186192      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&experiment_id=<%=experimentId%>&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
    187193    }
    188     var imageQueue = new Array();
    189     var nextImage = 0;
    190     function addImage(imageId, url)
    191     {
    192       imageQueue[imageQueue.length] = imageId;
    193       var img = document.getElementById(imageId);
    194       img.realSrc = url;
    195     }
    196     function imageLoaded()
    197     {
    198       var imageId = imageQueue[nextImage];
    199       var img = document.getElementById(imageId);
    200       img.src = img.realImg.src;
    201       nextImage++;
    202       setTimeout('loadNextImage()', 100);
    203     }
    204     function loadNextImage()
    205     {
    206       if (imageQueue.length > nextImage)
    207       {
    208         var imageId = imageQueue[nextImage];
     194
     195    function ImageQueue(baseId)
     196    {
     197      this.images = new Array();
     198      this.nextImage = 0;
     199
     200      this.addImage = function(imageId, url)
     201      {
     202        this.images[this.images.length] = imageId;
     203        var img = document.getElementById(imageId);
     204        img.realSrc = url;
     205      }
     206
     207      this.loadNextImage = function()
     208      {
     209        if (this.images.length <= this.nextImage) return;
     210        var imageId = this.images[this.nextImage];
    209211        var img = document.getElementById(imageId);
    210212        img.src = '../../../images/plot_generating_400x300.gif';
    211213        img.realImg = new Image();
    212         img.realImg.onload = imageLoaded;
     214        img.realImg.onload = function()
     215        {
     216          img.src = img.realImg.src;
     217          setTimeout('loadNextImage()', 100);
     218        };
    213219        img.realImg.src = img.realSrc;
    214       }
     220        this.nextImage++;
     221      }
     222    }
     223   
     224    var plotQueue = new Array();
     225    var currentQueue = null;
     226    function registerImage(baseId, plotId, url)
     227    {
     228      if (!currentQueue) currentQueue = baseId;
     229      var imageQueue = plotQueue[baseId];
     230      if (!imageQueue)
     231      {
     232        imageQueue = new ImageQueue(baseId);
     233        plotQueue[baseId] = imageQueue;
     234      }
     235      var imageId = baseId + '.' + plotId;
     236      imageQueue.addImage(imageId, url);
     237    }
     238    function switchOverview(tabControlId, tabId)
     239    {
     240      currentQueue = tabId;
     241      TabControl.setActiveTab(tabControlId, tabId);
     242      loadNextImage();
     243    }
     244    function loadNextImage()
     245    {
     246      var imageQueue = plotQueue[currentQueue];
     247      if (imageQueue) imageQueue.loadNextImage();
    215248    }
    216249    </script>
     
    219252      border: 1px solid #666666;
    220253      background-image: url('../../../images/plot_empty_400x300.png');
     254      margin: 2px;
    221255    }
    222256    </style>
     
    313347        visible="<%=pluginCount.containsKey(Plugin.MainType.ANALYZE)%>"
    314348      />
    315       <ext:render extensions="<%=invoker%>" context="<%=jspContext%>"
     349      <ext:render extensions="<%=toolbarInvoker%>" context="<%=jspContext%>"
    316350        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
    317351      <tbl:button
     
    518552     
    519553      <t:tab id="overviewplots" title="Overview plots"
    520         tooltip="MA-plots of each bioassay in this bioassay set"
    521         visible="<%=hasDbSpots && rawDataType.getChannels() == 2%>">
    522       <%
    523       if ("overviewplots".equals(tabId))
    524       {
    525         String M = HTML.urlEncode("log2(ch(1) / ch(2))");
    526         String A = HTML.urlEncode("log(ch(1) * ch(2)) / 2");
    527         String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2");
    528         String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)");
    529         String filter = HTML.urlEncode("ch(1) > 0 && ch(2) > 0");
    530         ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays();
    531         bioAssayQuery.order(Orders.asc(Hql.property("name")));
    532         StringBuilder script = new StringBuilder();
    533         for (BioAssay bioAssay : bioAssayQuery.list(dc))
     554        tooltip="Predefined plots for all bioassays in this bioassay set"
     555        visible="<%=overviewPlotInvoker.getNumExtensions() > 0%>">
     556        <%
     557        if ("overviewplots".equals(tabId))
    534558        {
    535           String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
    536           url += "&type=scatter&width=400&height=300";
    537           url += "&cache=overview/bioassay." + bioAssay.getId() + "/maplot.png";
    538           url += "&x="+A+"&y="+M+"&xLabel="+xLabel+"&yLabel="+yLabel;
    539           url += "&filter="+filter;
    540           url += "&title="+HTML.urlEncode(bioAssay.getName());
    541           script.append("addImage('MA").append(bioAssay.getId()).append("','").
    542               append(url).append("');\n");
     559          ActionIterator<OverviewPlotAction> plots = overviewPlotInvoker.iterate();
     560          StringBuilder script = new StringBuilder();
    543561          %>
    544           <img id="MA<%=bioAssay.getId()%>"
    545             src="../../../images/transparent_pixel.gif"
    546             width="400" height="300"
    547             alt="MA-plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"
    548             class="plot"
    549             >
     562          <t:tabcontrol id="overviewplots" switch="switchOverview">
     563          <%
     564          while (plots.hasNext())
     565          {
     566            OverviewPlotAction action = plots.next();
     567            String baseId = plots.getExtension().getId() + "." + action.getId();
     568            %>
     569            <t:tab
     570              tooltip="<%=action.getDescription() %>"
     571              title="<%=action.getTitle()%>"
     572              id="<%=baseId%>"
     573              >
     574              <%
     575              for (PlotGenerator generator : action.getPlotGenerators())
     576              {
     577                String plotId = generator.getId();
     578                script.append("registerImage('").append(baseId).append("','")
     579                    .append(plotId).append("','")
     580                    .append(HTML.javaScriptEncode(generator.getUrl())).append("');\n");
     581                %><img id="<%=baseId + "." + plotId%>"
     582                  class="plot"
     583                  src="../../../images/transparent_pixel.gif"
     584                  width="<%=generator.getWidth()%>"
     585                  height="<%=generator.getHeight()%>"
     586                  alt="<%=HTML.encodeTags(generator.getTitle())%>"
     587                >&#8203;&#8203;<%
     588              }
     589              %>
     590            </t:tab>
     591            <%
     592          }
     593          %>
     594          </t:tabcontrol>
     595          <script language="JavaScript">
     596          <%=script%>
     597          </script>
    550598          <%
    551599        }
    552600        %>
    553         <script language="JavaScript">
    554         <%=script%>
    555         </script>
    556         <%
    557       }
    558       %>
    559601      </t:tab>
    560      
    561       <t:tab id="cfplots" title="Correction factor plots"
    562         tooltip="MA-plot of the parent bioassays together with a correction factor for each spot in the current bioassayset."
    563         visible="<%=hasDbSpots && rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>">
    564       <%
    565       if ("cfplots".equals(tabId))
    566       {
    567         ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays();
    568         bioAssayQuery.order(Orders.asc(Hql.property("name")));
    569         String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2");
    570         String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)");
    571         StringBuilder script = new StringBuilder();
    572         for (BioAssay bioAssay : bioAssayQuery.list(dc))
    573         {
    574           String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
    575           url += "&type=cfplot&width=400&height=300";
    576           url += "&cache=overview/bioassay." + bioAssay.getId() + "/cfplot.png";
    577           url += "&xLabel="+xLabel+"&yLabel="+yLabel;
    578           url += "&title="+HTML.urlEncode(bioAssay.getName());
    579           script.append("addImage('CF").append(bioAssay.getId()).append("','").
    580           append(url).append("');\n");
    581           %>
    582           <img id="CF<%=bioAssay.getId()%>"
    583             src="../../../images/transparent_pixel.gif"
    584             width="400" height="300"
    585             alt="Correction factor plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"
    586             class="plot"
    587             >
    588           <%
    589         }
    590         %>
    591         <script language="JavaScript">
    592         <%=script%>
    593         </script>
    594         <%
    595       }
    596       %>
    597       </t:tab>
    598 
    599602      </t:tabcontrol>
    600603
  • trunk/www/views/experiments/spotdata/list_spotdata.jsp

    r4889 r4908  
    127127    guiContext, bioAssay == null ? bioAssaySet : bioAssay);
    128128  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
     129  ExtensionsInvoker overviewPlotInvoker = bioAssay != null ?
     130    null : ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.bioassayset.overviewplots");
    129131  %>
    130132  <base:page title="<%=title%>">
     
    165167        location.href = '../bioassaysets/index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=bioAssaySetId%>&tab=annotations';
    166168      }
    167       else if (tabId == 'overviewplots' || tabId == 'cfplots')
     169      else if (tabId == 'overviewplots')
    168170      {
    169171        location.href = '../bioassaysets/index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experimentId%>&item_id=<%=bioAssaySetId%>&tab='+tabId;
     
    430432    </t:tab>
    431433
    432     <t:tab id="overviewplots"
    433       visible="<%=bioAssay == null && rawDataType.getChannels() == 2%>"
    434       title="Overview plots"
    435       tooltip="MA-plots of each bioassay in this bioassay set"
     434    <t:tab id="overviewplots" title="Overview plots"
     435      visible="<%=overviewPlotInvoker != null && overviewPlotInvoker.getNumExtensions() > 0%>"
    436436    />
    437     <t:tab id="cfplots"
    438       title="Correction factor plots"
    439       visible="<%=bioAssay == null && rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>"
    440     />
    441 
    442437    </t:tabcontrol>
    443438
Note: See TracChangeset for help on using the changeset viewer.