Added polar charts.

This commit is contained in:
Christian P. MOMON 2020-01-20 17:46:54 +01:00
parent 489e845484
commit de34783f03
6 changed files with 322 additions and 1 deletions

View file

@ -0,0 +1,75 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of AgirStatool, simple key value database.
*
* AgirStatool 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.
*
* AgirStatool 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 AgirStatool. If not, see <http://www.gnu.org/licenses/>.
*/
package org.april.agirstatool.core.pages;
import java.io.IOException;
import org.apache.commons.codec.digest.DigestUtils;
import org.april.agirstatool.core.AgirStatool;
import org.april.agirstatool.core.AgirStatoolException;
import org.april.agirstatool.core.AgirStatoolUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class projectsRawPageBuilder.
*/
public class ChartPolarView
{
private static Logger logger = LoggerFactory.getLogger(ChartPolarView.class);
/**
* Builds the.
*
* @param projects
* the projects
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String build(final String title, final String labelTitle, final StringList labels, final StringList values) throws AgirStatoolException
{
String result;
try
{
logger.info("Building polar chart view…");
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartPolarView.xhtml"));
String code = XidynUtils.extractBodyContent(source);
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "chartPolar"));
code = code.replace("# of Votes", labelTitle);
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
result = code.toString();
}
catch (IOException exception)
{
throw new AgirStatoolException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -56,14 +56,19 @@ public class ProjectPage
TagDataManager data = new TagDataManager(); TagDataManager data = new TagDataManager();
data.setContent("projectName", project.getName()); data.setContent("projectName", project.getName());
data.setAttribute("agirLink", "href", "https://agir.april.org/projects/" + project.getIdentifier() + "/issues");
data.setContent("issueRawChart", IssueStatChartView.build("Issue Raw Count", project)); data.setContent("issueRawChart", IssueStatChartView.build("Issue Raw Count", project));
data.setContent("issueGroupedChart", IssueStatChartView.buildGrouped("Issue Grouped Count", project)); data.setContent("issueGroupedChart", IssueStatChartView.buildGrouped("Issue Grouped Count", project));
data.setContent("unassignedRawChart", UnassignedPolarChartView.build("Unassigned Raw Count", project));
data.setContent("unassignedGroupedChart", UnassignedPolarChartView.buildGrouped("Unassigned Grouped Count", project));
if (project.hasChild()) if (project.hasChild())
{ {
data.setContent("issueRawChartAlone", IssueStatChartView.build("Issue Raw Count", project.subProjects().get(0))); data.setContent("issueRawChartAlone", IssueStatChartView.build("Issue Raw Count", project.subProjects().get(0)));
data.setContent("issueGroupedChartAlone", IssueStatChartView.buildGrouped("Issue Grouped Count", project.subProjects().get(0))); data.setContent("issueGroupedChartAlone", IssueStatChartView.buildGrouped("Issue Grouped Count", project.subProjects().get(0)));
data.setContent("unassignedRawChartAlone", UnassignedPolarChartView.build("Unassigned Raw Count", project.subProjects().get(0)));
data.setContent("unassignedGroupedChartAlone", UnassignedPolarChartView.buildGrouped("Unassigned Grouped Count", project.subProjects().get(0)));
} }
String projectsRawView = ProjectsRawView.build(project); String projectsRawView = ProjectsRawView.build(project);

View file

@ -0,0 +1,96 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of AgirStatool, simple key value database.
*
* AgirStatool 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.
*
* AgirStatool 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 AgirStatool. If not, see <http://www.gnu.org/licenses/>.
*/
package org.april.agirstatool.core.pages;
import org.april.agirstatool.core.AgirStatoolException;
import org.april.agirstatool.core.IssueStats;
import org.april.agirstatool.core.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
/**
* The Class projectsRawPageBuilder.
*/
public class UnassignedPolarChartView
{
private static Logger logger = LoggerFactory.getLogger(UnassignedPolarChartView.class);
/**
* Builds the grouped.
*
* @param stats
* the stats
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String build(final String title, final Project project) throws AgirStatoolException
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Confirmed", "Ongoing", "Waiting", "Resolved", "Rejected", "Closed");
StringList values = new StringList();
IssueStats stats = project.issueStats();
values.append(stats.getUnassignedConfirmedCount());
values.append(stats.getUnassignedOngoingCount());
values.append(stats.getUnassignedWaitingCount());
values.append(stats.getUnassignedResolvedCount());
values.append(stats.getUnassignedRejectedCount());
values.append(stats.getUnassignedClosedCount());
String targetTitle = title + " " + project.getName();
result = ChartPolarView.build(targetTitle, targetTitle, labels, values);
//
return result;
}
/**
* Builds the.
*
* @param projects
* the projects
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildGrouped(final String title, final Project project) throws AgirStatoolException
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Started", "Resolved", "Concluded");
StringList values = new StringList();
IssueStats stats = project.issueStats();
values.append(stats.getUnassignedStartedCount());
values.append(stats.getUnassignedResolvedCount());
values.append(stats.getUnassignedConcludedCount());
String targetTitle = title + " " + project.getName();
result = ChartPolarView.build(targetTitle, targetTitle, labels, values);
//
return result;
}
}

View file

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Agir Statool</title>
<meta charset="UTF-8" />
<meta content="April" name="keywords" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="agirstatool.css" />
<script src="/commons/sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="width: 800px; height: 400px; text-align: center; margin: 0 0; border: 1px solid red;">
<canvas id="myChart" width="100%" height="100%"></canvas>
<script>
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx,
{
type: 'line',
data:
{
labels: ['New', 'Started', 'Waiting', 'Maybe', 'Resolved', 'Closed'],
datasets:
[{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor:
[
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor:
[
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options:
{
maintainAspectRatio: false,
scales:
{
xAxes:
[{
ticks:
{
beginAtZero: true
}
}],
yAxes:
[{
ticks:
{
beginAtZero: true
}
}]
}
}
});
</script>
</div>
</body>
</html>

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Agir Statool</title>
<meta charset="UTF-8" />
<meta content="April" name="keywords" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="agirstatool.css" />
<script src="/commons/sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="width: 340px; height: 200px; text-align: center; margin: 0 0; border: 1px solid red;">
<canvas id="myChart" width="100%" height="100%"></canvas>
<script>
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx,
{
type: 'polarArea',
data:
{
labels: ['New', 'Started', 'Waiting', 'Maybe', 'Resolved', 'Closed'],
datasets:
[{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor:
[
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor:
[
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options:
{
maintainAspectRatio: false,
title:
{
display: false,
text: 'Unassigned'
},
legend:
{
display: true,
position: 'right'
}
}
});
</script>
</div>
</body>
</html>

View file

@ -12,13 +12,17 @@
</head> </head>
<body> <body>
<div style="margin: 10px;"> <div style="margin: 10px;">
<h1><a href="index.xhtml">Agir Statool</a> Project <span id="projectName">n/a</span></h1> <h1><a href="index.xhtml">Agir Statool</a> <a id="agirLink" href="#">Project <span id="projectName">n/a</span></a></h1>
<div> <div>
<div id="issueRawChart" style="display: inline-block;">ISSUES BAR CHART</div> <div id="issueRawChart" style="display: inline-block;">ISSUES BAR CHART</div>
<div id="issueGroupedChart" style="display: inline-block;">ISSUES BAR CHART</div> <div id="issueGroupedChart" style="display: inline-block;">ISSUES BAR CHART</div>
<div id="unassignedRawChart" style="display: inline-block;"></div>
<div id="unassignedGroupedChart" style="display: inline-block;"></div>
<br/> <br/>
<div id="issueRawChartAlone" style="display: inline-block;"></div> <div id="issueRawChartAlone" style="display: inline-block;"></div>
<div id="issueGroupedChartAlone" style="display: inline-block;"></div> <div id="issueGroupedChartAlone" style="display: inline-block;"></div>
<div id="unassignedRawChartAlone" style="display: inline-block;"></div>
<div id="unassignedGroupedChartAlone" style="display: inline-block;"></div>
</div> </div>
<br/> <br/>
<div> <div>