Search in sources :

Example 11 with Plot

use of com.twosigma.beakerx.chart.xychart.Plot in project beakerx by twosigma.

the class GroovyEvaluatorChartTest method parseKeyboardCodesScript_returnLineObjectWithKeyTags.

@Test
public void parseKeyboardCodesScript_returnLineObjectWithKeyTags() {
    // when
    Object result = parseClassFromScript("line = new Line(y: (0..10))\n" + "line.onKey(KeyboardCodes.F1, \"tag1\")\n" + "new Plot() << line   ");
    // then
    Assertions.assertThat(result instanceof Plot).isTrue();
    Plot plot = (Plot) result;
    Assertions.assertThat(plot.getGraphics().get(0).getKeyTags()).isNotEmpty();
}
Also used : TimePlot(com.twosigma.beakerx.chart.xychart.TimePlot) SimpleTimePlot(com.twosigma.beakerx.chart.xychart.SimpleTimePlot) CombinedPlot(com.twosigma.beakerx.chart.xychart.CombinedPlot) Plot(com.twosigma.beakerx.chart.xychart.Plot) CategoryPlot(com.twosigma.beakerx.chart.categoryplot.CategoryPlot) NanoPlot(com.twosigma.beakerx.chart.xychart.NanoPlot) Test(org.junit.Test)

Example 12 with Plot

use of com.twosigma.beakerx.chart.xychart.Plot in project beakerx by twosigma.

the class JavaEvaluatorTest method evaluatePlot_shouldCreatePlotObject.

@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
    // given
    String code = "import com.twosigma.beakerx.chart.xychart.*;\n" + "Plot plot = new Plot(); plot.setTitle(\"test title\");\n" + "return plot;";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result() instanceof Plot).isTrue();
    assertThat(((Plot) evaluate.result()).getTitle()).isEqualTo("test title");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) Plot(com.twosigma.beakerx.chart.xychart.Plot) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 13 with Plot

use of com.twosigma.beakerx.chart.xychart.Plot in project beakerx by twosigma.

the class XYChartSerializerTest method initTestStubData.

@Before
public void initTestStubData() throws IOException {
    KernelManager.register(new KernelTest());
    sw = new StringWriter();
    jgen = mapper.getJsonFactory().createJsonGenerator(sw);
    plot = new Plot();
}
Also used : StringWriter(java.io.StringWriter) KernelTest(com.twosigma.beakerx.KernelTest) Plot(com.twosigma.beakerx.chart.xychart.Plot) Before(org.junit.Before)

Example 14 with Plot

use of com.twosigma.beakerx.chart.xychart.Plot in project beakerx by twosigma.

the class TabbedOutputContainerLayoutManagerTest method shouldSendChildModel.

@Test
public void shouldSendChildModel() throws Exception {
    // given
    TabbedOutputContainerLayoutManager layout = new TabbedOutputContainerLayoutManager();
    OutputContainer outputContainer = new OutputContainer();
    outputContainer.setLayoutManager(layout);
    outputContainer.addItem(new Plot(), "1990/01");
    // when
    outputContainer.display();
    // then
    Map model = getValueForProperty(plotUpdateMsg(), MODEL, Map.class);
    assertTrue("Child model should be sent.", model != null);
}
Also used : Plot(com.twosigma.beakerx.chart.xychart.Plot) Map(java.util.Map) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 15 with Plot

use of com.twosigma.beakerx.chart.xychart.Plot 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

Plot (com.twosigma.beakerx.chart.xychart.Plot)29 Test (org.junit.Test)27 CombinedPlot (com.twosigma.beakerx.chart.xychart.CombinedPlot)23 SimpleTimePlot (com.twosigma.beakerx.chart.xychart.SimpleTimePlot)22 CategoryPlot (com.twosigma.beakerx.chart.categoryplot.CategoryPlot)20 NanoPlot (com.twosigma.beakerx.chart.xychart.NanoPlot)19 TimePlot (com.twosigma.beakerx.chart.xychart.TimePlot)19 KernelTest (com.twosigma.beakerx.KernelTest)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)3 TryResult (com.twosigma.beakerx.TryResult)2 Points (com.twosigma.beakerx.chart.xychart.plotitem.Points)2 Stems (com.twosigma.beakerx.chart.xychart.plotitem.Stems)2 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)2 Map (java.util.Map)2 Chart (com.twosigma.beakerx.chart.Chart)1 CategoryBars (com.twosigma.beakerx.chart.categoryplot.plotitem.CategoryBars)1 Area (com.twosigma.beakerx.chart.xychart.plotitem.Area)1 Bars (com.twosigma.beakerx.chart.xychart.plotitem.Bars)1 Line (com.twosigma.beakerx.chart.xychart.plotitem.Line)1