Adds Figure.setLayout and Figure.setConfig
* Allows Layout argument to Vertical- and HorizontalBarPlot
* Revert "Allows Layout argument to Vertical- and HorizontalBarPlot"
This reverts commit
* Adds Figure.setLayout
* Adds Figure.getConfig and .setConfig
* Makes Figure more extendable
* Allows varargs in setTraces / setEventHandlers
@@ -26,10 +26,10 @@ import tech.tablesaw.plotly.traces.Trace;
*/
public class Figure {
- private final Trace[] data;
- private final Layout layout;
- private final Config config;
- private final EventHandler[] eventHandlers;
+ private Trace[] data;
+ private Layout layout;
+ private Config config;
+ private EventHandler[] eventHandlers;
private final Map<String, Object> context = new HashMap<>();
@@ -80,6 +80,34 @@ public class Figure {
return layout;
}
+ public void setLayout(Layout layout) {
+ this.layout = layout;
+ }
+
+ public Config getConfig() {
+ return config;
+ }
+
+ public void setConfig(Config config) {
+ this.config = config;
+ }
+
+ public EventHandler[] getEventHandlers() {
+ return eventHandlers;
+ }
+
+ public void setEventHandlers(EventHandler... handlers) {
+ eventHandlers = handlers;
+ }
+
+ public Trace[] getTraces() {
+ return data;
+ }
+
+ public void setTraces(Trace... data) {
+ this.data = data;
+ }
+
public String asJavascript(String divName) {
Writer writer = new StringWriter();
PebbleTemplate compiledTemplate;
@@ -97,7 +125,7 @@ public class Figure {
return writer.toString();
}
- private void buildContext(String divName) {
+ protected void buildContext(String divName) {
String targetName = "target_" + divName;
context.put("divName", divName);
@@ -124,7 +152,7 @@ public class Figure {
context.put("eventHandlerFunction", eventHandlerFunction(targetName, divName));
}
- private String plotFunction(String divName) {
+ protected String plotFunction(String divName) {
StringBuilder builder = new StringBuilder();
builder.append("var data = [ ");
@@ -152,7 +180,7 @@ public class Figure {
return builder.toString();
}
- private String eventHandlerFunction(String targetName, String divName) {
+ protected String eventHandlerFunction(String targetName, String divName) {
StringBuilder builder = new StringBuilder();
if (eventHandlers != null) {
