Improved statistics charts. Added doughnut chart.
This commit is contained in:
parent
96a7b338c7
commit
56132be606
6 changed files with 89 additions and 14 deletions
|
@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import fr.devinsy.statoolinfos.HtmlizerContext;
|
import fr.devinsy.statoolinfos.HtmlizerContext;
|
||||||
import fr.devinsy.statoolinfos.core.Federation;
|
import fr.devinsy.statoolinfos.core.Federation;
|
||||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
|
import fr.devinsy.statoolinfos.htmlize.charts.DoughnutChartView;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.PieChart;
|
import fr.devinsy.statoolinfos.htmlize.charts.PieChart;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView;
|
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView;
|
||||||
import fr.devinsy.statoolinfos.stats.StatAgent;
|
import fr.devinsy.statoolinfos.stats.StatAgent;
|
||||||
|
@ -74,9 +74,7 @@ public class FederationStatsPage
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation);
|
OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation);
|
||||||
PieChart pie = new PieChart("Participation");
|
PieChart pie = Htmlizer.toPieChart(turnout);
|
||||||
pie.add("Active", turnout.getActiveCount(), ChartColor.GREEN);
|
|
||||||
pie.add("Passive", turnout.getPassiveCount(), ChartColor.ORANGE);
|
|
||||||
data.setContent("turnoutChart", PieChartView.build(pie));
|
data.setContent("turnoutChart", PieChartView.build(pie));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +82,14 @@ public class FederationStatsPage
|
||||||
{
|
{
|
||||||
HostServerTypeStats stats = StatAgent.statHostServerType(federation);
|
HostServerTypeStats stats = StatAgent.statHostServerType(federation);
|
||||||
PieChart pie = Htmlizer.toPieChart(stats);
|
PieChart pie = Htmlizer.toPieChart(stats);
|
||||||
data.setContent("hostServerTypeChart", PieChartView.build(pie));
|
data.setContent("hostServerTypeChart", DoughnutChartView.build(pie));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
HostProviderTypeStats stats = StatAgent.statHostProviderType(federation);
|
HostProviderTypeStats stats = StatAgent.statHostProviderType(federation);
|
||||||
PieChart pie = Htmlizer.toPieChart(stats);
|
PieChart pie = Htmlizer.toPieChart(stats);
|
||||||
data.setContent("hostProviderTypeChart", PieChartView.build(pie));
|
data.setContent("hostProviderTypeChart", DoughnutChartView.build(pie));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -331,8 +331,8 @@ public class Htmlizer
|
||||||
PieChart result;
|
PieChart result;
|
||||||
|
|
||||||
result = new PieChart("Participation");
|
result = new PieChart("Participation");
|
||||||
result.add("Active", stats.getActiveCount(), ChartColor.GREEN);
|
result.add("Active", stats.getActiveCount(), ChartColor.RED);
|
||||||
result.add("Passive", stats.getPassiveCount(), ChartColor.ORANGE);
|
result.add("Passive", stats.getPassiveCount(), ChartColor.BLUE);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class BarMonthsChartView
|
||||||
code = code.replace("rgb(54, 162, 235, 0.2)", color.light());
|
code = code.replace("rgb(54, 162, 235, 0.2)", color.light());
|
||||||
code = code.replace("description", XidynUtils.escapeXmlBlank(description));
|
code = code.replace("description", XidynUtils.escapeXmlBlank(description));
|
||||||
code = code.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "barMonthsChart"));
|
code = code.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "barMonthsChart"));
|
||||||
code = code.replace("# of Votes", title.replaceAll("'", "\\\\'"));
|
code = code.replace("# of Votes", title.replace("'", "\\\\'"));
|
||||||
code = code.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels));
|
code = code.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels));
|
||||||
code = code.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
|
code = code.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||||
|
*
|
||||||
|
* This file is part of StatoolInfos, simple service statistics tool.
|
||||||
|
*
|
||||||
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* StatoolInfos is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package fr.devinsy.statoolinfos.htmlize.charts;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||||
|
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView.PieType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class DoughnutChartView.
|
||||||
|
*/
|
||||||
|
public class DoughnutChartView
|
||||||
|
{
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DoughnutChartView.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the.
|
||||||
|
*
|
||||||
|
* @param pie
|
||||||
|
* the pie
|
||||||
|
* @return the string
|
||||||
|
* @throws StatoolInfosException
|
||||||
|
* the statool infos exception
|
||||||
|
*/
|
||||||
|
public static String build(final PieChart pie) throws StatoolInfosException
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
|
||||||
|
result = PieChartView.build(PieType.DOUGHNUT, pie);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,6 +35,31 @@ public class PieChartView
|
||||||
{
|
{
|
||||||
private static Logger logger = LoggerFactory.getLogger(PieChartView.class);
|
private static Logger logger = LoggerFactory.getLogger(PieChartView.class);
|
||||||
|
|
||||||
|
enum PieType
|
||||||
|
{
|
||||||
|
DOUGHNUT,
|
||||||
|
PIE
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the.
|
||||||
|
*
|
||||||
|
* @param pie
|
||||||
|
* the pie
|
||||||
|
* @return the string
|
||||||
|
* @throws StatoolInfosException
|
||||||
|
* the statool infos exception
|
||||||
|
*/
|
||||||
|
public static String build(final PieChart pie) throws StatoolInfosException
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
|
||||||
|
result = build(PieType.PIE, pie);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the.
|
* Builds the.
|
||||||
*
|
*
|
||||||
|
@ -43,11 +68,11 @@ public class PieChartView
|
||||||
* @return the string
|
* @return the string
|
||||||
* @throws StatoolInfosException
|
* @throws StatoolInfosException
|
||||||
*/
|
*/
|
||||||
public static String build(final PieChart pie) throws StatoolInfosException
|
public static String build(final PieType type, final PieChart pie) throws StatoolInfosException
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
result = build(pie.getTitle(), pie.getLabels(), new StringList(pie.getValues()), pie.getColors());
|
result = build(type, pie.getTitle(), pie.getLabels(), new StringList(pie.getValues()), pie.getColors());
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
@ -70,7 +95,7 @@ public class PieChartView
|
||||||
* @throws StatoolInfosException
|
* @throws StatoolInfosException
|
||||||
* the statool infos exception
|
* the statool infos exception
|
||||||
*/
|
*/
|
||||||
public static String build(final String title, final StringList labels, final StringList values, final StringList colors) throws StatoolInfosException
|
public static String build(final PieType type, final String title, final StringList labels, final StringList values, final StringList colors) throws StatoolInfosException
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
try
|
try
|
||||||
|
@ -78,6 +103,7 @@ public class PieChartView
|
||||||
String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml"));
|
String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml"));
|
||||||
result = XidynUtils.extractBodyContent(source);
|
result = XidynUtils.extractBodyContent(source);
|
||||||
|
|
||||||
|
result = result.replaceFirst("type: '.*'", "type: '" + type.toString().toLowerCase() + "'");
|
||||||
result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "PieChart"));
|
result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "PieChart"));
|
||||||
result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
|
result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
|
||||||
result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(colors));
|
result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(colors));
|
||||||
|
|
|
@ -23,8 +23,7 @@ var myChart = new Chart(ctx,
|
||||||
datasets:
|
datasets:
|
||||||
[{
|
[{
|
||||||
data: [ 10,40,50 ],
|
data: [ 10,40,50 ],
|
||||||
backgroundColor: [window.chartColors.red,window.chartColors.orange,window.chartColors.yellow,window.chartColors.green,window.chartColors.blue],
|
backgroundColor: [window.chartColors.red,window.chartColors.orange,window.chartColors.yellow,window.chartColors.green,window.chartColors.blue]
|
||||||
/*label: 'Dataset 1'*/
|
|
||||||
}],
|
}],
|
||||||
labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue']
|
labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue']
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue