Skip to content

+ Changes for https://github.com/jtablesaw/plotly.java/issues/12 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<dependency>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
<version>3.1.2</version>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/tech/tablesaw/plotly/components/Component.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tech/tablesaw/plotly/components/Figure.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/tech/tablesaw/plotly/components/Layout.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -315,6 +315,7 @@ public static class LayoutBuilder {

/** The global font */
private final Font font = DEFAULT_FONT;

public Geo geo;

/** The plot title */
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/tech/tablesaw/plotly/components/Page.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
36 changes: 15 additions & 21 deletions src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {

Expand Down
23 changes: 9 additions & 14 deletions src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
* <p>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;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/tech/tablesaw/plotly/traces/BarTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
89 changes: 38 additions & 51 deletions src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java
Original file line number Diff line number Diff line change
@@ -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.
* <p>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 {

Expand Down Expand Up @@ -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.
* <p>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;

Expand Down Expand Up @@ -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`.
* <p>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.
* <p>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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -249,16 +239,14 @@ 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) {
this.hoverOnGaps = hoverOnGaps;
return this;
}


@Override
public ContourTrace.ContourBuilder xAxis(String xAxis) {
super.xAxis(xAxis);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading