diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index 70a6154..3e6d4f0 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -70,6 +70,7 @@ public class FederationStatsPage data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations())); data.setContent("organizationCountryChart", Htmlizer.htmlizeOrganizationCountryChart(federation.getOrganizations())); data.setContent("organizationCountChart", Htmlizer.htmlizeOrganizationCountChart(federation)); + data.setContent("organizationInOutChart", Htmlizer.htmlizeOrganizationInOutChart(federation)); data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(federation.getAllServices())); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(federation.getAllServices())); diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index b40af00..8756abe 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -327,6 +327,43 @@ public class Htmlizer return result; } + /** + * Htmlize organization in out chart. + * + * @param federation + * the federation + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeOrganizationInOutChart(final Federation federation) throws StatoolInfosException + { + String result; + + BarChart chart = new BarChart("Entrées/Sorties"); + // chart.setStacked(true); + + chart.addDataset("Entrées"); + PathPropertyList values = federation.getByYearPrefix("metrics.members.in").sortByPath(); + for (PathProperty property : values) + { + chart.getLabels().add(property.getLeaf()); + chart.add(0, Double.parseDouble(property.getValue()), ChartColor.GREEN); + } + + chart.addDataset("Sorties"); + values = federation.getByYearPrefix("metrics.members.out").sortByPath(); + for (PathProperty property : values) + { + chart.add(1, Double.parseDouble(property.getValue()), ChartColor.RED); + } + + result = BarChartView.build(chart); + + // + return result; + } + /** * Htmlize organization turnout chart. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java index 9a60751..d81aacd 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java @@ -34,6 +34,7 @@ public class BarChart private boolean displayTitle; private StringList labels; private BarChartDatasets datasets; + private boolean stacked; /** * Instantiates a new bar chart. @@ -47,6 +48,22 @@ public class BarChart this.displayTitle = true; this.labels = new StringList(); this.datasets = new BarChartDatasets(); + this.stacked = false; + } + + /** + * Adds the. + * + * @param datasetIndex + * the dataset index + * @param value + * the value + * @param color + * the color + */ + public void add(final int datasetIndex, final double value, final ChartColor color) + { + this.datasets.get(datasetIndex).add(new BarChartData(null, value, color)); } /** @@ -151,11 +168,21 @@ public class BarChart return this.displayTitle; } + public boolean isStacked() + { + return this.stacked; + } + public void setDisplayTitle(final boolean displayTitle) { this.displayTitle = displayTitle; } + public void setStacked(final boolean stacked) + { + this.stacked = stacked; + } + public void setTitle(final String title) { this.title = title; diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java index 6a06d33..b13042a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java @@ -39,13 +39,13 @@ public class BarChartView /** * Builds the. * - * @param bar + * @param chart * the bar * @return the string * @throws StatoolInfosException * the statool infos exception */ - public static String build(final BarChart bar) throws StatoolInfosException + public static String build(final BarChart chart) throws StatoolInfosException { String result; @@ -54,17 +54,17 @@ public class BarChartView String source = XidynUtils.load(BarChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml")); result = XidynUtils.extractBodyContent(source); - result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(bar.getTitle() + "barChart")); + result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(chart.getTitle() + "barChart")); StringList lines = new StringList(); lines.append("{\n"); lines.append(" type: 'bar',\n"); lines.append(" data: \n"); lines.append(" {\n"); - lines.append(" labels: ").append(ChabuUtils.toJSonStrings(bar.getLabels())).appendln(","); + lines.append(" labels: ").append(ChabuUtils.toJSonStrings(chart.getLabels())).appendln(","); lines.append(" datasets: \n"); lines.append(" [\n"); - for (BarChartDataset dataset : bar.getDatasets()) + for (BarChartDataset dataset : chart.getDatasets()) { lines.append(" {\n"); lines.append(" label: '").append(escape(dataset.getName())).appendln("',"); @@ -72,10 +72,10 @@ public class BarChartView lines.append(" backgroundColor: ").append(ChabuUtils.toJSonStrings(dataset.getColors().getCodes())).appendln(","); lines.append(" borderColor: ").append(ChabuUtils.toJSonStrings(dataset.getColors().getLights())).appendln(","); lines.append(" borderWidth: ").append(dataset.getBorderWidth()).appendln(","); - lines.append(" }\n"); - lines.append(" ]\n"); - lines.append(" },\n"); + lines.append(" },\n"); } + lines.append(" ]\n"); + lines.append(" },\n"); lines.append(" options: \n"); lines.append(" {\n"); lines.append(" maintainAspectRatio: false,\n"); @@ -89,7 +89,12 @@ public class BarChartView lines.append(" title:\n"); lines.append(" {\n"); lines.append(" display: true,\n"); - lines.append(" text: '").append(escape(bar.getTitle())).appendln("'"); + lines.append(" text: '").append(escape(chart.getTitle())).appendln("'"); + lines.append(" },\n"); + lines.append(" tooltips:\n"); + lines.append(" {\n"); + lines.append(" mode: 'index',\n"); + lines.append(" intersect: false\n"); lines.append(" },\n"); lines.append(" scales: \n"); lines.append(" {\n"); @@ -98,7 +103,8 @@ public class BarChartView lines.append(" ticks: \n"); lines.append(" {\n"); lines.append(" beginAtZero: true\n"); - lines.append(" }\n"); + lines.append(" },\n"); + lines.append(" stacked: ").append(chart.isStacked()).appendln(","); lines.append(" }],\n"); lines.append(" yAxes:\n"); lines.append(" [{\n"); @@ -107,7 +113,8 @@ public class BarChartView lines.append(" beginAtZero: true,\n"); lines.append(" suggestedMax: 10,\n"); lines.append(" precision: 0\n"); - lines.append(" }\n"); + lines.append(" },\n"); + lines.append(" stacked: ").append(chart.isStacked()).appendln(","); lines.append(" }]\n"); lines.append(" }\n"); lines.append(" }\n"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml index 1ec11fe..fe56e82 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml @@ -46,6 +46,11 @@ var myChart = new Chart(ctx, display: true, text: 'a title' }, + tooltips: + { + mode: 'index', + intersect: false + }, scales: { xAxes: diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml index 025debd..a7296cb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -19,6 +19,7 @@
+