Search in sources :

Example 1 with DisplayableWidget

use of com.twosigma.beakerx.widget.DisplayableWidget in project beakerx by twosigma.

the class ScalaEvaluatorTest method displayTable.

@Test
public void displayTable() throws Exception {
    // given
    String code = "val table = new TableDisplay(new CSV().readFile(\"src/test/resources/tableRowsTest.csv\"))\n" + "table";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = scalaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result() instanceof DisplayableWidget).isTrue();
}
Also used : DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 2 with DisplayableWidget

use of com.twosigma.beakerx.widget.DisplayableWidget 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)

Aggregations

DisplayableWidget (com.twosigma.beakerx.widget.DisplayableWidget)2 TryResult (com.twosigma.beakerx.TryResult)1 Plot (com.twosigma.beakerx.chart.xychart.Plot)1 XYGraphics (com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)1 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)1 Kernel (com.twosigma.beakerx.kernel.Kernel)1 MIMEContainer (com.twosigma.beakerx.mimetype.MIMEContainer)1 HIDDEN (com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN)1 Text (com.twosigma.beakerx.mimetype.MIMEContainer.Text)1 TableDisplay (com.twosigma.beakerx.table.TableDisplay)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Displayers (jupyter.Displayers)1 Test (org.junit.Test)1