1. Cleaned up paths in the freemarker templates to not refer old visualization urls.
2. Changed web.xml url-pattern mapping from old visualization servlet TO freemarkerized version. 3. Updated style for temporal graph vis. 4. Changed freemarkerized code snippets to not refer old visualization servlets.
This commit is contained in:
parent
f84cc726ac
commit
dea26c9527
8 changed files with 330 additions and 255 deletions
|
@ -1273,6 +1273,9 @@
|
|||
<url-pattern>/admin/sparqlquery</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DummyVisClient</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.visualization.DummyVisClientController</servlet-class>
|
||||
|
@ -1283,6 +1286,9 @@
|
|||
<url-pattern>/admin/dummyVisClient</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DummyVisClientFM</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.DummyVisClientController</servlet-class>
|
||||
|
@ -1293,16 +1299,31 @@
|
|||
<url-pattern>/admin/dummyVisClientfm</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>DummyVisClientFM</servlet-name>
|
||||
<url-pattern>/admin/dummyVisClient</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
<servlet>
|
||||
<servlet-name>VisualizationController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController</servlet-class>
|
||||
</servlet>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>VisualizationController</servlet-name>
|
||||
<url-pattern>/visualization</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
-->
|
||||
|
||||
<servlet>
|
||||
<servlet-name>StandardVisualizationController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.StandardVisualizationController</servlet-class>
|
||||
|
@ -1313,6 +1334,11 @@
|
|||
<url-pattern>/visualizationfm</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>StandardVisualizationController</servlet-name>
|
||||
<url-pattern>/visualization</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>AjaxVisualizationController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.AjaxVisualizationController</servlet-class>
|
||||
|
|
|
@ -187,6 +187,10 @@ li{
|
|||
background-color: #ECFFB3 !important;
|
||||
}
|
||||
|
||||
.datatablerowhighlight td {
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
/*
|
||||
.metallic{
|
||||
background-color: #212D34;
|
||||
|
|
|
@ -12,7 +12,7 @@ ${urls.base}
|
|||
<#assign loadingImageLink = '/${themeDir}site_icons/visualization/ajax-loader.gif'>
|
||||
|
||||
<#assign uri="http://vivo-trunk.indiana.edu/individual/n6079">
|
||||
<#assign testURL = '${urls.base}/visualization?vis=person_pub_count&container=ajax_recipient&render_mode=dynamic&vis_mode=wth&uri=${uri?url}'>
|
||||
<#assign testURL = '${urls.base}/visualizationfm?vis=person_pub_count&container=ajax_recipient&render_mode=dynamic&vis_mode=wth&uri=${uri?url}'>
|
||||
|
||||
<style type="text/css">
|
||||
.get_vis {
|
||||
|
@ -88,13 +88,6 @@ $(document).ready(function() {
|
|||
|
||||
<h2 id="ajax_activator">Hello World!</h2>
|
||||
|
||||
<c:url var="staticHref" value="/visualization">
|
||||
<c:param name="vis" value="person_pub_count"/>
|
||||
<c:param name="render_mode" value="standalone"/>
|
||||
<c:param name="vis_mode" value="wth"/>
|
||||
<c:param name="uri" value="http://vivo.library.cornell.edu/ns/0.1#individual5156"/>
|
||||
</c:url>
|
||||
|
||||
<a href="${testURL}">vis query for person -> "Crane, Brian"</a>
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#assign googleJSAPI = 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22areachart%22%2C%22imagesparkline%22%5D%7D%5D%7D'>
|
||||
|
||||
${headScripts.add(googleJSAPI)}
|
||||
|
||||
<#include "/visualization/grantSparklineContent.ftl">
|
|
@ -1,238 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
<#assign visContainerID = '${sparklineVO.visContainerDivID}'>
|
||||
|
||||
<#if sparklineVO.shortVisMode>
|
||||
<#assign sparklineContainerID = 'grant_count_short_sparkline_vis'>
|
||||
<#else>
|
||||
<#assign sparklineContainerID = 'grant_count_full_sparkline_vis'>
|
||||
</#if>
|
||||
|
||||
<#-- This is used to prevent collision between sparkline & visualization container div ids. -->
|
||||
<#if visContainerID?upper_case == sparklineContainerID?upper_case>
|
||||
<#assign sparklineContainerID = visContainerID + "_spark">
|
||||
</#if>
|
||||
|
||||
<div class="staticPageBackground">
|
||||
|
||||
<div id="${visContainerID}">
|
||||
|
||||
<style type='text/css'>
|
||||
.sparkline_style table {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: auto;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
vertical-align: inherit;
|
||||
}
|
||||
|
||||
table.sparkline_wrapper_table
|
||||
td,th {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.vis_link a {
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
td.sparkline_number {
|
||||
text-align: right;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
td.sparkline_text {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.incomplete-data-holder {
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function drawGrantCountVisualization(providedSparklineImgTD) {
|
||||
|
||||
var data = new google.visualization.DataTable();
|
||||
data.addColumn('string', 'Year');
|
||||
data.addColumn('number', 'Grants');
|
||||
data.addRows(${sparklineVO.numOfYearsToBeRendered});
|
||||
|
||||
<#list sparklineVO.yearToEntityCountDataTable as yearToGrantCountDataElement>
|
||||
data.setValue(${yearToGrantCountDataElement.yearToEntityCounter}, 0, '${yearToGrantCountDataElement.year}');
|
||||
data.setValue(${yearToGrantCountDataElement.yearToEntityCounter}, 1, ${yearToGrantCountDataElement.currentEntitiesCount});
|
||||
</#list>
|
||||
|
||||
<#-- Create a view of the data containing only the column pertaining to grant count. -->
|
||||
var sparklineDataView = new google.visualization.DataView(data);
|
||||
sparklineDataView.setColumns([1]);
|
||||
|
||||
<#if sparklineVO.shortVisMode>
|
||||
|
||||
<#-- For the short view we only want the last 10 year's view of grant count, hence we filter
|
||||
the data we actually want to use for render. -->
|
||||
|
||||
sparklineDataView.setRows(data.getFilteredRows([{
|
||||
column: 0,
|
||||
minValue: '${sparklineVO.earliestRenderedGrantYear?c}',
|
||||
maxValue: '${sparklineVO.latestRenderedGrantYear?c}'
|
||||
}]));
|
||||
|
||||
<#else>
|
||||
|
||||
</#if>
|
||||
|
||||
<#-- Create the vis object and draw it in the div pertaining to sparkline. -->
|
||||
var sparkline = new google.visualization.ImageSparkLine(providedSparklineImgTD[0]);
|
||||
sparkline.draw(sparklineDataView, {
|
||||
width: 65,
|
||||
height: 30,
|
||||
showAxisLines: false,
|
||||
showValueLabels: false,
|
||||
labelPosition: 'none'
|
||||
});
|
||||
|
||||
<#if sparklineVO.shortVisMode>
|
||||
|
||||
<#-- We want to display how many grant counts were considered, so this is used to calculate this. -->
|
||||
|
||||
var shortSparkRows = sparklineDataView.getViewRows();
|
||||
var renderedShortSparks = 0;
|
||||
$.each(shortSparkRows, function(index, value) {
|
||||
renderedShortSparks += data.getValue(value, 1);
|
||||
});
|
||||
|
||||
$('#${sparklineContainerID} td.sparkline_number').text(parseInt(renderedShortSparks) + parseInt(${sparklineVO.unknownYearGrants}));
|
||||
|
||||
var sparksText = ' grant(s) within the last 10 years <span class="incomplete-data-holder" title="This information'
|
||||
+ ' is based solely on grants which have been loaded into the VIVO system. This may only be a small'
|
||||
+ ' sample of the person\'s total work.">incomplete list</span>';
|
||||
|
||||
<#else>
|
||||
|
||||
/*
|
||||
* Sparks that will be rendered will always be the one's which has
|
||||
* any year associated with it. Hence.
|
||||
* */
|
||||
var renderedSparks = ${sparklineVO.renderedSparks};
|
||||
$('#${sparklineContainerID} td.sparkline_number').text(parseInt(renderedSparks) + parseInt(${sparklineVO.unknownYearGrants}));
|
||||
|
||||
var sparksText = ' grant(s) from <span class="sparkline_range">${sparklineVO.earliestYearConsidered?c}'
|
||||
+ ' to ${sparklineVO.latestRenderedGrantYear?c}</span> '
|
||||
+ ' <a href="${sparklineVO.downloadDataLink}" class="inline_href">(.CSV File)</a> ';
|
||||
</#if>
|
||||
|
||||
$('#${sparklineContainerID} td.sparkline_text').html(sparksText);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* This will activate the visualization. It takes care of creating
|
||||
* div elements to hold the actual sparkline image and then calling the
|
||||
* drawGrantCountVisualization function.
|
||||
* */
|
||||
|
||||
$(document).ready(function() {
|
||||
var sparklineImgTD;
|
||||
|
||||
/*
|
||||
* This is a nuclear option (creating the container in which everything goes)
|
||||
* the only reason this will be ever used is the API user never submitted a
|
||||
* container ID in which everything goes. The alternative was to let the
|
||||
* vis not appear in the calling page at all. So now atleast vis appears but
|
||||
* appended at the bottom of the body.
|
||||
* */
|
||||
|
||||
if ($('#${visContainerID}').length === 0) {
|
||||
$('<div/>', {
|
||||
'id': '${visContainerID}'
|
||||
}).appendTo('body');
|
||||
}
|
||||
|
||||
if ($('#${sparklineContainerID}').length === 0) {
|
||||
|
||||
$('<div/>', {
|
||||
'id': '${sparklineContainerID}',
|
||||
'class': 'sparkline_style'
|
||||
}).prependTo('#${visContainerID}');
|
||||
|
||||
var table = $('<table>');
|
||||
table.attr('class', 'sparkline_wrapper_table');
|
||||
var row = $('<tr>');
|
||||
sparklineImgTD = $('<td>');
|
||||
sparklineImgTD.attr('id', '${sparklineContainerID}_img');
|
||||
sparklineImgTD.attr('width', '65');
|
||||
sparklineImgTD.attr('align', 'right');
|
||||
sparklineImgTD.attr('class', 'sparkline_style');
|
||||
|
||||
row.append(sparklineImgTD);
|
||||
|
||||
console.log(sparklineImgTD);
|
||||
|
||||
var sparklineNumberTD = $('<td>');
|
||||
sparklineNumberTD.attr('width', '30');
|
||||
sparklineNumberTD.attr('align', 'right');
|
||||
sparklineNumberTD.attr('class', 'sparkline_number');
|
||||
row.append(sparklineNumberTD);
|
||||
var sparklineTextTD = $('<td>');
|
||||
sparklineTextTD.attr('width', '450');
|
||||
sparklineTextTD.attr('class', 'sparkline_text');
|
||||
row.append(sparklineTextTD);
|
||||
table.append(row);
|
||||
table.prependTo('#${sparklineContainerID}');
|
||||
|
||||
}
|
||||
|
||||
console.log(sparklineImgTD);
|
||||
drawGrantCountVisualization(sparklineImgTD);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<#if sparklineVO.shortVisMode>
|
||||
|
||||
<span class="vis_link">
|
||||
<a href="${sparklineVO.fullTimelineNetworkLink}">View all grants and corresponding co-pi network.</a>
|
||||
|
||||
</span>
|
||||
|
||||
<#else>
|
||||
|
||||
<!-- For Full Sparkline - Print the Table of Grant Counts per Year -->
|
||||
<p>
|
||||
<table id='sparkline_data_table'>
|
||||
<caption>
|
||||
Grants per year <a href="${sparklineVO.downloadDataLink}">(.CSV File)</a>
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Year
|
||||
</th>
|
||||
<th>
|
||||
Grants
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<#list sparklineVO.yearToActivityCount?keys as year>
|
||||
<tr>
|
||||
<td>
|
||||
${year}
|
||||
</td>
|
||||
<td>
|
||||
${sparklineVO.yearToActivityCount[year]}
|
||||
</td>
|
||||
</tr>
|
||||
</#list>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
Download data as <a href="${sparklineVO.downloadDataLink}">.csv</a> file.
|
||||
<br />
|
||||
</p>
|
||||
|
||||
</#if>
|
||||
|
||||
</div>
|
|
@ -25,7 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.AllPro
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.GenericQueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap;
|
||||
|
||||
/**
|
||||
* This request handler is used when you need helpful information to add more context
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.GenericQueryMap;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,297 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Stroke;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.itextpdf.text.BadElementException;
|
||||
import com.itextpdf.text.BaseColor;
|
||||
import com.itextpdf.text.Chunk;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.FontFactory;
|
||||
import com.itextpdf.text.Image;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.Phrase;
|
||||
import com.itextpdf.text.pdf.ColumnText;
|
||||
import com.itextpdf.text.pdf.PdfContentByte;
|
||||
import com.itextpdf.text.pdf.PdfGState;
|
||||
import com.itextpdf.text.pdf.PdfPCell;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
|
||||
public class PDFDocument {
|
||||
|
||||
|
||||
static Stroke stroke = new BasicStroke(5.f, BasicStroke.CAP_ROUND,
|
||||
BasicStroke.JOIN_ROUND);
|
||||
|
||||
final static Color bg = Color.green;
|
||||
|
||||
final static Color fg = Color.black;
|
||||
|
||||
public PDFDocument(String authorName,
|
||||
Map<String, Integer> yearToPublicationCount,
|
||||
Document document,
|
||||
PdfWriter pdfWriter) {
|
||||
|
||||
// setPreferredSize(new Dimension(600,400));
|
||||
|
||||
try {
|
||||
|
||||
document.addTitle("PDF Pipeline iText Prototype");
|
||||
document.addAuthor(authorName);
|
||||
document.addSubject("This example tests text, color, image, transparency & table functionality.");
|
||||
document.addKeywords("text, color, image, transparency, table");
|
||||
document.addCreator("Standalone PDF Renderer using iText");
|
||||
|
||||
Paragraph header = new Paragraph();
|
||||
|
||||
Font pageHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLDITALIC | Font.UNDERLINE);
|
||||
Font featureHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, new BaseColor(Color.red));
|
||||
|
||||
header.add(new Chunk("PDF Pipeline Prototype v2 using iText\n",
|
||||
pageHeaderStyle));
|
||||
|
||||
header.setSpacingAfter(15f);
|
||||
|
||||
|
||||
document.add(header);
|
||||
|
||||
|
||||
Paragraph content = new Paragraph();
|
||||
|
||||
content.add(new Chunk("Publication Count - Author Name - " + authorName,
|
||||
featureHeaderStyle));
|
||||
|
||||
content.setSpacingAfter(15f);
|
||||
|
||||
document.add(content);
|
||||
// step4
|
||||
|
||||
PdfPTable publicationCount = createTable(yearToPublicationCount);
|
||||
|
||||
document.add(publicationCount);
|
||||
|
||||
content = new Paragraph();
|
||||
|
||||
content.add(new Chunk("Transparency of Shapes",
|
||||
featureHeaderStyle));
|
||||
|
||||
content.setSpacingAfter(15f);
|
||||
|
||||
document.add(content);
|
||||
|
||||
createTransparencyShapes(document, pdfWriter);
|
||||
|
||||
|
||||
createImage(document, pdfWriter, featureHeaderStyle);
|
||||
|
||||
} catch (DocumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void createImage(Document document, PdfWriter writer,
|
||||
Font featureHeaderStyle) throws BadElementException,
|
||||
MalformedURLException, IOException, DocumentException {
|
||||
Image imageSprite = Image.getInstance(new URL("http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG"));
|
||||
imageSprite.setAbsolutePosition(400, 500);
|
||||
imageSprite.scaleAbsolute(171.0f, 250.0f);
|
||||
float imageSpriteY = document.getPageSize().getHeight() * 0.60f;
|
||||
float imageSpriteX = document.getPageSize().getWidth() * 0.65f;
|
||||
imageSprite.setAlignment(Image.UNDERLYING);
|
||||
|
||||
document.add(imageSprite);
|
||||
|
||||
PdfContentByte cb = writer.getDirectContent();
|
||||
ColumnText ct = new ColumnText(cb);
|
||||
Chunk imageHeader = new Chunk("Images",
|
||||
featureHeaderStyle);
|
||||
ct.addText(imageHeader);
|
||||
ct.setAlignment(Element.ALIGN_LEFT);
|
||||
ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(),
|
||||
imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20);
|
||||
ct.go();
|
||||
|
||||
ct = new ColumnText(cb);
|
||||
Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.",
|
||||
FontFactory.getFont(FontFactory.TIMES_ROMAN, 8));
|
||||
ct.addText(imageFooter);
|
||||
ct.setAlignment(Element.ALIGN_CENTER);
|
||||
ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY);
|
||||
ct.go();
|
||||
}
|
||||
|
||||
private void createTransparencyShapes(Document document,
|
||||
PdfWriter writer) throws Exception {
|
||||
PdfContentByte cb = writer.getDirectContent();
|
||||
|
||||
pictureBackdrop(document.leftMargin(), 350, cb);
|
||||
cb.saveState();
|
||||
PdfGState gs1 = new PdfGState();
|
||||
gs1.setFillOpacity(0.5f);
|
||||
cb.setGState(gs1);
|
||||
pictureCircles(document.leftMargin(), 350, cb);
|
||||
cb.restoreState();
|
||||
|
||||
cb.resetRGBColorFill();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a square and fills half of it with a gray rectangle.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param cb
|
||||
* @throws Exception
|
||||
*/
|
||||
public void pictureBackdrop(float x, float y, PdfContentByte cb) throws Exception {
|
||||
cb.setColorStroke(new BaseColor(Color.black));
|
||||
cb.setColorFill(new BaseColor(Color.gray));
|
||||
cb.rectangle(x, y, 100, 200);
|
||||
cb.fill();
|
||||
cb.setLineWidth(2);
|
||||
cb.rectangle(x, y, 200, 200);
|
||||
cb.stroke();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 3 circles in different colors that intersect with eachother.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param cb
|
||||
* @throws Exception
|
||||
*/
|
||||
public void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
|
||||
|
||||
cb.saveState();
|
||||
PdfGState gs1 = new PdfGState();
|
||||
gs1.setFillOpacity(1.0f);
|
||||
cb.setGState(gs1);
|
||||
cb.setColorFill(new BaseColor(Color.red));
|
||||
cb.circle(x + 70, y + 70, 50);
|
||||
cb.fill();
|
||||
cb.restoreState();
|
||||
|
||||
cb.setColorFill(new BaseColor(Color.yellow));
|
||||
cb.circle(x + 100, y + 130, 50);
|
||||
cb.fill();
|
||||
cb.setColorFill(new BaseColor(Color.blue));
|
||||
cb.circle(x + 130, y + 70, 50);
|
||||
cb.fill();
|
||||
}
|
||||
|
||||
private PdfPTable createTable(Map<String, Integer> yearToPublicationCount) {
|
||||
|
||||
Font normalContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11);
|
||||
Font summaryContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLDITALIC);
|
||||
BaseColor summaryBackgroundColor = new BaseColor(0xEE, 0xEE, 0xEE);
|
||||
BaseColor headerBackgroundColor = new BaseColor(0xC3, 0xD9, 0xFF);
|
||||
BaseColor bodyBackgroundColor = new BaseColor(Color.white);
|
||||
|
||||
PdfPTable table = new PdfPTable(2);
|
||||
table.setWidthPercentage(36.0f);
|
||||
|
||||
table.setHorizontalAlignment(Element.ALIGN_LEFT);
|
||||
table.getDefaultCell().setBorderWidth(0.0f);
|
||||
table.setHeaderRows(2);
|
||||
|
||||
PdfPCell cell;
|
||||
cell = new PdfPCell(new Phrase("Publications per year", normalContentStyle));
|
||||
setTableCaptionStyle(summaryBackgroundColor, cell);
|
||||
table.addCell(cell);
|
||||
|
||||
cell = new PdfPCell(new Phrase("Year", normalContentStyle));
|
||||
setTableHeaderStyle(headerBackgroundColor, cell);
|
||||
table.addCell(cell);
|
||||
|
||||
cell.setPhrase(new Phrase("Publications", normalContentStyle));
|
||||
table.addCell(cell);
|
||||
|
||||
|
||||
|
||||
setTableBodyStyle(bodyBackgroundColor, cell);
|
||||
int totalPublications = 0;
|
||||
|
||||
for (Entry<String, Integer> currentEntry : yearToPublicationCount.entrySet()) {
|
||||
|
||||
cell.setPhrase(new Phrase(currentEntry.getKey(), normalContentStyle));
|
||||
table.addCell(cell);
|
||||
|
||||
cell.setPhrase(new Phrase(currentEntry.getValue().toString(), normalContentStyle));
|
||||
table.addCell(cell);
|
||||
|
||||
totalPublications += currentEntry.getValue();
|
||||
}
|
||||
|
||||
setTableFooterStyle(summaryBackgroundColor, cell);
|
||||
cell.setPhrase(new Phrase("Total", summaryContentStyle));
|
||||
table.addCell(cell);
|
||||
|
||||
cell.setPhrase(new Phrase(String.valueOf(totalPublications), summaryContentStyle));
|
||||
table.addCell(cell);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private void setTableFooterStyle(BaseColor footerBackgroundColor,
|
||||
PdfPCell cell) {
|
||||
cell.setBorderWidth(0.0f);
|
||||
cell.setBackgroundColor(footerBackgroundColor);
|
||||
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cell.setPaddingTop(5f);
|
||||
cell.setPaddingRight(10f);
|
||||
cell.setPaddingBottom(5f);
|
||||
cell.setPaddingLeft(10f);
|
||||
}
|
||||
|
||||
private void setTableBodyStyle(BaseColor bodyBackgroundColor,
|
||||
PdfPCell cell) {
|
||||
cell.setBorderWidth(0.0f);
|
||||
cell.setBackgroundColor(bodyBackgroundColor);
|
||||
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cell.setPaddingTop(5f);
|
||||
cell.setPaddingRight(10f);
|
||||
cell.setPaddingBottom(5f);
|
||||
cell.setPaddingLeft(10f);
|
||||
}
|
||||
|
||||
private void setTableHeaderStyle(BaseColor headerBackgroundColor,
|
||||
PdfPCell cell) {
|
||||
cell.setBorderWidth(0.0f);
|
||||
cell.setBackgroundColor(headerBackgroundColor);
|
||||
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cell.setPaddingTop(5f);
|
||||
cell.setPaddingRight(10f);
|
||||
cell.setPaddingBottom(5f);
|
||||
cell.setPaddingLeft(10f);
|
||||
}
|
||||
|
||||
private void setTableCaptionStyle(BaseColor summaryBackgroundColor,
|
||||
PdfPCell cell) {
|
||||
cell.setBorderWidth(0.0f);
|
||||
cell.setBackgroundColor(summaryBackgroundColor);
|
||||
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cell.setPaddingTop(5.0f);
|
||||
cell.setPaddingRight(10.0f);
|
||||
cell.setPaddingBottom(5.0f);
|
||||
cell.setPaddingLeft(10.0f);
|
||||
cell.setColspan(2);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue