Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-16580: add plot color
  • Loading branch information
mheinzerling committed May 30, 2016
1 parent ad11847 commit af467da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
Binary file modified resources/test/multiple.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions src/main/java/hudson/plugins/jacoco/model/CoverageGraphLayout.java
Expand Up @@ -169,6 +169,7 @@ static class Plot
private CoverageValue value;
private CoverageType type;
private Axis axis;
private Color color;

public Plot(Axis axis)
{
Expand All @@ -193,7 +194,7 @@ public Axis getAxis()
@Override
public String toString()
{
return axis + " " + type + " " + value;
return axis + " " + type + " " + value + " " + color;
}
}

Expand Down Expand Up @@ -251,6 +252,13 @@ public CoverageGraphLayout value(CoverageValue value)
return this;
}

public CoverageGraphLayout color(Color color)
{
assurePlot();
plots.peek().color = color;
return this;
}

public List<Axis> getAxes()
{
return Collections.unmodifiableList(axes);
Expand Down Expand Up @@ -281,12 +289,9 @@ public void apply(JFreeChart chart)
axisId = axisIds.get(p.axis);
int lineIdPerAxis = plot.getDataset(axisId).getRowIndex(p.getMessage());
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(axisId);

Color color = lineIdPerAxis == 0 ? Color.GREEN : Color.RED; //TODO

renderer.setSeriesPaint(lineIdPerAxis, color);
renderer.setSeriesItemLabelPaint(lineIdPerAxis, color);
renderer.setSeriesFillPaint(lineIdPerAxis, color);
renderer.setSeriesPaint(lineIdPerAxis, p.color);
renderer.setSeriesItemLabelPaint(lineIdPerAxis, p.color);
renderer.setSeriesFillPaint(lineIdPerAxis, p.color);
//add line layout here
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/jacoco/model/CoverageObject.java
Expand Up @@ -14,6 +14,7 @@
import hudson.util.DataSetBuilder;
import hudson.util.Graph;
import hudson.util.ShiftedCategoryAxis;
import java.awt.Color;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
Expand Down Expand Up @@ -375,8 +376,8 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
CoverageGraphLayout layout = new CoverageGraphLayout()
.baseStroke(4f)
.axis()
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED);
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED).color(Color.RED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED).color(Color.GREEN);

createGraph(t, width, height,layout).doPng(req, rsp);
}
Expand Down
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertArrayEquals;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -68,8 +69,8 @@ public void simpleLineCoverage() throws IOException
{
CoverageGraphLayout layout = new CoverageGraphLayout()
/*.baseStroke(4f)*/
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED);
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED).color(Color.RED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED).color(Color.GREEN);

JFreeChart chart = createTestCoverage().createGraph(new GregorianCalendar(), WIDTH, HEIGHT, layout).getGraph();
assertGraph(chart, "simple.png");
Expand All @@ -80,8 +81,8 @@ public void baseStroke() throws IOException
{
CoverageGraphLayout layout = new CoverageGraphLayout().
baseStroke(2.0f)
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED);
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED).color(Color.RED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED).color(Color.GREEN);

JFreeChart chart = createTestCoverage().createGraph(new GregorianCalendar(), WIDTH, HEIGHT, layout).getGraph();
assertGraph(chart, "baseStroke.png");
Expand All @@ -93,12 +94,12 @@ public void multipleAccessAndDifferentCoverageType() throws IOException
CoverageGraphLayout layout = new CoverageGraphLayout()
.baseStroke(2f)
.axis().label("M")
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED)
.plot().type(CoverageType.LINE).value(CoverageValue.MISSED).color(Color.RED)
.axis().label("C")
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED)
.plot().type(CoverageType.LINE).value(CoverageValue.COVERED).color(Color.GREEN)
.axis().label("%")
.plot().type(CoverageType.BRANCH).value(CoverageValue.PERCENTAGE)
.plot().type(CoverageType.LINE).value(CoverageValue.PERCENTAGE);
.plot().type(CoverageType.BRANCH).value(CoverageValue.PERCENTAGE).color(Color.BLUE)
.plot().type(CoverageType.LINE).value(CoverageValue.PERCENTAGE).color(Color.YELLOW);

JFreeChart chart = createTestCoverage().createGraph(new GregorianCalendar(), WIDTH, HEIGHT, layout).getGraph();
assertGraph(chart, "multiple.png");
Expand Down

0 comments on commit af467da

Please sign in to comment.