Changeset 3015 for trunk


Ignore:
Timestamp:
Dec 11, 2006, 12:35:36 PM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #405: Highlight function in plot tool

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java

    r2993 r3015  
    4242import net.sf.basedb.core.query.Orders;
    4343import net.sf.basedb.core.query.Restriction;
     44import net.sf.basedb.core.query.Select;
    4445import net.sf.basedb.core.query.Selects;
    4546import net.sf.basedb.core.query.SqlResult;
    4647import net.sf.basedb.core.query.SqlResultIterator;
     48import net.sf.basedb.core.query.WhenStatement;
    4749import net.sf.basedb.clients.web.formatter.FormatterFactory;
    4850import net.sf.basedb.clients.web.util.HTML;
     
    6567
    6668import org.jfree.chart.JFreeChart;
     69import org.jfree.chart.renderer.xy.XYStepRenderer;
    6770import org.jfree.chart.title.TextTitle;
    6871
     
    341344    final String annotation = Values.getStringOrNull(request.getParameter("annotation"));
    342345    final boolean hasAnnotation = annotation != null;
     346    Select annotationSelect = null;
    343347
    344348    // Scatter plot specified parameters
     
    405409          annotations = new TreeSet<PlotAnnotation>();
    406410          List<BioAssay> bioAssays = bas.getBioAssays().list(dc);
     411          annotationSelect = Dynamic.select(VirtualColumn.COLUMN);
    407412          if ("bioassay".equals(annotation))
    408413          {
     
    434439              annotations.add(new PlotAnnotation(name, entry.getValue()));
    435440            }
     441          }
     442          else if (annotation.startsWith("="))
     443          {
     444            // JEP restriction
     445            Restriction r =
     446              BioAssaySetUtil.createJepRestriction(dc, bas, annotation.substring(1), false);
     447            Expression e = Expressions.caseWhen(Expressions.integer(0),
     448                new WhenStatement(r, Expressions.integer(1)));
     449            annotationSelect = Selects.expression(e, "ann");
     450            annotations.add(new PlotAnnotation("", 0));
     451            annotations.add(new PlotAnnotation(annotation.substring(1), 1));
    436452          }
    437453          else
     
    466482          {
    467483            query.reset();
    468             if (hasAnnotation)
    469             {
    470               query.select(Dynamic.select(VirtualColumn.COLUMN));
     484            if (annotationSelect != null)
     485            {
     486              query.select(annotationSelect);
    471487            }
    472488            query.select(Selects.expression(x[i], "x"));
     
    485501        else
    486502        {
    487           HistogramPlot plot = new HistogramPlot(xLabel, yLabel);
     503          HistogramPlot plot = new HistogramPlot(xLabel, yLabel,
     504            hasAnnotation ? new XYStepRenderer() : null);
    488505          query.setReturnTotalCount(true);
    489506          for (int i = 0; i < x.length; ++i)
    490507          {
    491508            query.reset();
    492             if (hasAnnotation)
    493             {
    494               query.select(Dynamic.select(VirtualColumn.COLUMN));
     509            if (annotationSelect != null)
     510            {
     511              query.select(annotationSelect);
    495512            }
    496513            query.select(Selects.expression(x[i], "x"));
  • trunk/src/core/net/sf/basedb/util/plot/HistogramPlot.java

    r2474 r3015  
    3434import org.jfree.chart.plot.XYPlot;
    3535import org.jfree.chart.renderer.xy.XYBarRenderer;
    36 import org.jfree.chart.renderer.xy.XYStepRenderer;
     36import org.jfree.chart.renderer.xy.XYItemRenderer;
    3737import org.jfree.chart.renderer.xy.YIntervalRenderer;
    3838import org.jfree.data.DomainOrder;
     
    4848import java.util.List;
    4949import java.util.Map;
     50
    5051
    5152/**
     
    7273    @param nameX The label on the X-axis
    7374    @param nameY The label on the Y-axis
    74   */
    75   public HistogramPlot(String nameX, String nameY)
     75    @param renderer The renderer to use or null for the default (XYBarRenderer)
     76  */
     77  public HistogramPlot(String nameX, String nameY, XYItemRenderer renderer)
    7678  {
    7779   
     
    8587      NumberAxis rangeAxis = new NumberAxis(nameY);
    8688    rangeAxis.setAutoRangeIncludesZero(true);
    87 
    88       plot = new XYPlot(histogram, domainAxis, rangeAxis, new XYBarRenderer());
     89    if (renderer == null) renderer = new XYBarRenderer();
     90      plot = new XYPlot(histogram, domainAxis, rangeAxis, renderer);
    8991      plot.setDataset(1, hilo);
    9092      YIntervalRenderer yRenderer = new YIntervalRenderer();
     
    179181    List<TempSeries> tempSeries = new ArrayList<TempSeries>(annotations.size());
    180182    int meanCount = (int)(data.getTotalCount() / annotations.size());
     183    plot.getRenderer().setSeriesVisibleInLegend(null);
    181184    for (PlotAnnotation pa : annotations)
    182185    {
     
    213216        hilo.addSeries(new HistogramSeries(ts.name, main, hiloAggregate));
    214217      }
     218      plot.getRenderer().setSeriesVisibleInLegend(histogram.getSeriesCount()-1, !ts.name.equals(""));
    215219    }
    216220    adjustRanges();
    217     plot.setRenderer(new XYStepRenderer());
    218221  }
    219222 
  • trunk/src/core/net/sf/basedb/util/plot/PlotAnnotation.java

    r2704 r3015  
    2424package net.sf.basedb.util.plot;
    2525
     26import java.util.Arrays;
    2627import java.util.Collection;
    2728
     
    4344  private final String name;
    4445  private final Collection<Integer> values;
     46 
     47  /**
     48    Create a new PlotAnnotation.
     49    @param name The name of the annotation, which will be used as a label in the image
     50    @param values The value that belongs to this annotation
     51    @since 2.2
     52  */
     53  public PlotAnnotation(String name, int value)
     54  {
     55    this(name, Arrays.asList(value));
     56  }
    4557 
    4658  /**
  • trunk/src/core/net/sf/basedb/util/plot/ScatterPlot.java

    r2327 r3015  
    137137    Map<Integer, XYSeries> series = new HashMap<Integer, XYSeries>(annotations.size());
    138138    List<XYSeries> newSeries = new ArrayList<XYSeries>(annotations.size());
     139    plot.getRenderer().setSeriesVisibleInLegend(null);
    139140    for (PlotAnnotation pa : annotations)
    140141    {
     
    160161    {
    161162      allSeries.addSeries(s);
     163      plot.getRenderer().setSeriesVisibleInLegend(allSeries.getSeriesCount()-1, !s.getKey().equals(""));
    162164    }
    163165  }
  • trunk/www/views/experiments/plotter/index.jsp

    r2993 r3015  
    196196  function switchTab(tabControlId, tabId)
    197197  {
    198     if (tabId != 'filter')
     198    if (tabId == 'scatter' || tabId == 'histogram')
    199199    {
    200200      plotType = tabId;
     
    240240    var frm = document.forms['plot'];
    241241    var selected = list[list.selectedIndex];
    242     var value = selected.value ? selected.text : '';
     242    var value = selected.value && selected.value != '$' ? selected.text : '';
    243243    value = value.replace('\[A\] ', '');
    244244    frm.subTitle.value = value;
    245   }
    246  
     245   
     246    var annotationFrm = document.forms['annotation'];
     247    if (selected.value.substring(0, 1) == '$')
     248    {
     249      annotationFrm.annotationExp.disabled = true;
     250    }
     251    else
     252    {
     253      if (selected.value)
     254      {
     255        annotationFrm.annotationExp.value = selected.value;
     256      }
     257      annotationFrm.annotationExp.disabled = false;
     258      annotationFrm.annotationExp.focus();
     259    }
     260  }
     261 
     262  function annotationExpressionOnChange()
     263  {
     264    var annotationFrm = document.forms['annotation'];
     265    annotationFrm.annotationPresets.selectedIndex = annotationFrm.annotationPresets.length-1;
     266  }
    247267 
    248268  function generatePlotUrl(fullSize)
     
    264284      {
    265285        url += '&filter='+Main.encodeURI(filterFrm.filter.value);
     286      }
     287     
     288      var annotationFrm = document.forms['annotation'];
     289      var annotation = '';
     290      if (!annotationFrm.annotationExp.disabled)
     291      {
     292        if (annotationFrm.annotationExp.value)
     293        {
     294          annotation = '=' + annotationFrm.annotationExp.value;
     295        }
     296      }
     297      else
     298      {
     299        annotation = annotationFrm.annotationPresets[annotationFrm.annotationPresets.selectedIndex].value.substring(1);
     300      }
     301      if (annotation)
     302      {
     303        url += '&annotation='+Main.encodeURI(annotation);
    266304      }
    267305
     
    277315        url += '&yLog='+(frm.yLog.checked ? 1 : 0);
    278316        url += '&yLabel='+Main.encodeURI(frm.yLabel.value);
    279         if (frm.annotation)
    280         {
    281           url += '&annotation='+frm.annotation[frm.annotation.selectedIndex].value;
    282         }
    283317      }
    284318      else
     
    299333        }
    300334        url += '&yLabel='+Main.encodeURI(frm.yLabel.value);
    301         if (frm.annotation)
    302         {
    303           url += '&annotation='+frm.annotation[frm.annotation.selectedIndex].value;
    304         }
    305335      }
    306336      return url;
     
    419449    <t:tabcontrol id="plotType" style="<%="width: "+(int)(scale*340)+"px;"%>" contentstyle="<%="height: "+(int)(scale*340)+"px;"%>"
    420450      switch="switchTab">
    421     <t:tab id="scatter" title="Scatter plot" helpid="plotter.scatterplot">
     451    <t:tab id="scatter" title="Scatter plot" helpid="plotter.scatterplot"
     452      tooltip="Create a scatter plot">
    422453      <form name="scatter">
    423454      <table border="0" cellspacing="0" cellpadding="2" class="form">
     
    490521        <td colspan="2"><input type="checkbox" name="xLog" value="1"></td>
    491522      </tr>
    492       <%
    493       if (ba == null)
    494       {
    495         %>
    496         <tr>
    497           <td class="prompt">Annotation</td>
    498           <td colspan="2">
    499           <select name="annotation" onchange="annotationOnChange(this)">
    500             <option value="">- none -
    501             <option value="bioassay">Bioassay
    502             <option value="spots">Spots
    503             <option value="arrayDesign.name">Array design
    504             <option value="software.name">Software
    505             <option value="protocol.name">Protocol
    506             <option value="scan.scanner.name">Scanner
    507             <option value="scan.protocol.name">Scanning protocol
    508             <option value="scan.hybridization.protocol.name">Hybridization protocol
    509             <option value="scan.hybridization.creationEvent.eventDate">Hybridization date
    510             <%
    511             for (AnnotationType at : experimentalFactors)
    512             {
    513               %>
    514               <option value="<%=at.getId()%>">[A] <%=HTML.encodeTags(at.getName())%>
    515               <%
    516             }
    517             %>
    518           </select>
    519           </td>
    520         </tr>
    521         <%
    522       }
    523       %>
    524523      </table>
    525524      </form>
    526525    </t:tab>
    527526
    528     <t:tab id="histogram" title="Histogram plot" helpid="plotter.histogram">
     527    <t:tab id="histogram" title="Histogram plot" helpid="plotter.histogram"
     528      tooltip="Create a histogram plot">
    529529      <form name="histogram">
    530530      <table border="0" cellspacing="0" cellpadding="2" class="form">
     
    617617        <td colspan="2"><input type="text" class="text" name="binSize" value="1"></td>
    618618      </tr>
    619       <%
    620       if (ba == null)
    621       {
    622         %>
    623         <tr>
    624           <td class="prompt">Annotation</td>
    625           <td colspan="2">
    626           <select name="annotation" onchange="annotationOnChange(this)">
    627             <option value="">- none -
    628             <option value="bioassay">Bioassay
    629             <option value="spots">Spots
    630             <option value="arrayDesign.name">Array design
    631             <option value="software.name">Software
    632             <option value="protocol.name">Protocol
    633             <option value="scan.scanner.name">Scanner
    634             <option value="scan.protocol.name">Scanning protocol
    635             <option value="scan.hybridization.protocol.name">Hybridization protocol
    636             <option value="scan.hybridization.creationEvent.eventDate">Hybridization date
    637             <%
    638             for (AnnotationType at : experimentalFactors)
    639             {
    640               %>
    641               <option value="<%=at.getId()%>">[A] <%=HTML.encodeTags(at.getName())%>
    642               <%
    643             }
    644             %>
    645           </select>
    646           </td>
    647         </tr>
    648         <%
    649       }
    650       %>
    651619      </table>
    652620      </form>
    653621    </t:tab>
    654622   
    655     <t:tab id="filter" title="Filter" helpid="plotter.filter">
     623    <t:tab id="filter" title="Filter" helpid="plotter.filter"
     624      tooltip="Specify a filter for spots that should be included in the plot">
    656625      <form name="filter">
    657626      <table border="0" cellspacing="0" cellpadding="2" class="form">
     
    683652      </tr>
    684653      </table>
     654      </form>
    685655    </t:tab>
     656   
     657    <t:tab id="annotation" title="Annotation" helpid="plotter.annotation"
     658      tooltip="Specify a property or expression for sub-grouping the plotted values">
     659      <form name="annotation">
     660     
     661      <table border="0" cellspacing="0" cellpadding="2" class="form">
     662      <tr>
     663        <td class="prompt" colspan="2">Annotation</td>
     664      </tr>
     665      <tr>
     666        <td>&nbsp;Presets</td>
     667        <td colspan="2">
     668        <select name="annotationPresets" onchange="annotationOnChange(this)">
     669          <option value="$">- none -
     670          <%
     671          if (ba == null)
     672          {
     673            %>
     674            <option value="$bioassay">Bioassay
     675            <option value="$spots">Spots
     676            <option value="$arrayDesign.name">Array design
     677            <option value="$software.name">Software
     678            <option value="$protocol.name">Protocol
     679            <option value="$scan.scanner.name">Scanner
     680            <option value="$scan.protocol.name">Scanning protocol
     681            <option value="$scan.hybridization.protocol.name">Hybridization protocol
     682            <option value="$scan.hybridization.creationEvent.eventDate">Hybridization date
     683            <option value="" disabled>- annotations -
     684            <%
     685            for (AnnotationType at : experimentalFactors)
     686            {
     687              %>
     688              <option value="$<%=at.getId()%>">[A] <%=HTML.encodeTags(at.getName())%>
     689              <%
     690            }
     691          }
     692          %>
     693          <option value="" disabled>- expressions -
     694          <%=filterOptions.toString()%>
     695          <option value="">Other...
     696        </select>
     697        </td>
     698      </tr>
     699      <tr>
     700        <td>&nbsp;Expression</td>
     701        <td><input type="text" class="text" size="30" maxlength="255" name="annotationExp"
     702          onchange="annotationExpressionOnChange()" disabled></td>
     703        <td>
     704          <base:button
     705            title=""
     706            image="expression_builder.gif"
     707            tooltip="Use the Expression builder"
     708            onclick="openExpressionBuilder('Annotation filter', 'annotation', 'annotationExp', 'COLUMN_RESTRICTION')"
     709          />
     710        </td>
     711      </tr>
     712      </table>
     713      </form>
     714    </t:tab>
    686715   
    687716    </t:tabcontrol>
Note: See TracChangeset for help on using the changeset viewer.