152 lines
3.2 KiB
Java
152 lines
3.2 KiB
Java
|
/*
|
||
|
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||
|
*
|
||
|
* 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 <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
package fr.devinsy.statoolinfos.htmlize.charts;
|
||
|
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
import fr.devinsy.strings.StringList;
|
||
|
|
||
|
/**
|
||
|
* The Class BarChart.
|
||
|
*/
|
||
|
public class BarChart
|
||
|
{
|
||
|
private static Logger logger = LoggerFactory.getLogger(BarChart.class);
|
||
|
|
||
|
private String title;
|
||
|
private boolean displayTitle;
|
||
|
private BarChartDatas datas;
|
||
|
|
||
|
/**
|
||
|
* Instantiates a new bar chart.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
*/
|
||
|
public BarChart(final String title)
|
||
|
{
|
||
|
this.title = title;
|
||
|
this.displayTitle = true;
|
||
|
this.datas = new BarChartDatas();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds the.
|
||
|
*
|
||
|
* @param label
|
||
|
* the label
|
||
|
* @param value
|
||
|
* the value
|
||
|
* @param color
|
||
|
* the color
|
||
|
*/
|
||
|
public void add(final String label, final double value, final ChartColor color)
|
||
|
{
|
||
|
this.datas.add(new BarChartData(label, value, color));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the colors.
|
||
|
*
|
||
|
* @return the colors
|
||
|
*/
|
||
|
public ChartColors getColors()
|
||
|
{
|
||
|
ChartColors result;
|
||
|
|
||
|
result = new ChartColors();
|
||
|
|
||
|
for (BarChartData data : this.datas)
|
||
|
{
|
||
|
result.add(data.getColor());
|
||
|
}
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
public BarChartDatas getDatas()
|
||
|
{
|
||
|
return this.datas;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the labels.
|
||
|
*
|
||
|
* @return the labels
|
||
|
*/
|
||
|
public StringList getLabels()
|
||
|
{
|
||
|
StringList result;
|
||
|
|
||
|
result = new StringList();
|
||
|
|
||
|
for (BarChartData data : this.datas)
|
||
|
{
|
||
|
result.add(data.getLabel());
|
||
|
}
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
public String getTitle()
|
||
|
{
|
||
|
return this.title;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the values.
|
||
|
*
|
||
|
* @return the values
|
||
|
*/
|
||
|
public double[] getValues()
|
||
|
{
|
||
|
double[] result;
|
||
|
|
||
|
result = new double[this.datas.size()];
|
||
|
|
||
|
int index = 0;
|
||
|
for (BarChartData data : this.datas)
|
||
|
{
|
||
|
result[index] = data.getValue();
|
||
|
index += 1;
|
||
|
}
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
public boolean isDisplayTitle()
|
||
|
{
|
||
|
return this.displayTitle;
|
||
|
}
|
||
|
|
||
|
public void setDisplayTitle(final boolean displayTitle)
|
||
|
{
|
||
|
this.displayTitle = displayTitle;
|
||
|
}
|
||
|
|
||
|
public void setTitle(final String title)
|
||
|
{
|
||
|
this.title = title;
|
||
|
}
|
||
|
}
|