2020-11-19 02:11:52 +01:00
|
|
|
/*
|
2021-01-23 04:09:41 +01:00
|
|
|
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
2020-11-19 02:11:52 +01:00
|
|
|
*
|
|
|
|
* 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;
|
2021-01-23 04:09:41 +01:00
|
|
|
private StringList labels;
|
|
|
|
private BarChartDatasets datasets;
|
2021-01-23 04:41:23 +01:00
|
|
|
private boolean stacked;
|
2021-05-29 11:18:51 +02:00
|
|
|
private boolean animated;
|
2020-11-19 02:11:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new bar chart.
|
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
*/
|
|
|
|
public BarChart(final String title)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
this.displayTitle = true;
|
2021-01-23 04:09:41 +01:00
|
|
|
this.labels = new StringList();
|
|
|
|
this.datasets = new BarChartDatasets();
|
2021-01-23 04:41:23 +01:00
|
|
|
this.stacked = false;
|
2021-05-29 11:18:51 +02:00
|
|
|
this.animated = true;
|
2021-01-23 04:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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));
|
2020-11-19 02:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2021-02-21 03:08:52 +01:00
|
|
|
this.labels.add(label);
|
|
|
|
this.datasets.get(0).add(new BarChartData(label, value, color));
|
2021-01-23 04:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the dataset.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* the name
|
|
|
|
* @return the int
|
|
|
|
*/
|
|
|
|
public int addDataset(final String name)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
this.datasets.add(new BarChartDataset(name));
|
|
|
|
|
|
|
|
result = this.datasets.size() - 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
2020-11-19 02:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the colors.
|
|
|
|
*
|
|
|
|
* @return the colors
|
|
|
|
*/
|
|
|
|
public ChartColors getColors()
|
|
|
|
{
|
|
|
|
ChartColors result;
|
|
|
|
|
2021-01-23 04:09:41 +01:00
|
|
|
result = this.datasets.get(0).getColors();
|
2020-11-19 02:11:52 +01:00
|
|
|
|
2021-01-23 04:09:41 +01:00
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the dataset.
|
|
|
|
*
|
|
|
|
* @param index
|
|
|
|
* the index
|
|
|
|
* @return the dataset
|
|
|
|
*/
|
|
|
|
public BarChartDataset getDataset(final int index)
|
|
|
|
{
|
|
|
|
BarChartDataset result;
|
|
|
|
|
|
|
|
result = this.datasets.get(index);
|
2020-11-19 02:11:52 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-23 04:09:41 +01:00
|
|
|
public BarChartDatasets getDatasets()
|
2020-11-19 02:11:52 +01:00
|
|
|
{
|
2021-01-23 04:09:41 +01:00
|
|
|
return this.datasets;
|
2020-11-19 02:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the labels.
|
|
|
|
*
|
|
|
|
* @return the labels
|
|
|
|
*/
|
|
|
|
public StringList getLabels()
|
|
|
|
{
|
|
|
|
StringList result;
|
|
|
|
|
2021-01-23 04:09:41 +01:00
|
|
|
result = this.labels;
|
2020-11-19 02:11:52 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-23 04:09:41 +01:00
|
|
|
* Gets the title.
|
2020-11-19 02:11:52 +01:00
|
|
|
*
|
2021-01-23 04:09:41 +01:00
|
|
|
* @return the title
|
2020-11-19 02:11:52 +01:00
|
|
|
*/
|
2021-01-23 04:09:41 +01:00
|
|
|
public String getTitle()
|
2020-11-19 02:11:52 +01:00
|
|
|
{
|
2021-01-23 04:09:41 +01:00
|
|
|
return this.title;
|
2020-11-19 02:11:52 +01:00
|
|
|
}
|
|
|
|
|
2021-05-29 11:18:51 +02:00
|
|
|
public boolean isAnimated()
|
|
|
|
{
|
|
|
|
return this.animated;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:11:52 +01:00
|
|
|
public boolean isDisplayTitle()
|
|
|
|
{
|
|
|
|
return this.displayTitle;
|
|
|
|
}
|
|
|
|
|
2021-01-23 04:41:23 +01:00
|
|
|
public boolean isStacked()
|
|
|
|
{
|
|
|
|
return this.stacked;
|
|
|
|
}
|
|
|
|
|
2021-05-29 11:18:51 +02:00
|
|
|
public void setAnimated(final boolean animated)
|
|
|
|
{
|
|
|
|
this.animated = animated;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:11:52 +01:00
|
|
|
public void setDisplayTitle(final boolean displayTitle)
|
|
|
|
{
|
|
|
|
this.displayTitle = displayTitle;
|
|
|
|
}
|
|
|
|
|
2021-01-23 04:41:23 +01:00
|
|
|
public void setStacked(final boolean stacked)
|
|
|
|
{
|
|
|
|
this.stacked = stacked;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:11:52 +01:00
|
|
|
public void setTitle(final String title)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
}
|