@Override public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws IOException { if (super.writeObject(obj, jgen, expand)) { return true; } else if (expand && obj instanceof XYChart) { jgen.writeObject((XYChart) obj); } else if (expand && obj instanceof XYGraphics) { jgen.writeObject(new Plot().add((XYGraphics) obj)); } else if (expand && obj instanceof CategoryPlot) { jgen.writeObject((CategoryPlot) obj); } else if (expand && obj instanceof CategoryGraphics) { jgen.writeObject(new CategoryPlot().add((CategoryGraphics) obj)); } else if (expand && obj instanceof Histogram) { jgen.writeObject((Histogram) obj); } else if (expand && obj instanceof TreeMap) { jgen.writeObject((TreeMap) obj); } else if (expand && obj instanceof TreeMapNode) { jgen.writeObject((TreeMapNode) obj); } else if (expand && obj instanceof CombinedPlot) { jgen.writeObject((CombinedPlot) obj); }else if (expand && obj instanceof HeatMap) { jgen.writeObject((HeatMap) obj); } else { return false; } return true; } }
@Test public void serializeXYChart_returnTrue() throws Exception { //when boolean result = plotObjectSerializer.writeObject(new Plot(), jgen, true); //then Assertions.assertThat(result).isTrue(); }
@Test public void createPlotByEmptyConstructor_plotHasGraphicsListIsEmpty() { //when Plot plot = new Plot(); //then assertThat(plot.getGraphics().size()).isEqualTo(0); }
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()); }
@Test public void addTwoPlotsAndWeightsToCombinedPlot_hasSubplotsSizeIsTwoAndWeightListSizeIsTwo() { //when combinedPlot.add(new Plot(), 3); combinedPlot.add(new Plot(), 3); //then assertThat(combinedPlot.getSubplots().size()).isEqualTo(2); assertThat(combinedPlot.getWeights().size()).isEqualTo(2); }
@Test public void serializePlotTypeOfCombinedPlot_resultJsonHasPlotType() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot()); combinedPlot.add(new Plot()); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("plot_type")).isTrue(); Assertions.assertThat(actualObj.get("plot_type").asText()).isEqualTo("Plot"); }
@Test public void serializeWeightsOfCombinedPlot_resultJsonHasWeights() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot(), 3); combinedPlot.add(new Plot(), 3); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("weights")).isTrue(); Assertions.assertThat(actualObj.get("weights")).isNotEmpty(); }
@Override public Plot createWidget() { Plot plot = new Plot(); plot.display(); kernel.clearMessages(); return plot; } }
@Test public void serializePlotsOfCombinedPlot_resultJsonHasPlots() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot()); combinedPlot.add(new Plot()); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("plots")).isTrue(); Assertions.assertThat(actualObj.get("plots")).isNotEmpty(); }
@Test public void registerChart_containsThatChart() { Chart chart = new Plot(); //when chartObjectManager.registerChart("id1", chart); //then Assertions.assertThat(chartObjectManager.getChart("id1")).isEqualTo(chart); }
@Test public void dispaly_activateChildren() throws Exception { //given GridOutputContainerLayoutManager manager = new GridOutputContainerLayoutManager(2); OutputContainer container = new OutputContainer(asList(new Plot())); container.setLayoutManager(manager); //when manager.display(container); //then verifyChildren(kernel); }
@Before public void initStubData() { plot = new Plot(); line = new Line(); line.setX(Arrays.asList(1, 2, 3)); line.setY(Arrays.asList(2, 3, 4)); area = new Area(); area.setX(Arrays.asList(1, 2, 3)); area.setY(Arrays.asList(2, 3, 4)); }
@Test public void shouldSendCommMsgWhenAddPlotByLeftShift() throws Exception { //given Plot plot = new Plot(); //when combinedPlot.leftShift(plot); //then verifyModel(); }
@Before public void initTestStubData() throws IOException { KernelManager.register(new KernelTest()); sw = new StringWriter(); jgen = mapper.getJsonFactory().createJsonGenerator(sw); plot = new Plot(); }
@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); }