Commit c4df3be2 by Alex Rhodes

initial commit

parent 0947bba5
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
#Google Charts JSF Wrapper#
###For detailed documentation and demonstration, please visit the [Project Page](https://www.alexscottrhodes.com/pages/projectPages/googleChart.xhtml)###
\ No newline at end of file
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.chartModel;
import java.util.ArrayList;
import java.util.HashMap;
import com.alexscottrhodes.constructionModel.ChartSeries;
import com.alexscottrhodes.enums.AxisType;
import com.alexscottrhodes.enums.CurveType;
import com.alexscottrhodes.enums.LegendPosition;
/**
* Model of the Google Combo chart object
* @author Alex Rhodes
*
*/
public class GoogleComboChart {
/**
* ID that will be provided by the JSF build cycle
*/
private String id;
/**
* The title of the chart
*/
private String title;
/**
* The width of the chart in pixels, provided in-line in the JSF tag with the "width" parameter, excluding "px". The width can also be provided
* in the backing bean, and will supersede the in-line width.
*/
private int width;
/**
* The height of the chart in pixels, provided in-line in the JSF tag with the "height" parameter, excluding "px". The height can also be provided
* in the backing bean, and will supersede the in-line height.
*/
private int height;
/**
* A y-value to display as a straight line across the chart to indicate some index.
*/
private int indexLineVal;
/**
* A label for the index line
*/
private String indexLineLabel;
/**
* A list of series to add to the chart, individual series should be added with the
{@link #addSeries(ChartSeries) addSeries} method.
*/
private ArrayList<ChartSeries> seriesList;
/**
* A list of axes to add to the chart
*/
private HashMap<AxisType, ArrayList<ChartSeries>> axes;
/**
* A color value to use for the chart's title. The value is a string that can represent any valid HTML or CSS color
*/
private String titleColor;
/**
* Boolean to indicate a bold title
*/
private boolean titleBold;
/**
* A label for the vertical axis
*/
private String verticalAxisLabel;
/**
* The style of chart line, as defined in the Google Chart API.
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private CurveType curveType = CurveType.DEFAULT;
/**
* The LegendPosition to place the legend when rendering the chart.
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private LegendPosition legendPosition = LegendPosition.RIGHT;
/**
* A boolean for Bar type charts to indicate if the bars should be stacked or adjacent.
*/
private boolean stacked;
/**
* An Integer to represent the starting index of the y-axis. Use {@link #setMinY(int) setMinY} method.
*/
private Integer minIndexInt = null;
/**
* A Double to represent the starting index of the y-axis. Use {@link #setMinY(double) setMinY} method.
*/
private Double minIndexDouble = null;
/**
* A Float to represent the start index of the y-axis. Use {@link #setMinY(float) setMinY} method.
*/
private Float minIndexFloat = null;
public GoogleComboChart(){
seriesList = new ArrayList<ChartSeries>();
axes = new HashMap<AxisType, ArrayList<ChartSeries>>();
axes.put(AxisType.X, new ArrayList<ChartSeries>());
axes.put(AxisType.Y, new ArrayList<ChartSeries>());
}
/**
* Create an index line to be displayed across the chart
* @param value an Int of the Y value to draw the index line
* @param label a String to display as the label for the index line
*/
public void setIndexLine(int value, String label) {
this.indexLineVal = value;
this.indexLineLabel = label;
}
/**
* Add a data series to the chart
* @param series a ChartSeries to be added to the chart
*/
public void addSeries(ChartSeries series){
seriesList.add(series);
}
/**
* Add a data series to be used as an axis
* @param series a ChartSeries object to be added as an axis
* @param axis an AxisType specifying which axis to use the series on
*/
public void addAxisSeries(ChartSeries series, AxisType axis){
axes.get(axis).add(series);
}
/**
* Add a minimum Y-axis index to a graph of integer values
* @param min an Integer of the desired starting index
*/
public void setMinY(int min){
this.minIndexInt = min;
}
/**
* Add a minimum Y-axis index to a graph of float values
* @param min a Float of the desired starting index
*/
public void setMinY(float min){
this.minIndexFloat = min;
}
/**
* Add a minimum Y-axis index to a graph of double values
* @param min a Double of the desired starting index
*/
public void setMinY(double min){
this.minIndexDouble = min;
}
//Getters and Setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public ArrayList<ChartSeries> getSeriesList() {
return seriesList;
}
public void setSeriesList(ArrayList<ChartSeries> seriesList) {
this.seriesList = seriesList;
}
public HashMap<AxisType, ArrayList<ChartSeries>> getAxes() {
return axes;
}
public void setAxes(HashMap<AxisType, ArrayList<ChartSeries>> axes) {
this.axes = axes;
}
public boolean isTitleBold() {
return titleBold;
}
public void setTitleBold(boolean titleBold) {
this.titleBold = titleBold;
}
public String getTitleColor() {
return titleColor;
}
public void setTitleColor(String titleColor) {
this.titleColor = titleColor;
}
public String getVerticalAxisLabel() {
return verticalAxisLabel;
}
public void setVerticalAxisLabel(String verticalAxisLabel) {
this.verticalAxisLabel = verticalAxisLabel;
}
public String getIndexLineLabel() {
return indexLineLabel;
}
public int getIndexLineVal() {
return indexLineVal;
}
public CurveType getCurveType() {
return curveType;
}
public void setCurveType(CurveType curveType) {
this.curveType = curveType;
}
public LegendPosition getLegendPosition() {
return legendPosition;
}
public void setLegendPosition(LegendPosition legendPosition) {
this.legendPosition = legendPosition;
}
public boolean isStacked() {
return stacked;
}
public void setStacked(boolean stacked) {
this.stacked = stacked;
}
public Integer getMinIndexInt() {
return minIndexInt;
}
public void setMinIndexInt(int minIndexInt) {
this.minIndexInt = minIndexInt;
}
public Double getMinIndexDouble() {
return minIndexDouble;
}
public void setMinIndexDouble(double minIndexDouble) {
this.minIndexDouble = minIndexDouble;
}
public Float getMinIndexFloat() {
return minIndexFloat;
}
public void setMinIndexFloat(float minIndexFloat) {
this.minIndexFloat = minIndexFloat;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.chartModel;
import java.util.ArrayList;
import com.alexscottrhodes.chartModel.components.PieSlice;
/**
* Model of the Google Pie Chart object
* @author Alex Rhodes
*
*/
public class GooglePieChart {
/**
* an ID that will be provided by the JSF build cycle
*/
String id;
/**
* The title of the chart.
*/
private String title;
/**
* The data type of the chart
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private String dataType;
/**
* The unit description of the data
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private String dataName;
/**
* A color value to use for the chart's title. The value is a string that can represent any valid HTML or CSS color
*/
private String titleColor;
/**
* A boolean to represent a bolded title
*/
private boolean titleBold;
/**
* A list of pie slices. Individual slices should be added using the
* {@link #addSlice(PieSlice) addSlice} method.
*/
private ArrayList<PieSlice> slices = new ArrayList<PieSlice>();
/**
* The width of the chart in pixels, provided in-line in the JSF tag with the "width" parameter, excluding "px". The width can also be provided
* in the backing bean, and will supersede the in-line width.
*/
private int width;
/**
* The height of the chart in pixels, provided in-line in the JSF tag with the "height" parameter, excluding "px". The height can also be provided
* in the backing bean, and will supersede the in-line height.
*/
private int height;
/**
* A boolean to represent a 3-Dimensional chart
*/
private boolean is3d;
/**
* A boolean to represent shown or hidden pie slice labels
*/
private boolean showSliceText = true;
/**
* The size of a donut hole in a donut hole chart as specified in the Charts API
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private double donutHoleSize;
/**
* Degrees of rotation to rotate the pie chart.
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private int rotation;
public GooglePieChart(String dataName, String dataType){
this.dataName = dataName;
this.dataType = dataType;
}
public void addSlice(PieSlice slice){
slices.add(slice);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitleColor() {
return titleColor;
}
public void setTitleColor(String titleColor) {
this.titleColor = titleColor;
}
public boolean isTitleBold() {
return titleBold;
}
public void setTitleBold(boolean titleBold) {
this.titleBold = titleBold;
}
public ArrayList<PieSlice> getSlices() {
return slices;
}
public void setSlices(ArrayList<PieSlice> slices) {
this.slices = slices;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public boolean isIs3d() {
return is3d;
}
public void setIs3d(boolean is3d) {
this.is3d = is3d;
}
public void setDonutHoleSize(double d) {
this.donutHoleSize = d;
}
public int getRotation() {
return rotation;
}
public void setRotation(int rotation) {
this.rotation = rotation;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getDataName() {
return dataName;
}
public void setDataName(String dataName) {
this.dataName = dataName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getDonutHoleSize() {
return donutHoleSize;
}
public boolean isShowSliceText() {
return showSliceText;
}
public void setShowSliceText(boolean showSliceText) {
this.showSliceText = showSliceText;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.chartModel.components;
/**
* Model of a Google Pie Slice object
* @author Alex Rhodes
*
*/
public class PieSlice {
private double value;
private String name;
private boolean visible = true;
private String color;
private double offset;
public PieSlice(String name, double value){
this.name = name;
this.value = value;
}
public PieSlice(String name, int value){
this.name = name;
this.value = value;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public void setOffset(double offset) {
this.offset = offset;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public double getOffset() {
return offset;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.constructionModel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import com.alexscottrhodes.enums.SeriesDisplayType;
import com.alexscottrhodes.enums.SeriesType;
/**
* An object representing a data series and related parameters to pass into a chart
* @author Alex Rhodes
*
*/
@SuppressWarnings("unchecked")
public class ChartSeries {
private String label = "";
private SeriesType type = SeriesType.STRING;
private SeriesDisplayType displayType = SeriesDisplayType.BAR;
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
/**
* Constructor that requires definition of the data type being put into the chart series
* @param type a SeriesType representative of the data type of the series
*/
public ChartSeries(SeriesType type){
this.type = type;
}
@SuppressWarnings("rawtypes")
private ArrayList dataset = new ArrayList();
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@SuppressWarnings("rawtypes")
public ArrayList getDataset() {
return dataset;
}
public void addPoint(Integer point){
dataset.add(point);
}
public void addPoint(String point){
dataset.add(point);
}
public void addPoint(Date point){
try{
point = simpleDateFormat.parse(simpleDateFormat.format(point));
dataset.add(point);
}catch(Exception e){
try {
throw new Exception("Unable to parse date: " + point);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public void addPoint(Float point){
dataset.add(point);
}
public SeriesType getType(){
return type;
}
public SimpleDateFormat getDateFormat() {
return simpleDateFormat;
}
public void setDateFormat(String format) {
simpleDateFormat = new SimpleDateFormat(format);
}
public SeriesDisplayType getDisplayType() {
return displayType;
}
public void setDisplayType(SeriesDisplayType displayType) {
this.displayType = displayType;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.demo;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import com.alexscottrhodes.chartModel.GoogleComboChart;
import com.alexscottrhodes.chartModel.GooglePieChart;
import com.alexscottrhodes.chartModel.components.PieSlice;
import com.alexscottrhodes.constructionModel.ChartSeries;
import com.alexscottrhodes.enums.AxisType;
import com.alexscottrhodes.enums.CurveType;
import com.alexscottrhodes.enums.LegendPosition;
import com.alexscottrhodes.enums.SeriesDisplayType;
import com.alexscottrhodes.enums.SeriesType;
/**
* Demonstration of the Google Chart object construction
* @author Alex Rhodes
*
*/
public class Charts {
/**
* Build a Combo chart
* @return a GoogleComboChart
*/
public static GoogleComboChart getComboChart() {
GoogleComboChart gcc;
gcc = new GoogleComboChart();
gcc.setTitle("This is the Title");
gcc.setTitleBold(true); // Bolded title
gcc.setTitleColor("#59b300"); // Green title
gcc.setCurveType(CurveType.FUNCTION); // Smoothed curve
gcc.setVerticalAxisLabel("Y-Axis vals"); // Label for Y-axis
gcc.setIndexLine(50, "Target Amount"); // add an index line
ChartSeries s = new ChartSeries(SeriesType.NUMBER); // Add a series of
// numbers
s.setDisplayType(SeriesDisplayType.BAR); // Make this series a line
s.setLabel("A line of values over time.");
for (Integer i : getRandVals()) {
s.addPoint(i); // Populate with some random numbers
}
ChartSeries t = new ChartSeries(SeriesType.NUMBER); // Add a series of
// numbers
t.setDisplayType(SeriesDisplayType.BAR); // Make this series bars
t.setLabel("A second set of values over time");
for (Integer i : getRandVals()) {
t.addPoint(i); // Populate with some random numbers
}
ChartSeries x = new ChartSeries(SeriesType.DATE); // Add a series of
// Dates
x.setDateFormat("yyyy-MM-dd"); // Format the date output
x.setLabel("Date - X-axis vals");
for (Date d : getDates()) {
x.addPoint(d); // Populate with some dates
}
gcc.addSeries(s); // Add series S
gcc.addSeries(t);// Add series T
gcc.addAxisSeries(x, AxisType.X); // Add the X-axis
gcc.setStacked(true);
gcc.setLegendPosition(LegendPosition.HIDDEN);
return gcc;
}
/**
* Build a Google Pie Chart
* @return a Google Pie Chart object
*/
public static GooglePieChart getPieChart(){
GooglePieChart gpc = new GooglePieChart("Activity","Time Spent");
gpc.setDataName("Activity");
gpc.setDataType("Time spent");
gpc.setIs3d(true);
gpc.setRotation(45);
gpc.setTitle("Debugging Code");
gpc.setTitleBold(true);
gpc.setTitleColor("#ff6600");
PieSlice p = new PieSlice("Googling",20);
p.setOffset(0.4);
PieSlice q = new PieSlice("Stack Exchange",30);
q.setOffset(0.2);
PieSlice r = new PieSlice("Stepping Through",40);
PieSlice s = new PieSlice("Crying", 10);
gpc.addSlice(p);
gpc.addSlice(q);
gpc.addSlice(r);
gpc.addSlice(s);
return gpc;
}
// Utility to get some random numbers
public static ArrayList<Integer> getRandVals() {
Random r = new Random();
ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
result.add(r.nextInt(100 - 10) + 10);
}
return result;
}
// Utility to get some dates
public static ArrayList<Date> getDates() {
ArrayList<Date> result = new ArrayList<Date>();
Calendar c = Calendar.getInstance();
c.setTime(new Date());
for (int i = 0; i < 10; i++) {
c.add(Calendar.DATE, 7);
result.add(c.getTime());
}
return result;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.demo;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.alexscottrhodes.chartModel.GoogleComboChart;
import com.alexscottrhodes.chartModel.GooglePieChart;
/**
* A demo of the Google Chart JSF wrapper
* @author Alex
*
*/
@ManagedBean
@ViewScoped
public class GoogleChartBean {
private GoogleComboChart gcc;
private GooglePieChart gpc;
/**
* Build some charts
*/
@PostConstruct
public void init(){
gcc = Charts.getComboChart();
gpc = Charts.getPieChart();
}
//Return the charts to render
public GoogleComboChart getCombo(){
return gcc;
}
public GooglePieChart getPie(){
return gpc;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An Enum representing the Axis types of the graph
* @author Alex Rhodes
*
*/
public enum AxisType {
X("x-axis"),
Y("y-axis");
private String name;
AxisType(String name){
this.name = name;
}
public String getName(){
return name;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An Enum for the "curve type" parameter of the Google chart API;
* @author arhodes
*
*/
public enum CurveType {
FUNCTION("function"),
DEFAULT("line");
private String plainText;
CurveType(String pt){
this.plainText = pt;
}
@Override
public String toString(){
return plainText;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An Enum for the "curve type" parameter of the Google chart API;
* @author arhodes
*
*/
public enum LegendPosition {
TOP("top"),
LEFT("left"),
RIGHT("right"),
BOTTOM("bottom"),
IN("in"),
HIDDEN("none");
private String plainText;
LegendPosition(String pt){
this.plainText = pt;
}
@Override
public String toString(){
return plainText;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An Enum for the format to display the data of a chart series
* @author Alex Rhodes
*
*/
public enum SeriesDisplayType {
LINE("line"), BAR("bars"),AREA("area"), CANDLESTICKS("candlesticks"), STEPPED_AREA("steppedArea");
private String chartDef;
SeriesDisplayType(String chartDef){
this.chartDef = chartDef;
}
@Override
public String toString(){
return chartDef;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An enum to represent the type of data of a given chart series
* @author Alex Rhodes
*
*/
public enum SeriesType {
DATE("string"),STRING("string"),NUMBER("number");
private String chartDef;
private SeriesType(String def){
this.chartDef = def;
}
public String getDef(){
return chartDef;
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.exceptions;
/**
* An exception thrown when problems are found with a chart's axes
* @author Alex Rhodes
*
*/
public class AxesException extends RuntimeException{
private static final long serialVersionUID = 1L;
//No overrides
public AxesException(String string) {
super(string);
}
public AxesException(Throwable t){
super(t);
}
public AxesException(String string, Throwable t){
super(string,t);
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.exceptions;
/**
* A generic exception involving a chart object, designed to be thrown with an informative message
* @author Alex Rhodes
*
*/
public class ChartException extends RuntimeException{
private static final long serialVersionUID = 1L;
//No overrides
public ChartException(String string) {
super(string);
}
public ChartException(Throwable t){
super(t);
}
public ChartException(String string, Throwable t){
super(string,t);
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.exceptions;
/**
* An exception thrown from construction of pie chart
* @author Alex Rhodes
*/
public class PieChartException extends RuntimeException{
private static final long serialVersionUID = 1L;
//No overrides
public PieChartException(String string) {
super(string);
}
public PieChartException(Throwable t){
super(t);
}
public PieChartException(String string, Throwable t){
super(string,t);
}
}
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
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.
2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.handler;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import com.alexscottrhodes.builder.Builder;
import com.alexscottrhodes.chartModel.GoogleComboChart;
import com.alexscottrhodes.chartModel.GooglePieChart;
import com.alexscottrhodes.exceptions.ChartException;
/**
* Tag handler for the google charts API wrapper.
*
* @author Alex Rhodes
*
*/
@FacesComponent(tagName = "googleChart", createTag = true, namespace = "http://alexscottrhodes.com/facelets", value = "com.alexscottrhodes.googleChart")
public class GoogleChartTagHandler extends UIComponentBase {
@Override
public String getFamily() {
return "com.alexscottrhodes.googleChart";
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
GoogleComboChart gcc = null;
GooglePieChart gpc = null;
ResponseWriter writer = context.getResponseWriter();
String output = null;
String id = "";
try {
id = (String) this.getAttributes().get("id");
} catch (Exception e) {
throw new ChartException("No ID Specified");
}
// Collect parameters
String typeString = (String) getAttributes().get("type");
int height = 0;
int width = 0;
try{
if(getAttributes().get("height") != null){
height = Integer.valueOf((String)getAttributes().get("height"));
}
}catch(Exception e){
throw new ChartException("Invalid height:" + getAttributes().get("width"));
}
try{
if(getAttributes().get("width") != null){
width = Integer.valueOf((String)getAttributes().get("width"));
}
}catch(Exception e){
throw new ChartException("Invalid width:" + getAttributes().get("width"));
}
Object chartObject = getAttributes().get("value");
if (typeString == null) {
throw new ChartException("Invalid or missing chart type.");
}
// Cast to appropriate chart model
if (typeString.equals("combo")) {
try {
gcc = (GoogleComboChart) chartObject;
if(gcc.getHeight()==0){
gcc.setHeight(height);
}
if(gcc.getWidth()==0){
gcc.setWidth(width);
}
gcc.setId(id);
} catch (Exception e) {
throw new ChartException("Invalid chart model.");
}
Builder b = new Builder();
try {
output = b.buildComboChart(gcc);
} catch (Exception e) {
throw new ChartException("Error rendering.");
}
}
else if (typeString.equals("pie")) {
try {
gpc = (GooglePieChart) chartObject;
gpc.setId(id);
if(gpc.getHeight()==0){
gpc.setHeight(height);
}
if(gpc.getWidth()==0){
gpc.setWidth(width);
}
} catch (Exception e) {
throw new ChartException("Invalid chart model.");
}
Builder b = new Builder();
output = b.buildPieChart(gpc);
}
else {
throw new ChartException("Invalid chart type:" + typeString);
}
writer.write(output);
}
}
function tabSwitch(active,inactive){
document.getElementById(active).className = "active";
document.getElementById(inactive).className = "";
return true;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment