Added active issue chart. Improved Javascript code.

This commit is contained in:
Christian P. MOMON 2020-01-24 13:15:24 +01:00
parent 740bb43cb6
commit 5d913617d9
6 changed files with 402 additions and 47 deletions

View File

@ -39,6 +39,17 @@ public class DateCountList extends ArrayList<DateCount>
super();
}
/**
* Instantiates a new date count list.
*
* @param capacity
* the capacity
*/
public DateCountList(final int capacity)
{
super(capacity);
}
/**
* Indexof.
*

View File

@ -37,9 +37,9 @@ import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class projectsRawPageBuilder.
*/
public class CreatedConcludedCountChartView
public class CreatedClosedCountChartView
{
private static Logger logger = LoggerFactory.getLogger(CreatedConcludedCountChartView.class);
private static Logger logger = LoggerFactory.getLogger(CreatedClosedCountChartView.class);
/**
* Builds the.

View File

@ -0,0 +1,274 @@
/*
* 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 java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import org.apache.commons.codec.digest.DigestUtils;
import org.april.agirstatool.charts.DateCount;
import org.april.agirstatool.charts.DateCountList;
import org.april.agirstatool.core.AgirStatool;
import org.april.agirstatool.core.AgirStatoolException;
import org.april.agirstatool.core.AgirStatoolUtils;
import org.april.agirstatool.core.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class projectsRawPageBuilder.
*/
public class CreatedClosedDiffChartView
{
private static Logger logger = LoggerFactory.getLogger(CreatedClosedDiffChartView.class);
/**
* Builds the.
*
* @param title
* the title
* @param project
* the project
* @param start
* the start
* @param end
* the end
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String build(final String title, final Project project, final LocalDate start, final LocalDate end) throws AgirStatoolException
{
String result;
try
{
if (project.hasIssue())
{
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView2.xhtml"));
String code = XidynUtils.extractBodyContent(source);
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "line2Chart"));
StringList labels = buildWeekLabels(start, end);
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
DateCountList createdDates = project.issueStats().getWeekCreatedIssueCounts();
DateCountList closedDates = project.issueStats().getWeekConcludedIssueCounts();
DateCountList dates = new DateCountList(createdDates.size());
for (int dateIndex = 0; dateIndex < createdDates.size(); dateIndex++)
{
DateCount createdDate = createdDates.get(dateIndex);
DateCount closedDate = closedDates.get(dateIndex);
dates.add(new DateCount(createdDate.getDate(), createdDate.getCount() - closedDate.getCount()));
}
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
result = code.toString();
}
else
{
result = "No issue.";
}
}
catch (IOException exception)
{
throw new AgirStatoolException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
}
//
return result;
}
/**
* Builds the full.
*
* @param title
* the title
* @param project
* the project
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildFull(final String title, final Project project) throws AgirStatoolException
{
String result;
try
{
logger.debug("Building created/concluded chart view…");
if (project.hasIssue())
{
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView.xhtml"));
String code = XidynUtils.extractBodyContent(source);
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "lineBar"));
StringList labels = buildWeekLabels(project.issueStats().getFirstCreate().toLocalDate());
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
StringList values = project.issueStats().getWeekCreatedIssueCounts().toValueList();
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
values = project.issueStats().getWeekConcludedIssueCounts().toValueList();
code = code.replaceAll("data: \\[.*\\] ", "data: " + AgirStatoolUtils.toJSonNumbers(values));
result = code.toString();
}
else
{
result = "No issue.";
}
}
catch (IOException exception)
{
throw new AgirStatoolException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
}
//
return result;
}
/**
* Builds the last months.
*
* @param title
* the title
* @param project
* the project
* @param monthCount
* the month count
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildLastMonths(final String title, final Project project, final int monthCount) throws AgirStatoolException
{
String result;
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
//
return result;
}
/**
* Builds the previous year.
*
* @param title
* the title
* @param project
* the project
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildPreviousYear(final String title, final Project project) throws AgirStatoolException
{
String result;
result = buildYear(title, project, LocalDate.now().getYear() - 1);
//
return result;
}
/**
* Builds the week labels.
*
* @param start
* the start
* @return the string list
*/
private static StringList buildWeekLabels(final LocalDate start)
{
StringList result;
result = buildWeekLabels(start, LocalDate.now());
//
return result;
}
/**
* Builds the week labels.
*
* @param start
* the start
* @param end
* the end
* @return the string list
*/
private static StringList buildWeekLabels(final LocalDate start, final LocalDate end)
{
StringList result;
result = new StringList();
if (start != null)
{
LocalDate normalizedEnd = AgirStatoolUtils.normaliseWeekDate(end);
LocalDate date = AgirStatoolUtils.normaliseWeekDate(start);
while (date.isBefore(normalizedEnd) || date.isEqual(normalizedEnd))
{
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM"));
result.add(label);
date = date.plusWeeks(1);
}
}
//
return result;
}
/**
* Builds the year.
*
* @param title
* the title
* @param project
* the project
* @param year
* the year
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildYear(final String title, final Project project, final int year) throws AgirStatoolException
{
String result;
LocalDate start = LocalDate.of(year, 1, 1).minusDays(7);
LocalDate end = LocalDate.of(year + 1, 1, 1).minusDays(1);
result = build(title, project, start, end);
//
return result;
}
}

View File

@ -58,17 +58,23 @@ public class ProjectPage
data.setContent("agirLink", project.getName());
data.setAttribute("agirLink", "href", "https://agir.april.org/projects/" + project.getIdentifier() + "/issues");
data.setContent("issueCreatedClosed3MonthsChart", CreatedConcludedCountChartView.buildLastMonths("Created/closed 3 months Count", project, 3));
data.setContent("issueCreatedClosed6MonthsChart", CreatedConcludedCountChartView.buildLastMonths("Created/closed 6 months Count", project, 6));
data.setContent("issueCreatedClosedPreviousYearChart", CreatedConcludedCountChartView.buildPreviousYear("Created/closed last year Count", project));
data.setContent("issueCreatedClosedFullChart", CreatedConcludedCountChartView.buildFull("Created/closed Count", project));
data.setContent("createdClosed3MonthsChart", CreatedClosedCountChartView.buildLastMonths("Created/closed 3 months Count", project, 3));
data.setContent("created-Closed3MonthsChart", CreatedClosedDiffChartView.buildLastMonths("Created-closed 3 months Count", project, 3));
data.setContent("createdClosed6MonthsChart", CreatedClosedCountChartView.buildLastMonths("Created/closed 6 months Count", project, 6));
data.setContent("created-Closed6MonthsChart", CreatedClosedDiffChartView.buildLastMonths("Created-closed 6 months Count", project, 6));
data.setContent("createdClosedPreviousYearChart", CreatedClosedCountChartView.buildPreviousYear("Created/closed last year Count", project));
data.setContent("created-ClosedPreviousYearChart", CreatedClosedDiffChartView.buildPreviousYear("Created-closed last year Count", project));
data.setContent("createdClosedFullChart", CreatedClosedCountChartView.buildFull("Created/closed Count", project));
data.setContent("issueRawChart", IssueStatChartView.build("Issue Raw 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));
data.setContent("issueCreatedClosed6MonthsChartA", CreatedConcludedCountChartView.buildLastMonths("Created/closed 6 months CountA", project, 6));
data.setContent("issueCreatedClosed6MonthsChartB", CreatedConcludedCountChartView.buildLastMonths("Created/closed 6 months CountB", project, 6));
data.setContent("createdClosed6MonthsChartA", CreatedClosedCountChartView.buildLastMonths("Created/closed 6 months CountA", project, 6));
data.setContent("createdClosed6MonthsChartB", CreatedClosedCountChartView.buildLastMonths("Created/closed 6 months CountB", project, 6));
data.setContent("created-Closed6MonthsChartA", CreatedClosedDiffChartView.buildLastMonths("Created-closed 6 months CountA", project, 6));
data.setContent("created-Closed6MonthsChartB", CreatedClosedDiffChartView.buildLastMonths("Created-closed 6 months CountB", project, 6));
String projectsRawView = ProjectsRawView.build(project);
data.setContent("projectsRawView", projectsRawView);

View File

@ -0,0 +1,69 @@
<?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: 100%; height: 100%; 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: ['S01', 'S02', 'S03', 'S04', 'S05'],
datasets:
[
{
label: 'Active',
data: [2, 9, 13, 15, 22, 23],
backgroundColor: 'rgba(255, 159, 64, 0.2)',
borderColor: 'rgba(255, 159, 64, 1)',
borderWidth: 1,
fill: true,
/* cubicInterpolationMode: 'monotone', */
lineTension: 0,
pointBorderWidth: 0.00000001
},
]
},
options:
{
maintainAspectRatio: false,
title: {
display: false,
text: 'Min and Max Settings'
},
scales:
{
xAxes:
[{
ticks:
{
beginAtZero: false
}
}],
yAxes:
[{
ticks:
{
beginAtZero: false,
suggestedMax: 10
}
}]
}
}
});
</script>
</div>
</body>
</html>

View File

@ -26,10 +26,21 @@
<a href="admins.xhtml" class="button">Admins</a>
<a href="chapril.xhtml" class="button">Chapril</a>
</div>
<div id="issueCreatedClosed3MonthsChart" style="display: none; width: 50%; height: 400px;">CREATED/CLOSED 3 MONTHS CHART</div>
<div id="issueCreatedClosed6MonthsChart" style="display: none; width: 50%; height: 400px;">CREATED/CLOSED 6 MONTHS CHART</div>
<div id="issueCreatedClosedPreviousYearChart" style="display: none; width: 50%; height: 400px;">CREATED/CLOSED PREVIOUS YEAR CHART</div>
<div id="issueCreatedClosedFullChart" style="height: 400px;">CREATED/CLOSED FULL CHART</div>
<div id="3MonthsBox" style="display: none;">
<div id="createdClosed3MonthsChart" style="display: inline-block; width: 50%; height: 400px;">CREATED/CLOSED 3 MONTHS CHART</div>
<div id="created-Closed3MonthsChart" style="display: inline-block; width: 49%; height: 400px;">CREATED-CLOSED 3 MONTHS CHART</div>
</div>
<div id="6MonthsBox" style="display: none;">
<div id="createdClosed6MonthsChart" style="display: inline-block; width: 50%; height: 400px;">CREATED/CLOSED 6 MONTHS CHART</div>
<div id="created-Closed6MonthsChart" style="display: inline-block; width: 49%; height: 400px;">CREATED-CLOSED 6 MONTHS CHART</div>
</div>
<div id="previousYearBox" style="display: none;">
<div id="createdClosedPreviousYearChart" style="display: inline-block; width: 50%; height: 400px;">CREATED/CLOSED PREVIOUS YEAR CHART</div>
<div id="created-ClosedPreviousYearChart" style="display: inline-block; width: 49%; height: 400px;">CREATED-CLOSED PREVIOUS YEAR CHART</div>
</div>
<div id="fullBox">
<div id="createdClosedFullChart" style="height: 400px;">CREATED/CLOSED FULL CHART</div>
</div>
</div>
<div id="part2" style="margin: 4px;">
@ -43,7 +54,8 @@
<div>
<div id="issueRawChart" style="width: 400px; height: 200px; display: inline-block;">ISSUES BAR CHART</div>
<div id="unassignedRawChart" style="width: 360px; height: 200px; display: inline-block;"></div>
<div id="issueCreatedClosed6MonthsChartA" style="width: 340px; height: 200px; display: inline-block;">CREATED/CLOSED 6 MONTHS CHART</div>
<div id="createdClosed6MonthsChartA" style="width: 340px; height: 200px; display: inline-block;">CREATED/CLOSED 6 MONTHS CHART A</div>
<div id="created-Closed6MonthsChartA" style="width: 340px; height: 200px; display: inline-block;">CREATED-CLOSED 6 MONTHS CHART A</div>
</div>
<br/>
<div>
@ -54,7 +66,8 @@
<div>
<div id="issueGroupedChart" style="width: 400px; height: 200px; display: inline-block;">ISSUES BAR CHART</div>
<div id="unassignedGroupedChart" style="width: 360px; height: 200px; display: inline-block;"></div>
<div id="issueCreatedClosed6MonthsChartB" style="width: 340px; height: 200px; display: inline-block;">CREATED/CLOSED 6 MONTHS CHARTB</div>
<div id="createdClosed6MonthsChartB" style="width: 340px; height: 200px; display: inline-block;">CREATED/CLOSED 6 MONTHS CHARTB</div>
<div id="created-Closed6MonthsChartB" style="width: 340px; height: 200px; display: inline-block;">CREATED-CLOSED 6 MONTHS CHART B</div>
</div>
<br/>
<div>
@ -65,53 +78,35 @@
<script type="text/javascript">
function createClosedSelect(selection)
{
if (selection == '3months')
document.getElementById ('createClose3MonthsButton').classList.remove('selected');
document.getElementById ('createClose6MonthsButton').classList.remove('selected');
document.getElementById ('createClosePreviousYearButton').classList.remove('selected');
document.getElementById ('createCloseFullButton').classList.remove('selected');
document.getElementById ('3MonthsBox').style.display = 'none';
document.getElementById ('6MonthsBox').style.display = 'none';
document.getElementById ('previousYearBox').style.display = 'none';
document.getElementById ('fullBox').style.display = 'none';
if (selection == '3months')
{
document.getElementById ('createClose3MonthsButton').classList.add('selected');
document.getElementById ('createClose6MonthsButton').classList.remove('selected');
document.getElementById ('createClosePreviousYearButton').classList.remove('selected');
document.getElementById ('createCloseFullButton').classList.remove('selected');
document.getElementById ('issueCreatedClosed3MonthsChart').style.display = 'block';
document.getElementById ('issueCreatedClosed6MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosedPreviousYearChart').style.display = 'none';
document.getElementById ('issueCreatedClosedFullChart').style.display = 'none';
document.getElementById ('3MonthsBox').style.display = 'block';
}
else if (selection == '6months')
{
document.getElementById ('createClose3MonthsButton').classList.remove('selected');
document.getElementById ('createClose6MonthsButton').classList.add('selected');
document.getElementById ('createClosePreviousYearButton').classList.remove('selected');
document.getElementById ('createCloseFullButton').classList.remove('selected');
document.getElementById ('issueCreatedClosed3MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosed6MonthsChart').style.display = 'block';
document.getElementById ('issueCreatedClosedPreviousYearChart').style.display = 'none';
document.getElementById ('issueCreatedClosedFullChart').style.display = 'none';
document.getElementById ('6MonthsBox').style.display = 'block';
}
else if (selection == 'previousYear')
{
document.getElementById ('createClose3MonthsButton').classList.remove('selected');
document.getElementById ('createClose6MonthsButton').classList.remove('selected');
document.getElementById ('createClosePreviousYearButton').classList.add('selected');
document.getElementById ('createCloseFullButton').classList.remove('selected');
document.getElementById ('issueCreatedClosed3MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosed6MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosedPreviousYearChart').style.display = 'block';
document.getElementById ('issueCreatedClosedFullChart').style.display = 'none';
document.getElementById ('previousYearBox').style.display = 'block';
}
else if (selection == 'full')
{
document.getElementById ('createClose3MonthsButton').classList.remove('selected');
document.getElementById ('createClose6MonthsButton').classList.remove('selected');
document.getElementById ('createClosePreviousYearButton').classList.remove('selected');
document.getElementById ('createCloseFullButton').classList.add('selected');
document.getElementById ('issueCreatedClosed3MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosed6MonthsChart').style.display = 'none';
document.getElementById ('issueCreatedClosedPreviousYearChart').style.display = 'none';
document.getElementById ('issueCreatedClosedFullChart').style.display = 'block';
document.getElementById ('fullBox').style.display = 'block';
}
}
</script>