Newer
Older
* Copyright 2015 Knowm Inc. (http://knowm.org) and contributors.
* Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors.
*
* 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.
import java.awt.Color;
import java.awt.Font;
import java.awt.Stroke;
import java.util.Locale;
import java.util.TimeZone;
import org.knowm.xchart.internal.style.GGPlot2Theme;
import org.knowm.xchart.internal.style.MatlabTheme;
import org.knowm.xchart.internal.style.Theme;
import org.knowm.xchart.internal.style.XChartTheme;
* The StyleManager is used to manage all things related to styling of the vast number of Chart components
* @author timmolter
*/
public class StyleManager {
Tim Molter
committed
public enum ChartType {
Tim Molter
committed
}
Tim Molter
committed
OutsideE, InsideNW, InsideNE, InsideSE, InsideSW, InsideN
XChart, GGPlot2, Matlab;
public Theme newInstance(ChartTheme chartTheme) {
switch (chartTheme) {
Martin Crawford
committed
public enum TextAlignment {
Martin Crawford
committed
}
// Chart Style ///////////////////////////////
Tim Molter
committed
private ChartType chartType;
private Color chartBackgroundColor;
public Color chartFontColor;
// Chart Title ///////////////////////////////
private boolean isChartTitleBoxVisible;
private Color chartTitleBoxBackgroundColor;
private Color chartTitleBoxBorderColor;
// Chart Legend ///////////////////////////////
private boolean isLegendVisible;
private Color legendBackgroundColor;
private Font legendFont;
private int legendPadding;
private int legendSeriesLineLength;
// Chart Axes ///////////////////////////////
private boolean xAxisTitleVisible;
private boolean yAxisTitleVisible;
private Font axisTitleFont;
private boolean xAxisTicksVisible;
private boolean yAxisTicksVisible;
private int axisTickMarkLength;
private int axisTickPadding;
private Color axisTickMarksColor;
private Stroke axisTickMarksStroke;
private Color axisTickLabelsColor;
private int plotPadding;
private int axisTitlePadding;
Tim Molter
committed
private int xAxisTickMarkSpacingHint;
private int yAxisTickMarkSpacingHint;
private boolean isXAxisLogarithmic;
private boolean isYAxisLogarithmic;
private Double xAxisMin;
private Double xAxisMax;
private Double yAxisMin;
private Double yAxisMax;
Martin Crawford
committed
private TextAlignment xAxisLabelAlignment = TextAlignment.Centre;
private TextAlignment yAxisLabelAlignment = TextAlignment.Left;
private int xAxisLabelRotation = 0;
// Chart Plot Area ///////////////////////////////
private boolean isPlotGridHorizontalLinesVisible;
private boolean isPlotGridVerticalLinesVisible;
private Color plotBackgroundColor;
private Color plotBorderColor;
private boolean isPlotBorderVisible;
private Color plotGridLinesColor;
// Bar Charts ///////////////////////////////
private boolean isBarFilled;
// Line, Scatter, Area Charts ///////////////////////////////
private int markerSize;
// Error Bars ///////////////////////////////
private Color errorBarsColor;
private boolean isErrorBarsColorSeriesColor;
Tim Molter
committed
private String datePattern;
private String xAxisDecimalPattern;
private String yAxisDecimalPattern;
/**
* Constructor
*/
public StyleManager() {
// Chart Style ///////////////////////////////
Tim Molter
committed
chartType = ChartType.Line;
chartBackgroundColor = theme.getChartBackgroundColor();
chartFontColor = theme.getChartFontColor();
// Chart Title ///////////////////////////////
isChartTitleBoxVisible = theme.isChartTitleBoxVisible();
chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor();
chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor();
chartTitlePadding = theme.getChartTitlePadding();
// legend
isLegendVisible = theme.isLegendVisible();
legendBackgroundColor = theme.getLegendBackgroundColor();
legendBorderColor = theme.getLegendBorderColor();
legendFont = theme.getLegendFont();
legendPadding = theme.getLegendPadding();
legendSeriesLineLength = theme.getLegendSeriesLineLength();
legendPosition = theme.getLegendPosition();
// axes
xAxisTitleVisible = theme.isXAxisTitleVisible();
yAxisTitleVisible = theme.isYAxisTitleVisible();
axisTitleFont = theme.getAxisTitleFont();
xAxisTicksVisible = theme.isXAxisTicksVisible();
yAxisTicksVisible = theme.isYAxisTicksVisible();
axisTickLabelsFont = theme.getAxisTickLabelsFont();
axisTickMarkLength = theme.getAxisTickMarkLength();
axisTickPadding = theme.getAxisTickPadding();
axisTickMarksColor = theme.getAxisTickMarksColor();
axisTickMarksStroke = theme.getAxisTickMarksStroke();
axisTickLabelsColor = theme.getAxisTickLabelsColor();
isAxisTicksLineVisible = theme.isAxisTicksLineVisible();
isAxisTicksMarksVisible = theme.isAxisTicksMarksVisible();
plotPadding = theme.getPlotPadding();
axisTitlePadding = theme.getAxisTitlePadding();
Tim Molter
committed
xAxisTickMarkSpacingHint = theme.getXAxisTickMarkSpacingHint();
yAxisTickMarkSpacingHint = theme.getYAxisTickMarkSpacingHint();
isXAxisLogarithmic = false;
isYAxisLogarithmic = false;
xAxisMin = null;
xAxisMax = null;
yAxisMin = null;
yAxisMax = null;
// Chart Plot Area ///////////////////////////////
isPlotGridVerticalLinesVisible = theme.isPlotGridVerticalLinesVisible();
isPlotGridHorizontalLinesVisible = theme.isPlotGridHorizontalLinesVisible();
plotBackgroundColor = theme.getPlotBackgroundColor();
plotBorderColor = theme.getPlotBorderColor();
isPlotBorderVisible = theme.isPlotBorderVisible();
isPlotTicksMarksVisible = theme.isPlotTicksMarksVisible();
plotGridLinesColor = theme.getPlotGridLinesColor();
plotGridLinesStroke = theme.getPlotGridLinesStroke();
// Bar Charts ///////////////////////////////
barWidthPercentage = theme.getBarWidthPercentage();
isBarsOverlapped = theme.isBarsOverlapped();
isBarFilled = theme.isBarFilled();
// Line, Scatter, Area Charts ///////////////////////////////
markerSize = theme.getMarkerSize();
// Error Bars ///////////////////////////////
errorBarsColor = theme.getErrorBarsColor();
isErrorBarsColorSeriesColor = theme.isErrorBarsColorSeriesColor();
locale = Locale.getDefault();
timezone = TimeZone.getDefault();
Tim Molter
committed
datePattern = null; // if not null, this override pattern will be used
xAxisDecimalPattern = null;
yAxisDecimalPattern = null;
}
/**
* Set the theme the style manager should use
Tim Molter
committed
protected void setTheme(Theme theme) {
public Theme getTheme() {
return theme;
}
Tim Molter
committed
/**
* sets the Chart Type
Tim Molter
committed
* @param chartType
*/
public void setChartType(ChartType chartType) {
this.chartType = chartType;
}
public ChartType getChartType() {
return chartType;
}
/**
* Set the chart background color - the part around the edge of the chart
public void setChartBackgroundColor(Color color) {
this.chartBackgroundColor = color;
}
public Color getChartBackgroundColor() {
* Set the chart font color. includes: Chart title, axes label, legend
* @param chartPadding
*/
public void setChartPadding(int chartPadding) {
this.chartPadding = chartPadding;
}
public int getChartPadding() {
return chartPadding;
}
// Chart Title ///////////////////////////////
/**
* Set the chart title font
public void setChartTitleFont(Font chartTitleFont) {
*/
public void setChartTitleVisible(boolean isChartTitleVisible) {
this.isChartTitleVisible = isChartTitleVisible;
}
public boolean isChartTitleVisible() {
return isChartTitleVisible;
}
public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) {
this.isChartTitleBoxVisible = isChartTitleBoxVisible;
public boolean isChartTitleBoxVisible() {
* set the chart title box background color
public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) {
this.chartTitleBoxBackgroundColor = chartTitleBoxBackgroundColor;
public Color getChartTitleBoxBackgroundColor() {
return chartTitleBoxBackgroundColor;
}
/**
* set the chart title box border color
* @param chartTitleBoxBorderColor
*/
public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) {
this.chartTitleBoxBorderColor = chartTitleBoxBorderColor;
}
public Color getChartTitleBoxBorderColor() {
return chartTitleBoxBorderColor;
}
/**
* set the chart title padding; the space between the chart title and the plot area
* @param chartTitlePadding
*/
public void setChartTitlePadding(int chartTitlePadding) {
this.chartTitlePadding = chartTitlePadding;
}
public int getChartTitlePadding() {
return chartTitlePadding;
}
public void setLegendBackgroundColor(Color color) {
* @return
*/
public Color getLegendBorderColor() {
return legendBorderColor;
}
public void setLegendBorderColor(Color legendBorderColor) {
this.legendBorderColor = legendBorderColor;
}
}
/**
* Set the chart legend visibility
public void setLegendVisible(boolean isLegendVisible) {
}
/**
* Set the chart legend padding
public void setLegendPadding(int legendPadding) {
/**
* Set the chart legend series line length
* @param legendPadding
*/
public void setLegendSeriesLineLength(int legendSeriesLineLength) {
if (legendSeriesLineLength < 0) {
this.legendSeriesLineLength = 0;
}
else {
this.legendSeriesLineLength = legendSeriesLineLength;
}
}
public int getLegendSeriesLineLength() {
return legendSeriesLineLength;
}
* @param legendPosition
*/
public void setLegendPosition(LegendPosition legendPosition) {
this.legendPosition = legendPosition;
}
public LegendPosition getLegendPosition() {
return legendPosition;
}
// Chart Axes ///////////////////////////////
/**
* Set the x-axis title visibility
public void setXAxisTitleVisible(boolean xAxisTitleVisible) {
this.xAxisTitleVisible = xAxisTitleVisible;
}
public boolean isXAxisTitleVisible() {
return xAxisTitleVisible;
}
/**
* Set the y-axis title visibility
public void setYAxisTitleVisible(boolean yAxisTitleVisible) {
this.yAxisTitleVisible = yAxisTitleVisible;
}
public boolean isYAxisTitleVisible() {
return yAxisTitleVisible;
}
/**
* Set the x- and y-axis titles visibility
* @param isVisible
*/
public void setAxisTitlesVisible(boolean isVisible) {
this.xAxisTitleVisible = isVisible;
this.yAxisTitleVisible = isVisible;
}
/**
* Set the x- and y-axis title font
* @param axisTitleFont
*/
public void setAxisTitleFont(Font axisTitleFont) {
this.axisTitleFont = axisTitleFont;
}
public Font getAxisTitleFont() {
return axisTitleFont;
}
/**
* Set the x-axis tick marks and labels visibility
public void setXAxisTicksVisible(boolean xAxisTicksVisible) {
this.xAxisTicksVisible = xAxisTicksVisible;
}
public boolean isXAxisTicksVisible() {
return xAxisTicksVisible;
}
/**
* Set the y-axis tick marks and labels visibility
public void setYAxisTicksVisible(boolean yAxisTicksVisible) {
this.yAxisTicksVisible = yAxisTicksVisible;
}
public boolean isYAxisTicksVisible() {
return yAxisTicksVisible;
}
/**
* Set the x- and y-axis tick marks and labels visibility
* @param isVisible
*/
public void setAxisTicksVisible(boolean isVisible) {
this.xAxisTicksVisible = isVisible;
this.yAxisTicksVisible = isVisible;
}
/**
* Set the x- and y-axis tick label font
public void setAxisTickLabelsFont(Font axisTicksFont) {
* @param axisTickMarkLength
*/
public void setAxisTickMarkLength(int axisTickMarkLength) {
this.axisTickMarkLength = axisTickMarkLength;
}
public int getAxisTickMarkLength() {
return axisTickMarkLength;
}
/**
* sets the padding between the tick labels and the tick marks
* @param axisTickPadding
*/
public void setAxisTickPadding(int axisTickPadding) {
this.axisTickPadding = axisTickPadding;
}
public int getAxisTickPadding() {
return axisTickPadding;
}
* @param axisTickColor
*/
public void setAxisTickMarksColor(Color axisTickColor) {
this.axisTickMarksColor = axisTickColor;
}
public Color getAxisTickMarksColor() {
return axisTickMarksColor;
}
/**
* sets the axis tick marks Stroke
* @param axisTickMarksStroke
*/
public void setAxisTickMarksStroke(Stroke axisTickMarksStroke) {
this.axisTickMarksStroke = axisTickMarksStroke;
}
public Stroke getAxisTickMarksStroke() {
return axisTickMarksStroke;
}
/**
* sets the axis tick label color
* @param axisTickLabelsColor
*/
public void setAxisTickLabelsColor(Color axisTickLabelsColor) {
this.axisTickLabelsColor = axisTickLabelsColor;
}
public Color getAxisTickLabelsColor() {
return axisTickLabelsColor;
}
/**
* sets the visibility of the line parallel to the plot edges that go along with the tick marks
* @param isAxisTicksLineVisible
*/
public void setAxisTicksLineVisible(boolean isAxisTicksLineVisible) {
this.isAxisTicksLineVisible = isAxisTicksLineVisible;
}
public boolean isAxisTicksLineVisible() {
return isAxisTicksLineVisible;
}
/**
* @param isAxisTicksMarksVisible
*/
public void setAxisTicksMarksVisible(boolean isAxisTicksMarksVisible) {
this.isAxisTicksMarksVisible = isAxisTicksMarksVisible;
}
public boolean isAxisTicksMarksVisible() {
return isAxisTicksMarksVisible;
}
/**
* sets the padding between the tick marks and the plot area
* @param plotPadding
*/
public void setPlotPadding(int plotPadding) {
this.plotPadding = plotPadding;
}
public int getPlotPadding() {
return plotPadding;
}
/**
* sets the padding between the axis title and the tick labels
* @param axisTitlePadding
*/
public void setAxisTitlePadding(int axisTitlePadding) {
this.axisTitlePadding = axisTitlePadding;
}
public int getAxisTitlePadding() {
return axisTitlePadding;
}
Tim Molter
committed
/**
* set the spacing between tick marks for the X-Axis
Tim Molter
committed
* @param xAxisTickMarkSpacingHint
*/
public void setXAxisTickMarkSpacingHint(int xAxisTickMarkSpacingHint) {
this.xAxisTickMarkSpacingHint = xAxisTickMarkSpacingHint;
}
public int getXAxisTickMarkSpacingHint() {
return xAxisTickMarkSpacingHint;
}
/**
* set the spacing between tick marks for the Y-Axis
Tim Molter
committed
* @param xAxisTickMarkSpacingHint
*/
public void setYAxisTickMarkSpacingHint(int yAxisTickMarkSpacingHint) {
this.yAxisTickMarkSpacingHint = yAxisTickMarkSpacingHint;
}
public int getYAxisTickMarkSpacingHint() {
return yAxisTickMarkSpacingHint;
}
/**
* sets the X-Axis to be rendered with a logarithmic scale or not
Tim Molter
committed
* @param isxAxisLogarithmic
public void setXAxisLogarithmic(boolean isXAxisLogarithmic) {
this.isXAxisLogarithmic = isXAxisLogarithmic;
return isXAxisLogarithmic;
}
/**
* sets the Y-Axis to be rendered with a logarithmic scale or not
Tim Molter
committed
* @param isyAxisLogarithmic
public void setYAxisLogarithmic(boolean isYAxisLogarithmic) {
this.isYAxisLogarithmic = isYAxisLogarithmic;
public void setXAxisMin(double xAxisMin) {
public Double getXAxisMin() {
public void setXAxisMax(double xAxisMax) {
public Double getXAxisMax() {
public void setYAxisMin(double yAxisMin) {
public Double getYAxisMin() {
public void setYAxisMax(double yAxisMax) {
public Double getYAxisMax() {
public void setAxisTickSpacePercentage(double axisTickSpacePercentage) {
this.axisTickSpacePercentage = axisTickSpacePercentage;
Martin Crawford
committed
public TextAlignment getXAxisLabelAlignment() {
Martin Crawford
committed
return xAxisLabelAlignment;
}
public void setXAxisLabelAlignment(TextAlignment xAxisLabelAlignment) {
Martin Crawford
committed
this.xAxisLabelAlignment = xAxisLabelAlignment;
}
public TextAlignment getYAxisLabelAlignment() {
Martin Crawford
committed
return yAxisLabelAlignment;
}
public void setYAxisLabelAlignment(TextAlignment yAxisLabelAlignment) {
Martin Crawford
committed
this.yAxisLabelAlignment = yAxisLabelAlignment;
}
public int getXAxisLabelRotation() {
return xAxisLabelRotation;
}
public void setXAxisLabelRotation(int xAxisLabelRotation) {
this.xAxisLabelRotation = xAxisLabelRotation;
}
// Chart Plot Area ///////////////////////////////
/**
* sets the visibility of the gridlines on the plot area
* @param isPlotGridLinesVisible
*/
public void setPlotGridLinesVisible(boolean isPlotGridLinesVisible) {
this.isPlotGridHorizontalLinesVisible = isPlotGridLinesVisible;
this.isPlotGridVerticalLinesVisible = isPlotGridLinesVisible;
public boolean isPlotGridLinesVisible() {
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
return isPlotGridHorizontalLinesVisible && isPlotGridVerticalLinesVisible;
}
/**
* sets the visibility of the horizontal gridlines on the plot area
*
* @param isPlotGridLinesVisible
*/
public void setPlotGridHorizontalLinesVisible(boolean isPlotGridHorizontalLinesVisible) {
this.isPlotGridHorizontalLinesVisible = isPlotGridHorizontalLinesVisible;
}
public boolean isPlotGridHorizontalLinesVisible() {
return isPlotGridHorizontalLinesVisible;
}
/**
* sets the visibility of the vertical gridlines on the plot area
*
* @param isPlotGridLinesVisible
*/
public void setPlotGridVerticalLinesVisible(boolean isPlotGridVerticalLinesVisible) {
this.isPlotGridVerticalLinesVisible = isPlotGridVerticalLinesVisible;
}
public boolean isPlotGridVerticalLinesVisible() {
return isPlotGridVerticalLinesVisible;
/**
* set the plot area's background color
* @param plotBackgroundColor
*/
public void setPlotBackgroundColor(Color plotBackgroundColor) {
this.plotBackgroundColor = plotBackgroundColor;
}
public Color getPlotBackgroundColor() {
return plotBackgroundColor;
}
* @param plotBorderColor
*/
public void setPlotBorderColor(Color plotBorderColor) {
this.plotBorderColor = plotBorderColor;
}
public Color getPlotBorderColor() {
return plotBorderColor;
}
/**
* sets the visibility of the border around the plot area