In lower resolution systems, create smaller test trend chart.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9000 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2008-05-01 22:12:34 +00:00
1 parent b3f8f5369b
commit cf218bbc22
9 files changed
+499 -13

No files matched your search

+13
View File
@@ -26,6 +26,7 @@ import hudson.tasks.Publisher;
import hudson.security.SecurityRealm;
import hudson.security.AuthorizationStrategy;
import hudson.security.Permission;
import hudson.util.Area;
import org.apache.commons.jexl.parser.ASTSizeFunction;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jelly.JellyContext;
@@ -61,6 +62,7 @@ import java.util.TreeMap;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
* Utility functions used in views.
@@ -181,6 +183,17 @@ public class Functions {
return new RunUrl( (Run) f.getObject(), head, base, rest);
}
/**
* If we know the user's screen resolution, return it. Otherwise null.
* @since 1.213
*/
public static Area getScreenResolution() {
Cookie res = Functions.getCookie(Stapler.getCurrentRequest(),"screenResolution");
if(res!=null)
return Area.parse(res.getValue());
return null;
}
/**
* URL decomposed for easier computation of relevant URLs.
*
@@ -10,6 +10,7 @@ import hudson.util.ColorPalette;
import hudson.util.DataSetBuilder;
import hudson.util.ShiftedCategoryAxis;
import hudson.util.StackedAreaRenderer2;
import hudson.util.Area;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
@@ -164,7 +165,7 @@ public abstract class AbstractTestResultAction<T extends AbstractTestResultActio
if(req.checkIfModified(owner.getTimestamp(),rsp))
return;
ChartUtil.generateGraph(req,rsp,createChart(req,buildDataSet(req)),500,200);
ChartUtil.generateGraph(req,rsp,createChart(req,buildDataSet(req)),calcDefaultSize());
}
/**
@@ -173,9 +174,23 @@ public abstract class AbstractTestResultAction<T extends AbstractTestResultActio
public void doGraphMap( StaplerRequest req, StaplerResponse rsp) throws IOException {
if(req.checkIfModified(owner.getTimestamp(),rsp))
return;
ChartUtil.generateClickableMap(req,rsp,createChart(req,buildDataSet(req)),500,200);
ChartUtil.generateClickableMap(req,rsp,createChart(req,buildDataSet(req)),calcDefaultSize());
}
/**
* Determines the default size of the trend graph.
*
* This is default because the query parameter can choose arbitrary size.
* If the screen resolution is too low, use a smaller size.
*/
private Area calcDefaultSize() {
Area res = Functions.getScreenResolution();
if(res!=null && res.width<=800)
return new Area(250,100);
else
return new Area(500,200);
}
private CategoryDataset buildDataSet(StaplerRequest req) {
boolean failureOnly = Boolean.valueOf(req.getParameter("failureOnly"));
+40
View File
@@ -0,0 +1,40 @@
package hudson.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Represents a two dimensional area.
*
* @author Kohsuke Kawaguchi
* @since 1.213
*/
public final class Area {
public final int width;
public final int height;
public Area(int width, int height) {
this.width = width;
this.height = height;
}
/**
* Opposite of {@link #toString()}.
*/
public static Area parse(String s) {
Matcher m = PATTERN.matcher(s);
if(m.matches())
return new Area(Integer.parseInt(m.group(1)),Integer.parseInt(m.group(2)));
return null;
}
public int area() {
return width*height;
}
public String toString() {
return width+"x"+height;
}
private static final Pattern PATTERN = Pattern.compile("(\\d+)x(\\d+)");
}
@@ -58,6 +58,17 @@ public class ChartUtil {
*/
public static boolean awtProblem = false;
/**
* Generates the graph in PNG format and sends that to the response.
*
* @param defaultSize
* The size of the picture to be generated. These values can be overridden
* by the query paramter 'width' and 'height' in the request.
*/
public static void generateGraph(StaplerRequest req, StaplerResponse rsp, JFreeChart chart, Area defaultSize) throws IOException {
generateGraph(req,rsp,chart,defaultSize.width, defaultSize.height);
}
/**
* Generates the graph in PNG format and sends that to the response.
*
@@ -83,6 +94,13 @@ public class ChartUtil {
}
}
/**
* Generates the clickable map info and sends that to the response.
*/
public static void generateClickableMap(StaplerRequest req, StaplerResponse rsp, JFreeChart chart, Area defaultSize) throws IOException {
generateClickableMap(req,rsp,chart,defaultSize.width,defaultSize.height);
}
/**
* Generates the clickable map info and sends that to the response.
*/