Changeset 5114


Ignore:
Timestamp:
Oct 2, 2009, 2:29:28 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #1386: Plot function in the bioassay table in experiment explorer

First version is checked in since it is friday. Most major functions should be in place. Some minor options may need tweaking as well as some visual aspects. As usual, error handling must be tested.

The code for generating an image with a stack trace has been moved to ThrowableUtil?.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/web.xml

    r4975 r5114  
    157157    <url-pattern>/views/experiments/plotter/plot</url-pattern>
    158158  </servlet-mapping>
     159
     160  <!-- The ExperimentExplorer PlotServlet  -->
     161  <servlet>
     162    <servlet-name>eeplotter</servlet-name>
     163    <servlet-class>
     164      net.sf.basedb.clients.web.servlet.ExperimentExplorerPlotServlet
     165    </servlet-class>
     166  </servlet>
     167  <servlet-mapping>
     168    <servlet-name>eeplotter</servlet-name>
     169    <url-pattern>/views/experiments/explorer/plot</url-pattern>
     170  </servlet-mapping>
     171
    159172
    160173  <!-- Axis2 servlets for web services -->
  • trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java

    r5109 r5114  
    2323package net.sf.basedb.clients.web;
    2424
     25import java.awt.Color;
    2526import java.sql.SQLException;
    2627import java.util.ArrayList;
     
    10121013    private final Map<Short, AnnotationGroup> assayGroups;
    10131014    private final Set<AnnotationGroup> groups;
     1015    private final AnnotationType annotationType;
    10141016   
    10151017    @SuppressWarnings("unchecked")
     
    10191021      this.assayGroups = new HashMap<Short, AnnotationGroup>();
    10201022      this.groups = new TreeSet<AnnotationGroup>();
     1023      this.annotationType = annotationType;
    10211024     
    10221025      Formatter formatter = FormatterFactory.getTypeFormatter(dc.getSessionControl(), annotationType.getValueType());
     
    10431046   
    10441047    /**
     1048      Get the annotation type this summary is based on.
     1049      @since 2.14
     1050    */
     1051    public AnnotationType getAnnotationType()
     1052    {
     1053      return annotationType;
     1054    }
     1055   
     1056    /**
    10451057      Get the annotation group for the bioassay with the
    10461058      give data cube column.
     
    11601172    {
    11611173      return color;
     1174    }
     1175   
     1176    /**
     1177      Get the AWT color object that corresponds to the HTML color string.
     1178      The color string must have been set with a seven-character
     1179      string with 2 hex characters for every color component, eg.
     1180      '#rrggbb'.
     1181      @since 2.14
     1182    */
     1183    public Color getAwtColor()
     1184    {
     1185      int r = Integer.parseInt(color.substring(1, 3), 16);
     1186      int g = Integer.parseInt(color.substring(3, 5), 16);
     1187      int b = Integer.parseInt(color.substring(5), 16);
     1188      return new Color(r, g, b);
    11621189    }
    11631190   
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java

    r4889 r5114  
    5151import net.sf.basedb.util.StaticCache;
    5252import net.sf.basedb.util.Values;
     53import net.sf.basedb.util.error.ThrowableUtil;
    5354import net.sf.basedb.util.formatter.Formatter;
    5455import net.sf.basedb.util.jep.ChannelFunction;
     
    7172import org.jfree.chart.title.TextTitle;
    7273
    73 import java.awt.Color;
    74 import java.awt.Font;
    75 import java.awt.Graphics2D;
    76 import java.awt.font.FontRenderContext;
    77 import java.awt.geom.Rectangle2D;
    78 import java.awt.image.BufferedImage;
    7974import java.awt.image.RenderedImage;
    8075import java.io.InputStream;
     
    611606          try
    612607          {
    613             BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    614             Graphics2D graphics = img.createGraphics();
    615             graphics.setBackground(Color.WHITE);
    616             graphics.clearRect(0, 0, width, height);
    617             graphics.setColor(Color.RED);
    618             FontRenderContext context = graphics.getFontRenderContext();
    619  
    620             Font topFont = new Font("SansSerif", Font.BOLD, 12);
    621             Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12);
    622  
    623             float x = .0f;
    624             float y = .0f;
    625             String causedBy = "";
    626             do
    627             {
    628               graphics.setFont(topFont);
    629               String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage();
    630               x = 5.0f;
    631               Rectangle2D bounds = topFont.getStringBounds(msg, context);
    632               y += bounds.getHeight()+5;
    633               if (bounds.getWidth() > width - x)
    634               {
    635                 msg = cutMiddle(msg, (width - x) / bounds.getWidth());
    636               }
    637               graphics.drawString(msg, x, y);
    638              
    639               graphics.setFont(stackTraceFont);
    640               x = 15.0f;
    641               for (StackTraceElement st : t.getStackTrace())
    642               {
    643                 msg = "at " + st.getClassName() + "." + st.getMethodName() +
    644                   ":" + st.getLineNumber();
    645                 bounds = stackTraceFont.getStringBounds(msg, context);
    646                 y += bounds.getHeight();
    647                 if (bounds.getWidth() > width - x)
    648                 {
    649                   msg = cutMiddle(msg, (width - x) / bounds.getWidth());
    650                 }
    651                 graphics.drawString(msg, x, y);
    652               }
    653               t = t.getCause();
    654               causedBy = "Caused by: ";
    655             } while (t != null && y < height);
    656             image = img;
     608            image = ThrowableUtil.stackTraceToImage(t, width, height);
    657609          }
    658610          catch (Throwable t2)
     
    774726  }
    775727 
    776  
    777   private String cutMiddle(String msg, double fraction)
    778   {
    779     int charactersToCut = (int)(msg.length() * (1 - fraction)) + 3;
    780     int beginAt = (msg.length() - charactersToCut) / 2;
    781     return msg.substring(0, beginAt) + "..." + msg.substring(beginAt + charactersToCut);
    782   }
    783  
    784728  /**
    785729    Special implementation of a <code>SqlResultIterator</code>
  • trunk/src/core/net/sf/basedb/core/StringUtil.java

    r5014 r5114  
    157157    return s;
    158158  }
     159 
     160  /**
     161    Trim a string to a maximum length. Strings longer than the specified
     162    length will have text cut-out from the middle and replaced by three
     163    dots. If no trimming is needed the original string is returned.
     164    @param s The string to trim
     165    @param length The maximum length of the string
     166    @return The trimmed string
     167    @since 2.14
     168  */
     169  public static final String trimStringMiddle(String s, int length)
     170  {
     171    if (s != null && s.length() > length)
     172    {
     173      int charactersToCut = s.length() + 3 - length;
     174      int beginAt = (s.length() - charactersToCut) / 2;
     175      s = s.substring(0, beginAt) + "..." + s.substring(beginAt + charactersToCut);
     176    }
     177    return s;
     178  }
    159179
    160180}
  • trunk/src/core/net/sf/basedb/util/error/ThrowableUtil.java

    r4618 r5114  
    2222package net.sf.basedb.util.error;
    2323
     24import java.awt.Color;
     25import java.awt.Font;
     26import java.awt.Graphics2D;
     27import java.awt.font.FontRenderContext;
     28import java.awt.geom.Rectangle2D;
     29import java.awt.image.BufferedImage;
    2430import java.io.PrintWriter;
    2531import java.io.StringWriter;
     32
     33import net.sf.basedb.core.StringUtil;
    2634
    2735/**
     
    4957    return sw.toString();
    5058  }
     59 
     60  /**
     61    Prints as much of a stacktrace as possible to an image.
     62    @param t The throwable
     63    @param width The width of the image
     64    @param height The height of the image
     65    @since 2.14
     66  */
     67  public static BufferedImage stackTraceToImage(Throwable t, int width, int height)
     68  {
     69    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     70    Graphics2D graphics = img.createGraphics();
     71    graphics.setBackground(Color.WHITE);
     72    graphics.clearRect(0, 0, width, height);
     73    graphics.setColor(Color.RED);
     74    FontRenderContext context = graphics.getFontRenderContext();
     75
     76    Font topFont = new Font("SansSerif", Font.BOLD, 12);
     77    Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12);
     78
     79    float x = .0f;
     80    float y = .0f;
     81    String causedBy = "";
     82    do
     83    {
     84      graphics.setFont(topFont);
     85      String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage();
     86      x = 5.0f;
     87      Rectangle2D bounds = topFont.getStringBounds(msg, context);
     88      y += bounds.getHeight()+5;
     89      if (bounds.getWidth() > width - x)
     90      {
     91        msg = StringUtil.trimStringMiddle(msg,(int)(msg.length() * (width - x) / bounds.getWidth()));
     92      }
     93      graphics.drawString(msg, x, y);
     94     
     95      graphics.setFont(stackTraceFont);
     96      x = 15.0f;
     97      for (StackTraceElement st : t.getStackTrace())
     98      {
     99        msg = "at " + st.getClassName() + "." + st.getMethodName() +
     100          ":" + st.getLineNumber();
     101        bounds = stackTraceFont.getStringBounds(msg, context);
     102        y += bounds.getHeight();
     103        if (bounds.getWidth() > width - x)
     104        {
     105          msg = StringUtil.trimStringMiddle(msg,(int)(msg.length() * (width - x) / bounds.getWidth()));
     106        }
     107        graphics.drawString(msg, x, y);
     108      }
     109      t = t.getCause();
     110      causedBy = "Caused by: ";
     111    } while (t != null && y < height);
     112    return img;
     113  }
     114 
    51115}
  • trunk/www/views/experiments/explorer/view/view.jsp

    r5111 r5114  
    254254      }
    255255    }
     256    function plotSpotData()
     257    {
     258      var url = 'plotter.jsp?ID=<%=ID%>';
     259      url += '&bioAssaySetId=<%=bioAssaySetId%>';
     260      url += '&reporterIndex=<%=reporterIndex%>';
     261      url += '&positionIndex=<%=positionIndex%>';
     262      Main.openPopup(url, 'SpotPlot', 1100, 700);
     263    }
    256264  </script>
    257265  </base:head>
     
    448456            <table border="0" cellspacing="0" cellpadding="2" class="annotationsummary">
    449457            <tr>
    450               <td class="summaryheader"><%=HTML.encodeTags(at.getName())%></td>
     458              <td class="summaryheader"><%=Base.getLinkedName(ID, at, false, true)%></td>
    451459              <%
    452460              for (AnnotationGroup ag : summary.getAnnotationGroups())
     
    707715          tooltip="Show, hide and re-order columns"
    708716        />
     717        <tbl:button
     718          image="plotter.gif"
     719          onclick="plotSpotData()"
     720          title="Plot&hellip;"
     721          tooltip="Plot selected data from this table"
     722        />
    709723      </tbl:toolbar>
    710724      <tbl:data>
Note: See TracChangeset for help on using the changeset viewer.