Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-9745] Added new graphs that shows the totals (scaled).
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jun 17, 2011
1 parent 120a026 commit bdb83f4
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
Expand Up @@ -22,6 +22,7 @@
import hudson.plugins.analysis.graph.NewVersusFixedGraph;
import hudson.plugins.analysis.graph.NullGraph;
import hudson.plugins.analysis.graph.PriorityGraph;
import hudson.plugins.analysis.graph.TotalsGraph;
import hudson.plugins.analysis.graph.UserGraphConfigurationView;
import hudson.plugins.analysis.graph.GraphConfigurationView;
import hudson.plugins.analysis.graph.TrendDetails;
Expand Down Expand Up @@ -212,6 +213,7 @@ protected List<BuildResultGraph> getAvailableGraphs() {

availableGraphs.add(new NewVersusFixedGraph());
availableGraphs.add(new PriorityGraph());
availableGraphs.add(new TotalsGraph());
if (hasValidResults()) {
availableGraphs.add(new HealthGraph(getLastAction().getHealthDescriptor()));
}
Expand Down
@@ -1,5 +1,6 @@
package hudson.plugins.analysis.graph;

import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Calendar;
import java.util.Collection;
Expand All @@ -18,6 +19,7 @@
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.joda.time.LocalDate;

Expand Down Expand Up @@ -487,5 +489,17 @@ public JFreeChart createBlockChart(final CategoryDataset dataset) {

return chart;
}

/**
* Creates a line renderer with predefined stroke.
*
* @return a line renderer
* @since 1.23
*/
protected CategoryItemRenderer createLineRenderer() {
LineAndShapeRenderer render = new LineAndShapeRenderer(true, false);
render.setBaseStroke(new BasicStroke(2.0f));
return render;
}
}

76 changes: 76 additions & 0 deletions src/main/java/hudson/plugins/analysis/graph/TotalsGraph.java
@@ -0,0 +1,76 @@
package hudson.plugins.analysis.graph;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;

import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.util.ToolTipProvider;

import hudson.util.ColorPalette;

/**
* Builds a graph showing the total of warnings in a scaled line graph.
*
* @author Ulli Hafner
* @since 1.23
*/
public class TotalsGraph extends CategoryBuildResultGraph {
@Override
public String getId() {
return "TOTALS";
}

@Override
public String getLabel() {
return Messages.Trend_type_totals();
}

@Override
protected List<Integer> computeSeries(final BuildResult current) {
List<Integer> series = new ArrayList<Integer>();
series.add(current.getNumberOfWarnings());
return series;
}

@Override
protected JFreeChart createChart(final CategoryDataset dataSet) {
NumberAxis numberAxis = new NumberAxis("count");
numberAxis.setAutoRange(true);
numberAxis.setAutoRangeIncludesZero(false);

CategoryAxis domainAxis = new CategoryAxis();
domainAxis.setCategoryMargin(0.0);

CategoryPlot plot = new CategoryPlot(dataSet, domainAxis, numberAxis, new LineAndShapeRenderer(true, false));
plot.setOrientation(PlotOrientation.VERTICAL);

JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(Color.white);

setCategoryPlotProperties(plot);

return chart;
}

@Override
protected Color[] getColors() {
return new Color[] {ColorPalette.BLUE};
}

@Override
protected CategoryItemRenderer createRenderer(final GraphConfiguration configuration, final String pluginName, final ToolTipProvider toolTipProvider) {
return createLineRenderer();
}
}

Expand Up @@ -52,6 +52,7 @@ Trend.type.priority=Priority distribution of all warnings
Trend.type.fixed=Distribution of new and fixed warnings
Trend.type.difference=Difference between new and fixed warnings (cumulative)
Trend.type.health=Number of warnings colored according to the health report thresholds
Trend.type.totals=Total number of warnings

ResultAction.Status=Plug-in Result:

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/hudson/plugins/analysis/graph/Main.java
Expand Up @@ -80,7 +80,7 @@ public Main(final BuildResultGraph graph) {
private BuildResult createResult(final int buildNumber, final int fixedWarnings, final int newWarnings) {
BuildResult result = mock(BuildResult.class);

when(result.getNumberOfWarnings()).thenReturn(newWarnings);
when(result.getNumberOfWarnings()).thenReturn(newWarnings + 1000);
when(result.getNumberOfAnnotations(Priority.HIGH)).thenReturn(newWarnings);
when(result.getNumberOfAnnotations(Priority.NORMAL)).thenReturn(fixedWarnings);
when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(Math.abs(newWarnings - fixedWarnings));
Expand Down Expand Up @@ -109,6 +109,7 @@ public static void main(final String[] args) {
availableGraphs.add(new NewVersusFixedGraph());
availableGraphs.add(new PriorityGraph());
availableGraphs.add(new DifferenceGraph());
availableGraphs.add(new TotalsGraph());

for (BuildResultGraph graph : availableGraphs) {
Main chart = new Main(graph);
Expand Down

0 comments on commit bdb83f4

Please sign in to comment.