Search in sources :

Example 1 with DoublePoint

use of ubic.basecode.dataStructure.DoublePoint in project Gemma by PavlidisLab.

the class FactorProfile method addValues.

/**
 * Y values are the continuous measures; otherwise we just use zero as the y axis value. The x axis is simply an
 * index.
 *
 * @param values A list of values which indicate how we should draw the plots. Each different value in this list
 *               indicates a new list. For example, 1 1 1 2 2 2 would lead to two sublists, 1 1 1 2 2 2 3 3 3 would lead to
 *               three, etc. 1 1 2 2 1 1 2 2 would lead to four plots.
 */
private void addValues(List<Double> values) {
    this.plots = new ArrayList<>();
    List<DoublePoint> currentList = new ArrayList<>();
    int i = 0;
    Double lastValue = 0.0;
    boolean first = true;
    int nullCount = 0;
    for (Double d : values) {
        if (d == null) {
            nullCount++;
        } else {
            if (this.isContinuous) {
                currentList.add(new DoublePoint(i, d));
                i++;
                continue;
            }
            if (first) {
                currentList.add(new DoublePoint(i, 0));
                first = false;
            } else if (d != lastValue) {
                // save the list we just finished.
                currentList.add(new DoublePoint(i, 0));
                if (currentList.size() > 0) {
                    this.plots.add(currentList);
                }
                // start a new list, don't increment the X axis.
                currentList = new ArrayList<>();
                currentList.add(new DoublePoint(i, 0));
            } else {
                i++;
            }
            lastValue = d;
        }
    }
    if (nullCount > 0) {
        FactorProfile.log.warn(nullCount + " null value(s) not added to plot list of DoublePoints.");
    }
    if (currentList.size() > 0) {
        this.plots.add(currentList);
    }
}
Also used : DoublePoint(ubic.basecode.dataStructure.DoublePoint) ArrayList(java.util.ArrayList) DoublePoint(ubic.basecode.dataStructure.DoublePoint)

Example 2 with DoublePoint

use of ubic.basecode.dataStructure.DoublePoint in project Gemma by PavlidisLab.

the class DoublePointConverter method convertOutbound.

@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    if (!(data instanceof DoublePoint))
        return super.convertOutbound(data, outctx);
    // Where we collect out converted children
    Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>();
    // We need to do this before collecting the children to save recursion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(data, ov);
    try {
        Map<String, Property> properties = getPropertyMapFromObject(data, true, false);
        for (Iterator<Entry<String, Property>> it = properties.entrySet().iterator(); it.hasNext(); ) {
            Entry<String, Property> entry = it.next();
            String name = entry.getKey();
            Property property = entry.getValue();
            Object value = property.getValue(data);
            OutboundVariable nested;
            if (value instanceof Double) {
                // Reduce precision to save bandwidth
                Double v = Double.parseDouble(String.format("%.3f", value));
                nested = getConverterManager().convertOutbound(v, outctx);
            } else {
                nested = getConverterManager().convertOutbound(value, outctx);
            }
            ovs.put(name, nested);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) MarshallException(org.directwebremoting.extend.MarshallException) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) Entry(java.util.Map.Entry) MarshallException(org.directwebremoting.extend.MarshallException) DoublePoint(ubic.basecode.dataStructure.DoublePoint) Property(org.directwebremoting.extend.Property)

Aggregations

DoublePoint (ubic.basecode.dataStructure.DoublePoint)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)1 MarshallException (org.directwebremoting.extend.MarshallException)1 OutboundVariable (org.directwebremoting.extend.OutboundVariable)1 Property (org.directwebremoting.extend.Property)1