Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-16787: add shape and center plot for single-build-graphs
  • Loading branch information
mheinzerling committed Jan 5, 2017
1 parent eb29267 commit 6a41ae8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Binary file added resources/test/singleBuild.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -305,14 +305,15 @@ public List<Plot> getPlots()
return Collections.unmodifiableList(plots);
}

public void apply(JFreeChart chart)
public void apply(JFreeChart chart, boolean onlyOneBuild)
{
final CategoryPlot plot = chart.getCategoryPlot();
Map<Axis, Integer> axisIds = new HashMap<>();
int axisId = 0;
for (Axis axis : axes)
{
LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, onlyOneBuild);
if (onlyOneBuild) renderer.setUseOutlinePaint(true);
renderer.setBaseStroke(new BasicStroke(baseStroke));
//add axis layout here
plot.setRenderer(axisId, renderer);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/jacoco/model/CoverageObject.java
Expand Up @@ -470,6 +470,7 @@ protected JFreeChart createGraph() {
dataSets.put(e.getKey(), e.getValue().build());
}
List<Axis> axes = new ArrayList<>(dataSets.keySet());
boolean onlyOneBuild = dataSets.entrySet().iterator().next().getValue().getColumnCount() < 2;

final JFreeChart chart = ChartFactory.createLineChart(
null, // chart title
Expand All @@ -487,7 +488,7 @@ protected JFreeChart createGraph() {
CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setLowerMargin(onlyOneBuild ? 0.5 : 0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);

Expand All @@ -504,7 +505,7 @@ protected JFreeChart createGraph() {
axisId++;
}

layout.apply(chart);
layout.apply(chart, onlyOneBuild);
return chart;
}

Expand Down
Expand Up @@ -73,6 +73,19 @@ public void simpleLineCoverage() throws IOException
assertGraph(chart, "simple.png");
}

@Test
public void singeBuildCoverage() throws IOException
{
CoverageGraphLayout layout = new CoverageGraphLayout()
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED).color(Color.RED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED).color(Color.GREEN);

TestCoverageObject t = new TestCoverageObject().branch(6, 30).line(5000, 19000);
ctl.replay();
JFreeChart chart = t.createGraph(new GregorianCalendar(), WIDTH, HEIGHT, layout).getGraph();
assertGraph(chart, "singleBuild.png");
}

@Test
public void baseStroke() throws IOException
{
Expand Down

0 comments on commit 6a41ae8

Please sign in to comment.