return styleKey;
}
@Override
public void appendToResponse(WOResponse response, WOContext context) {
ERXMutableURL chartUrl = new ERXMutableURL();
chartUrl.setProtocol("http");
chartUrl.setHost("chart.apis.google.com");
chartUrl.setPath("/chart");
WOComponent component = context.component();
int width = 300;
int height = 200;
if (_size != null) {
String sizeStr = (String) _size.valueInComponent(component);
if (sizeStr != null) {
String[] sizeStrs = sizeStr.split("x");
width = Integer.parseInt(sizeStrs[0]);
height = Integer.parseInt(sizeStrs[1]);
}
}
else {
if (_width != null) {
width = ERXValueUtilities.intValueWithDefault(_width.valueInComponent(component), width);
}
if (_height != null) {
height = ERXValueUtilities.intValueWithDefault(_height.valueInComponent(component), height);
}
}
chartUrl.setQueryParameter("chs", width + "x" + height);
NSArray<String> colors = AjaxUtils.arrayValueForAssociation(component, _colors);
if (colors != null) {
chartUrl.setQueryParameter("chco", colors.componentsJoinedByString(","));
}
List<List<Number>> data = null;
if (_data != null) {
Object dataValue = _data.valueInComponent(component);
if (dataValue instanceof String && ((String) dataValue).length() >= 2 && ((String) dataValue).charAt(1) == ':') {
chartUrl.setQueryParameter("chd", (String) dataValue);
}
else {
data = GCEncoding.convertToNumberLists(AjaxUtils.arrayValueForAssociation(component, _data));
chartUrl.setQueryParameter("chd", encode(data, response, context));
}
}
Object scaling = scaling(response, context);
if (scaling instanceof Boolean && ((Boolean) scaling).booleanValue()) {
if (data != null) {
NSMutableArray<String> scaleNumbers = new NSMutableArray<String>();
for (List<Number> innerList : data) {
Float minValue = Float.valueOf(GCEncoding.minValueInList(innerList));
scaleNumbers.addObject(String.format("%1$.1f", minValue));
Number maxValue = maxValue(response, context);
if (maxValue == null) {
maxValue = Float.valueOf(GCEncoding.minValueInList(innerList));
}
scaleNumbers.addObject(String.format("%1$.1f", maxValue));
}
chartUrl.setQueryParameter("chds", scaleNumbers.componentsJoinedByString(","));
}
}
else {
chartUrl.setQueryParameter("chds", (String) scaling);
}
if (_title != null) {
String title = (String) _title.valueInComponent(component);
if (title != null) {
chartUrl.setQueryParameter("chtt", title);
}
}
if (_titleColor != null || _titleSize != null) {
String titleColor = "454545";
if (_titleColor != null) {
titleColor = (String) _titleColor.valueInComponent(component);
}
if (_titleSize != null) {
Object titleSize = _titleSize.valueInComponent(component);
chartUrl.setQueryParameter("chts", titleColor + "," + titleSize);
}
else {
chartUrl.setQueryParameter("chts", titleColor);
}
}
if (_lineStyles != null) {
chartUrl.setQueryParameter("chls", (String) _lineStyles.valueInComponent(component));
}
if (_fillArea != null) {
chartUrl.setQueryParameter("chm", (String) _fillArea.valueInComponent(component));
}
if (_rangeMarkers != null) {
chartUrl.setQueryParameter("chm", (String) _rangeMarkers.valueInComponent(component));
}
if (_shapeMarkers != null) {
chartUrl.setQueryParameter("chm", (String) _shapeMarkers.valueInComponent(component));
}
if (_gridLines != null) {
chartUrl.setQueryParameter("chg", (String) _gridLines.valueInComponent(component));
}
else if (_gridXStep != null || _gridYStep != null || _gridLineSize != null || _gridBlankSize != null) {
StringBuilder chg = new StringBuilder();
if (_gridXStep != null && _gridYStep != null) {
chg.append(_gridXStep.valueInComponent(component));
chg.append(',');
chg.append(_gridYStep.valueInComponent(component));
}
if (_gridLineSize != null || _gridBlankSize != null) {
if (chg.length() == 0) {
chg.append("20,50");
}
if (_gridLineSize != null) {
chg.append(',');
chg.append(_gridLineSize.valueInComponent(component));
}
if (_gridBlankSize != null) {
if (_gridLineSize == null) {
chg.append(",5");
}
chg.append(',');
chg.append(_gridBlankSize.valueInComponent(component));
}
}
chartUrl.setQueryParameter("chg", chg.toString());
}
StringBuilder fill = new StringBuilder();
String backgroundStyle = "solid";
if (_backgroundStyle != null) {
backgroundStyle = (String) _backgroundStyle.valueInComponent(component);
}
if (_background != null) {
fill.append("bg,");
fill.append(styleKey(backgroundStyle));
fill.append(',');
fill.append(_background.valueInComponent(component));
}
String chartBackgroundStyle = "solid";
if (_chartBackgroundStyle != null) {
chartBackgroundStyle = (String) _chartBackgroundStyle.valueInComponent(component);
}
if (_chartBackground != null) {
if (fill.length() > 0) {
fill.append('|');
}
fill.append("c,");
fill.append(styleKey(chartBackgroundStyle));
fill.append(',');
fill.append(_chartBackground.valueInComponent(component));
}
if (_chartBackground != null || _transparency != null) {
if (_transparency != null) {
if (fill.length() > 0) {
fill.append('|');
}
fill.append("a,s,");
fill.append(_transparency.valueInComponent(component));
}
}
if (fill.length() > 0) {
chartUrl.setQueryParameter("chf", fill.toString());
}
NSArray<String> legend = AjaxUtils.arrayValueForAssociation(component, _legend);
if (legend != null) {
chartUrl.setQueryParameter("chdl", legend.componentsJoinedByString("|"));
}
NSArray<String> labeledAxes = AjaxUtils.arrayValueForAssociation(component, _labeledAxes);
if (labeledAxes != null) {
chartUrl.setQueryParameter("chxt", labeledAxes.componentsJoinedByString(","));
}
NSArray<Object> axisLabels = AjaxUtils.arrayValueForAssociation(component, _axisLabels);
if (axisLabels != null) {
StringBuilder axisLabelsStr = new StringBuilder();
for (int i = 0; i < axisLabels.count(); i++) {
Object singleAxisLabels = axisLabels.objectAtIndex(i);
if (i > 0) {
axisLabelsStr.append('|');
}
axisLabelsStr.append(i + ":|");
if (singleAxisLabels instanceof Object[]) {
axisLabelsStr.append(new NSArray<Object>((Object[]) singleAxisLabels).componentsJoinedByString("|"));
}
else {
axisLabelsStr.append(singleAxisLabels);
}
}
chartUrl.setQueryParameter("chxl", axisLabelsStr.toString());
}
if (_custom != null) {
String custom = (String) _custom.valueInComponent(component);
if (custom != null) {
try {
chartUrl.addQueryParameters(custom);
}
catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to add the query parameters '" + custom + "'.", e);
}
}
}
addQueryParameters(chartUrl, response, context);
response.appendContentString("<img");
if (_id != null) {
response._appendTagAttributeAndValue("id", (String) _id.valueInComponent(component), true);
}
if (_class != null) {
response._appendTagAttributeAndValue("class", (String) _class.valueInComponent(component), true);
}
if (_alt != null) {
response._appendTagAttributeAndValue("alt", (String) _alt.valueInComponent(component), true);
}
String chartSrc = WOMessage.stringByEscapingHTMLAttributeValue(chartUrl.toExternalForm());
response._appendTagAttributeAndValue("src", chartSrc, false);
response._appendTagAttributeAndValue("width", String.valueOf(width), false);
response._appendTagAttributeAndValue("height", String.valueOf(height), false);
response.appendContentString("/>");
}