Skip to content

Commit

Permalink
SAK-43708 JFreeChart 1.5.0 (sakaiproject#8252)
Browse files Browse the repository at this point in the history
Threads get stuck in tight loops within JFreeChart.
  • Loading branch information
axxter99 authored May 29, 2020
1 parent 34ee34f commit 2b77370
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion sitestats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<commons-betwixt.version>0.8</commons-betwixt.version>
<fop.version>1.0</fop.version>
<jfreechart.version>1.0.19</jfreechart.version>
<jfreechart.version>1.5.0</jfreechart.version>
<sst.wicket.version>6.30.0</sst.wicket.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.DateTickUnitType;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.CategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
Expand All @@ -73,8 +74,8 @@
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.Week;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.ui.RectangleInsets;
import org.jfree.util.SortOrder;
import org.jfree.chart.ui.RectangleInsets;
import org.jfree.chart.util.SortOrder;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.db.api.SqlReader;
import org.sakaiproject.db.api.SqlService;
Expand Down Expand Up @@ -735,8 +736,8 @@ private IntervalXYDataset getMonthlyLoginsDataSet() {
return null;
}

TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"), Month.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"), Month.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"));
for (ServerWideStatsRecord login : totalLogins) {
Month month = new Month ((Date) login.get (0));
s1.add (month, (Long) login.get (1));
Expand Down Expand Up @@ -783,8 +784,8 @@ private IntervalXYDataset getWeeklyLoginsDataSet() {
return null;
}

TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"),Week.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"), Week.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"));

for (ServerWideStatsRecord login : totalLogins) {
Week week = new Week ((Date) login.get (0));
Expand Down Expand Up @@ -812,8 +813,8 @@ private IntervalXYDataset getDailyLoginsDataSet() {
return null;
}

TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"),Day.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"), Day.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_logins"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_unique_logins"));
for (ServerWideStatsRecord login : totalLogins) {
Day day = new Day ((Date) login.get (0));
s1.add (day, (Long) login.get (1));
Expand Down Expand Up @@ -843,8 +844,8 @@ private IntervalXYDataset getMonthlySiteUserDataSet ()
List<ServerWideStatsRecord> siteCreatedDeletedList = getSiteCreatedDeletedStats ("monthly");
TimeSeriesCollection dataset = new TimeSeriesCollection ();
if (siteCreatedDeletedList != null) {
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"), Month.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"), Month.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"));

for (ServerWideStatsRecord login : siteCreatedDeletedList) {
Month month = new Month ((Date) login.get (0));
Expand All @@ -858,7 +859,7 @@ private IntervalXYDataset getMonthlySiteUserDataSet ()

List<ServerWideStatsRecord> newUserList = getNewUserStats ("monthly");
if (newUserList != null) {
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"), Month.class);
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"));

for (ServerWideStatsRecord login : newUserList) {
Month month = new Month ((Date) login.get (0));
Expand All @@ -877,8 +878,8 @@ private IntervalXYDataset getWeeklySiteUserDataSet ()
List<ServerWideStatsRecord> siteCreatedDeletedList = getSiteCreatedDeletedStats ("weekly");
TimeSeriesCollection dataset = new TimeSeriesCollection ();
if (siteCreatedDeletedList != null) {
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"), Week.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"), Week.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"));

for (ServerWideStatsRecord login : siteCreatedDeletedList) {
Week week = new Week ((Date) login.get (0));
Expand All @@ -892,7 +893,7 @@ private IntervalXYDataset getWeeklySiteUserDataSet ()

List<ServerWideStatsRecord> newUserList = getNewUserStats ("weekly");
if (newUserList != null) {
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"), Week.class);
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"));

for (ServerWideStatsRecord login : newUserList) {
Week week = new Week ((Date) login.get (0));
Expand All @@ -910,8 +911,8 @@ private IntervalXYDataset getDailySiteUserDataSet ()
List<ServerWideStatsRecord> siteCreatedDeletedList = getSiteCreatedDeletedStats ("daily");
TimeSeriesCollection dataset = new TimeSeriesCollection ();
if (siteCreatedDeletedList != null) {
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"), Day.class);
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"), Day.class);
TimeSeries s1 = new TimeSeries (msgs.getString ("legend_site_created"));
TimeSeries s2 = new TimeSeries (msgs.getString ("legend_site_deleted"));

for (ServerWideStatsRecord login : siteCreatedDeletedList) {
Day day = new Day ((Date) login.get (0));
Expand All @@ -925,7 +926,7 @@ private IntervalXYDataset getDailySiteUserDataSet ()

List<ServerWideStatsRecord> newUserList = getNewUserStats ("daily");
if (newUserList != null) {
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"), Day.class);
TimeSeries s3 = new TimeSeries (msgs.getString ("legend_new_user"));

for (ServerWideStatsRecord login : newUserList) {
Day day = new Day ((Date) login.get (0));
Expand Down Expand Up @@ -1051,7 +1052,7 @@ private byte[] createMonthlyLoginChart (int width, int height)
renderer1.setSeriesPaint (0, Color.RED);

DateAxis domainAxis = new DateAxis("");
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.MONTH, 1, new SimpleDateFormat ("yyyy-MM")));
domainAxis.setTickUnit (new DateTickUnit (DateTickUnitType.MONTH, 1, new SimpleDateFormat ("yyyy-MM")));
domainAxis.setTickMarkPosition (DateTickMarkPosition.START);
domainAxis.setVerticalTickLabels (true);
domainAxis.setLowerMargin (0.01);
Expand Down Expand Up @@ -1156,7 +1157,7 @@ private byte[] createWeeklyLoginChart (int width, int height)
renderer1.setSeriesPaint(0, Color.BLUE);

DateAxis domainAxis = new DateAxis("");
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd")));
domainAxis.setTickUnit (new DateTickUnit (DateTickUnitType.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd")));
domainAxis.setTickMarkPosition (DateTickMarkPosition.START);
domainAxis.setVerticalTickLabels (true);
domainAxis.setLowerMargin (0.01);
Expand Down Expand Up @@ -1243,7 +1244,7 @@ private byte[] createDailyLoginChart (int width, int height)


DateAxis domainAxis = new DateAxis("");
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd")));
domainAxis.setTickUnit (new DateTickUnit (DateTickUnitType.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd")));
domainAxis.setTickMarkPosition (DateTickMarkPosition.START);
domainAxis.setVerticalTickLabels (true);
domainAxis.setLowerMargin (0.01);
Expand Down Expand Up @@ -1522,9 +1523,9 @@ private byte[] createToolAnalysisChart (int width, int height)
CategoryItemLabelGenerator generator
= new StandardCategoryItemLabelGenerator("{1}",
NumberFormat.getInstance(new ResourceLoader().getLocale()));
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
renderer.setBaseItemLabelsVisible(true);
renderer.setDefaultItemLabelGenerator(generator);
renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
renderer.setDefaultItemLabelsVisible(true);
renderer.setItemMargin (0);
renderer.setSeriesPaint (0, Color.BLUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.RectangleInsets;
import org.jfree.util.SortOrder;
import org.jfree.chart.ui.RectangleInsets;
import org.jfree.chart.util.SortOrder;

import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.site.api.SiteService;
Expand Down Expand Up @@ -333,11 +334,8 @@ private byte[] generateBarChart(
boolean render3d, float transparency,
boolean itemLabelsVisible,
boolean smallFontInDomainAxis) {
JFreeChart chart = null;
if(render3d)
chart = ChartFactory.createBarChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
else
chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
// JFreechart 1.5 doesn't support 3D rendering so this was changed to a bar chart
JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();

// set transparency
Expand Down Expand Up @@ -375,7 +373,7 @@ private byte[] generateBarChart(
// item labels
if(itemLabelsVisible) {
plot.getRangeAxis().setUpperMargin(0.2);
barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
barrenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -388,8 +386,8 @@ public String generateLabel(CategoryDataset dataset, int row, int column) {
return "";
}
});
barrenderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
barrenderer.setBaseItemLabelsVisible(true);
barrenderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
barrenderer.setDefaultItemLabelsVisible(true);
}

BufferedImage img = chart.createBufferedImage(width, height);
Expand All @@ -407,11 +405,8 @@ private byte[] generateLineChart(
boolean render3d, float transparency,
boolean itemLabelsVisible,
boolean smallFontInDomainAxis) {
JFreeChart chart = null;
if(render3d)
chart = ChartFactory.createLineChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
else
chart = ChartFactory.createLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
// JFreechart 1.5 doesn't support 3D rendering so this was changed to a line chart
JFreeChart chart = ChartFactory.createLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();

// set transparency
Expand Down Expand Up @@ -441,7 +436,7 @@ private byte[] generateLineChart(
// item labels
if(itemLabelsVisible) {
plot.getRangeAxis().setUpperMargin(0.2);
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -453,8 +448,8 @@ public String generateLabel(CategoryDataset dataset, int row, int column) {
return "";
}
});
renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
renderer.setBaseItemLabelsVisible(true);
renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
renderer.setDefaultItemLabelsVisible(true);
}

BufferedImage img = chart.createBufferedImage(width, height);
Expand Down Expand Up @@ -565,9 +560,12 @@ private byte[] generateTimeSeriesChart(
TimeSeriesCollection tsc = (TimeSeriesCollection) dataset;
if(tsc.getSeriesCount() > 0) {
timePeriodClass = tsc.getSeries(0).getTimePeriodClass();
}else{
}

if (timePeriodClass == null) {
timePeriodClass = org.jfree.data.time.Day.class;
}

periodaxis.setAutoRangeTimePeriodClass(timePeriodClass);
}
PeriodAxisLabelInfo aperiodaxislabelinfo[] = null;
Expand Down Expand Up @@ -615,8 +613,8 @@ private byte[] generateTimeSeriesChart(
if(renderer instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer;
r.setDrawSeriesLineAsPath(true);
r.setBaseShapesVisible(true);
r.setBaseShapesFilled(true);
r.setDefaultShapesVisible(true);
r.setDefaultShapesFilled(true);
}else if(renderer instanceof XYBarRenderer) {
//XYBarRenderer r = (XYBarRenderer) renderer;
ClusteredXYBarRenderer r = new ClusteredXYBarRenderer();
Expand All @@ -632,7 +630,7 @@ private byte[] generateTimeSeriesChart(
// item labels
if(itemLabelsVisible) {
plot.getRangeAxis().setUpperMargin(0.2);
renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
renderer.setDefaultItemLabelGenerator(new XYItemLabelGenerator() {
private static final long serialVersionUID = 1L;

public String generateLabel(XYDataset dataset, int series, int item) {
Expand All @@ -644,8 +642,8 @@ public String generateLabel(XYDataset dataset, int series, int item) {


});
renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
renderer.setBaseItemLabelsVisible(true);
renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
renderer.setDefaultItemLabelsVisible(true);
}

BufferedImage img = chart.createBufferedImage(width, height);
Expand Down Expand Up @@ -1033,7 +1031,7 @@ private AbstractDataset getTimeSeriesCollectionDataset(Report report) {
if(!visitsTotalsChart && seriesFrom == null){
// without additional series
String name = msgs.getString("th_total");
TimeSeries ts = new TimeSeries(name, periodGrouping);
TimeSeries ts = new TimeSeries(name);
for(Stat s : reportData){
RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping);
if(key != null) {
Expand All @@ -1059,7 +1057,7 @@ private AbstractDataset getTimeSeriesCollectionDataset(Report report) {
// determine appropriate serie
TimeSeries ts = null;
if(!series.containsKey(serie)) {
ts = new TimeSeries(serie.toString(), periodGrouping);
ts = new TimeSeries(serie.toString());
series.put(serie, ts);
}else{
ts = series.get(serie);
Expand All @@ -1081,8 +1079,8 @@ private AbstractDataset getTimeSeriesCollectionDataset(Report report) {
}
}else if(visitsTotalsChart){
// 2 series: visits & unique visitors
TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"), periodGrouping);
TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"), periodGrouping);
TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"));
TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"));
for(Stat _s : reportData){
SiteVisits s = (SiteVisits) _s;
RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping);
Expand Down

0 comments on commit 2b77370

Please sign in to comment.