1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Modified signature for returning the file instance (Heroku read-only needs this)

This commit is contained in:
Beruto 2017-08-09 22:07:24 +02:00
parent d95b1d2f14
commit 6e13ce07f0

View file

@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
@ -270,20 +271,21 @@ public class Plotter {
*
* @param pngFileName - path and filename
* @param plotTitle - title that appears on top of image
* @return BufferedImage image to write
*/
public void plot(String pngFileName, String plotTitle) {
public BufferedImage plot(String pngFileName, String plotTitle) {
String filename = pngFileName;
if (!pngFileName.endsWith(".png")) filename += ".png";
if (plotSolutionAsWell) {
plot(vrp, routes, filename, plotTitle);
return plot(vrp, routes, filename, plotTitle);
} else if (!(vrp.getInitialVehicleRoutes().isEmpty())) {
plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle);
return plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle);
} else {
plot(vrp, null, filename, plotTitle);
return plot(vrp, null, filename, plotTitle);
}
}
private void plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) {
private BufferedImage plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) {
log.info("plot to {}", pngFile);
XYSeriesCollection problem;
XYSeriesCollection solution = null;
@ -295,7 +297,7 @@ public class Plotter {
if (routes != null) solution = makeSolutionSeries(vrp, routes);
} catch (NoLocationFoundException e) {
log.warn("cannot plot vrp, since coord is missing");
return;
return null;
}
final XYPlot plot = createPlot(problem, shipments, solution);
JFreeChart chart = new JFreeChart(title, plot);
@ -305,6 +307,7 @@ public class Plotter {
chart.addLegend(legend);
save(chart, pngFile);
return chart.createBufferedImage(1024, 1024);
}