
xdev.ui.charts.utils.VirtualTableChartUtils Maven / Gradle / Ivy
package xdev.ui.charts.utils;
/*-
* #%L
* XDEV BI Suite
* %%
* Copyright (C) 2011 - 2021 XDEV Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import xdev.ui.charts.AbstractRelationalStructureChart;
import xdev.ui.charts.model.Chart3DOrientationStrategy;
import xdev.ui.charts.model.ChartColorScheme;
import xdev.ui.charts.model.VerticalChartOrientationStrategy;
import xdev.vt.VirtualTable;
import xdev.vt.VirtualTable.VirtualTableRow;
import xdev.vt.VirtualTableColumn;
import com.jidesoft.chart.Chart;
import com.jidesoft.chart.ChartType;
import com.jidesoft.chart.model.ChartModel;
import com.jidesoft.chart.model.DefaultChartModel;
import com.jidesoft.chart.style.ChartStyle;
/**
* Provides utilities dealing with chart data associated with
* {@link VirtualTable}s.
*
* @author XDEV Software jwill
*
* @since 4.0
*/
public class VirtualTableChartUtils
{
private static final int SINGLE_SERIES_MODEL = 1;
private static void addSingleSeriesModel(
AbstractRelationalStructureChart, ?> chart, ChartModel model, ChartColorScheme scheme)
{
scheme.getHightlightStrategy().addPointColorSchemeHighlights(chart,model,
scheme.getBaseColor());
// use "empty" style
chart.addModel(model,chart.createStyle());
}
/**
* Resets all models from a particular {@link Chart}.
*
* @param chart
* to reset.
*/
public static void resetChartModels(final AbstractRelationalStructureChart, ?> chart)
{
if(chart.getModels() != null)
{
// reset chart models
chart.getModels().removeAll(chart.getModels());
}
}
/**
* Adds the given chart models to a certain {@link Chart}.
*
* @param chart
* the chart to add the models to.
* @param orientation
* the plotting orientation.
* @param models
* the models to add.
* @param colorScheme
* the colorization basis.
* @param groupCount
* the group indicator.
*/
public static void addChartModels(
final AbstractRelationalStructureChart, ?> chart,
final Chart3DOrientationStrategy orientation, Collection models,
ChartColorScheme colorScheme, int groupCount)
{
resetChartModels(chart);
final List scheme = colorScheme.getHightlightStrategy().getColorScheme(models,
colorScheme);
int modelCount = 0;
for(final T model : models)
{
if(model.getPointCount() > 0)
{
if(chart.getChartType().equals(ChartType.PIE)
|| (groupCount == 0 && models.size() == SINGLE_SERIES_MODEL))
{
addSingleSeriesModel(chart,model,colorScheme);
}
else
{
ChartStyle style = chart.createStyle(scheme.get(modelCount));
orientation.setGraphOrientation(style);
chart.addModel(model,style);
}
}
modelCount++;
}
}
/**
* Creates the seriesDataContext-{@link Map} which is the mapping between a
* concrete {@link ChartModel} and its seriesData.
*
* @param container
* @param seriesColumnIndices
* @return the mapping between chart and group data.
*/
public static Map, DefaultChartModel> createChartSeriesDataContext(
VirtualTable container, VirtualTableColumn>... seriesColumnIndices)
{
Map, DefaultChartModel> seriesContextMap = new HashMap, DefaultChartModel>();
if(seriesColumnIndices.length > 0)
{
List> seriesRowDataList = createChartSeriesData(container,
seriesColumnIndices);
for(int i = 0; i < seriesRowDataList.size(); i++)
{
DefaultChartModel model = new DefaultChartModel(
createUniqueSeriesName(seriesRowDataList.get(i)));
seriesContextMap.put(seriesRowDataList.get(i),model);
}
}
return seriesContextMap;
}
/**
* Returns all unique (grouped) chart series data sets from the given
* {@link VirtualTable}
*
* @param container
* the data container.
* @param seriesColumnIndices
* the groupColumns.
* @return all unique groups from the given {@link VirtualTable}.
*/
public static List> createChartSeriesData(VirtualTable container,
VirtualTableColumn>... seriesColumnIndices)
{
List> seriesDataList = new ArrayList>();
for(int row = 0; row < container.getRowCount(); row++)
{
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy