use of org.xwiki.chart.axis.AxisType in project xwiki-platform by xwiki.
the class AxisConfigurator method setAxes.
/**
* Set the axes in the chart model.
*
* @param plotType The target plot type.
* @param chartModel The target chart model.
* @throws MacroExecutionException if the axes are incorrectly configured.
*/
public void setAxes(PlotType plotType, SimpleChartModel chartModel) throws MacroExecutionException {
AxisType[] defaultAxisTypes = plotType.getDefaultAxisTypes();
for (int i = 0; i < axisTypes.length; i++) {
AxisType type = axisTypes[i];
if (i >= defaultAxisTypes.length) {
if (type != null) {
throw new MacroExecutionException("To many axes for plot type.");
}
continue;
}
if (type == null) {
type = defaultAxisTypes[i];
}
Axis axis;
switch(type) {
case NUMBER:
NumberAxis numberAxis = new NumberAxis();
axis = numberAxis;
setNumberLimits(numberAxis, i);
break;
case CATEGORY:
axis = new CategoryAxis();
break;
case DATE:
DateAxis dateAxis = new DateAxis();
axis = dateAxis;
dateAxis.setTickMarkPosition(DateTickMarkPosition.END);
if (axisDateFormat[i] != null) {
try {
DateFormat dateFormat = new SimpleDateFormat(axisDateFormat[i], localeConfiguration.getLocale());
dateAxis.setDateFormatOverride(dateFormat);
} catch (IllegalArgumentException e) {
throw new MacroExecutionException(String.format("Invalid date format [%s].", axisDateFormat[i]));
}
}
setDateLimits(dateAxis, i);
break;
default:
throw new MacroExecutionException(String.format("Unsupported axis type [%s]", type.getName()));
}
chartModel.setAxis(i, axis);
}
}
use of org.xwiki.chart.axis.AxisType in project xwiki-platform by xwiki.
the class AxisConfigurator method setParameter.
@Override
public boolean setParameter(String key, String value) throws MacroExecutionException {
boolean claimed = true;
if (DOMAIN_AXIS_PARAM.equals(key)) {
AxisType type = AxisType.forName(value);
if (type == null) {
invalidParameterValue(DOMAIN_AXIS_PARAM, value);
}
setAxisType(0, type);
} else if (DOMAIN_AXIS_DATE_FORMAT_PARAM.equals(key)) {
setAxisDateFormat(0, value);
} else if (RANGE_AXIS_PARAM.equals(key)) {
AxisType type = AxisType.forName(value);
if (type == null) {
invalidParameterValue(RANGE_AXIS_PARAM, value);
}
setAxisType(1, type);
} else if (RANGE_AXIS_DATE_FORMAT_PARAM.equals(key)) {
setAxisDateFormat(0, value);
} else if (!claimLimitParameters(key, value)) {
claimed = false;
}
return claimed;
}
Aggregations