@Test public void parsePlotWithTitleScript_returnPlotObjectWithTitle() { //when Object result = parseClassFromScript("def plot = new Plot(title: \"Setting line properties\")"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getTitle()).isEqualTo("Setting line properties"); }
@Test public void addLineAndAreaToPlot_plotHasGraphicsListSizeIsTwo() { //when plot.add(line); plot.add(area); //then assertThat(plot.getGraphics().size()).isEqualTo(2); }
@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 addListOfPlotObjects_hasAllPlotObjects() { //given Rasters rasters = new Rasters(); List<Number> value = Collections.singletonList(1); rasters.setY(value); rasters.setWidth(value); rasters.setHeight(value); //when plot.add(Arrays.asList( line, new ConstantLine(), new ConstantBand(), rasters, new Text() )); //then assertThat(plot.getGraphics().size()).isEqualTo(1); assertThat(plot.getConstantLines().size()).isEqualTo(1); assertThat(plot.getConstantBands().size()).isEqualTo(1); assertThat(plot.getRasters().size()).isEqualTo(1); assertThat(plot.getTexts().size()).isEqualTo(1); }
@Test public void parsePlotWithBarsScript_returnPlotObjectWithBars() { //when Object result = parseClassFromScript( "def plot = new Plot()\n" + "plot << new Bars(x: (1..5), y: [3, 5, 2, 3, 7])"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getGraphics()).isNotEmpty(); Assertions.assertThat(plot.getGraphics().get(0) instanceof Bars).isTrue(); }
@Test public void createPlotByEmptyConstructor_plotHasGraphicsListIsEmpty() { //when Plot plot = new Plot(); //then assertThat(plot.getGraphics().size()).isEqualTo(0); }
@Test public void serializeConstantLinesOfXYChartPlot_resultJsonHasConstantLines() throws IOException { //given ConstantLine constantLine = new ConstantLine(); plot.add(constantLine); //when xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("constant_lines")).isTrue(); Assertions.assertThat(actualObj.get("constant_lines")).isNotEmpty(); }
@Test public void leftShiftForRasters_plotHasRastersListSizeIsOne() { //given Rasters raster = new Rasters(); List<Number> value = Collections.singletonList(1); raster.setY(value); raster.setWidth(value); raster.setHeight(value); //when plot.add(raster); //then assertThat(plot.getRasters().size()).isEqualTo(1); }
@Test public void parsePlotWithConstantBandScript_returnPlotObjectWithConstantBand() { //when Object result = parseClassFromScript("def plot = new Plot()\n" + "plot << new ConstantBand(x: [1, 2])"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getConstantBands()).isNotEmpty(); Assertions.assertThat(plot.getConstantBands().get(0)).isNotNull(); }
@Test public void parsePlotWithConstantLineScript_returnPlotObjectWithConstantLine() { //when Object result = parseClassFromScript("def plot = new Plot ()\n" + "plot << new ConstantLine(x: 0.65)"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getConstantLines()).isNotEmpty(); Assertions.assertThat(plot.getConstantLines().get(0)).isNotNull(); }
@Test public void parsePlotWithTextScript_returnPlotObjectWithText() { //when Object result = parseClassFromScript("def plot = new Plot ()\n" + "plot << new Text(text: \"labelText \")"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getTexts()).isNotEmpty(); Assertions.assertThat(plot.getTexts().get(0)).isNotNull(); }
@Test public void parsePlotWithCrosshairScript_returnPlotObjectWithCrosshair() { //when Object result = parseClassFromScript("def plot = new Plot(crosshair: new Crosshair(color: Color.BLUE))"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getCrosshair()).isNotNull(); }
@Test public void parsePlotWithLineScript_returnPlotObjectWithLine() { //when Object result = parseClassFromScript( "def plot = new Plot()\n" + "def ys = [0, 1, 6, 5, 2, 8]\n" + "plot << new Line(y: ys)"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getGraphics()).isNotEmpty(); Assertions.assertThat(plot.getGraphics().get(0) instanceof Line).isTrue(); }
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 serializeTextsOfXYChartPlot_resultJsonHasTexts() throws IOException { //given plot.add(new Text()); //when xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("texts")).isTrue(); Assertions.assertThat(actualObj.get("texts")).isNotEmpty(); }
@Test public void addLineToPlot_plotHasGraphicsListSizeIsOne() { //when plot.add(line); //then assertThat(plot.getGraphics().size()).isEqualTo(1); }
@Test public void parsePlotWithPointsScript_returnPlotObjectWithPoints() { //when Object result = parseClassFromScript( "def plot = new Plot();\n" + "def y1 = [6, 7, 12, 11, 8, 14]\n" + "plot << new Points(y: y1)"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getGraphics()).isNotEmpty(); Assertions.assertThat(plot.getGraphics().get(0) instanceof Points).isTrue(); }