Improved color management for country chart. Back to rgb colors.
This commit is contained in:
parent
979ebac18d
commit
4b9de167e0
4 changed files with 115 additions and 24 deletions
|
@ -38,6 +38,7 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.BarChart;
|
import fr.devinsy.statoolinfos.htmlize.charts.BarChart;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.BarChartView;
|
import fr.devinsy.statoolinfos.htmlize.charts.BarChartView;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
|
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
|
||||||
|
import fr.devinsy.statoolinfos.htmlize.charts.ChartColors;
|
||||||
import fr.devinsy.statoolinfos.htmlize.charts.DoughnutChartView;
|
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.PieChart.Position;
|
import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position;
|
||||||
|
@ -52,6 +53,7 @@ import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats;
|
||||||
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
|
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
|
||||||
import fr.devinsy.statoolinfos.stats.services.ServiceInstallTypeStats;
|
import fr.devinsy.statoolinfos.stats.services.ServiceInstallTypeStats;
|
||||||
import fr.devinsy.statoolinfos.util.URLUtils;
|
import fr.devinsy.statoolinfos.util.URLUtils;
|
||||||
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Htmlizer.
|
* The Class Htmlizer.
|
||||||
|
@ -294,14 +296,27 @@ public class Htmlizer
|
||||||
CountryStats stats = StatAgent.statsCountry(organizations);
|
CountryStats stats = StatAgent.statsCountry(organizations);
|
||||||
|
|
||||||
PieChart pie = new PieChart("Pays des membres");
|
PieChart pie = new PieChart("Pays des membres");
|
||||||
|
|
||||||
|
StringList countries = new StringList(stats.keySet()).sort();
|
||||||
|
countries.remove(CountryStats.UNKNOWN_LABEL);
|
||||||
|
|
||||||
|
ChartColors colors = new ChartColors();
|
||||||
|
colors.add(ChartColor.GREEN);
|
||||||
|
colors.add(ChartColor.ORANGE);
|
||||||
|
colors.add(ChartColor.RED);
|
||||||
|
colors.add(ChartColor.PURPLE);
|
||||||
|
colors.add(ChartColor.TURQUOISE);
|
||||||
|
colors.add(ChartColor.YELLOW);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int maxIndex = ChartColor.values().length;
|
for (String country : countries)
|
||||||
for (String country : stats.keySet())
|
|
||||||
{
|
{
|
||||||
pie.add(country, stats.get(country), ChartColor.values()[index % maxIndex]);
|
pie.add(country, stats.get(country), colors.get(index));
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
pie.add("Inconnu", stats.getUnknown(), ChartColor.BLUE);
|
||||||
|
|
||||||
pie.setLegendPosition(Position.RIGHT);
|
pie.setLegendPosition(Position.RIGHT);
|
||||||
|
|
||||||
result = PieChartView.build(pie);
|
result = PieChartView.build(pie);
|
||||||
|
@ -375,14 +390,26 @@ public class Htmlizer
|
||||||
CountryStats stats = StatAgent.statsCountry(services);
|
CountryStats stats = StatAgent.statsCountry(services);
|
||||||
|
|
||||||
PieChart pie = new PieChart("Pays des services");
|
PieChart pie = new PieChart("Pays des services");
|
||||||
|
StringList countries = new StringList(stats.keySet()).sort();
|
||||||
|
countries.remove(CountryStats.UNKNOWN_LABEL);
|
||||||
|
|
||||||
|
ChartColors colors = new ChartColors();
|
||||||
|
colors.add(ChartColor.GREEN);
|
||||||
|
colors.add(ChartColor.ORANGE);
|
||||||
|
colors.add(ChartColor.RED);
|
||||||
|
colors.add(ChartColor.PURPLE);
|
||||||
|
colors.add(ChartColor.TURQUOISE);
|
||||||
|
colors.add(ChartColor.YELLOW);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int maxIndex = ChartColor.values().length;
|
for (String country : countries)
|
||||||
for (String country : stats.keySet())
|
|
||||||
{
|
{
|
||||||
pie.add(country, stats.get(country), ChartColor.values()[index % maxIndex]);
|
pie.add(country, stats.get(country), colors.get(index));
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
pie.add("Inconnu", stats.getUnknown(), ChartColor.BLUE);
|
||||||
|
|
||||||
pie.setLegendPosition(Position.RIGHT);
|
pie.setLegendPosition(Position.RIGHT);
|
||||||
|
|
||||||
result = PieChartView.build(pie);
|
result = PieChartView.build(pie);
|
||||||
|
@ -427,7 +454,7 @@ public class Htmlizer
|
||||||
* To bar chart.
|
* To bar chart.
|
||||||
*
|
*
|
||||||
* @param stats
|
* @param stats
|
||||||
* the stats
|
* the statsf
|
||||||
* @return the bar chart
|
* @return the bar chart
|
||||||
*/
|
*/
|
||||||
public static BarChart toBarChart(final RegistrationStats stats)
|
public static BarChart toBarChart(final RegistrationStats stats)
|
||||||
|
|
|
@ -24,14 +24,15 @@ package fr.devinsy.statoolinfos.htmlize.charts;
|
||||||
public enum ChartColor
|
public enum ChartColor
|
||||||
{
|
{
|
||||||
// https://html-color-codes.info/
|
// https://html-color-codes.info/
|
||||||
RED("#ff6384"),
|
|
||||||
ORANGE("#ff9f40"),
|
RED("rgb(255, 99, 132)"),
|
||||||
YELLOW("#ffcd56"),
|
ORANGE("rgb(255, 159, 64)"),
|
||||||
TURQUOISE("#40E0D0"),
|
YELLOW("rgb(255, 205, 86)"),
|
||||||
GREEN("#4bc0c0"),
|
TURQUOISE("rgb(64, 224, 208)"),
|
||||||
BLUE("#36a2eb"),
|
GREEN("rgb(75, 192, 192)"),
|
||||||
PURPLE("#9966ff"),
|
BLUE("rgb(54, 162, 235)"),
|
||||||
GREY("#c9cbcf");
|
PURPLE("rgb(153, 102, 255)"),
|
||||||
|
GREY("rgb(201, 203, 207)");
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
private String light;
|
private String light;
|
||||||
|
|
|
@ -37,6 +37,24 @@ public class ChartColors extends ArrayList<ChartColor>
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ChartColor of the index with safe overflow.
|
||||||
|
*
|
||||||
|
* @param index
|
||||||
|
* the index
|
||||||
|
* @return the chart color
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ChartColor get(final int index)
|
||||||
|
{
|
||||||
|
ChartColor result;
|
||||||
|
|
||||||
|
result = super.get(index % size());
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the colors.
|
* Gets the colors.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,12 +29,41 @@ public class CountryStats extends HashMap<String, Integer>
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -8177123413128556290L;
|
private static final long serialVersionUID = -8177123413128556290L;
|
||||||
|
|
||||||
|
public static final String UNKNOWN_LABEL = "Inconnu";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new country stats.
|
* Instantiates a new country stats.
|
||||||
*/
|
*/
|
||||||
public CountryStats()
|
public CountryStats()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
put(UNKNOWN_LABEL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the.
|
||||||
|
*
|
||||||
|
* @param country
|
||||||
|
* the country
|
||||||
|
* @return the integer
|
||||||
|
*/
|
||||||
|
public int get(final String country)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
Integer count = super.get(country);
|
||||||
|
|
||||||
|
if (count == null)
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,6 +85,21 @@ public class CountryStats extends HashMap<String, Integer>
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the unknown.
|
||||||
|
*
|
||||||
|
* @return the unknown
|
||||||
|
*/
|
||||||
|
public int getUnknown()
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = get(UNKNOWN_LABEL);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inc.
|
* Inc.
|
||||||
*
|
*
|
||||||
|
@ -66,18 +110,19 @@ public class CountryStats extends HashMap<String, Integer>
|
||||||
{
|
{
|
||||||
if (StringUtils.isBlank(country))
|
if (StringUtils.isBlank(country))
|
||||||
{
|
{
|
||||||
inc("Inconnu");
|
incUnknown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Integer currentValue = get(country);
|
put(country, get(country) + 1);
|
||||||
if (currentValue == null)
|
|
||||||
{
|
|
||||||
currentValue = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentValue += 1;
|
|
||||||
put(country, currentValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inc unknown.
|
||||||
|
*/
|
||||||
|
public void incUnknown()
|
||||||
|
{
|
||||||
|
inc(UNKNOWN_LABEL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue