public DatasetMap calculateValue() throws Exception {
logger.debug("IN");
String res=DataSetAccessFunctions.getDataSetResultFromId(profile, getData(),parametersObject);
DefaultXYZDataset dataset = new DefaultXYZDataset();
SourceBean sbRows=SourceBean.fromXMLString(res);
List listAtts=sbRows.getAttributeAsList("ROW");
series=new Vector();
serie_values=new LinkedHashMap();
serie_selected=new LinkedHashMap();
boolean firstX=true;
boolean firstY=true;
boolean firstZ=true;
double xTempMax=0.0;
double xTempMin=0.0;
double yTempMax=0.0;
double yTempMin=0.0;
boolean first=true;
// In list atts there are all the series, let's run each
int i=0;
for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
SourceBean row = (SourceBean) iterator.next();
List attsRow=row.getContainedAttributes();
String serieName="";
/*if(first){
if (name.indexOf("$F{") >= 0){
setTitleParameter(atts);
}
first=false;
}*/
String name="";
String value="";
String tmpSerieName = "";
//run all the attributes of the serie
for (Iterator iterator2 = attsRow.iterator(); iterator2.hasNext();) { // run attributes, serieName, x, y, z
SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();
name=new String(object.getKey());
value=new String((String)object.getValue());
boolean newSerie=true;
if(name.equalsIgnoreCase("serie_name"))
{
serieName=value;
logger.debug("New Serie: "+serieName);
tmpSerieName = serieName;
if(!(serie_values.keySet().contains(serieName))) // new serie create the arrays
{
i=0;
newSerie=true;
SerieCluster serieCluster=new SerieCluster(serieName, new double[listAtts.size()], new double[listAtts.size()], new double[listAtts.size()]);
serie_values.put(serieName, serieCluster);
}
else // serie already present
{ newSerie=false;
i++;
}
}
else if (name.equalsIgnoreCase("x") || name.equalsIgnoreCase("y") || name.equalsIgnoreCase("z")){
// after the name of serie here are values
SerieCluster serieCluster=(SerieCluster)serie_values.get(serieName);
if(serieCluster == null){
logger.error("Order of dataset not correct");
return null;
}
double valueD=0.0;
try{
Integer intero=Integer.valueOf(value);
valueD=intero.doubleValue();
}
catch (NumberFormatException e) {
valueD=(Double.valueOf(value)).doubleValue();
if(name.equalsIgnoreCase("x")){
decimalXValues=true;
}
else if(name.equalsIgnoreCase("y")){
decimalYValues=true;
}
}
if(name.equalsIgnoreCase("x")){
double[] xArr=serieCluster.getX();
xArr[i]=valueD;
if(firstX){
xTempMin=valueD;
xTempMax=valueD;
firstX=false;
}
if(valueD<xTempMin)xTempMin=valueD;
if(valueD>xTempMax)xTempMax=valueD;
serieCluster.setX(xArr);
}
else
if(name.equalsIgnoreCase("y")){
double[] yArr=serieCluster.getY();
yArr[i]=valueD;
if(firstY){
yTempMin=valueD;
yTempMax=valueD;
firstY=false;
}
if(valueD<yTempMin)yTempMin=valueD;
if(valueD>yTempMax)yTempMax=valueD;
serieCluster.setY(yArr);
}
else
if(name.equalsIgnoreCase("z")){
double[] zArr=serieCluster.getZ();
zArr[i]=valueD;
if(firstZ){
zMax=valueD;
firstZ=false;
}
if(zMax<valueD)zMax=valueD;
serieCluster.setZ(zArr);
}
}
else if (name.equalsIgnoreCase(colSel)){
//defines map with selection series informations
String tmpName = tmpSerieName.replaceAll(" ", "");
tmpName = tmpName.replace('.', ' ').trim();
if(!(serie_selected.keySet().contains(tmpName)) && !tmpName.equals(""))
serie_selected.put(tmpName, value);
}
}
}
//xMin=xTempMin-zMax;
//xMax=xTempMax+zMax;
xMin=xTempMin-1.0;
xMax=xTempMax+1.0;
yMin=yTempMin;
yMax=yTempMax;
double xOrder=calculateOrder(xMax)*10;
// I have all the map full, create the Dataset
for (Iterator iterator = serie_values.keySet().iterator(); iterator.hasNext();) {
String serieName = (String) iterator.next();
SerieCluster serieCluster=(SerieCluster)serie_values.get(serieName);
double[] xArr=serieCluster.getX();
double[] yArr=serieCluster.getY();
double[] zArr=serieCluster.getZ();
// normalizing all z
for (int j = 0; j < zArr.length; j++) {
zArr[j]=(zArr[j]/zMax);
if(xOrder>0) zArr[j]=zArr[j]*xOrder;
}
double[][] seriesT = new double[][] { yArr, xArr, zArr };
//double[][] seriesT = new double[][] { xArr, yArr, zArr };
dataset.addSeries(serieName, seriesT);
series.add(serieName);
}