@Override public void serialize(CombinedPlot plot, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(plot, jgen); jgen.writeObjectField("type", SerializerUtil.getTypeName(plot)); jgen.writeObjectField("init_width", plot.getInitWidth()); jgen.writeObjectField("init_height", plot.getInitHeight()); jgen.writeObjectField("title", plot.getTitle()); jgen.writeObjectField(X_LABEL, plot.getXLabel()); List<XYChart> subplots = plot.getSubplots(); if (!subplots.isEmpty()) { String plot_type = subplots.get(0).getClass().getSimpleName(); if ("SimpleTimePlot".equals(plot_type)){ jgen.writeObjectField("plot_type", "TimePlot"); }else { jgen.writeObjectField("plot_type", plot_type); } } jgen.writeObjectField("plots", subplots); jgen.writeObjectField("weights", plot.getWeights()); jgen.writeObjectField("version", "groovy"); jgen.writeObjectField("x_tickLabels_visible", plot.isxTickLabelsVisible()); jgen.writeObjectField("y_tickLabels_visible", plot.isyTickLabelsVisible()); jgen.writeObjectField(AUTO_ZOOM, plot.getAutoZoom()); jgen.writeEndObject(); }
public CombinedPlot leftShift(Object obj) { if (obj instanceof XYChart) { this.add((XYChart) obj, 1); } else if (obj instanceof List && ((List) obj).size() == 2) { List list = (List) obj; XYChart plot = (XYChart) list.get(0); int weight = ((Number) list.get(1)).intValue(); this.add(plot, weight); } else { throw new IllegalArgumentException( "leftShift takes XYChart or List that hold a XYChart and weight"); } return this; }
public void setXTickLabelsVisible(boolean xTickLabelsVisible) { setxTickLabelsVisible(xTickLabelsVisible); }
@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 leftShiftWithListParam_shouldAddPlotToFirstPosition() { Plot plot = new Plot(); //when combinedPlot.add(new Plot(), 1); combinedPlot.leftShift(Arrays.asList(plot, 3)); //then assertThat(combinedPlot.getSubplots().get(1)).isEqualTo(plot); }
@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"); }
@Override protected void updateDetails(GraphicsActionObject info) { CombinedPlotActionObject combinedPlotActionObject = (CombinedPlotActionObject) info; XYChart xyChart = getSubplots().get(combinedPlotActionObject.getSubplotIndex()); xyChart.setDetails(info); }
@Test public void serializeXTickLabelsVisibleOfCombinedPlot_resultJsonHasXTickLabelsVisible() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setxTickLabelsVisible(true); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("x_tickLabels_visible").asBoolean()).isTrue(); }
@Test public void serializeYTickLabelsVisibleOfCombinedPlot_resultJsonHasYTickLabelsVisible() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setyTickLabelsVisible(true); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("y_tickLabels_visible").asBoolean()).isTrue(); }
@Before public void setUp() throws Exception { kernel = new KernelTest(); KernelManager.register(kernel); combinedPlot = new CombinedPlot(); combinedPlot.display(); }
@Test public void serializeCombinedPlot_resultJsonHasType() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("CombinedPlot"); }
public void setYTickLabelsVisible(boolean yTickLabelsVisible) { setyTickLabelsVisible(yTickLabelsVisible); }
@Test public void serializeInitWidthOfCombinedPlot_resultJsonHasInitWidth() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setInitWidth(600); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("init_width")).isTrue(); Assertions.assertThat(actualObj.get("init_width").asInt()).isEqualTo(600); }
@Test public void serializeInitHeightOfCombinedPlot_resultJsonHasInitHeight() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setInitHeight(300); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("init_height")).isTrue(); Assertions.assertThat(actualObj.get("init_height").asInt()).isEqualTo(300); }
@Test public void serializeXLabelNameOfCombinedPlot_resultJsonHasXLabelName() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setXLabel("X label name"); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_label")).isTrue(); Assertions.assertThat(actualObj.get("x_label").asText()).isEqualTo("X label name"); }
@Test public void serializeTitleOfCombinedPlot_resultJsonHasTitle() throws IOException { //when CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setTitle("Some title"); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("title")).isTrue(); Assertions.assertThat(actualObj.get("title").asText()).isEqualTo("Some title"); }
@Test public void addTwoPlotsToCombinedPlot_hasSubplotsSizeIsTwoAndWeightListSizeIsTwo() { //when combinedPlot.add(new Plot()); combinedPlot.add(new Plot()); //then assertThat(combinedPlot.getSubplots().size()).isEqualTo(2); assertThat(combinedPlot.getWeights().size()).isEqualTo(2); }
@Test public void leftShiftWithPlot_shouldAddPlotToFirstPosition() { Plot plot = new Plot(); //when combinedPlot.add(new Plot(), 1); combinedPlot.leftShift(plot); //then assertThat(combinedPlot.getSubplots().get(1)).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(); }
/** * Taken from code{@code com.twosigma.beaker.groovy.rest.ChartRest#getGraphics} * * @param info GraphicsActionObject * @param chart ChartDetails * @return list of Graphics for given plot data */ protected List<? extends Graphics> getGraphics(GraphicsActionObject info, ChartDetails chart) { List<? extends Graphics> graphics = null; if (chart instanceof XYChart) { graphics = ((XYChart) chart).getGraphics(); } else if (chart instanceof CategoryPlot) { graphics = ((CategoryPlot) chart).getGraphics(); } else if (chart instanceof CombinedPlot) { XYChart subplot = ((CombinedPlot) chart).getSubplots().get(((CombinedPlotActionObject) info).getSubplotIndex()); graphics = subplot.getGraphics(); } return graphics; }