
com.sun.mojarra.scales.component.YuiChart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mojarra-scales Show documentation
Show all versions of mojarra-scales Show documentation
This is the core for Mojarra Scales. It has everything that Scales offers minus the multi-file upload component dependencies due to their size.
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don\"t indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.mojarra.scales.component;
import com.sun.mojarra.scales.util.RenderingHelper;
import com.sun.mojarra.scales.util.ScalesUtil;
import com.sun.mojarra.scales.util.YuiConstants;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
/**
* @author Jason Lee
*
*/
public class YuiChart extends UIOutput {
public static final String COMPONENT_FAMILY = "com.sun.mojarra.scales.YuiChart";
public static final String RENDERER_TYPE = COMPONENT_FAMILY;
private Object[] _state;
protected String type = "line";
protected String horizontalField;
protected String verticalField;
protected String horizontalAxis = "";
protected String verticalAxis = "";
protected String labelFunction = "";
protected String categoryField;
protected String dataField;
protected String seriesDef = "[{}]";
protected String width = "500px";
protected String height = "250px";
protected String style = "";
public YuiChart() {
setRendererType(RENDERER_TYPE);
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
String baseUrl = context.getExternalContext().getRequestContextPath();
Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_DATASOURCE);
Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_JSON);
Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_CHARTS);
Links.addScript(Links.DOM_READY_SCRIPTS, "YAHOO.widget.Chart.SWFURL = '" +
baseUrl + ScalesUtil.createResourceUrl(context, YuiConstants.OTHER_CHART_FLASH) + "';");
}
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
super.encodeBegin(context);
// suppress rendering if "rendered" property on the component is false.
if (!isRendered()) {
return;
}
ResponseWriter writer = context.getResponseWriter();
String clientId = getClientId(context);
writer.startElement("div", this);
writer.writeAttribute("id", clientId, "id");
writer.writeAttribute("style", "height: " + getAttributes().get("height") + "; width: " + getAttributes().get("width") + " " +
getAttributes().get("style"), "style");
writer.write("Unable to load Flash content. The chart Control requires Flash Player 9.0.45 or higher.");
writer.endElement("div");
RenderingHelper.writeOnDomReady(writer, "scales.createChart('" + clientId + "', '" +
((String)getAttributes().get("type")).toLowerCase() + "', " + buildConfig() + ");");
}
public String getCategoryField() {
return categoryField;
}
public void setCategoryField(String categoryField) {
this.categoryField = categoryField;
}
public String getDataField() {
return dataField;
}
public void setDataField(String dataField) {
this.dataField = dataField;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getHorizontalAxis() {
return horizontalAxis;
}
public void setHorizontalAxis(String horizontalAxis) {
this.horizontalAxis = horizontalAxis;
}
public String getHorizontalField() {
return horizontalField;
}
public void setHorizontalField(String horizontalField) {
this.horizontalField = horizontalField;
}
public String getLabelFunction() {
return labelFunction;
}
public void setLabelFunction(String labelFunction) {
this.labelFunction = labelFunction;
}
public String getSeriesDef() {
return seriesDef;
}
public void setSeriesDef(String seriesDef) {
this.seriesDef = seriesDef;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getVerticalAxis() {
return verticalAxis;
}
public void setVerticalAxis(String verticalAxis) {
this.verticalAxis = verticalAxis;
}
public String getVerticalField() {
return verticalField;
}
public void setVerticalField(String verticalField) {
this.verticalField = verticalField;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
protected String buildConfig() {
Object chartValue = getValue();
StringBuilder data = new StringBuilder();
String sep = "";
Set keys = null;
if (chartValue instanceof List) {
List list = (List) chartValue;
if (list.get(0) instanceof Map) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy