All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.digilabs.jqplot.chart.AbstractChart Maven / Gradle / Ivy

/*
 *  Copyright 2011 Inaiat H. Moraes.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package br.com.digilabs.jqplot.chart;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import br.com.digilabs.jqplot.Chart;
import br.com.digilabs.jqplot.ChartConfiguration;
import br.com.digilabs.jqplot.axis.Axis;
import br.com.digilabs.jqplot.axis.XAxis;
import br.com.digilabs.jqplot.axis.YAxis;
import br.com.digilabs.jqplot.data.ChartData;
import br.com.digilabs.jqplot.elements.Axes;
import br.com.digilabs.jqplot.elements.GridPadding;
import br.com.digilabs.jqplot.elements.Legend;
import br.com.digilabs.jqplot.elements.Serie;
import br.com.digilabs.jqplot.elements.SeriesDefaults;
import br.com.digilabs.jqplot.elements.Title;

/**
 * Abstract class to help build charts.
 * 
 * @author inaiat
 * 
 * @param 
 *            Type of {@link Axis}
 * 
 */
public abstract class AbstractChart, S extends Serializable>
		implements Chart {

	private static final long serialVersionUID = -5744130130488157491L;

	public AbstractChart addSeriesColors(String... colors) {

		getChartConfiguration().seriesColorsInstance().addAll(
				Arrays.asList(colors));
		return this;
	}

	public AbstractChart addSeriesColors(Collection colors) {
		getChartConfiguration().seriesColorsInstance().addAll(colors);
		return this;
	}

	public AbstractChart setSeriesColors(Collection colors) {
		getChartConfiguration().setSeriesColors(colors);
		return this;
	}

	public Collection getSeriesColors() {
		return getChartConfiguration().seriesColorsInstance();
	}

	/**
	 * Adiciona uma serie
	 * 
	 * @param serie
	 */
	public AbstractChart addSerie(Serie serie) {
		Collection series = getSeries();
		if (series == null) {
			series = new ArrayList();
		}
		series.add(serie);
		return this;
	}

	/**
	 * Adiciona uma serie
	 * 
	 * @param series
	 */
	public AbstractChart addSeries(Serie... series) {
		Collection chartSeries = getSeries();
		if (chartSeries == null) {
			chartSeries = new ArrayList();
		}
		for (int i = series.length - 1; i >= 0; i--) {
			chartSeries.add(series[i]);
		}
		return this;

	}

	/**
	 * 
	 * @return chartConfiguration
	 */
	public abstract ChartConfiguration getChartConfiguration();

	/**
	 * 
	 * @param title
	 */
	public AbstractChart setSimpleTitle(String title) {
		getChartConfiguration().setSimpleTitle(title);
		return this;
	}

	/**
	 * 
	 * @return Axes
	 */
	@Deprecated
	public Axes createAxes() {
		return getChartConfiguration().createAxes();
	}

	/**
	 * 
	 * @return xAxis
	 */
	@Deprecated
	public XAxis createXAxis() {
		return getChartConfiguration().createXAxis();
	}

	/**
	 * 
	 * @return yAxis
	 */
	@Deprecated
	public YAxis createYAxis() {
		return getChartConfiguration().createYAxis();
	}

	/**
	 * 
	 * @return axis
	 */
	@Deprecated
	public Axis createAxesDefaults() {
		return getChartConfiguration().createAxesDefaults();
	}

	/**
	 * 
	 * @param label
	 */
	public AbstractChart setLabelX(String label) {
		getChartConfiguration().setLabelX(label);
		return this;
	}

	/**
	 * 
	 * @param label
	 */
	public AbstractChart setLabelY(String label) {
		getChartConfiguration().setLabelY(label);
		return this;
	}

	/**
	 * @return the series
	 */
	public Collection getSeries() {
		return getChartConfiguration().seriesInstance();
	}

	/**
	 * @param series
	 *            the series to set
	 */
	public AbstractChart setSeries(Collection series) {
		this.getChartConfiguration().setSeries(series);
		return this;
	}

	/**
	 * @return the title
	 */
	public Title getTitle() {
		return getChartConfiguration().getTitle();
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public AbstractChart setTitle(Title title) {
		getChartConfiguration().setTitle(title);
		return this;
	}

	/**
	 * @return the axesDefaults
	 */
	public Axis getAxesDefaults() {
		return getChartConfiguration().axesDefaultsInstance();
	}

	/**
	 * @param axesDefaults
	 *            the axesDefaults to set
	 */
	public AbstractChart setAxesDefaults(Axis axesDefaults) {
		getChartConfiguration().setAxesDefaults(axesDefaults);
		return this;
	}

	/**
	 * @return the seriesDefaults
	 */
	public SeriesDefaults getSeriesDefaults() {
		return getChartConfiguration().seriesDefaultsInstance();
	}

	/**
	 * @param seriesDefaults
	 *            the seriesDefaults to set
	 */
	public AbstractChart setSeriesDefaults(SeriesDefaults seriesDefaults) {
		getChartConfiguration().setSeriesDefaults(seriesDefaults);
		return this;
	}

	/**
	 * 
	 * @param values
	 */
	public AbstractChart addIntervalColors(String... values) {
		getChartConfiguration().seriesDefaultsInstance().getRendererOptions()
				.getIntervalColors().addAll(Arrays.asList(values));
		return this;
	}

	/**
	 * 
	 * @param values
	 */
	public AbstractChart addIntervals(Integer... values) {
		getChartConfiguration().seriesDefaultsInstance().getRendererOptions()
				.getIntervals().addAll(Arrays.asList(values));
		return this;
	}

	/**
	 * 
	 * @param stackSeries
	 */
	public AbstractChart setStackSeries(Boolean stackSeries) {
		getChartConfiguration().setStackSeries(stackSeries);
		return this;
	}

	/**
	 * 
	 * @param captureRightClick
	 */
	public AbstractChart setCaptureRightClick(Boolean captureRightClick) {
		getChartConfiguration().setCaptureRightClick(captureRightClick);
		return this;
	}

	/**
	 * 
	 * @param highlightMouseDown
	 */
	public AbstractChart setHighlightMouseDown(Boolean highlightMouseDown) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setHighlightMouseDown(highlightMouseDown);
		return this;
	}

	/**
	 * 
	 * @param margin
	 */
	public AbstractChart setBarMargin(Integer margin) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setBarMargin(margin);
		return this;
	}

	/**
	 * 
	 * @param margin
	 */
	public AbstractChart setSliceMargin(Integer margin) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setSliceMargin(margin);
		return this;
	}

	/**
	 * 
	 * @param dataLabels
	 */
	public AbstractChart setDataLabels(String dataLabels) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setDataLabels(dataLabels);
		return this;
	}

	/**
	 * 
	 * @param width
	 */
	public AbstractChart setLineWidth(Integer width) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setLineWidth(width);
		return this;
	}

	/**
	 * 
	 * @param showDataLabels
	 */
	public AbstractChart setShowDataLabels(Boolean showDataLabels) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setShowDataLabels(showDataLabels);
		return this;
	}

	/**
	 * 
	 * @param fill
	 */
	public AbstractChart setFill(Boolean fill) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setFill(fill);
		return this;
	}

	/**
	 * 
	 * @param alpha
	 */
	public AbstractChart setBubbleAlpha(Float alpha) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setBubbleAlpha(alpha);
		return this;
	}

	/**
	 * 
	 * @param alpha
	 */
	public AbstractChart setHighlightAlpha(Float alpha) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setHighlightAlpha(alpha);
		return this;
	}

	/**
	 * 
	 * @param showLabels
	 */
	public AbstractChart setShowLabels(Boolean showLabels) {
		getChartConfiguration().seriesDefaultsInstance().rendererOptionsInstance()
				.setShowLables(showLabels);
		return this;
	}

	/**
	 * 
	 * @param alpha
	 */
	public AbstractChart setShadowAlpha(String alpha) {
		getChartConfiguration().seriesDefaultsInstance().setShadowAlpha(alpha);
		return this;
	}

	/**
	 * 
	 * @param fillZero
	 */
	public AbstractChart setFillZero(Boolean fillZero) {
		getChartConfiguration().seriesDefaultsInstance().getRendererOptions()
				.setFillZero(fillZero);
		return this;
	}

	/**
	 * 
	 * @param shadow
	 */
	public AbstractChart setShadow(Boolean shadow) {
		getChartConfiguration().getSeriesDefaults().setShadow(shadow);
		return this;
	}

	/**
	 * 
	 * @param legend
	 */
	public AbstractChart setLegend(Legend legend) {
		getChartConfiguration().setLegend(legend);
		return this;
	}

	public AbstractChart setGridPadding(GridPadding gridPadding) {
		getChartConfiguration().setGridPadding(gridPadding);
		return this;
	}

	public GridPadding getGridPadding() {
		return getChartConfiguration().getGridPadding();
	}

	/**
	 * @return the axes
	 */
	public Axes getAxes() {
		return getChartConfiguration().axesInstance();
	}

	/**
	 * @param axes
	 *            the axes to set
	 */
	public AbstractChart setAxes(Axes axes) {
		getChartConfiguration().setAxes(axes);
		return this;
	}

	public XAxis getXAxis() {
		return getChartConfiguration().xAxisInstance();
	}

	public YAxis getYAxis() {
		return getChartConfiguration().yAxisInstance();
	}

	/**
	 * 
	 * @param ticks
	 */
	@Deprecated
	public void setTicks(String... ticks) {
		getChartConfiguration().xAxisInstance().setTicks(ticks);
	}

	/**
	 * 
	 * @param padMin
	 */
	@Deprecated
	public void setPadMin(Float padMin) {
		getChartConfiguration().yAxisInstance().setPadMin(1.05f);
	}
}