diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index afe06f6..1c900fa 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.core.Federation; 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.PieChartView; import fr.devinsy.statoolinfos.stats.StatAgent; @@ -74,9 +74,7 @@ public class FederationStatsPage // { OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation); - PieChart pie = new PieChart("Participation"); - pie.add("Active", turnout.getActiveCount(), ChartColor.GREEN); - pie.add("Passive", turnout.getPassiveCount(), ChartColor.ORANGE); + PieChart pie = Htmlizer.toPieChart(turnout); data.setContent("turnoutChart", PieChartView.build(pie)); } @@ -84,14 +82,14 @@ public class FederationStatsPage { HostServerTypeStats stats = StatAgent.statHostServerType(federation); PieChart pie = Htmlizer.toPieChart(stats); - data.setContent("hostServerTypeChart", PieChartView.build(pie)); + data.setContent("hostServerTypeChart", DoughnutChartView.build(pie)); } // { HostProviderTypeStats stats = StatAgent.statHostProviderType(federation); PieChart pie = Htmlizer.toPieChart(stats); - data.setContent("hostProviderTypeChart", PieChartView.build(pie)); + data.setContent("hostProviderTypeChart", DoughnutChartView.build(pie)); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 0a3d8b1..821b261 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -331,8 +331,8 @@ public class Htmlizer PieChart result; result = new PieChart("Participation"); - result.add("Active", stats.getActiveCount(), ChartColor.GREEN); - result.add("Passive", stats.getPassiveCount(), ChartColor.ORANGE); + result.add("Active", stats.getActiveCount(), ChartColor.RED); + result.add("Passive", stats.getPassiveCount(), ChartColor.BLUE); // return result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java index 3cbb424..b383429 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java @@ -107,7 +107,7 @@ public class BarMonthsChartView code = code.replace("rgb(54, 162, 235, 0.2)", color.light()); code = code.replace("description", XidynUtils.escapeXmlBlank(description)); 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("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values)); diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java new file mode 100644 index 0000000..d257d0a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +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; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java index 3e8c28f..4c5bc7e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java @@ -35,6 +35,31 @@ public class PieChartView { 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. * @@ -43,11 +68,11 @@ public class PieChartView * @return the string * @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; - 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; @@ -70,7 +95,7 @@ public class PieChartView * @throws StatoolInfosException * 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; try @@ -78,6 +103,7 @@ public class PieChartView String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml")); result = XidynUtils.extractBodyContent(source); + result = result.replaceFirst("type: '.*'", "type: '" + type.toString().toLowerCase() + "'"); result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "PieChart")); result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values)); result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(colors)); diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml index 6137b0c..699442c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml @@ -23,8 +23,7 @@ var myChart = new Chart(ctx, datasets: [{ data: [ 10,40,50 ], - backgroundColor: [window.chartColors.red,window.chartColors.orange,window.chartColors.yellow,window.chartColors.green,window.chartColors.blue], - /*label: 'Dataset 1'*/ + backgroundColor: [window.chartColors.red,window.chartColors.orange,window.chartColors.yellow,window.chartColors.green,window.chartColors.blue] }], labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue'] },