use of uk.ac.ebi.spot.goci.pussycat.renderlet.RenderingEvent in project goci by EBISPOT.
the class ChromosomeRenderlet method render.
public void render(RenderletNexus nexus, C context, E entity) {
int position = getPosition();
int height = SVGCanvas.canvasHeight;
int width = SVGCanvas.canvasWidth;
double chromWidth = (double) width / 12;
double chromHeight = (double) height / 2;
double xCoordinate;
double yCoordinate = 0;
if (position < 12) {
xCoordinate = position * chromWidth;
} else {
xCoordinate = (position - 12) * chromWidth;
yCoordinate = (double) height / 2;
}
InputStream in = null;
try {
in = getSVGFile().openStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document chromSVG = db.parse(in);
Element root = chromSVG.getDocumentElement();
Element g = (Element) root.getElementsByTagName("g").item(0).cloneNode(true);
setChromBands(g, nexus);
StringBuilder builder = new StringBuilder();
builder.append("translate(");
builder.append(Double.toString(xCoordinate));
builder.append(",");
builder.append(Double.toString(yCoordinate));
builder.append(")");
g.setAttribute("transform", builder.toString());
g.setAttribute("gwasname", getName());
g.removeAttribute("title");
SVGArea currentArea = new SVGArea(xCoordinate, yCoordinate, chromWidth, chromHeight, 0);
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(g), new StreamResult(buffer));
String str = buffer.toString();
RenderingEvent<E> event = new RenderingEvent<E>(entity, str, currentArea, this);
nexus.renderingEventOccurred(event);
} catch (ParserConfigurationException e) {
throw new RuntimeException("Failed to read in template chromosome SVG from original resource", e);
} catch (SAXException e) {
throw new RuntimeException("Failed to read in template chromosome SVG from original resource", e);
} catch (IOException e) {
throw new RuntimeException("Failed to render chromosome SVG", e);
} catch (TransformerConfigurationException e) {
throw new RuntimeException("Failed to render chromosome SVG", e);
} catch (TransformerException e) {
throw new RuntimeException("Failed to render chromosome SVG", e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// tried our best!
}
}
}
}
Aggregations