Search in sources :

Example 1 with TableDisplay

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

the class ScalaListOfPrimitiveTypeMapsSerializer method writeObject.

@Override
public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException {
    logger.debug("list of maps");
    // convert this 'on the fly' to a datatable
    Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj);
    List<Map<String, Object>> tab = new ArrayList<Map<String, Object>>();
    for (Object o : col) {
        Map<String, Object> row = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<String, Object>) o);
        tab.add(row);
    }
    TableDisplay t = new TableDisplay(tab, parent);
    jgen.writeObject(t);
    return true;
}
Also used : TableDisplay(com.twosigma.beakerx.table.TableDisplay) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with TableDisplay

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

the class SQLEvaluatorTest method verifyResult.

private void verifyResult(TryResult seo) {
    assertThat(seo.result() instanceof TableDisplay).isTrue();
    TableDisplay result = (TableDisplay) seo.result();
    assertThat(result.getValues().size()).isEqualTo(3);
}
Also used : TableDisplay(com.twosigma.beakerx.table.TableDisplay)

Example 3 with TableDisplay

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

the class MIMEContainerFactory method createMIMEContainersFromObject.

private static List<MIMEContainer> createMIMEContainersFromObject(final Object data) {
    Object input = DisplayerDataMapper.convert(data);
    if (input instanceof DisplayableWidget) {
        ((DisplayableWidget) input).display();
        return HIDDEN_MIME;
    }
    TableDisplay table = getTableDisplay(input);
    if (table != null) {
        table.display();
        return HIDDEN_MIME;
    }
    if (input instanceof Collection) {
        return singletonList(MIMEContainer.Text(collectionToString((Collection<?>) input)));
    }
    if (input instanceof XYGraphics) {
        new Plot().add((XYGraphics) input).display();
        return HIDDEN_MIME;
    }
    if (input instanceof MIMEContainer) {
        return singletonList((MIMEContainer) input);
    }
    return Displayers.display(input).entrySet().stream().map(item -> new MIMEContainer(item.getKey(), item.getValue())).collect(Collectors.toList());
}
Also used : Displayers(jupyter.Displayers) Plot(com.twosigma.beakerx.chart.xychart.Plot) Iterator(java.util.Iterator) Text(com.twosigma.beakerx.mimetype.MIMEContainer.Text) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Collection(java.util.Collection) MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) HIDDEN(com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN) Collectors(java.util.stream.Collectors) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) Map(java.util.Map) Kernel(com.twosigma.beakerx.kernel.Kernel) DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Plot(com.twosigma.beakerx.chart.xychart.Plot) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) Collection(java.util.Collection)

Example 4 with TableDisplay

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

the class MIMEContainerFactory method getTableDisplay.

public static TableDisplay getTableDisplay(final Object input) {
    TableDisplay ret = null;
    if (input instanceof Map) {
        Map map = (Map) input;
        ret = new TableDisplay(map);
    } else if (input instanceof Collection) {
        Collection items = (Collection) input;
        if (!items.isEmpty()) {
            Object item = items.iterator().next();
            if (item instanceof Map) {
                if (((Map) item).keySet().stream().allMatch(o -> o instanceof String)) {
                    ret = new TableDisplay(items);
                }
            }
        }
    } else if (input instanceof Map[]) {
        Map[] items = (Map[]) input;
        if (items.length > 0) {
            ret = new TableDisplay(items);
        }
    }
    return ret;
}
Also used : Displayers(jupyter.Displayers) Plot(com.twosigma.beakerx.chart.xychart.Plot) Iterator(java.util.Iterator) Text(com.twosigma.beakerx.mimetype.MIMEContainer.Text) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Collection(java.util.Collection) MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) HIDDEN(com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN) Collectors(java.util.stream.Collectors) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) Map(java.util.Map) Kernel(com.twosigma.beakerx.kernel.Kernel) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Collection(java.util.Collection) Map(java.util.Map)

Example 5 with TableDisplay

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

the class TableDisplaySerializerTest method setUp.

@Before
public void setUp() throws Exception {
    KernelManager.register(new KernelTest());
    tableDisplay = new TableDisplay(ObservableTableDisplayTest.getListOfMapsData());
}
Also used : KernelTest(com.twosigma.beakerx.KernelTest) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Before(org.junit.Before)

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