diff --git a/pom.xml b/pom.xml index 0142573..f498961 100644 --- a/pom.xml +++ b/pom.xml @@ -285,7 +285,7 @@ io.pebbletemplates pebble - 3.1.2 + 3.2.2 org.junit.jupiter diff --git a/src/main/java/tech/tablesaw/plotly/components/Component.java b/src/main/java/tech/tablesaw/plotly/components/Component.java index 3bf7a3b..bdeeee0 100644 --- a/src/main/java/tech/tablesaw/plotly/components/Component.java +++ b/src/main/java/tech/tablesaw/plotly/components/Component.java @@ -1,19 +1,17 @@ package tech.tablesaw.plotly.components; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.mitchellbosecke.pebble.PebbleEngine; +import static tech.tablesaw.plotly.JsonMapper.JSON_MAPPER; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.pebbletemplates.pebble.PebbleEngine; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.util.Map; -import static tech.tablesaw.plotly.JsonMapper.JSON_MAPPER; - public abstract class Component { - @JsonIgnore - private final PebbleEngine engine = TemplateUtils.getNewEngine(); + @JsonIgnore private final PebbleEngine engine = TemplateUtils.getNewEngine(); protected PebbleEngine getEngine() { return engine; diff --git a/src/main/java/tech/tablesaw/plotly/components/Figure.java b/src/main/java/tech/tablesaw/plotly/components/Figure.java index 649e6e1..e4c2c8d 100644 --- a/src/main/java/tech/tablesaw/plotly/components/Figure.java +++ b/src/main/java/tech/tablesaw/plotly/components/Figure.java @@ -1,9 +1,9 @@ package tech.tablesaw.plotly.components; import com.google.common.base.Preconditions; -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/components/Layout.java b/src/main/java/tech/tablesaw/plotly/components/Layout.java index dae8bcc..c2641a6 100644 --- a/src/main/java/tech/tablesaw/plotly/components/Layout.java +++ b/src/main/java/tech/tablesaw/plotly/components/Layout.java @@ -1,9 +1,9 @@ package tech.tablesaw.plotly.components; import com.fasterxml.jackson.annotation.JsonValue; -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; @@ -315,6 +315,7 @@ public static class LayoutBuilder { /** The global font */ private final Font font = DEFAULT_FONT; + public Geo geo; /** The plot title */ diff --git a/src/main/java/tech/tablesaw/plotly/components/Page.java b/src/main/java/tech/tablesaw/plotly/components/Page.java index da1f69d..2c3e0d8 100644 --- a/src/main/java/tech/tablesaw/plotly/components/Page.java +++ b/src/main/java/tech/tablesaw/plotly/components/Page.java @@ -1,8 +1,7 @@ package tech.tablesaw.plotly.components; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; - +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java b/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java index 7a85336..058e5a1 100644 --- a/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java +++ b/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java @@ -1,11 +1,11 @@ package tech.tablesaw.plotly.components; -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.loader.ClasspathLoader; -import com.mitchellbosecke.pebble.loader.DelegatingLoader; -import com.mitchellbosecke.pebble.loader.FileLoader; -import com.mitchellbosecke.pebble.loader.Loader; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.loader.ClasspathLoader; +import io.pebbletemplates.pebble.loader.DelegatingLoader; +import io.pebbletemplates.pebble.loader.FileLoader; +import io.pebbletemplates.pebble.loader.Loader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java b/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java index 43a53de..d872c4c 100644 --- a/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java +++ b/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java @@ -1,11 +1,5 @@ package tech.tablesaw.plotly.components.threeD; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import java.io.IOException; -import java.io.StringWriter; -import java.io.UncheckedIOException; -import java.io.Writer; import java.util.HashMap; import java.util.Map; import tech.tablesaw.plotly.components.Axis; @@ -50,22 +44,22 @@ public static Scene.SceneBuilder sceneBuilder() { return new Scene.SceneBuilder(); } -/* - @Override - public String asJavascript() { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - try { - compiledTemplate = getEngine().getTemplate("scene_template.html"); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); + /* + @Override + public String asJavascript() { + Writer writer = new StringWriter(); + PebbleTemplate compiledTemplate; + try { + compiledTemplate = getEngine().getTemplate("scene_template.html"); + compiledTemplate.evaluate(writer, getContext()); + } catch (PebbleException e) { + throw new IllegalStateException(e); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return writer.toString(); } - return writer.toString(); - } -*/ + */ public static class SceneBuilder { diff --git a/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java b/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java index 624d0b9..4e22419 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java @@ -1,15 +1,14 @@ package tech.tablesaw.plotly.traces; -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.HashMap; import java.util.Map; - import tech.tablesaw.plotly.components.ColorBar; import tech.tablesaw.plotly.components.HoverLabel; import tech.tablesaw.plotly.components.LegendGroupTitle; @@ -47,24 +46,20 @@ public String toString() { private final Boolean showLegend; /** - * Default = "" - * Sets the legend group for this trace. Traces part of the same legend group hide/show at the - * same time when toggling legend items. + * Default = "" Sets the legend group for this trace. Traces part of the same legend group + * hide/show at the same time when toggling legend items. */ private final String legendGroup; - /** - * Sets the title for the legend group. It includes text, color and font - */ + /** Sets the title for the legend group. It includes text, color and font */ private final LegendGroupTitle legendGroupTitle; /** - * * The default legendrank is 1000 * - * Sets the legend rank for this trace. Items and groups with smaller ranks are presented on top/left side - * while with `"reversed" `legend.traceorder` they are on bottom/right side. - * The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items + *

Sets the legend rank for this trace. Items and groups with smaller ranks are presented on + * top/left side while with `"reversed" `legend.traceorder` they are on bottom/right side. The + * default legendrank is 1000, so that you can use ranks less than 1000 to place certain items * before all unranked items, and ranks greater than 1000 to go after all unranked items. */ private final double legendRank; diff --git a/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java b/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java index d8debbe..46fbc07 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java @@ -3,14 +3,13 @@ import static tech.tablesaw.plotly.Utils.dataAsString; import com.fasterxml.jackson.annotation.JsonValue; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Map; - import tech.tablesaw.plotly.components.Marker; public class BarTrace extends AbstractTrace { diff --git a/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java b/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java index 1b7c82c..4fd394b 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java @@ -2,8 +2,8 @@ import static tech.tablesaw.plotly.Utils.dataAsString; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java b/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java index 9fdfc0d..580d58d 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java @@ -1,28 +1,26 @@ package tech.tablesaw.plotly.traces; +import static tech.tablesaw.plotly.Utils.dataAsString; + import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import tech.tablesaw.plotly.components.*; - +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Map; - -import static tech.tablesaw.plotly.Utils.dataAsString; +import tech.tablesaw.plotly.components.*; /** - * A `contour` trace is an object with the key `"type"` equal to `"contour"` (i.e. `{"type": "contour"}`) - * and any of the keys listed below. + * A `contour` trace is an object with the key `"type"` equal to `"contour"` (i.e. `{"type": + * "contour"}`) and any of the keys listed below. * - * The data from which contour lines are computed is set in `z`. Data in `z` must be a 2D array of numbers. - * Say that `z` has N rows and M columns, then by default, - * these N rows correspond to N y coordinates (set in `y` or auto-generated) - * and the M columns correspond to M x coordinates (set in `x` or auto-generated). - * By setting `transpose` to "true", the above behavior is flipped. + *

The data from which contour lines are computed is set in `z`. Data in `z` must be a 2D array + * of numbers. Say that `z` has N rows and M columns, then by default, these N rows correspond to N + * y coordinates (set in `y` or auto-generated) and the M columns correspond to M x coordinates (set + * in `x` or auto-generated). By setting `transpose` to "true", the above behavior is flipped. */ public class ContourTrace extends AbstractTrace { @@ -53,10 +51,10 @@ public String toString() { /** * subplotid * - * Sets a reference to a shared color axis. - * References to these shared color axes are "coloraxis", "coloraxis2", "coloraxis3", etc. - * Settings for these shared color axes are set in the layout, under `layout.coloraxis`, `layout.coloraxis2`, etc. - * Note that multiple color scales can be linked to the same color axis. + *

Sets a reference to a shared color axis. References to these shared color axes are + * "coloraxis", "coloraxis2", "coloraxis3", etc. Settings for these shared color axes are set in + * the layout, under `layout.coloraxis`, `layout.coloraxis2`, etc. Note that multiple color scales + * can be linked to the same color axis. */ private final String colorAxis; @@ -179,18 +177,18 @@ public ContourBuilder colorScale(Marker.Palette colorScale) { /** * number or categorical coordinate string * - * Controls persistence of some user-driven changes to the trace: `constraintrange` in `parcoords` traces, - * as well as some `editable: true` modifications such as `name` and `colorbar.title`. - * Defaults to `layout.uirevision`. - * Note that other user-driven trace attribute changes are controlled by `layout` attributes: - * `trace.visible` is controlled by `layout.legend.uirevision`, - * `selectedpoints` is controlled by `layout.selectionrevision`, and ` - * colorbar.(x|y)` (accessible with `config: {editable: true}`) is controlled by `layout.editrevision`. + *

Controls persistence of some user-driven changes to the trace: `constraintrange` in + * `parcoords` traces, as well as some `editable: true` modifications such as `name` and + * `colorbar.title`. Defaults to `layout.uirevision`. Note that other user-driven trace + * attribute changes are controlled by `layout` attributes: `trace.visible` is controlled by + * `layout.legend.uirevision`, `selectedpoints` is controlled by `layout.selectionrevision`, and + * ` colorbar.(x|y)` (accessible with `config: {editable: true}`) is controlled by + * `layout.editrevision`. * - * Trace changes are tracked by `uid`, which only falls back on trace index if no `uid` is provided. - * So if your app can add/remove traces before the end of the `data` array, - * such that the same trace has a different index, you can still preserve user-driven changes - * if you give each trace a `uid` that stays with it as it moves. + *

Trace changes are tracked by `uid`, which only falls back on trace index if no `uid` is + * provided. So if your app can add/remove traces before the end of the `data` array, such that + * the same trace has a different index, you can still preserve user-driven changes if you give + * each trace a `uid` that stays with it as it moves. */ public ContourBuilder uiRevision(String uiRevision) { this.uiRevision = uiRevision; @@ -202,27 +200,19 @@ public ContourBuilder colorAxis(String colorAxis) { return this; } - /** - * Sets the calendar system to use with the x data - * default = gregorian - */ + /** Sets the calendar system to use with the x data default = gregorian */ public ContourBuilder xCalendar(Calendar calendar) { this.xCalendar = calendar; return this; } - /** - * Sets the calendar system to use with the y data - * default = gregorian - */ + /** Sets the calendar system to use with the y data default = gregorian */ public ContourBuilder yCalendar(Calendar calendar) { this.yCalendar = calendar; return this; } - /** - * Transposes the z data. - */ + /** Transposes the z data. */ public ContourBuilder transpose(boolean transpose) { this.transpose = transpose; return this; @@ -238,9 +228,9 @@ public ContourBuilder connectGaps(boolean connectGaps) { } /** - * Sets the maximum number of contour levels. - * The actual number of contours will be chosen automatically to be less than or equal to the value of - * `ncontours`. Has an effect only if `autocontour` is "true" or if `contours.size` is missing. + * Sets the maximum number of contour levels. The actual number of contours will be chosen + * automatically to be less than or equal to the value of `ncontours`. Has an effect only if + * `autocontour` is "true" or if `contours.size` is missing. */ public ContourBuilder nContours(int nContours) { Preconditions.checkArgument(nContours > 0); @@ -249,8 +239,7 @@ public ContourBuilder nContours(int nContours) { } /** - * default = true - * Determines whether or not gaps (i.e. {nan} or missing values) in the `z` data + * default = true Determines whether or not gaps (i.e. {nan} or missing values) in the `z` data * have hover labels associated with them. */ public ContourBuilder hoverOnGaps(boolean hoverOnGaps) { @@ -258,7 +247,6 @@ public ContourBuilder hoverOnGaps(boolean hoverOnGaps) { return this; } - @Override public ContourTrace.ContourBuilder xAxis(String xAxis) { super.xAxis(xAxis); @@ -272,12 +260,11 @@ public ContourTrace.ContourBuilder yAxis(String yAxis) { } /** - * default = true - * Sets a reference to a shared color axis. - * References to these shared color axes are "coloraxis", "coloraxis2", "coloraxis3", etc. - * Settings for these shared color axes are set in the layout, under `layout.coloraxis`, `layout.coloraxis2`, etc. - * Note that multiple color scales can be linked to the same color axis. - **/ + * default = true Sets a reference to a shared color axis. References to these shared color axes + * are "coloraxis", "coloraxis2", "coloraxis3", etc. Settings for these shared color axes are + * set in the layout, under `layout.coloraxis`, `layout.coloraxis2`, etc. Note that multiple + * color scales can be linked to the same color axis. + */ public ContourTrace.ContourBuilder autoContour(boolean autoContour) { this.autoContour = autoContour; return this; diff --git a/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java b/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java index 6aea6b7..97928ac 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java @@ -2,8 +2,8 @@ import static tech.tablesaw.plotly.Utils.dataAsString; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java b/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java index 4a1e929..14994e9 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java @@ -1,7 +1,7 @@ package tech.tablesaw.plotly.traces; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java b/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java index 2b6cfe3..f783e3c 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java @@ -1,15 +1,14 @@ package tech.tablesaw.plotly.traces; import com.fasterxml.jackson.annotation.JsonValue; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Arrays; import java.util.Map; -import tech.tablesaw.plotly.Utils; import tech.tablesaw.plotly.components.Marker; public class HistogramTrace extends AbstractTrace { @@ -130,10 +129,8 @@ private Map getContext(int i) { } return context; - } - public static class HistogramBuilder extends TraceBuilder { private final String type = "histogram"; diff --git a/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java b/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java index 4f077b0..a39c1a1 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java @@ -1,14 +1,13 @@ package tech.tablesaw.plotly.traces; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Arrays; import java.util.Map; - import tech.tablesaw.plotly.Utils; import tech.tablesaw.plotly.components.Domain; diff --git a/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java b/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java index 789bb98..e803ba0 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; diff --git a/src/main/java/tech/tablesaw/plotly/traces/ScatterGeo.java b/src/main/java/tech/tablesaw/plotly/traces/ScatterGeo.java index 3781e54..b822ab3 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/ScatterGeo.java +++ b/src/main/java/tech/tablesaw/plotly/traces/ScatterGeo.java @@ -2,188 +2,187 @@ import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import tech.tablesaw.plotly.Utils; -import tech.tablesaw.plotly.components.LocationMode; -import tech.tablesaw.plotly.components.Marker; - +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Arrays; import java.util.Map; +import tech.tablesaw.plotly.Utils; +import tech.tablesaw.plotly.components.LocationMode; +import tech.tablesaw.plotly.components.Marker; public class ScatterGeo extends AbstractTrace { - public enum TextPosition { - TOP_RIGHT("top right"), - TOP_CENTER("top center"), - TOP_LEFT("top left"), - BOTTOM_RIGHT("bottom right"), - BOTTOM_CENTER("bottom center"), - BOTTOM_LEFT("bottom left"), - MIDDLE_RIGHT("middle right"), - MIDDLE_CENTER("middle center"), - MIDDLE_LEFT("middle left"); - - final String value; - - TextPosition(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - private final LocationMode locationMode; - private final String geo; - private final ScatterTrace.Mode mode; - private final Marker marker; - private final double[] lat; - private final double[] lon; - private final TextPosition[] textPosition; - private final String[] text; - - private ScatterGeo(ScatterGeoBuilder builder) { - super(builder); - this.locationMode = builder.locationMode; - this.geo = builder.geo; - this.mode = builder.mode; - this.marker = builder.marker; - this.lat = builder.lat; - this.lon = builder.lon; - this.textPosition = builder.textPosition; - this.text = builder.text; + public enum TextPosition { + TOP_RIGHT("top right"), + TOP_CENTER("top center"), + TOP_LEFT("top left"), + BOTTOM_RIGHT("bottom right"), + BOTTOM_CENTER("bottom center"), + BOTTOM_LEFT("bottom left"), + MIDDLE_RIGHT("middle right"), + MIDDLE_CENTER("middle center"), + MIDDLE_LEFT("middle left"); + + final String value; + + TextPosition(String value) { + this.value = value; + } + + @JsonValue + @Override + public String toString() { + return value; + } + } + + private final LocationMode locationMode; + private final String geo; + private final ScatterTrace.Mode mode; + private final Marker marker; + private final double[] lat; + private final double[] lon; + private final TextPosition[] textPosition; + private final String[] text; + + private ScatterGeo(ScatterGeoBuilder builder) { + super(builder); + this.locationMode = builder.locationMode; + this.geo = builder.geo; + this.mode = builder.mode; + this.marker = builder.marker; + this.lat = builder.lat; + this.lon = builder.lon; + this.textPosition = builder.textPosition; + this.text = builder.text; + } + + @Override + public String asJavascript(int i) { + Writer writer = new StringWriter(); + PebbleTemplate compiledTemplate; + + try { + compiledTemplate = engine.getTemplate("trace_template.html"); + Map context = getContext(i); + compiledTemplate.evaluate(writer, context); + } catch (PebbleException e) { + throw new IllegalStateException(e); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return writer.toString(); + } + + public Map getContext(int i) { + Map context = super.getContext(); + context.put("variableName", "trace" + i); + context.put("type", type); + context.put("mode", mode); + if (marker != null) { + context.put("marker", marker); + } + context.put("lat", Arrays.toString(lat)); + context.put("lon", Arrays.toString(lon)); + if (locationMode != null) context.put("locationmode", locationMode); + if (textPosition != null) { + if (textPosition.length == 1) { + context.put("textposition", textPosition[0]); + } else { + context.put("textposition", Arrays.toString(Utils.dataAsArrayofStrings(textPosition))); + } + } + if (text != null) { + if (text.length == 1) { + context.put("text", text[0]); + } else { + context.put("text", Arrays.toString(Utils.dataAsArrayofStrings(text))); + } + } + return context; + } + + public static ScatterGeoBuilder builder(double[] lat, double[] lon) { + return new ScatterGeoBuilder(lat, lon); + } + + public static class ScatterGeoBuilder extends TraceBuilder { + + private final String type = "scattergeo"; + private ScatterTrace.Mode mode = ScatterTrace.Mode.MARKERS; + private Marker marker; + private String geo = "geo"; + private double[] lat; + private double[] lon; + private LocationMode locationMode = LocationMode.ISO_3; + private TextPosition[] textPosition; + private String[] text; + + public ScatterGeoBuilder(double[] lat, double[] lon) { + this.lat = lat; + this.lon = lon; + } + + public ScatterGeoBuilder locationMode(LocationMode locationMode) { + this.locationMode = locationMode; + return this; + } + + /** + * Sets a reference between this trace's geospatial coordinates and a geographic map. If "geo" + * (the default value), the geospatial coordinates refer to `layout.geo`. If "geo2", the + * geospatial coordinates refer to `layout.geo2`, and so on. + */ + public ScatterGeoBuilder geo(String geo) { + this.geo = geo; + return this; + } + + public ScatterGeoBuilder mode(ScatterTrace.Mode mode) { + this.mode = mode; + return this; + } + + public ScatterGeoBuilder marker(Marker marker) { + this.marker = marker; + return this; + } + + public ScatterGeoBuilder textPosition(TextPosition position) { + this.textPosition = new TextPosition[1]; + this.textPosition[0] = position; + return this; + } + + public ScatterGeoBuilder textPosition(TextPosition[] position) { + Preconditions.checkArgument(position.length > 0); + this.textPosition = position; + return this; + } + + public ScatterGeoBuilder text(String[] text) { + Preconditions.checkArgument(text.length > 0); + this.text = text; + return this; + } + + public ScatterGeoBuilder text(String text) { + this.text = new String[1]; + this.text[0] = text; + return this; + } + + public ScatterGeo build() { + return new ScatterGeo(this); } @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - Map context = getContext(i); - compiledTemplate.evaluate(writer, context); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - public Map getContext(int i) { - Map context = super.getContext(); - context.put("variableName","trace"+i); - context.put("type", type); - context.put("mode", mode); - if (marker != null) { - context.put("marker", marker); - } - context.put("lat", Arrays.toString(lat)); - context.put("lon", Arrays.toString(lon)); - if (locationMode != null) context.put("locationmode", locationMode); - if (textPosition != null) { - if (textPosition.length == 1) { - context.put("textposition", textPosition[0]); - } else { - context.put("textposition", Arrays.toString(Utils.dataAsArrayofStrings(textPosition))); - } - } - if (text != null) { - if (text.length == 1) { - context.put("text", text[0]); - } else { - context.put("text", Arrays.toString(Utils.dataAsArrayofStrings(text))); - } - } - return context; - } - - public static ScatterGeoBuilder builder(double[] lat, double[] lon) { - return new ScatterGeoBuilder(lat, lon); - } - - public static class ScatterGeoBuilder extends TraceBuilder { - - private final String type = "scattergeo"; - private ScatterTrace.Mode mode = ScatterTrace.Mode.MARKERS; - private Marker marker; - private String geo = "geo"; - private double[] lat; - private double[] lon; - private LocationMode locationMode = LocationMode.ISO_3; - private TextPosition[] textPosition; - private String[] text; - - public ScatterGeoBuilder(double[] lat, double[] lon) { - this.lat = lat; - this.lon = lon; - } - - public ScatterGeoBuilder locationMode(LocationMode locationMode) { - this.locationMode = locationMode; - return this; - } - - /** - * Sets a reference between this trace's geospatial coordinates and a geographic map. - * If "geo" (the default value), the geospatial coordinates refer to `layout.geo`. - * If "geo2", the geospatial coordinates refer to `layout.geo2`, and so on. - */ - public ScatterGeoBuilder geo(String geo) { - this.geo = geo; - return this; - } - - public ScatterGeoBuilder mode(ScatterTrace.Mode mode) { - this.mode = mode; - return this; - } - - public ScatterGeoBuilder marker(Marker marker) { - this.marker = marker; - return this; - } - - public ScatterGeoBuilder textPosition(TextPosition position) { - this.textPosition = new TextPosition[1]; - this.textPosition[0] = position; - return this; - } - - public ScatterGeoBuilder textPosition(TextPosition[] position) { - Preconditions.checkArgument(position.length > 0); - this.textPosition = position; - return this; - } - - public ScatterGeoBuilder text(String[] text) { - Preconditions.checkArgument(text.length > 0); - this.text = text; - return this; - } - - public ScatterGeoBuilder text(String text) { - this.text = new String[1]; - this.text[0] = text; - return this; - } - - public ScatterGeo build() { - return new ScatterGeo(this); - } - - @Override - protected String getType() { - return type; - } + protected String getType() { + return type; } + } } diff --git a/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java b/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java index c51d5f5..11ad01d 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java @@ -2,21 +2,20 @@ import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Arrays; import java.util.Map; - import tech.tablesaw.plotly.Utils; +import tech.tablesaw.plotly.change.Decreasing; +import tech.tablesaw.plotly.change.Increasing; import tech.tablesaw.plotly.components.HoverLabel; import tech.tablesaw.plotly.components.Line; import tech.tablesaw.plotly.components.Marker; -import tech.tablesaw.plotly.change.Decreasing; -import tech.tablesaw.plotly.change.Increasing; public class ScatterTrace extends AbstractTrace { diff --git a/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java b/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java index ffc7f54..fc776aa 100644 --- a/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java +++ b/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java @@ -2,15 +2,14 @@ import static tech.tablesaw.plotly.Utils.dataAsString; -import com.mitchellbosecke.pebble.error.PebbleException; -import com.mitchellbosecke.pebble.template.PebbleTemplate; -import tech.tablesaw.plotly.components.Marker; - +import io.pebbletemplates.pebble.error.PebbleException; +import io.pebbletemplates.pebble.template.PebbleTemplate; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; import java.io.Writer; import java.util.Map; +import tech.tablesaw.plotly.components.Marker; public class ViolinTrace extends AbstractTrace {