gral
gral copied to clipboard
DrawableWriter.write hangs on PDF pie chart
Consider this main file (sorry, it is a bit verbose, but required to reproduce the bug):
package ca.uqac.lif.labpal.export;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import de.erichseifert.gral.data.DataSource;
import de.erichseifert.gral.graphics.Insets2D;
import de.erichseifert.gral.io.data.DataReader;
import de.erichseifert.gral.io.data.DataReaderFactory;
import de.erichseifert.gral.io.plots.DrawableWriter;
import de.erichseifert.gral.io.plots.DrawableWriterFactory;
import de.erichseifert.gral.plots.PiePlot;
public class Reprogral
{
public static void main(String[] args) throws IOException
{
DataSource ds = readData("/tmp/share.csv");
PiePlot plot = new PiePlot(ds);
plot.setInsets(new Insets2D.Double(20d, 60d, 60d, 40d));
plot.getTitle().setText("Something");
plot.setLegendVisible(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DrawableWriter wr = DrawableWriterFactory.getInstance().get("application/pdf");
try
{
wr.write(plot, baos, 640, 480);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static DataSource readData(String filename) throws IOException {
FileInputStream dataStream = new FileInputStream(filename);
DataReaderFactory factory = DataReaderFactory.getInstance();
DataReader reader = factory.get("text/tab-separated-values");
try {
DataSource data = reader.read(dataStream, Double.class);
return data;
} finally {
dataStream.close();
}
}
}
The contents of share.csv
being:
10.0
15.0
20.0
25.0
30.0
Expected result: the program puts the image data into the bytes
array and terminates.
Observed result: the program never terminates; debugging shows it stalls on the line wr.write(...)
Additional info: replacing application/pdf
by image/png
as the image type produces the correct result. The bug seems to occur only with the PDF image type.
By the way, thanks for this great library! I am using it in one of my projects called LabPal.