Search in sources :

Example 6 with TableDisplay

use of com.twosigma.beakerx.table.TableDisplay in project beakerx by twosigma.

the class TableDisplayDeSerializer method getDeserializeObject.

public static Pair<String, Object> getDeserializeObject(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) {
    Object o = null;
    String subtype = null;
    try {
        List<List<?>> values = TableDisplayDeSerializer.getValues(parent, n, mapper);
        List<String> columns = TableDisplayDeSerializer.getColumns(n, mapper);
        List<String> classes = TableDisplayDeSerializer.getClasses(n, mapper);
        if (n.has("subtype"))
            subtype = mapper.readValue(n.get("subtype").asText(), String.class);
        if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) {
            o = getValuesAsDictionary(parent, n, mapper);
        } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE) && columns != null && values != null) {
            o = getValuesAsRows(parent, n, mapper);
        } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) {
            o = getValuesAsMatrix(parent, n, mapper);
        }
        if (o == null) {
            if (n.has("hasIndex") && mapper.readValue(n.get("hasIndex").asText(), String.class).equals("true") && columns != null && values != null) {
                columns.remove(0);
                classes.remove(0);
                for (List<?> v : values) {
                    v.remove(0);
                }
                o = new TableDisplay(values, columns, classes);
            } else {
                o = new TableDisplay(values, columns, classes);
            }
        }
    } catch (Exception e) {
        logger.error("exception deserializing TableDisplay ", e);
    }
    return new ImmutablePair<String, Object>(subtype, o);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TableDisplay(com.twosigma.beakerx.table.TableDisplay) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Aggregations

TableDisplay (com.twosigma.beakerx.table.TableDisplay)6 List (java.util.List)3 Map (java.util.Map)3 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 XYGraphics (com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)2 Kernel (com.twosigma.beakerx.kernel.Kernel)2 MIMEContainer (com.twosigma.beakerx.mimetype.MIMEContainer)2 HIDDEN (com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN)2 Text (com.twosigma.beakerx.mimetype.MIMEContainer.Text)2 DisplayableWidget (com.twosigma.beakerx.widget.DisplayableWidget)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections.singletonList (java.util.Collections.singletonList)2 Iterator (java.util.Iterator)2 Collectors (java.util.stream.Collectors)2 Displayers (jupyter.Displayers)2 KernelTest (com.twosigma.beakerx.KernelTest)1 IOException (java.io.IOException)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Before (org.junit.Before)1