Figure { public String asJavascript(String divName) { Writer writer = new StringWriter(); PebbleTemplate compiledTemplate; buildContext(divName); try { compiledTemplate = engine.getTemplate("figure_template.html"); compiledTemplate.evaluate(writer, getContext()); } catch (PebbleException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new UncheckedIOException(e); } return writer.toString(); } Figure(FigureBuilder builder);  Figure(Trace... traces);  Figure(Layout layout, Trace... traces);  Figure(Layout layout, Config config, Trace... traces); @Deprecated  Figure(Layout layout, EventHandler eventHandler, Trace... traces); @Deprecated  Figure(Layout layout, EventHandler[] eventHandlers, Trace... traces); String divString(String divName); Layout getLayout(); void setLayout(Layout layout); Config getConfig(); void setConfig(Config config); EventHandler[] getEventHandlers(); void setEventHandlers(EventHandler... handlers); Trace[] getTraces(); void setTraces(Trace... data); String asJavascript(String divName); Map<String, Object> getContext(); static FigureBuilder builder();  }
@Test void asJavascript() { Trace trace = ScatterTrace.builder(x, y).build(); Figure figure = new Figure(trace); assertEquals( " <script>\n" + " var target_target = document.getElementById('target');\n" + " \n" + "var trace0 =\n" + "{\n" + "x: [\"1.0\",\"2.0\",\"3.0\",\"4.0\",\"5.0\"],\n" + "y: [\"1.0\",\"4.0\",\"9.0\",\"16.0\",\"25.0\"],\n" + "mode: 'markers',\n" + "xaxis: 'x',\n" + "yaxis: 'y',\n" + "type: 'scatter',\n" + "name: '',\n" + "};\n" + "\n" + " var data = [ trace0];\n" + "Plotly.newPlot(target_target, data); </script>\n", figure.asJavascript(divName)); }