diff --git a/jsplot/pom.xml b/jsplot/pom.xml index 1cd691a20..6d131c888 100644 --- a/jsplot/pom.xml +++ b/jsplot/pom.xml @@ -67,13 +67,13 @@ jackson-databind - io.pebbletemplates - pebble - 3.1.2 + tech.tablesaw + tablesaw-core + 1.0.0-SNAPSHOT tech.tablesaw - tablesaw-core + plotly-java 1.0.0-SNAPSHOT @@ -81,5 +81,11 @@ junit-jupiter-engine test + + org.skyscreamer + jsonassert + 1.5.0 + test + diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/Plot.java b/jsplot/src/main/java/tech/tablesaw/plotly/Plot.java deleted file mode 100644 index 8bcb969e3..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/Plot.java +++ /dev/null @@ -1,99 +0,0 @@ -package tech.tablesaw.plotly; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.UncheckedIOException; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.UUID; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Page; -import tech.tablesaw.plotly.display.Browser; - -/** - * Displays plots in a development setting, by exporting a file containing the HTML and Javascript, - * and then opening the file in the default browser on the developer's machine. - */ -public class Plot { - - protected static final String DEFAULT_DIV_NAME = "target"; - protected static final String DEFAULT_OUTPUT_FILE = "output.html"; - protected static final String DEFAULT_OUTPUT_FILE_NAME = "output"; - protected static final String DEFAULT_OUTPUT_FOLDER = "testoutput"; - - public static void show(Figure figure, String divName, File outputFile) { - Page page = Page.pageBuilder(figure, divName).build(); - String output = page.asJavascript(); - - try { - try (Writer writer = - new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { - writer.write(output); - } - new Browser().browse(outputFile); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - /** - * Opens the default browser on the given HTML page. This is a convenience method for anyone who - * wants total control over the HTML file containing one or more plots, but still wants to use the - * mechanism for opening the default browser on it. - * - * @param html An arbitrary HTML page, it doesn't even need plots - * @param outputFile The file where the page will be written - */ - public static void show(String html, File outputFile) { - try { - try (Writer writer = - new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { - writer.write(html); - } - new Browser().browse(outputFile); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public static void show(Figure figure, String divName) { - show(figure, divName, defaultFile()); - } - - public static void show(Figure figure) { - show(figure, randomFile()); - } - - public static void show(Figure figure, File outputFile) { - show(figure, DEFAULT_DIV_NAME, outputFile); - } - - protected static File defaultFile() { - Path path = Paths.get(DEFAULT_OUTPUT_FOLDER, DEFAULT_OUTPUT_FILE); - try { - Files.createDirectories(path.getParent()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return path.toFile(); - } - - protected static File randomFile() { - Path path = Paths.get(DEFAULT_OUTPUT_FOLDER, randomizedFileName()); - try { - Files.createDirectories(path.getParent()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return path.toFile(); - } - - protected static String randomizedFileName() { - return DEFAULT_OUTPUT_FILE_NAME + UUID.randomUUID().toString() + ".html"; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/Utils.java b/jsplot/src/main/java/tech/tablesaw/plotly/Utils.java deleted file mode 100644 index e72d4efc0..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/Utils.java +++ /dev/null @@ -1,56 +0,0 @@ -package tech.tablesaw.plotly; - -import com.fasterxml.jackson.core.io.JsonStringEncoder; -import java.util.Arrays; - -public class Utils { - - private Utils() {} - - public static String dataAsString(double[] data) { - return Arrays.toString(data); - } - - /** @return un-escaped quote of argument */ - public static String quote(String string) { - return "'" + string + "'"; - } - - /** - * Escapes string for Javascript, assuming but without surrounding it with doublequotes (") and - * saves to output to the given StringBuilder. - */ - private static void escape(String s, StringBuilder sb) { - JsonStringEncoder.getInstance().quoteAsString(s, sb); - } - - /** @return a Javascript array of strings (escaped if needed) */ - public static String dataAsString(Object[] data) { - StringBuilder builder = new StringBuilder("["); - for (int i = 0; i < data.length; i++) { - Object o = data[i]; - builder.append("\""); - escape(String.valueOf(o), builder); - builder.append("\""); - if (i < data.length - 1) { - builder.append(","); - } - } - builder.append("]"); - return builder.toString(); - } - - public static String dataAsString(double[][] data) { - StringBuilder builder = new StringBuilder("["); - for (double[] row : data) { - builder.append("["); - for (double value : row) { - builder.append(value); - builder.append(","); - } - builder.append("],"); - } - builder.append("]"); - return builder.toString(); - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/AreaPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/AreaPlot.java index 57a3eb8bd..fb4a7c6f3 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/AreaPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/AreaPlot.java @@ -20,7 +20,8 @@ public static Figure create( List tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( - tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) + tableList.get(i).numberColumn(xCol).asDoubleArray(), + tableList.get(i).numberColumn(yCol).asDoubleArray()) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) @@ -33,7 +34,8 @@ public static Figure create( public static Figure create(String title, Table table, String xCol, String yCol) { Layout layout = Layout.builder(title, xCol, yCol).build(); ScatterTrace trace = - ScatterTrace.builder(table.numberColumn(xCol), table.numberColumn(yCol)) + ScatterTrace.builder( + table.numberColumn(xCol).asDoubleArray(), table.numberColumn(yCol).asDoubleArray()) .mode(ScatterTrace.Mode.LINE) .fill(ScatterTrace.Fill.TO_NEXT_Y) .build(); diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/BarPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/BarPlot.java index 028f589b3..68ca4b4c7 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/BarPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/BarPlot.java @@ -22,7 +22,9 @@ protected static Figure create( Layout layout = standardLayout(title).build(); BarTrace trace = - BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(numberColName)) + BarTrace.builder( + table.categoricalColumn(groupColName).asObjectArray(), + table.numberColumn(numberColName).asDoubleArray()) .orientation(orientation) .build(); return new Figure(layout, trace); @@ -42,7 +44,9 @@ protected static Figure create( for (int i = 0; i < numberColNames.length; i++) { String name = numberColNames[i]; BarTrace trace = - BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(name)) + BarTrace.builder( + table.categoricalColumn(groupColName).asObjectArray(), + table.numberColumn(name).asDoubleArray()) .orientation(orientation) .showLegend(true) .name(name) diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/BoxPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/BoxPlot.java index ce298e932..28edcdbef 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/BoxPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/BoxPlot.java @@ -15,7 +15,9 @@ public static Figure create( Layout layout = Layout.builder().title(title).height(HEIGHT).width(WIDTH).build(); BoxTrace trace = - BoxTrace.builder(table.categoricalColumn(groupingColumn), table.nCol(numericColumn)) + BoxTrace.builder( + table.categoricalColumn(groupingColumn).asObjectArray(), + table.nCol(numericColumn).asDoubleArray()) .build(); return new Figure(layout, trace); } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/BubblePlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/BubblePlot.java index 0c0889b25..c72f1ee75 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/BubblePlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/BubblePlot.java @@ -26,13 +26,14 @@ public static Figure create( Marker marker = Marker.builder() - .size(tableList.get(i).numberColumn(sizeColumn)) + .size(tableList.get(i).numberColumn(sizeColumn).asDoubleArray()) // .opacity(.75) .build(); traces[i] = ScatterTrace.builder( - tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) + tableList.get(i).numberColumn(xCol).asDoubleArray(), + tableList.get(i).numberColumn(yCol).asDoubleArray()) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) @@ -67,7 +68,7 @@ public static Figure create( Marker marker = null; MarkerBuilder builder = Marker.builder(); if (sizeColumn != null) { - builder.size(sizeColumn); + builder.size(sizeColumn.asDoubleArray()); } if (opacity != null) { builder.opacity(opacity); @@ -80,7 +81,10 @@ public static Figure create( } marker = builder.build(); - ScatterTrace trace = ScatterTrace.builder(xColumn, yColumn).marker(marker).build(); + ScatterTrace trace = + ScatterTrace.builder(xColumn.asObjectArray(), yColumn.asObjectArray()) + .marker(marker) + .build(); return new Figure(layout, trace); } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/ContourPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/ContourPlot.java index 7f52b6c3e..4f6ba72dc 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/ContourPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/ContourPlot.java @@ -1,5 +1,6 @@ package tech.tablesaw.plotly.api; +import java.util.List; import tech.tablesaw.api.Table; import tech.tablesaw.columns.Column; import tech.tablesaw.plotly.components.Figure; @@ -7,12 +8,9 @@ import tech.tablesaw.plotly.traces.ContourTrace; import tech.tablesaw.util.DoubleArrays; -import java.util.List; - public class ContourPlot { - private ContourPlot() { - } + private ContourPlot() {} public static Figure create(String title, Table table, String categoryCol1, String categoryCol2) { Layout layout = Layout.builder(title).build(); diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/Histogram2D.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/Histogram2D.java index 3b5e8233f..1bf36e38d 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/Histogram2D.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/Histogram2D.java @@ -9,7 +9,9 @@ public class Histogram2D { public static Figure create(String title, Table table, String xCol, String yCol) { Histogram2DTrace trace = - Histogram2DTrace.builder(table.numberColumn(xCol), table.numberColumn(yCol)).build(); + Histogram2DTrace.builder( + table.numberColumn(xCol).asDoubleArray(), table.numberColumn(yCol).asDoubleArray()) + .build(); return new Figure(Layout.builder(title, xCol, yCol).build(), trace); } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/LinePlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/LinePlot.java index 7997988a5..8060ca52b 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/LinePlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/LinePlot.java @@ -21,7 +21,8 @@ public static Figure create( List
tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( - tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) + tableList.get(i).numberColumn(xCol).asDoubleArray(), + tableList.get(i).numberColumn(yCol).asDoubleArray()) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) @@ -33,7 +34,8 @@ public static Figure create( public static Figure create(String title, Table table, String xCol, String yCol) { Layout layout = Layout.builder(title, xCol, yCol).build(); ScatterTrace trace = - ScatterTrace.builder(table.numberColumn(xCol), table.numberColumn(yCol)) + ScatterTrace.builder( + table.numberColumn(xCol).asDoubleArray(), table.numberColumn(yCol).asDoubleArray()) .mode(ScatterTrace.Mode.LINE) .build(); return new Figure(layout, trace); diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/PiePlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/PiePlot.java index 73e5c7ba0..d811ec764 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/PiePlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/PiePlot.java @@ -13,7 +13,9 @@ public static Figure create( Layout layout = Layout.builder(title).build(); PieTrace trace = - PieTrace.builder(table.column(groupColName), table.numberColumn(numberColName)) + PieTrace.builder( + table.column(groupColName).asObjectArray(), + table.numberColumn(numberColName).asDoubleArray()) .showLegend(true) .build(); return new Figure(layout, trace); diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java index b0f11efa3..43ed7386f 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java @@ -29,17 +29,32 @@ public static Figure create( ScatterTrace trace; if (x.type() == ColumnType.LOCAL_DATE) { trace = - ScatterTrace.builder(table.dateColumn(xCol), open, high, low, close) + ScatterTrace.builder( + table.dateColumn(xCol).asObjectArray(), + open.asDoubleArray(), + high.asDoubleArray(), + low.asDoubleArray(), + close.asDoubleArray()) .type(plotType) .build(); } else if (x.type() == ColumnType.LOCAL_DATE_TIME) { trace = - ScatterTrace.builder(table.dateTimeColumn(xCol), open, high, low, close) + ScatterTrace.builder( + table.dateColumn(xCol).asObjectArray(), + open.asDoubleArray(), + high.asDoubleArray(), + low.asDoubleArray(), + close.asDoubleArray()) .type(plotType) .build(); } else if (x.type() == ColumnType.INSTANT) { trace = - ScatterTrace.builder(table.instantColumn(xCol), open, high, low, close) + ScatterTrace.builder( + table.dateColumn(xCol).asObjectArray(), + open.asDoubleArray(), + high.asDoubleArray(), + low.asDoubleArray(), + close.asDoubleArray()) .type(plotType) .build(); } else { diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/Scatter3DPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/Scatter3DPlot.java index da519ffad..d7e966e6a 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/Scatter3DPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/Scatter3DPlot.java @@ -27,9 +27,9 @@ public static Figure create( List
tableList = tables.asTableList(); traces[i] = Scatter3DTrace.builder( - tableList.get(i).numberColumn(xCol), - tableList.get(i).numberColumn(yCol), - tableList.get(i).numberColumn(zCol)) + tableList.get(i).numberColumn(xCol).asDoubleArray(), + tableList.get(i).numberColumn(yCol).asDoubleArray(), + tableList.get(i).numberColumn(zCol).asDoubleArray()) .showLegend(true) .name(tableList.get(i).name()) .build(); @@ -43,7 +43,9 @@ public static Figure create(String title, Table table, String xCol, String yCol, Scatter3DTrace trace = Scatter3DTrace.builder( - table.numberColumn(xCol), table.numberColumn(yCol), table.numberColumn(zCol)) + table.numberColumn(xCol).asDoubleArray(), + table.numberColumn(yCol).asDoubleArray(), + table.numberColumn(zCol).asDoubleArray()) .build(); return new Figure(layout, trace); } @@ -67,15 +69,15 @@ public static Figure create( List
tableList = tables.asTableList(); Marker marker = Marker.builder() - .size(tableList.get(i).numberColumn(sizeColumn)) + .size(tableList.get(i).numberColumn(sizeColumn).asDoubleArray()) // .opacity(.75) .build(); traces[i] = Scatter3DTrace.builder( - tableList.get(i).numberColumn(xCol), - tableList.get(i).numberColumn(yCol), - tableList.get(i).numberColumn(zCol)) + tableList.get(i).numberColumn(xCol).asDoubleArray(), + tableList.get(i).numberColumn(yCol).asDoubleArray(), + tableList.get(i).numberColumn(zCol).asDoubleArray()) .marker(marker) .showLegend(true) .name(tableList.get(i).name()) diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/ScatterPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/ScatterPlot.java index 4a2fb8a91..1147f0963 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/ScatterPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/ScatterPlot.java @@ -23,9 +23,10 @@ public static Figure create( Marker marker = Marker.builder().opacity(OPACITY).build(); for (int i = 0; i < tables.size(); i++) { List
tableList = tables.asTableList(); + double[] x = tableList.get(i).numberColumn(xCol).asDoubleArray(); + double[] y = tableList.get(i).numberColumn(yCol).asDoubleArray(); traces[i] = - ScatterTrace.builder( - tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) + ScatterTrace.builder(x, y) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) @@ -37,7 +38,9 @@ public static Figure create( public static Figure create(String title, Table table, String xCol, String yCol) { Layout layout = Layout.builder(title, xCol, yCol).build(); ScatterTrace trace = - ScatterTrace.builder(table.numberColumn(xCol), table.numberColumn(yCol)).build(); + ScatterTrace.builder( + table.numberColumn(xCol).asDoubleArray(), table.numberColumn(yCol).asDoubleArray()) + .build(); return new Figure(layout, trace); } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/TimeSeriesPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/TimeSeriesPlot.java index 32b5d92bb..e2b7398ff 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/TimeSeriesPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/TimeSeriesPlot.java @@ -25,7 +25,8 @@ public static Figure create( List
tableList = tables.asTableList(); Table t = tableList.get(i).sortOn(dateColX); traces[i] = - ScatterTrace.builder(t.dateColumn(dateColX), t.numberColumn(yCol)) + ScatterTrace.builder( + t.dateColumn(dateColX).asObjectArray(), t.numberColumn(yCol).asObjectArray()) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) @@ -37,7 +38,9 @@ public static Figure create( public static Figure create(String title, Table table, String dateColXName, String yColName) { Layout layout = Layout.builder(title, dateColXName, yColName).build(); ScatterTrace trace = - ScatterTrace.builder(table.column(dateColXName), table.numberColumn(yColName)) + ScatterTrace.builder( + table.column(dateColXName).asObjectArray(), + table.numberColumn(yColName).asObjectArray()) .mode(ScatterTrace.Mode.LINE) .build(); return new Figure(layout, trace); @@ -46,21 +49,30 @@ public static Figure create(String title, Table table, String dateColXName, Stri public static Figure create( String title, String xTitle, DateColumn xCol, String yTitle, NumericColumn yCol) { Layout layout = Layout.builder(title, xTitle, yTitle).build(); - ScatterTrace trace = ScatterTrace.builder(xCol, yCol).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(xCol.asObjectArray(), yCol.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); return new Figure(layout, trace); } public static Figure create( String title, String xTitle, DateTimeColumn xCol, String yTitle, NumericColumn yCol) { Layout layout = Layout.builder(title, xTitle, yTitle).build(); - ScatterTrace trace = ScatterTrace.builder(xCol, yCol).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(xCol.asObjectArray(), yCol.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); return new Figure(layout, trace); } public static Figure create( String title, String xTitle, InstantColumn xCol, String yTitle, NumericColumn yCol) { Layout layout = Layout.builder(title, xTitle, yTitle).build(); - ScatterTrace trace = ScatterTrace.builder(xCol, yCol).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(xCol.asObjectArray(), yCol.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); return new Figure(layout, trace); } @@ -81,7 +93,10 @@ public static Figure createDateTimeSeries( Layout layout = Layout.builder(title, xCol.name(), yCol.name()).build(); - ScatterTrace trace = ScatterTrace.builder(xCol, yCol).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(xCol.asObjectArray(), yCol.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); return new Figure(layout, trace); } } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/api/ViolinPlot.java b/jsplot/src/main/java/tech/tablesaw/plotly/api/ViolinPlot.java index 75d7901dd..81b45d333 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/ViolinPlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/ViolinPlot.java @@ -3,22 +3,25 @@ import tech.tablesaw.api.Table; import tech.tablesaw.plotly.components.Figure; import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.traces.BoxTrace; import tech.tablesaw.plotly.traces.ViolinTrace; public class ViolinPlot { - private static final int HEIGHT = 600; - private static final int WIDTH = 800; + private static final int HEIGHT = 600; + private static final int WIDTH = 800; - public static Figure create( - String title, Table table, String groupingColumn, String numericColumn, boolean showBoxPlot, boolean showMeanLine) { - Layout layout = Layout.builder().title(title).height(HEIGHT).width(WIDTH).build(); - ViolinTrace trace = - ViolinTrace.builder(table.categoricalColumn(groupingColumn), table.nCol(numericColumn)) - .boxPlot(showBoxPlot) - .meanLine(showMeanLine) - .build(); - return new Figure(layout, trace); - } + public static Figure create( + String title, + Table table, + String groupingColumn, + String numericColumn, + boolean showBoxPlot, + boolean showMeanLine) { + Layout layout = Layout.builder().title(title).height(HEIGHT).width(WIDTH).build(); + Object[] x = table.column(groupingColumn).asObjectArray(); + double[] y = table.numberColumn(numericColumn).asDoubleArray(); + ViolinTrace trace = + ViolinTrace.builder(x, y).boxPlot(showBoxPlot).meanLine(showMeanLine).build(); + return new Figure(layout, trace); + } } diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Annotation.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Annotation.java deleted file mode 100644 index 561a3cc17..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Annotation.java +++ /dev/null @@ -1,582 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; - -public class Annotation extends Component { - - /** - * This is to supply annotation in Plot.ly reference to - * https://plotly.com/javascript/reference/layout/annotations/. Support most of - * apis there. - */ - - /** - * The horizontal alignment of the 'text' within the box. - */ - public enum Align { - LEFT("left"), CENTER("center"), RIGHT("right"); - - private final String value; - - Align(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - /* - * The vertical alignment of the 'text' within the box. - */ - public enum Valign { - TOP("top"), MIDDLE("middle"), BOTTOM("bottom"); - - private final String value; - - Valign(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - public enum Xanchor { - AUTO("auto"), LEFT("left"), CENTER("center"), RIGHT("right"); - - private final String value; - - Xanchor(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - public enum Yanchor { - AUTO("auto"), TOP("top"), MIDDLE("center"), BOTTOM("right"); - - private final String value; - - Yanchor(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - public enum ClicktoShow { - FALSE(), ONOFF("onoff"), ONOUT("onout"); - - private final String value; - - ClicktoShow(String value) { - this.value = value; - } - - ClicktoShow() { - this.value = "false"; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - private static final boolean DEFAULT_VISIBLE = true; - private static final Font DEFAULT_FONT = Font.builder().build(); - private static final double DEFAULT_OPACITY = 1; - private static final Align DEFAULT_ALIGN = Align.CENTER; - private static final Valign DEFAULT_VALIGN = Valign.MIDDLE; - private static final String DEFAULT_BGCOLOR = "rgba(0,0,0,0)"; - private static final String DEFAULT_BORDERCOLOR = "rgba(0,0,0,0)"; - private static final double DEFAULT_BORDERPAD = 1; - private static final double DEFAULT_BORDERWIDTH = 1; - private static final boolean DEFAULT_SHOWARROW = true; - private static final int DEFAULT_ARROWHEAD = 1; - private static final int DEFAULT_STARTARROWHEAD = 1; - private static final String DEFAULT_ARROWSIDE = "END"; - private static final double DEFAULT_ARROWSIZE = 1; - private static final double DEFAULT_STARTARROWSIZE = 1; - private static final double DEFAULT_ARROWWIDTH = 1; - private static final double DEFAULT_STANDOFF = 0; - private static final double DEFAULT_STARTSTANDOFF = 0; - private static final String DEFAULT_AXREF = "paper"; - private static final String DEFAULT_AYREF = "paper"; - private static final String DEFAULT_XREF = "paper"; - private static final Xanchor DEFAULT_XANCHOR = Xanchor.AUTO; - private static final double DEFAULT_XSHIFT = 0; - private static final String DEFAULT_YREF = "paper"; - private static final Yanchor DEFAULT_YANCHOR = Yanchor.AUTO; - private static final double DEFAULT_YSHIFT = 0; - private static final ClicktoShow DEFAULT_CLICKTOSHOW = ClicktoShow.FALSE; - private static final boolean DEFAULT_CAPTUREEVENTS = true; - - private final boolean visible; - private final String text; - private final Font font; - private final Double width; - private final Double height; - private final double opacity; - private final Align align; - private final Valign valign; - private final String bgcolor; - private final String bordercolor; - private final double borderpad; - private final double borderwidth; - private final boolean showarrow; - private final String arrowcolor; - private final int arrowhead; - private final int startarrowhead; - private final String arrowside; - private final double arrowsize; - private final double startarrowsize; - private final double arrowwidth; - private final double standoff; - private final double startstandoff; - private final Double ax; - private final Double ay; - private final String axref; - private final String ayref; - private final String xref; - private final Double x; - private final Xanchor xanchor; - private final double xshift; - private final String yref; - private final Double y; - private final Yanchor yanchor; - private final double yshift; - private final ClicktoShow clicktoshow; - private final Double xclick; - private final Double yclick; - private final String hovertext; - private final HoverLabel hoverlabel; - private final boolean captureevents; - private final String name; - private final String templateitemname; - - private Annotation(AnnotationBuilder builder) { - this.visible = builder.visible; - this.text = builder.text; - this.font = builder.font; - this.width = builder.width; - this.height = builder.height; - this.opacity = builder.opacity; - this.align = builder.align; - this.valign = builder.valign; - this.bgcolor = builder.bgcolor; - this.bordercolor = builder.bordercolor; - this.borderpad = builder.borderpad; - this.borderwidth = builder.borderwidth; - this.showarrow = builder.showarrow; - this.arrowcolor = builder.arrowcolor; - this.arrowhead = builder.arrowhead; - this.startarrowhead = builder.startarrowhead; - this.arrowside = builder.arrowside; - this.arrowsize = builder.arrowsize; - this.startarrowsize = builder.startarrowsize; - this.arrowwidth = builder.arrowwidth; - this.standoff = builder.standoff; - this.startstandoff = builder.startstandoff; - this.ax = builder.ax; - this.ay = builder.ay; - this.axref = builder.axref; - this.ayref = builder.ayref; - this.xref = builder.xref; - this.x = builder.x; - this.xanchor = builder.xanchor; - this.xshift = builder.xshift; - this.yref = builder.yref; - this.y = builder.y; - this.yanchor = builder.yanchor; - this.yshift = builder.yshift; - this.clicktoshow = builder.clicktoshow; - this.xclick = builder.xclick; - this.yclick = builder.yclick; - this.hovertext = builder.hovertext; - this.hoverlabel = builder.hoverLabel; - this.captureevents = builder.captureevents; - this.name = builder.name; - this.templateitemname = builder.templateitemname; - } - - @Override - public String asJavascript() { - return asJavascript("annotation_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - if (DEFAULT_VISIBLE != visible) - context.put("visible", visible); - if (text != null) - context.put("text", text); - if (!DEFAULT_FONT.equals(font)) - context.put("font", font); - if (width != null) - context.put("width", width); - if (height != null) - context.put("height", height); - if (opacity != DEFAULT_OPACITY) - context.put("opacity", opacity); - if (!DEFAULT_ALIGN.equals(align)) - context.put("align", align); - if (!DEFAULT_VALIGN.equals(valign)) - context.put("valign", valign); - if (!DEFAULT_BGCOLOR.equals(bgcolor)) - context.put("bgcolor", bgcolor); - if (borderpad != DEFAULT_BORDERPAD) - context.put("borderpad", borderpad); - if (borderwidth != borderwidth) - context.put("borderwidth", bordercolor); - if (showarrow != DEFAULT_SHOWARROW) - context.put("showarrow", showarrow); - if (arrowcolor != null) - context.put("arrowcolor", arrowcolor); - if (arrowhead != DEFAULT_ARROWHEAD) - context.put("arrowhead", arrowhead); - if (startarrowhead != DEFAULT_STARTARROWHEAD) - context.put("startarrowhead", startarrowhead); - if (arrowwidth != DEFAULT_ARROWWIDTH) - context.put("arrowwidth", arrowwidth); - if (standoff != DEFAULT_STANDOFF) - context.put("standoff", standoff); - if (ax != null) - context.put("ax", ax); - if (ay != null) - context.put("ay", ay); - if (!DEFAULT_AXREF.equals(axref)) - context.put("axref", axref); - if (!DEFAULT_AYREF.equals(ayref)) - context.put("ayref", ayref); - if (!DEFAULT_XREF.equals(xref)) - context.put("xref", xref); - if (x != null) - context.put("x", x); - if (!DEFAULT_XANCHOR.equals(xanchor)) - context.put("xanchor", xanchor); - if (xshift != DEFAULT_XSHIFT) - context.put("xshift", xshift); - if (!DEFAULT_YREF.equals(yref)) - context.put("yref", yref); - if (y != null) - context.put("y", y); - if (!DEFAULT_YANCHOR.equals(yanchor)) - context.put("yanchor", yanchor); - if (yshift != DEFAULT_YSHIFT) - context.put("yshift", yshift); - if (!DEFAULT_CLICKTOSHOW.equals(clicktoshow)) - context.put("clicktoshow", clicktoshow); - if (xclick != null) - context.put("xclick", xclick); - if (yclick != null) - context.put("yclick", yclick); - if (hoverlabel != null) - context.put("hoverlabel", hoverlabel); - if (captureevents != DEFAULT_CAPTUREEVENTS) - context.put("captureevents", captureevents); - if (name != null) - context.put("name", name); - if (templateitemname != null) - context.put("templateitemname", templateitemname); - - return context; - } - - public static AnnotationBuilder builder() { - return new AnnotationBuilder(); - } - - public static class AnnotationBuilder { - private boolean visible = DEFAULT_VISIBLE; - private String text; - private Font font = DEFAULT_FONT; - private Double width; - private Double height; - private double opacity = DEFAULT_OPACITY; - private Align align = DEFAULT_ALIGN; - private Valign valign = DEFAULT_VALIGN; - private String bgcolor = DEFAULT_BGCOLOR; - private String bordercolor = DEFAULT_BORDERCOLOR; - private double borderpad = DEFAULT_BORDERPAD; - private double borderwidth = DEFAULT_BORDERWIDTH; - private boolean showarrow = DEFAULT_SHOWARROW; - private String arrowcolor; - private int arrowhead = DEFAULT_ARROWHEAD; - private int startarrowhead = DEFAULT_STARTARROWHEAD; - private String arrowside = DEFAULT_ARROWSIDE; - private double arrowsize = DEFAULT_ARROWSIZE; - private double startarrowsize = DEFAULT_STARTARROWSIZE; - private double arrowwidth = DEFAULT_ARROWWIDTH; - private double standoff = DEFAULT_STANDOFF; - private double startstandoff = DEFAULT_STARTSTANDOFF; - private Double ax; - private Double ay; - private String axref = DEFAULT_AXREF; - private String ayref = DEFAULT_AYREF; - private String xref = DEFAULT_XREF; - private Double x; - private Xanchor xanchor = DEFAULT_XANCHOR; - private double xshift = DEFAULT_XSHIFT; - private String yref = DEFAULT_YREF; - private Double y; - private Yanchor yanchor = DEFAULT_YANCHOR; - private double yshift = DEFAULT_YSHIFT; - private ClicktoShow clicktoshow; - private Double xclick; - private Double yclick; - private String hovertext; - private HoverLabel hoverLabel; - private boolean captureevents = DEFAULT_CAPTUREEVENTS; - private String name; - private String templateitemname; - - private AnnotationBuilder() { - } - - public AnnotationBuilder visible(boolean visible) { - this.visible = visible; - return this; - } - - public AnnotationBuilder text(String text) { - this.text = text; - return this; - } - - public AnnotationBuilder font(Font font) { - this.font = font; - return this; - } - - public AnnotationBuilder width(double width) { - Preconditions.checkArgument(width >= 0); - this.width = width; - return this; - } - - public AnnotationBuilder height(double height) { - Preconditions.checkArgument(height >= 0); - this.height = height; - return this; - } - - public AnnotationBuilder opacity(double opacity) { - Preconditions.checkArgument(opacity >= 0 && opacity <= 1); - this.opacity = opacity; - return this; - } - - public AnnotationBuilder align(Align align) { - this.align = align; - return this; - } - - public AnnotationBuilder Valign(Valign valign) { - this.valign = valign; - return this; - } - - public AnnotationBuilder bgcolor(String bgcolor) { - this.bgcolor = bgcolor; - return this; - } - - public AnnotationBuilder bordercolor(String bordercolor) { - this.bordercolor = bordercolor; - return this; - } - - public AnnotationBuilder borderpad(double borderpad) { - Preconditions.checkArgument(borderpad >= 0); - this.borderpad = borderpad; - return this; - } - - public AnnotationBuilder borderwidth(double borderwidth) { - Preconditions.checkArgument(borderwidth >= 0); - this.borderwidth = borderwidth; - return this; - } - - public AnnotationBuilder showarrow(boolean showarrow) { - this.showarrow = showarrow; - return this; - } - - public AnnotationBuilder arrowcolor(String arrowcolor) { - this.arrowcolor = arrowcolor; - return this; - } - - public AnnotationBuilder arrowhead(int arrowhead) { - this.arrowhead = arrowhead; - return this; - } - - public AnnotationBuilder startarrowhead(int startarrowhead) { - this.startarrowhead = startarrowhead; - return this; - } - - public AnnotationBuilder arrowside(String arrowside) { - this.arrowside = arrowside; - return this; - } - - public AnnotationBuilder arrowsize(double arrowsize) { - Preconditions.checkArgument(arrowsize >= 0.3); - this.arrowsize = arrowsize; - return this; - } - - public AnnotationBuilder startarrowsize(double startarrowsize) { - Preconditions.checkArgument(startarrowsize >= 0.3); - this.startarrowsize = startarrowsize; - return this; - } - - public AnnotationBuilder arrowwidth(double arrowwidth) { - Preconditions.checkArgument(arrowwidth >= 0.1); - this.arrowwidth = arrowwidth; - return this; - } - - public AnnotationBuilder standoff(double standoff) { - Preconditions.checkArgument(standoff >= 0); - this.standoff = standoff; - return this; - } - - public AnnotationBuilder startstandoff(double startstandoff) { - Preconditions.checkArgument(startstandoff >= 0); - this.startstandoff = startstandoff; - return this; - } - - public AnnotationBuilder ax(double ax) { - this.ax = ax; - return this; - } - - public AnnotationBuilder ay(double ay) { - this.ay = ay; - return this; - } - - public AnnotationBuilder axref(String axref) { - this.axref = axref; - return this; - } - - public AnnotationBuilder ayref(String ayref) { - this.ayref = ayref; - return this; - } - - public AnnotationBuilder xref(String xref) { - this.xref = xref; - return this; - } - - public AnnotationBuilder x(double x) { - this.x = x; - return this; - } - - public AnnotationBuilder xanchor(Xanchor xanchor) { - this.xanchor = xanchor; - return this; - } - - public AnnotationBuilder xshift(double xshift) { - this.xshift = xshift; - return this; - } - - public AnnotationBuilder yref(String yref) { - this.yref = yref; - return this; - } - - public AnnotationBuilder y(double y) { - this.y = y; - return this; - } - - public AnnotationBuilder yanchor(Yanchor yanchor) { - this.yanchor = yanchor; - return this; - } - - public AnnotationBuilder yshift(double yshift) { - this.yshift = yshift; - return this; - } - - public AnnotationBuilder clicktoshow(ClicktoShow clicktoShow) { - this.clicktoshow = clicktoShow; - return this; - } - - public AnnotationBuilder xclick(double xclick) { - this.xclick = xclick; - return this; - } - - public AnnotationBuilder yclick(double yclick) { - this.yclick = yclick; - return this; - } - - public AnnotationBuilder hovertext(String hovertext) { - this.hovertext = hovertext; - return this; - } - - public AnnotationBuilder hoverlabel(HoverLabel hoverLabel) { - this.hoverLabel = hoverLabel; - return this; - } - - public AnnotationBuilder captureevents(boolean captureevents) { - this.captureevents = captureevents; - return this; - } - - public AnnotationBuilder name(String name) { - this.name = name; - return this; - } - - public AnnotationBuilder templateitemname(String templateitemname) { - this.templateitemname = templateitemname; - return this; - } - - public Annotation build() { - return new Annotation(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Axis.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Axis.java deleted file mode 100644 index 97b8cbe06..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Axis.java +++ /dev/null @@ -1,734 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static tech.tablesaw.plotly.components.Axis.Spikes.SpikeSnap.DATA; - -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.plotly.Utils; -import tech.tablesaw.plotly.traces.ScatterTrace; - -public class Axis extends Component { - - public enum CategoryOrder { - TRACE("trace"), - CATEGORY_ASCENDING("category ascending"), - CATEGORY_DESCENDING("category descending"), - ARRAY("array"); - - private final String value; - - CategoryOrder(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * Sets the axis type. By default, plotly attempts to determined the axis type by looking into the - * data of the traces that referenced the axis in question. - */ - public enum Type { - LINEAR("linear"), - LOG("log"), - DATE("date"), - CATEGORY("category"), - DEFAULT("-"); - - private final String value; - - Type(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * Determines whether or not the range of this axis is computed in relation to the input data. See - * `rangemode` for more info. If `range` is provided, then `autorange` is set to "False". - */ - public enum AutoRange { - TRUE("true"), - FALSE("false"), - REVERSED("reversed"); - - private final String value; - - AutoRange(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or - * those of the other axis), determines how that happens: by increasing the "range" (default), or - * by decreasing the "domain". - */ - public enum Constrain { - RANGE("range"), - DOMAIN("domain"); - - private final String value; - - Constrain(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or - * those of the other axis), determines which direction we push the originally specified plot - * area. Options are "left", "center" (default), and "right" for x axes, and "top", "middle" - * (default), and "bottom" for y axes. - */ - public enum ConstrainToward { - LEFT("left"), - CENTER("center"), - RIGHT("right"), - TOP("top"), - MIDDLE("middle"), - BOTTOM("bottom"); - - private final String value; - - ConstrainToward(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the - * range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. - * Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, - * keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the - * constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but - * you can only link axes of the same `type`. The linked axis can have the opposite letter (to - * constrain the aspect ratio) or the same letter (to match scales across subplots). Loops - * (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last - * constraint encountered will be ignored to avoid possible inconsistent constraints via - * `scaleratio`. - * - *

TODO: Just make this a string? - */ - public enum ScaleAnchor { - X("/^x([2-9]|[1-9][0-9]+)?$/"), - Y("/^y([2-9]|[1-9][0-9]+)?$/"); - - private final String value; - - ScaleAnchor(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * If "normal", the range is computed in relation to the extrema of the input data. If "tozero"`, - * the range extends to 0, regardless of the input data If "nonnegative", the range is - * non-negative, regardless of the input data. - */ - public enum RangeMode { - NORMAL("normal"), - TO_ZERO("tozero"), - NON_NEGATIVE("nonnegative"); - private final String value; - - RangeMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * Determines whether an x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of - * the plotting area. - */ - public enum Side { - left("left"), // DEFAULT - right("right"), - top("top"), - bottom("bottom"); - - private final String value; - - Side(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - private static final String DEFAULT_COLOR = "#444"; - private static final String DEFAULT_ZERO_LINE_COLOR = "#444"; - private static final String DEFAULT_LINE_COLOR = "#444"; - private static final String DEFAULT_GRID_COLOR = "#eee"; - private static final int DEFAULT_LINE_WIDTH = 1; - - private static final int DEFAULT_ZERO_LINE_WIDTH = 1; - private static final int DEFAULT_GRID_WIDTH = 1; - private static final boolean DEFAULT_SHOW_LINE = true; - private static final boolean DEFAULT_SHOW_GRID = true; - private static final boolean DEFAULT_ZERO_LINE = false; - private static final double DEFAULT_SCALE_RATIO = 1.0; - private static final Constrain DEFAULT_CONSTRAIN_RANGE = Constrain.RANGE; - - private static final AutoRange DEFAULT_AUTO_RANGE = AutoRange.TRUE; - private static final Type DEFAULT_TYPE = Type.DEFAULT; - private static final boolean DEFAULT_VISIBLE = true; - - private final String title; - private final boolean visible; - private final String color; - private final Font font; - private final Font titleFont; - private final Type type; - - private final RangeMode rangeMode; - private final AutoRange autoRange; - private final Object[] range; - private final boolean fixedRange; // true means the axis cannot be zoomed - private final Constrain constrain; - private final ConstrainToward constrainToward; - private final double scaleRatio; - - private final Spikes spikes; - - private final int lineWidth; - private final int zeroLineWidth; - private final int gridWidth; - - private final String lineColor; - private final String zeroLineColor; - private final String gridColor; - - private final boolean showLine; - private final boolean zeroLine; - private final boolean showGrid; - - private final Side side; - private final ScatterTrace.YAxis overlaying; - - private final CategoryOrder categoryOrder; - - private final TickSettings tickSettings; - - private final float[] domain; - - private final String rangeSlider; - - public static AxisBuilder builder() { - return new AxisBuilder(); - } - - private Axis(AxisBuilder builder) { - title = builder.title; - titleFont = builder.titleFont; - type = builder.type; - visible = builder.visible; - color = builder.color; - font = builder.font; - autoRange = builder.autoRange; - range = builder.range; - rangeMode = builder.rangeMode; - fixedRange = builder.fixedRange; - tickSettings = builder.tickSettings; - side = builder.side; - overlaying = builder.overlaying; - spikes = builder.spikes; - - showLine = builder.showLine; - zeroLine = builder.zeroLine; - showGrid = builder.showGrid; - - lineColor = builder.lineColor; - zeroLineColor = builder.zeroLineColor; - gridColor = builder.gridColor; - - lineWidth = builder.lineWidth; - zeroLineWidth = builder.zeroLineWidth; - gridWidth = builder.gridWidth; - - constrain = builder.constrain; - constrainToward = builder.constrainToward; - scaleRatio = builder.scaleRatio; - categoryOrder = builder.categoryOrder; - domain = builder.domain; - rangeSlider = builder.rangeSlider; - } - - @Override - public String asJavascript() { - return asJavascript("axis_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("title", title); - context.put("titleFont", titleFont); - if (visible != DEFAULT_VISIBLE) context.put("visible", visible); - if (!type.equals(DEFAULT_TYPE)) context.put("type", type); - if (!color.equals(DEFAULT_COLOR)) context.put("color", color); - if (font != null) { - context.put("font", font); - } - if (side != null) { - context.put("side", side); - } - if (overlaying != null) { - context.put("overlaying", overlaying); - } - if (!autoRange.equals(DEFAULT_AUTO_RANGE)) context.put("autoRange", autoRange); - context.put("rangeMode", rangeMode); - if (range != null) { - context.put("range", Utils.dataAsString(range)); - } - context.put("fixedRange", fixedRange); - if (scaleRatio != DEFAULT_SCALE_RATIO) context.put("scaleRatio", scaleRatio); - if (!constrain.equals(DEFAULT_CONSTRAIN_RANGE)) context.put("constrain", constrain); - if (constrainToward != null) { - context.put("constrainToward", constrainToward); - } - if (spikes != null) { - spikes.updateContext(context); - } - - if (tickSettings != null) { - tickSettings.updateContext(context); - } - - if (categoryOrder != null) { - context.put("categoryOrder", categoryOrder); - } - - if (gridWidth != DEFAULT_GRID_WIDTH) context.put("gridWidth", gridWidth); - if (lineWidth != DEFAULT_LINE_WIDTH) context.put("lineWidth", lineWidth); - if (zeroLineWidth != DEFAULT_ZERO_LINE_WIDTH) context.put("zeroLineWidth", zeroLineWidth); - if (!lineColor.equals(DEFAULT_LINE_COLOR)) context.put("lineColor", lineColor); - if (!zeroLineColor.equals(DEFAULT_ZERO_LINE_COLOR)) context.put("zeroLineColor", zeroLineColor); - if (!gridColor.equals(DEFAULT_GRID_COLOR)) context.put("gridColor", gridColor); - if (showLine != DEFAULT_SHOW_LINE) context.put("showLine", showLine); - if (zeroLine != DEFAULT_ZERO_LINE) context.put("zeroLine", zeroLine); - if (showGrid != DEFAULT_SHOW_GRID) context.put("showGrid", showGrid); - if (domain != null) { - context.put("domain", String.format("[%.2f, %.2f]", domain[0], domain[1])); - } - if (rangeSlider != null) { - context.put("rangeslider", rangeSlider); - } - return context; - } - - public static class AxisBuilder { - - private Constrain constrain = DEFAULT_CONSTRAIN_RANGE; - private ConstrainToward constrainToward; - private double scaleRatio = DEFAULT_SCALE_RATIO; - - private Font titleFont; - private String title = ""; - private boolean visible = DEFAULT_VISIBLE; - private String color = DEFAULT_COLOR; - private Font font; - private Side side; - - private Type type = DEFAULT_TYPE; - private RangeMode rangeMode = RangeMode.NORMAL; - private AutoRange autoRange = DEFAULT_AUTO_RANGE; - private Object[] range; - private boolean fixedRange = true; // true means the axis cannot be zoomed - - private TickSettings tickSettings; - - private Spikes spikes = null; - - private boolean showLine = DEFAULT_SHOW_LINE; - private String lineColor = DEFAULT_LINE_COLOR; - private int lineWidth = DEFAULT_LINE_WIDTH; - - private boolean zeroLine = DEFAULT_ZERO_LINE; - private String zeroLineColor = DEFAULT_ZERO_LINE_COLOR; - private int zeroLineWidth = DEFAULT_ZERO_LINE_WIDTH; - - private boolean showGrid = DEFAULT_SHOW_GRID; - private String gridColor = DEFAULT_GRID_COLOR; - private int gridWidth = DEFAULT_GRID_WIDTH; - - private ScatterTrace.YAxis overlaying; - - private CategoryOrder categoryOrder; - - private float[] domain = null; - - private String rangeSlider = null; - - private AxisBuilder() {} - - public AxisBuilder title(String title) { - this.title = title; - return this; - } - - public AxisBuilder titleFont(Font titleFont) { - this.titleFont = titleFont; - return this; - } - - public AxisBuilder type(Type type) { - this.type = type; - return this; - } - - public AxisBuilder categoryOrder(CategoryOrder categoryOrder) { - this.categoryOrder = categoryOrder; - return this; - } - - public AxisBuilder domain(float start, float end) { - this.domain = new float[] {start, end}; - return this; - } - - public AxisBuilder visible(boolean visible) { - this.visible = visible; - return this; - } - - public AxisBuilder side(Side side) { - this.side = side; - return this; - } - - /** - * Instructs plotly to overly the trace with this axis on top of a trace with another axis - * - * @param axisToOverlay The axis we want to overlay - * @return this AxisBuilder - */ - public AxisBuilder overlaying(ScatterTrace.YAxis axisToOverlay) { - this.overlaying = axisToOverlay; - return this; - } - - /** Determines whether or not this axis is zoom-able. If True, then zoom is disabled. */ - public AxisBuilder fixedRange(boolean fixedRange) { - this.fixedRange = fixedRange; - return this; - } - - public AxisBuilder color(String color) { - this.color = color; - return this; - } - - public AxisBuilder font(Font font) { - this.font = font; - return this; - } - - /** - * If "normal", the range is computed in relation to the extrema of the input data. If - * "tozero"`, the range extends to 0, regardless of the input data If "nonnegative", the range - * is non-negative, regardless of the input data. - * - *

The default is normal. - */ - public AxisBuilder rangeMode(RangeMode rangeMode) { - this.rangeMode = rangeMode; - return this; - } - - public AxisBuilder spikes(Spikes spikes) { - this.spikes = spikes; - return this; - } - - /** - * Determines whether or not the range of this axis is computed in relation to the input data. - * See `rangemode` for more info. If `range` is provided, then `autorange` is set to "False". - */ - public AxisBuilder autoRange(AutoRange autoRange) { - this.autoRange = autoRange; - if (range != null && autoRange != AutoRange.FALSE) { - throw new IllegalArgumentException( - "Can't set autoRange to anything but FALSE after specifying a range."); - } - return this; - } - - /** - * Sets the range of this axis. If the axis `type` is "log", then you must take the log of your - * desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). - * - *

If the axis `type` is "date", it should be date strings, like date data, though Date - * objects and unix milliseconds will be accepted and converted to strings. If the axis `type` - * is "category", it should be numbers, using the scale where each category is assigned a serial - * number from zero in the order it appears. - */ - public AxisBuilder range(Object[] range) { - this.range = range; - this.autoRange = AutoRange.FALSE; - return this; - } - - /** - * Sets the range of this axis. If the axis `type` is "log", then you must take the log of your - * desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). - * - *

If the axis `type` is "date", it should be date strings, like date data, though Date - * objects and unix milliseconds will be accepted and converted to strings. If the axis `type` - * is "category", it should be numbers, using the scale where each category is assigned a serial - * number from zero in the order it appears. - */ - public AxisBuilder range(Object low, Object high) { - Object[] range = new Object[2]; - range[0] = low; - range[1] = high; - this.range = range; - this.autoRange = AutoRange.FALSE; - return this; - } - - public AxisBuilder constrain(Constrain constrain) { - this.constrain = constrain; - return this; - } - - public AxisBuilder constrainToward(ConstrainToward constrainToward) { - this.constrainToward = constrainToward; - return this; - } - - /** - * If this axis is linked to another by `scaleanchor`, this determines the pixel to unit scale - * ratio. For example, if this value is 10, then every unit on this axis spans 10 times the - * number of pixels as a unit on the linked axis. Use this for example to create an elevation - * profile where the vertical scale is exaggerated a fixed amount with respect to the - * horizontal. - * - * @param scaleRatio a number >= 1 - * @return this AxisBuilder - */ - public AxisBuilder scaleRatio(double scaleRatio) { - Preconditions.checkArgument(scaleRatio >= 1.0); - this.scaleRatio = scaleRatio; - return this; - } - - /** Defines all the settings related to the display of tick marks on this axis */ - public AxisBuilder tickSettings(TickSettings tickSettings) { - this.tickSettings = tickSettings; - return this; - } - - public AxisBuilder lineWidth(int lineWidth) { - Preconditions.checkArgument(lineWidth >= 0); - this.lineWidth = lineWidth; - return this; - } - - public AxisBuilder zeroLineWidth(int zeroLineWidth) { - Preconditions.checkArgument(zeroLineWidth >= 0); - this.zeroLineWidth = zeroLineWidth; - return this; - } - - public AxisBuilder gridWidth(int width) { - Preconditions.checkArgument(width >= 0); - this.gridWidth = width; - return this; - } - - public AxisBuilder lineColor(String color) { - this.lineColor = color; - return this; - } - - public AxisBuilder gridColor(String color) { - this.gridColor = color; - return this; - } - - public AxisBuilder zeroLineColor(String color) { - this.zeroLineColor = color; - return this; - } - - public AxisBuilder showLine(boolean showLine) { - this.showLine = showLine; - return this; - } - - public AxisBuilder showGrid(boolean showGrid) { - this.showGrid = showGrid; - return this; - } - - public AxisBuilder showZeroLine(boolean zeroLine) { - this.zeroLine = zeroLine; - return this; - } - - public AxisBuilder rangeslider(String slider) { - this.rangeSlider = slider; - return this; - } - - public Axis build() { - return new Axis(this); - } - } - - public static class Spikes { - private final String color; - private final int thickness; - private final String dash; - private final SpikeMode mode; - private final SpikeSnap snap; - - private Spikes(SpikesBuilder builder) { - this.color = builder.color; - this.thickness = builder.thickness; - this.dash = builder.dash; - this.mode = builder.mode; - this.snap = builder.snap; - } - - private void updateContext(Map context) { - context.put("showSpikes", true); - context.put("spikeMode", mode); - context.put("spikeThickness", thickness); - context.put("spikeDash", dash); - context.put("spikeColor", color); - context.put("spikeSnap", snap); - } - - public enum SpikeSnap { - DATA("data"), - CURSOR("cursor"); - - private final String value; - - SpikeSnap(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum SpikeMode { - TO_AXIS("toaxis"), - ACROSS("across"), - MARKER("marker"), - TO_AXIS_AND_ACROSS("toaxis+across"), - TO_AXIS_AND_MARKER("toaxis+marker"), - ACROSS_AND_MARKER("across+marker"), - TO_AXIS_AND_ACROSS_AND_MARKER("toaxis+across+marker"); - - private final String value; - - SpikeMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public static SpikesBuilder builder() { - return new SpikesBuilder(); - } - - public static class SpikesBuilder { - private String color = null; - private int thickness = 3; - private String dash = "dash"; - private SpikeMode mode = SpikeMode.TO_AXIS; - private SpikeSnap snap = DATA; - - private SpikesBuilder() {} - - public SpikesBuilder color(String color) { - this.color = color; - return this; - } - - /** - * Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", - * "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg - * "5px,10px,2px,2px"). - */ - public SpikesBuilder dash(String dash) { - this.dash = dash; - return this; - } - - /** - * Any combination of "toaxis", "across", "marker" examples: "toaxis", "across", - * "toaxis+across", "toaxis+across+marker" default: "toaxis" - */ - public SpikesBuilder mode(SpikeMode mode) { - this.mode = mode; - return this; - } - - /** - * Determines whether spikelines are stuck to the cursor or to the closest datapoints. - * default: DATA - */ - public SpikesBuilder snap(SpikeSnap snap) { - this.snap = snap; - return this; - } - - /** Sets the width (in px) of the zero line. default: 3 */ - public SpikesBuilder thickness(int thickness) { - this.thickness = thickness; - return this; - } - - public Spikes build() { - return new Spikes(this); - } - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/ColorBar.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/ColorBar.java deleted file mode 100644 index 405e2e386..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/ColorBar.java +++ /dev/null @@ -1,358 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; - -public class ColorBar extends Component { - - private static final ThicknessMode DEFAULT_THICKNESS_MODE = ThicknessMode.PIXELS; - private static final double DEFAULT_THICKNESS = 30.0; - - private static final LenMode DEFAULT_LEN_MODE = LenMode.FRACTION; - private static final double DEFAULT_LEN = 1.0; - - private static final double DEFAULT_X = 1.02; - private static final double DEFAULT_Y = 0.5; - - private static final int DEFAULT_X_PAD = 10; - private static final int DEFAULT_Y_PAD = 10; - - private static final Xanchor DEFAULT_X_ANCHOR = Xanchor.LEFT; - private static final Yanchor DEFAULT_Y_ANCHOR = Yanchor.MIDDLE; - - private static final String DEFAULT_OUTLINE_COLOR = "444"; - private static final String DEFAULT_BORDER_COLOR = "444"; - - private static final int DEFAULT_BORDER_WIDTH = 1; - private static final int DEFAULT_OUTLINE_WIDTH = 0; - - private static final String DEFAULT_BG_COLOR = "rgba(0,0,0,0)"; - - /** - * Determines whether this color bar's thickness (i.e. the measure in the constant color - * direction) is set in units of plot "fraction" or in "pixels". Use `thickness` to set the value. - */ - public enum ThicknessMode { - FRACTION("fraction"), - PIXELS("pixels"); - - private final String value; - - ThicknessMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum LenMode { - FRACTION("fraction"), - PIXELS("pixels"); - - private final String value; - - LenMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum Xanchor { - LEFT("left"), - CENTER("center"), - RIGHT("right"); - - private final String value; - - Xanchor(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum Yanchor { - TOP("top"), - MIDDLE("middle"), - BOTTOM("bottom"); - - private final String value; - - Yanchor(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - private final ThicknessMode thicknessMode; - - private final double thickness; - - private final LenMode lenMode; - - private final double len; - - private final double x; - - private final int xPad; - - private final int yPad; - - private final double y; - - private final Xanchor xAnchor; - - private final Yanchor yAnchor; - - private final String outlineColor; - - private final int outlineWidth; - - private final String borderColor; - - private final int borderWidth; - - private final String bgColor; - - private final TickSettings tickSettings; - - private ColorBar(ColorBarBuilder builder) { - this.thicknessMode = builder.thicknessMode; - this.lenMode = builder.lenMode; - this.thickness = builder.thickness; - this.len = builder.len; - this.x = builder.x; - this.y = builder.y; - this.xPad = builder.xPad; - this.yPad = builder.yPad; - this.xAnchor = builder.xAnchor; - this.yAnchor = builder.yAnchor; - this.outlineColor = builder.outlineColor; - this.borderColor = builder.borderColor; - this.bgColor = builder.bgColor; - this.borderWidth = builder.borderWidth; - this.outlineWidth = builder.outlineWidth; - this.tickSettings = builder.tickSettings; - } - - @Override - public String asJavascript() { - return asJavascript("colorbar_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - if (!thicknessMode.equals(DEFAULT_THICKNESS_MODE)) context.put("thicknessMode", thicknessMode); - if (!lenMode.equals(DEFAULT_LEN_MODE)) context.put("lenMode", lenMode); - - if (len != DEFAULT_LEN) context.put("len", len); - if (thickness != DEFAULT_THICKNESS) context.put("thickness", thickness); - - if (x != DEFAULT_X) context.put("x", x); - if (y != DEFAULT_Y) context.put("y", y); - - if (xPad != DEFAULT_X_PAD) context.put("xPad", xPad); - if (yPad != DEFAULT_Y_PAD) context.put("yPad", yPad); - - if (borderWidth != DEFAULT_BORDER_WIDTH) context.put("borderWidth", borderWidth); - if (outlineWidth != DEFAULT_OUTLINE_WIDTH) context.put("outlineWidth", outlineWidth); - - if (!xAnchor.equals(DEFAULT_X_ANCHOR)) context.put("xAnchor", xAnchor); - if (!yAnchor.equals(DEFAULT_Y_ANCHOR)) context.put("yAnchor", yAnchor); - - if (!outlineColor.equals(DEFAULT_OUTLINE_COLOR)) context.put("outlineColor", outlineColor); - if (!borderColor.equals(DEFAULT_BORDER_COLOR)) context.put("borderColor", borderColor); - if (!bgColor.equals(DEFAULT_BG_COLOR)) context.put("bgColor", bgColor); - - if (tickSettings != null) tickSettings.updateContext(context); - return context; - } - - public static ColorBarBuilder builder() { - return new ColorBarBuilder(); - } - - public static class ColorBarBuilder { - - private ThicknessMode thicknessMode = DEFAULT_THICKNESS_MODE; - - private double thickness = DEFAULT_THICKNESS; // (number greater than or equal to 0) - - private LenMode lenMode = DEFAULT_LEN_MODE; - - private double len = DEFAULT_LEN; - - private double x = DEFAULT_X; - - private int xPad = DEFAULT_X_PAD; - - private int yPad = DEFAULT_Y_PAD; - - private double y = DEFAULT_Y; - - private Xanchor xAnchor = DEFAULT_X_ANCHOR; - - private Yanchor yAnchor = DEFAULT_Y_ANCHOR; - - private String outlineColor = DEFAULT_OUTLINE_COLOR; - - private int outlineWidth = DEFAULT_OUTLINE_WIDTH; - - private String borderColor = DEFAULT_BORDER_COLOR; - - private int borderWidth = DEFAULT_BORDER_WIDTH; - - private String bgColor = DEFAULT_BG_COLOR; - - private TickSettings tickSettings; - - /** - * Sets the thickness of the color bar, This measure excludes the size of the padding, ticks and - * labels. - * - * @param thickness a double greater than 0 - * @return this ColorBar - */ - public ColorBarBuilder thickness(double thickness) { - Preconditions.checkArgument(thickness >= 0); - this.thickness = thickness; - return this; - } - - /** - * Sets the length of the color bar, This measure excludes the size of the padding, ticks and - * labels. - * - * @param len a double greater than 0 - * @return this ColorBar - */ - public ColorBarBuilder len(double len) { - Preconditions.checkArgument(len >= 0); - this.len = len; - return this; - } - - /** - * Determines whether this color bar's length (i.e. the measure in the color variation - * direction) is set in units of plot "fraction" or in "pixels. Use `len` to set the value. - */ - public ColorBarBuilder lenMode(LenMode lenMode) { - this.lenMode = lenMode; - return this; - } - - public ColorBarBuilder thicknessMode(ThicknessMode mode) { - this.thicknessMode = mode; - return this; - } - - /** - * A number between or equal to -2and 3) default:1.02 Sets the x position of the color bar(in - * plot fraction). - */ - public ColorBarBuilder x(double x) { - Preconditions.checkArgument(x >= -2 && x <= 3); - this.x = x; - return this; - } - - /** - * A number between or equal to -2and 3) default:0.5 Sets the y position of the color bar (in - * plot fraction). - */ - public ColorBarBuilder y(double y) { - Preconditions.checkArgument(y >= -2 && y <= 3); - this.y = y; - return this; - } - - /** - * Sets this color bar's horizontal position anchor. This anchor binds the `x` position to the - * "left", "center" or "right" of the color bar. - */ - public ColorBarBuilder xAnchor(Xanchor xAnchor) { - this.xAnchor = xAnchor; - return this; - } - - /** - * Sets this color bar's vertical position anchor This anchor binds the `y` position to the - * "top", "middle" or "bottom" of the color bar. - */ - public ColorBarBuilder yAnchor(Yanchor yAnchor) { - this.yAnchor = yAnchor; - return this; - } - - /** Sets the amount of paddng (in px) along the y direction. */ - public ColorBarBuilder yPad(int yPad) { - Preconditions.checkArgument(yPad >= 0); - this.yPad = yPad; - return this; - } - - /** Sets the amount of padding(in px) along the x direction. */ - public ColorBarBuilder xPad(int xPad) { - Preconditions.checkArgument(y >= 0); - this.xPad = xPad; - return this; - } - - /** Sets the axis line color. */ - public ColorBarBuilder outlineColor(String outlineColor) { - this.outlineColor = outlineColor; - return this; - } - - /** Sets the color of the border enclosing this color bar. */ - public ColorBarBuilder borderColor(String color) { - this.borderColor = color; - return this; - } - - /** Sets the color of padded area. */ - public ColorBarBuilder bgColor(String color) { - this.bgColor = color; - return this; - } - - /** Sets the width (in px) or the border enclosing this color bar. */ - public ColorBarBuilder borderWidth(int width) { - Preconditions.checkArgument(width >= 0); - this.borderWidth = width; - return this; - } - - /** Sets the width (in px) of the axis line. */ - public ColorBarBuilder outlineWidth(int width) { - Preconditions.checkArgument(width >= 0); - this.outlineWidth = width; - return this; - } - - public ColorBarBuilder tickSettings(TickSettings tickSettings) { - this.tickSettings = tickSettings; - return this; - } - - public ColorBar build() { - return new ColorBar(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Component.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Component.java deleted file mode 100644 index 6f8a8a387..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Component.java +++ /dev/null @@ -1,70 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.mitchellbosecke.pebble.PebbleEngine; -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.Map; - -public abstract class Component { - - protected static final ObjectMapper mapper = new ObjectMapper(); - - static { - mapper.enable(SerializationFeature.INDENT_OUTPUT); - mapper.setSerializationInclusion(Include.NON_NULL); - mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); - } - - private final PebbleEngine engine = TemplateUtils.getNewEngine(); - - protected PebbleEngine getEngine() { - return engine; - } - - @Deprecated - public abstract String asJavascript(); - - @Deprecated - protected abstract Map getContext(); - - protected Map getJSONContext() { - return null; - } - - public String asJSON() { - StringWriter w = new StringWriter(); - try { - mapper.writeValue(w, getJSONContext()); - } catch (IOException ioe) { - throw new UncheckedIOException(ioe); - } - return w.toString(); - } - - protected String asJavascript(String filename) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = getEngine().getTemplate(filename); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - @Override - public String toString() { - return asJavascript(); - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Config.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Config.java deleted file mode 100644 index 69d6548ff..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Config.java +++ /dev/null @@ -1,68 +0,0 @@ -package tech.tablesaw.plotly.components; - -import java.util.HashMap; -import java.util.Map; - -public class Config extends Component { - - private final Boolean displayModeBar; - private final Boolean responsive; - private final Boolean displayLogo; - - private Config(Builder builder) { - this.displayModeBar = builder.displayModeBar; - this.responsive = builder.responsive; - this.displayLogo = builder.displayLogo; - } - - public static Builder builder() { - return new Builder(); - } - - @Override - public String asJavascript() { - return "var config = " + asJSON(); - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("displayModeBar", displayModeBar); - context.put("responsive", responsive); - context.put("displaylogo", displayLogo); - return context; - } - - public static class Builder { - - Boolean displayModeBar; - Boolean responsive; - Boolean displayLogo; - - private Builder() {} - - public Builder displayModeBar(boolean displayModeBar) { - this.displayModeBar = displayModeBar; - return this; - } - - public Builder responsive(boolean responsive) { - this.responsive = responsive; - return this; - } - - public Builder displayLogo(boolean displayLogo) { - this.displayLogo = displayLogo; - return this; - } - - public Config build() { - return new Config(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Domain.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Domain.java deleted file mode 100644 index 83e0aa6e0..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Domain.java +++ /dev/null @@ -1,75 +0,0 @@ -package tech.tablesaw.plotly.components; - -import java.util.HashMap; -import java.util.Map; - -public class Domain extends Component { - - private final Integer row; - private final Integer column; - private final double[] x; - private final double[] y; - - private Domain(DomainBuilder builder) { - this.x = builder.x; - this.y = builder.y; - this.row = builder.row; - this.column = builder.column; - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("column", column); - context.put("row", row); - context.put("x", x); - context.put("y", y); - return context; - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - public static DomainBuilder builder() { - return new DomainBuilder(); - } - - public static class DomainBuilder { - - private Integer row; - private Integer column; - private double[] x; - private double[] y; - - public DomainBuilder row(int row) { - this.row = row; - return this; - } - - public DomainBuilder column(int column) { - this.column = column; - return this; - } - - public DomainBuilder x(double[] x) { - this.x = x; - return this; - } - - public DomainBuilder y(double[] y) { - this.y = y; - return this; - } - - public Domain build() { - return new Domain(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Figure.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Figure.java deleted file mode 100644 index 47352e460..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Figure.java +++ /dev/null @@ -1,230 +0,0 @@ -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 java.io.IOException; -import java.io.StringWriter; -import java.io.UncheckedIOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import tech.tablesaw.plotly.event.EventHandler; -import tech.tablesaw.plotly.traces.Trace; - -/** - * Plotly's graph description places attributes into two categories: traces (objects that describe a - * single series of data in a graph like Scatter or Heatmap) and layout attributes that apply to the - * rest of the chart, like the title, xaxis, or annotations). - * - *

Figure combines the two parts, associating one or more traces with a layout. If the layout is - * null a default layout is provided. - */ -public class Figure { - - private Trace[] data; - private Layout layout; - private Config config; - private EventHandler[] eventHandlers; - - private final Map context = new HashMap<>(); - - private final PebbleEngine engine = TemplateUtils.getNewEngine(); - - public Figure(FigureBuilder builder) { - this.data = builder.traces(); - this.layout = builder.layout; - this.config = builder.config; - this.eventHandlers = builder.eventHandlers(); - } - - public Figure(Trace... traces) { - this((Layout) null, traces); - } - - public Figure(Layout layout, Trace... traces) { - this(layout, (Config) null, traces); - } - - public Figure(Layout layout, Config config, Trace... traces) { - this.data = traces; - this.layout = layout; - this.config = config; - this.eventHandlers = null; - } - - public String divString(String divName) { - return String.format("

" + System.lineSeparator(), divName); - } - - public Layout getLayout() { - 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; - - 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(); - } - - protected void buildContext(String divName) { - - String targetName = "target_" + divName; - context.put("divName", divName); - context.put("targetName", targetName); - - StringBuilder builder = new StringBuilder(); - - if (layout != null) { - builder.append(layout.asJavascript()); - } - if (config != null) { - builder.append(config.asJavascript()); - } - builder.append(System.lineSeparator()); - for (int i = 0; i < data.length; i++) { - Trace trace = data[i]; - builder.append(trace.asJavascript(i)); - builder.append(System.lineSeparator()); - } - builder.append(System.lineSeparator()); - String figure = builder.toString(); - context.put("figure", figure); - context.put("plotFunction", plotFunction(targetName)); - context.put("eventHandlerFunction", eventHandlerFunction(targetName, divName)); - } - - protected String plotFunction(String divName) { - StringBuilder builder = new StringBuilder(); - - builder.append("var data = [ "); - for (int i = 0; i < data.length; i++) { - builder.append("trace").append(i); - if (i < data.length - 1) { - builder.append(", "); - } - } - builder.append("];").append(System.lineSeparator()); - - builder.append("Plotly.newPlot(").append(divName).append(", ").append("data"); - - if (layout != null) { - builder.append(", "); - builder.append("layout"); - } - if (config != null) { - builder.append(", "); - builder.append("config"); - } - - builder.append(");"); - - return builder.toString(); - } - - protected String eventHandlerFunction(String targetName, String divName) { - StringBuilder builder = new StringBuilder(); - - if (eventHandlers != null) { - builder.append(System.lineSeparator()); - for (EventHandler eventHandler : eventHandlers) { - builder.append(eventHandler.asJavascript(targetName, divName)); - } - builder.append(System.lineSeparator()); - } - - return builder.toString(); - } - - public Map getContext() { - return context; - } - - public static FigureBuilder builder() { - return new FigureBuilder(); - } - - public static class FigureBuilder { - - private Layout layout; - private Config config; - private List traces = new ArrayList<>(); - private List eventHandlers = new ArrayList<>(); - - public FigureBuilder layout(Layout layout) { - this.layout = layout; - return this; - } - - public FigureBuilder config(Config config) { - this.config = config; - return this; - } - - public FigureBuilder addTraces(Trace... traces) { - this.traces.addAll(Arrays.asList(traces)); - return this; - } - - public FigureBuilder addEventHandlers(EventHandler... handlers) { - this.eventHandlers.addAll(Arrays.asList(handlers)); - return this; - } - - public Figure build() { - Preconditions.checkState(!traces.isEmpty(), "A figure must have at least one trace"); - return new Figure(this); - } - - private EventHandler[] eventHandlers() { - return eventHandlers.toArray(new EventHandler[0]); - } - - private Trace[] traces() { - return traces.toArray(new Trace[0]); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Font.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Font.java deleted file mode 100644 index 6ea12171a..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Font.java +++ /dev/null @@ -1,119 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -public class Font extends Component { - - /** - * HTML font family - the typeface that will be applied by the web browser. The web browser will - * only be able to apply a font if it is available on the system which it operates. Provide - * multiple font families, separated by commas, to indicate the preference in which to apply fonts - * if they aren't available on the system. The plotly service (at https://plot.ly or on-premise) - * generates images on a server, where only a select number of fonts are installed and supported. - * These include "Arial", "Balto", "Courier New", "Droid Sans",, "Droid Serif", "Droid Sans Mono", - * "Gravitas One", "Old Standard TT", "Open Sans", "Overpass", "PT Sans Narrow", "Raleway", "Times - * New Roman". - */ - public enum Family { - OPEN_SANS("Open Sans"), - VERDANA("verdana"), - ARIAL("arial"), - SANS_SERIF("sans-serif"); - - private final String value; - - Family(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - private final Family fontFamily; - - private final int size; // number greater than or equal to 1 - - private final String color; - - private Font(FontBuilder builder) { - this.color = builder.color; - this.fontFamily = builder.fontFamily; - this.size = builder.size; - } - - public static FontBuilder builder() { - return new FontBuilder(); - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("size", size); - context.put("family", fontFamily); - context.put("color", color); - return context; - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - public static class FontBuilder { - - private Family fontFamily = Family.OPEN_SANS; - - private int size = 12; // number greater than or equal to 1 - - private String color = "#444"; - - private FontBuilder() {} - - public FontBuilder size(int size) { - Preconditions.checkArgument(size >= 1); - this.size = size; - return this; - } - - public FontBuilder color(String color) { - this.color = color; - return this; - } - - public FontBuilder family(Family family) { - this.fontFamily = family; - return this; - } - - public Font build() { - return new Font(this); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Font font = (Font) o; - return size == font.size && fontFamily == font.fontFamily && Objects.equals(color, font.color); - } - - @Override - public int hashCode() { - - return Objects.hash(fontFamily, size, color); - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Gradient.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Gradient.java deleted file mode 100644 index 1542d8b11..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Gradient.java +++ /dev/null @@ -1,92 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.fasterxml.jackson.annotation.JsonValue; -import java.util.HashMap; -import java.util.Map; - -public class Gradient extends Component { - - /** Defines the gradient type */ - public enum Type { - RADIAL("radial"), - HORIZONTAL("horizontal"), - VERTICAL("vertical"), - NONE("none"); - - private final String value; - - Type(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - private final Type type; - private final String[] color; - - private Gradient(GradientBuilder builder) { - this.type = builder.type; - color = builder.color; - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("type", type); - if (color != null && color.length > 0) { - if (color.length > 1) { - context.put("color", color); - } else { - context.put("color", color[0]); - } - } - - return context; - } - - public static GradientBuilder builder() { - return new GradientBuilder(); - } - - public static class GradientBuilder { - - private Type type = Type.NONE; - private String[] color; - - public GradientBuilder type(Type type) { - this.type = type; - return this; - } - - /** Sets the marker color to a single value */ - public GradientBuilder color(String color) { - this.color = new String[1]; - this.color[0] = color; - return this; - } - /** Sets the marker color to an array of color values */ - public GradientBuilder color(String[] color) { - this.color = color; - return this; - } - - public Gradient build() { - return new Gradient(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Grid.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Grid.java deleted file mode 100644 index 75c57630f..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Grid.java +++ /dev/null @@ -1,250 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; - -public class Grid extends Component { - - public enum RowOrder { - ENUMERATED, - TOP_TO_BOTTOM, - BOTTOM_TO_TOP; - - @Override - public String toString() { - return this.name().toLowerCase().replaceAll("_", " "); - } - } - - public enum XSide { - BOTTOM, - BOTTOM_PLOT, - TOP, - TOP_PLOT; - - @Override - public String toString() { - return this.name().toLowerCase().replaceAll("_", " "); - } - } - - public enum YSide { - LEFT, - LEFT_PLOT, - RIGHT, - RIGHT_PLOT; - - @Override - public String toString() { - return this.name().toLowerCase().replaceAll("_", " "); - } - } - - public enum Pattern { - INDEPENDENT, - COUPLED; - - @Override - public String toString() { - return this.name().toLowerCase(); - } - } - - /** - * The number of rows in the grid. If you provide a 2D `subplots` array or a `yaxes` array, its - * length is used as the default. But it's also possible to have a different length, if you want - * to leave a row at the end for non-cartesian subplots. - */ - private final int rows; - - /** - * Is the first row the top or the bottom? Note that columns are always enumerated from left to - * right. - */ - private final RowOrder rowOrder; - - /** - * If no `subplots`, `xaxes`, or `yaxes` are given but we do have `rows` and `columns`,', we can - * generate defaults using consecutive axis IDs, in two ways:', '*coupled* gives one x axis per - * column and one y axis per row.', '*independent* uses a new xy pair for each cell, left-to-right - * across each row', 'then iterating rows according to `roworder`. - */ - private final Pattern pattern; - - /** - * The number of columns in the grid. If you provide a 2D `subplots` array, the length of its - * longest row is used as the default. If you give an `xaxes` array, its length is used as the - * default. But it's also possible to have a different length, if you want to leave a row at the - * end for non-cartesian subplots. - */ - private final int columns; - - /** - * Horizontal space between grid cells, expressed as a fraction of the total width available to - * one cell. Defaults to 0.1 for coupled-axes grids and 0.2 for independent grids. - */ - private final double xGap; // number between or equal to 0 and 1 - - /** - * Vertical space between grid cells, expressed as a fraction of the total height available to one - * cell. Defaults to 0.1 for coupled-axes grids and 0.3 for independent grids. - */ - private final double yGap; // number between or equal to 0 and 1 - - private final XSide xSide; - - private final YSide ySide; - - public Grid(GridBuilder gridBuilder) { - this.rows = gridBuilder.rows; - this.columns = gridBuilder.columns; - this.rowOrder = gridBuilder.rowOrder; - this.xGap = gridBuilder.xGap; - this.yGap = gridBuilder.yGap; - this.pattern = gridBuilder.pattern; - this.xSide = gridBuilder.xSide; - this.ySide = gridBuilder.ySide; - } - - @Override - public String asJavascript() { - return asJavascript("grid_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("xGap", xGap); - context.put("yGap", yGap); - context.put("rows", rows); - context.put("columns", columns); - context.put("rowOrder", rowOrder); - context.put("pattern", pattern); - context.put("xSide", xSide); - context.put("ySide", ySide); - return context; - } - - public static GridBuilder builder() { - return new GridBuilder(); - } - - public static class GridBuilder { - - private int rows = 80; - - private int columns = 80; - - private double xGap = 100; - - private double yGap = 80; - - private XSide xSide = XSide.BOTTOM; - - private YSide ySide = YSide.LEFT; - - private RowOrder rowOrder = RowOrder.TOP_TO_BOTTOM; - private Pattern pattern = Pattern.COUPLED; - - private GridBuilder() {} - - /** - * The number of rows in the grid. If you provide a 2D `subplots` array or a `yaxes` array, its - * length is used as the default. But it's also possible to have a different length, if you want - * to leave a row at the end for non-cartesian subplots. - * - * @param rows an integer greater than or equal to 1 - * @return this GridBuilder - */ - public GridBuilder rows(int rows) { - Preconditions.checkArgument(rows >= 1); - this.rows = rows; - return this; - } - - /** - * The number of columns in the grid. If you provide a 2D `subplots` array, the length of its - * longest row is used as the default. If you give an `xaxes` array, its length is used as the - * default. But it's also possible to have a different length, if you want to leave a row at the - * end for non-cartesian subplots. - * - * @param columns an integer greater than or equal to 1 - * @return this GridBuilder - */ - public GridBuilder columns(int columns) { - Preconditions.checkArgument(rows >= 1); - this.columns = columns; - return this; - } - - /** - * Horizontal space between grid cells, expressed as a fraction of the total width available to - * one cell. Defaults to 0.1 for coupled-axes grids and 0.2 for independent grids. - * - * @param xGap a double >= 0 && <= 1 - * @return this GridBuilder - */ - public GridBuilder xGap(double xGap) { - Preconditions.checkArgument(xGap >= 0 && xGap <= 1); - this.xGap = xGap; - return this; - } - - /** - * Vertical space between grid cells, expressed as a fraction of the total height available to - * one cell. Defaults to 0.1 for coupled-axes grids and 0.3 for independent grids. - * - * @param yGap a double >= 0 && <= 1 - * @return this GridBuilder - */ - public GridBuilder yGap(double yGap) { - Preconditions.checkArgument(yGap >= 0 && yGap <= 1); - this.yGap = yGap; - return this; - } - - /** - * Sets where the y axis labels and titles go. "left" means the very left edge of the grid. - * "left plot" is the leftmost plot that each y axis is used in. "right" and "right plot" are - * similar. - */ - public GridBuilder ySide(YSide ySide) { - this.ySide = ySide; - return this; - } - - /** - * Sets where the x axis labels and titles go. "bottom" means the very bottom of the grid. - * "bottom plot" is the lowest plot that each x axis is used in. "top" and "top plot" are - * similar. - */ - public GridBuilder xSide(XSide xSide) { - this.xSide = xSide; - return this; - } - - public GridBuilder rowOrder(RowOrder rowOrder) { - this.rowOrder = rowOrder; - return this; - } - - /** - * If no `subplots`, `xaxes`, or `yaxes` are given but we do have `rows` and `columns`,', we can - * generate defaults using consecutive axis IDs, in two ways:', '*coupled* gives one x axis per - * column and one y axis per row.', '*independent* uses a new xy pair for each cell, - * left-to-right across each row', 'then iterating rows according to `roworder`. - * - * @param pattern defaults to COUPLED - * @return this GridBuilder - */ - public GridBuilder pattern(Pattern pattern) { - this.pattern = pattern; - return this; - } - - public Grid build() { - return new Grid(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/HoverLabel.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/HoverLabel.java deleted file mode 100644 index 5ac1ae024..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/HoverLabel.java +++ /dev/null @@ -1,99 +0,0 @@ -package tech.tablesaw.plotly.components; - -import java.util.HashMap; -import java.util.Map; - -public class HoverLabel extends Component { - - /** Sets the background color of all hover labels on graph */ - private final String bgColor; - - /** Sets the border color of all hover labels on graph. */ - private final String borderColor; - - /** Sets the default hover label font used by all traces on the graph. */ - private final Font font; - - /** - * Sets the default length (in number of characters) of the trace name in the hover labels for all - * traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, and - * an integer >3 will show the whole name if it is less than that many characters, but if it is - * longer, will truncate to `namelength - 3` characters and add an ellipsis. - */ - private final int nameLength; - - HoverLabel(HoverLabelBuilder builder) { - this.bgColor = builder.bgColor; - this.borderColor = builder.borderColor; - this.font = builder.font; - this.nameLength = builder.nameLength; - } - - public static HoverLabelBuilder builder() { - return new HoverLabelBuilder(); - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getJSONContext() { - Map context = new HashMap<>(); - context.put("bgcolor", bgColor); - context.put("bordercolor", borderColor); - context.put("namelength", nameLength); - context.put("font", font.getJSONContext()); - return context; - } - - @Override - protected Map getContext() { - return getJSONContext(); - } - - public static class HoverLabelBuilder { - - /** Sets the background color of all hover labels on graph */ - private String bgColor = ""; - - /** Sets the border color of all hover labels on graph. */ - private String borderColor = ""; - - /** Sets the default hover label font used by all traces on the graph. */ - private Font font; - - /** - * Sets the default length (in number of characters) of the trace name in the hover labels for - * all traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, - * and an integer >3 will show the whole name if it is less than that many characters, but if it - * is longer, will truncate to `namelength - 3` characters and add an ellipsis. - */ - private int nameLength = 15; - - public HoverLabel build() { - return new HoverLabel(this); - } - - public HoverLabelBuilder nameLength(int nameLength) { - this.nameLength = nameLength; - return this; - } - - public HoverLabelBuilder font(Font font) { - this.font = font; - return this; - } - - public HoverLabelBuilder borderColor(String borderColor) { - this.borderColor = borderColor; - return this; - } - - public HoverLabelBuilder bgColor(String bgColor) { - this.bgColor = bgColor; - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Layout.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Layout.java deleted file mode 100644 index fdc2571f5..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Layout.java +++ /dev/null @@ -1,494 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.mitchellbosecke.pebble.PebbleEngine; -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.threeD.Scene; - -public class Layout { - - private static final int DEFAULT_HEIGHT = 600; - private static final int DEFAULT_WIDTH = 800; - private static final String DEFAULT_TITLE = ""; - private static final String DEFAULT_PAPER_BG_COLOR = "#fff"; - private static final String DEFAULT_PLOT_BG_COLOR = "#fff"; - private static final String DEFAULT_DECIMAL_SEPARATOR = "."; - private static final String DEFAULT_THOUSANDS_SEPARATOR = ","; - private static final boolean DEFAULT_AUTO_SIZE = false; - private static final HoverMode DEFAULT_HOVER_MODE = HoverMode.FALSE; - private static final DragMode DEFAULT_DRAG_MODE = DragMode.ZOOM; - private static final int DEFAULT_HOVER_DISTANCE = 20; - private static final BarMode DEFAULT_BAR_MODE = BarMode.GROUP; - private static final Font DEFAULT_TITLE_FONT = Font.builder().build(); - private static final Font DEFAULT_FONT = Font.builder().build(); - - private final PebbleEngine engine = TemplateUtils.getNewEngine(); - private final Scene scene; - - /** Determines the mode of hover interactions. */ - public enum HoverMode { - X("x"), - Y("y"), - CLOSEST("closest"), - FALSE("false"); - - private final String value; - - HoverMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * Determines the display mode for bars when you have multiple bar traces. This also applies to - * histogram bars. Group is the default. - * - *

With "stack", the bars are stacked on top of one another. With "relative", the bars are - * stacked on top of one another, but with negative values below the axis, positive values above. - * With "group", the bars are plotted next to one another centered around the shared location. - * With "overlay", the bars are plotted over one another, provide an "opacity" to see through the - * overlaid bars. - */ - public enum BarMode { - STACK("stack"), - GROUP("group"), - OVERLAY("overlay"), - RELATIVE("relative"); - - private final String value; - - BarMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** - * Determines the mode of drag interactions. "select" and "lasso" apply only to scatter traces - * with markers or text. "orbit" and "turntable" apply only to 3D scenes. - */ - public enum DragMode { - ZOOM("zoom"), - PAN("pan"), - SELECT("select"), - LASSO("lasso"), - ORBIT("orbit"), - TURNTABLE("turntable"); - - private final String value; - - DragMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** The global font */ - private final Font font; - - /* - * The plot title - */ - private final String title; - - /** Sets the title font */ - private final Font titleFont; - - /** - * Determines whether or not a layout width or height that has been left undefined by the user is - * initialized on each re-layout. Note that, regardless of this attribute, an undefined layout - * width or height is always initialized on the first call to plot. - */ - private final boolean autoSize; - - private final boolean heightSet; - private final boolean widthSet; - - /** The width of the plot in pixels */ - private final int width; - - /** The height of the plot in pixels */ - private final int height; - - /** Sets the margins around the plot */ - private final Margin margin; - - /** Sets the color of paper where the graph is drawn. */ - private final String paperBgColor; - - /** Sets the color of plotting area in-between x and y axes. */ - private final String plotBgColor; - - /** Sets the decimal. For example, "." puts a '.' before decimals */ - private final String decimalSeparator; - - /** Sets the separator. For example, a " " puts a space between thousands. */ - private final String thousandsSeparator; - - /** Determines whether or not a legend is drawn. */ - private final Boolean showLegend; - - /** Determines the mode of hover interactions. */ - private final HoverMode hoverMode; - - /** - * Determines the mode of drag interactions. "select" and "lasso" apply only to scatter traces - * with markers or text. "orbit" and "turntable" apply only to 3D scenes. - */ - private final DragMode dragMode; - - /** - * Sets the default distance (in pixels) to look for data to add hover labels (-1 means no cutoff, - * 0 means no looking for data). This is only a real distance for hovering on point-like objects, - * like scatter points. For area-like objects (bars, scatter fills, etc) hovering is on inside the - * area and off outside, but these objects will not supersede hover on point-like objects in case - * of conflict. - */ - private final int hoverDistance; - - private final Axis xAxis; - - private final Axis yAxis; - - private final Axis yAxis2; - private final Axis yAxis3; - private final Axis yAxis4; - - private final Axis zAxis; - - private final Grid grid; - - private final BarMode barMode; - - private Layout(LayoutBuilder builder) { - this.title = builder.title; - this.autoSize = builder.autoSize; - this.widthSet = builder.widthSet; - this.heightSet = builder.heightSet; - this.decimalSeparator = builder.decimalSeparator; - this.thousandsSeparator = builder.thousandsSeparator; - this.dragMode = builder.dragMode; - this.font = builder.font; - this.titleFont = builder.titleFont; - this.hoverDistance = builder.hoverDistance; - this.hoverMode = builder.hoverMode; - this.margin = builder.margin; - this.height = builder.height; - this.width = builder.width; - this.xAxis = builder.xAxis; - this.yAxis = builder.yAxis; - this.zAxis = builder.zAxis; - this.yAxis2 = builder.yAxis2; - this.yAxis3 = builder.yAxis3; - this.yAxis4 = builder.yAxis4; - this.paperBgColor = builder.paperBgColor; - this.plotBgColor = builder.plotBgColor; - this.showLegend = builder.showLegend; - this.barMode = builder.barMode; - this.scene = builder.scene; - this.grid = builder.grid; - } - - public String getTitle() { - return title; - } - - public String asJavascript() { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - try { - compiledTemplate = engine.getTemplate("layout_template.html"); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - protected Map getContext() { - Map context = new HashMap<>(); - if (!title.equals(DEFAULT_TITLE)) context.put("title", title); - if (!titleFont.equals(DEFAULT_TITLE_FONT)) context.put("titlefont", titleFont); - if (!font.equals(DEFAULT_FONT)) context.put("font", font); - if (autoSize != DEFAULT_AUTO_SIZE) { - context.put("autosize", autoSize); - // since autosize is true, we assume the default width / height values are not wanted, not - // serialize them, and let Plotly compute them - if (widthSet) { - context.put("width", width); - } - if (heightSet) { - context.put("height", height); - } - } else { - context.put("width", width); - context.put("height", height); - } - if (hoverDistance != DEFAULT_HOVER_DISTANCE) context.put("hoverdistance", hoverDistance); - if (!hoverMode.equals(DEFAULT_HOVER_MODE)) context.put("hoverMode", hoverMode); - if (margin != null) { - context.put("margin", margin); - } - if (!decimalSeparator.equals(DEFAULT_DECIMAL_SEPARATOR)) - context.put("decimalSeparator", decimalSeparator); - if (!thousandsSeparator.equals(DEFAULT_THOUSANDS_SEPARATOR)) - context.put("thousandsSeparator", thousandsSeparator); - if (!dragMode.equals(DEFAULT_DRAG_MODE)) context.put("dragmode", dragMode); - if (showLegend != null) { - context.put("showlegend", showLegend); - } - if (!plotBgColor.equals(DEFAULT_PLOT_BG_COLOR)) context.put("plotbgcolor", plotBgColor); - if (!paperBgColor.equals(DEFAULT_PAPER_BG_COLOR)) context.put("paperbgcolor", paperBgColor); - if (!barMode.equals(DEFAULT_BAR_MODE)) context.put("barMode", barMode); - if (scene != null) context.put("scene", scene); - - if (xAxis != null) { - context.put("xAxis", xAxis); - } - if (yAxis != null) { - context.put("yAxis", yAxis); - } - if (yAxis2 != null) { - context.put("yAxis2", yAxis2); - } - if (yAxis3 != null) { - context.put("yAxis3", yAxis3); - } - if (yAxis4 != null) { - context.put("yAxis4", yAxis4); - } - if (zAxis != null) { // TODO: remove? It's in scene for 3d scatters at least. - context.put("zAxis", zAxis); - } - if (grid != null) { - context.put("grid", grid); - } - return context; - } - - public static LayoutBuilder builder() { - return new LayoutBuilder(); - } - - public static LayoutBuilder builder(String title) { - return Layout.builder().title(title).height(DEFAULT_HEIGHT).width(DEFAULT_WIDTH); - } - - public static LayoutBuilder builder(String title, String xTitle) { - return Layout.builder(title).xAxis(Axis.builder().title(xTitle).build()); - } - - public static LayoutBuilder builder(String title, String xTitle, String yTitle) { - return Layout.builder(title, xTitle).yAxis(Axis.builder().title(yTitle).build()); - } - - public static class LayoutBuilder { - - /** The global font */ - private final Font font = DEFAULT_FONT; - - /** The plot title */ - private String title = ""; - - /** Sets the title font */ - private Font titleFont = DEFAULT_TITLE_FONT; - - /** - * Determines whether or not a layout width or height that has been left undefined by the user - * is initialized on each relayout. Note that, regardless of this attribute, an undefined layout - * width or height is always initialized on the first call to plot. - */ - private boolean autoSize = false; - - private boolean widthSet = false; - private boolean heightSet = false; - - /** The width of the plot in pixels */ - private int width = 700; - - /** The height of the plot in pixels */ - private int height = 450; - - /** Sets the margins around the plot */ - private Margin margin; - - /** Sets the color of paper where the graph is drawn. */ - private String paperBgColor = DEFAULT_PAPER_BG_COLOR; - - /** Sets the color of plotting area in-between x and y axes. */ - private String plotBgColor = DEFAULT_PLOT_BG_COLOR; - - /** Sets the decimal. For example, "." puts a '.' before decimals */ - private final String decimalSeparator = DEFAULT_DECIMAL_SEPARATOR; - - /** Sets the separator. For example, a " " puts a space between thousands. */ - private final String thousandsSeparator = DEFAULT_THOUSANDS_SEPARATOR; - - /** Determines whether or not a legend is drawn. */ - private Boolean showLegend = null; - - /** Determines the mode of hover interactions. */ - private HoverMode hoverMode = DEFAULT_HOVER_MODE; - - /** - * Determines the mode of drag interactions. "select" and "lasso" apply only to scatter traces - * with markers or text. "orbit" and "turntable" apply only to 3D scenes. - */ - private final DragMode dragMode = DEFAULT_DRAG_MODE; - - /** - * Sets the default distance (in pixels) to look for data to add hover labels (-1 means no - * cutoff, 0 means no looking for data). This is only a real distance for hovering on point-like - * objects, like scatter points. For area-like objects (bars, scatter fills, etc) hovering is on - * inside the area and off outside, but these objects will not supersede hover on point-like - * objects in case of conflict. - */ - private int hoverDistance = DEFAULT_HOVER_DISTANCE; // greater than or equal to -1 - - private Axis xAxis; - - private Axis yAxis; - - private Axis yAxis2; - private Axis yAxis3; - private Axis yAxis4; - - private Axis zAxis; - - private BarMode barMode = DEFAULT_BAR_MODE; - - private Scene scene; - - /** Define grid to use when creating subplots */ - private Grid grid; - - public Layout build() { - return new Layout(this); - } - - private LayoutBuilder() {} - - public LayoutBuilder title(String title) { - this.title = title; - return this; - } - - public LayoutBuilder titleFont(Font titleFont) { - this.titleFont = titleFont; - return this; - } - - public LayoutBuilder barMode(BarMode barMode) { - this.barMode = barMode; - return this; - } - - public LayoutBuilder margin(Margin margin) { - this.margin = margin; - return this; - } - - public LayoutBuilder scene(Scene scene) { - this.scene = scene; - return this; - } - - public LayoutBuilder hoverMode(HoverMode hoverMode) { - this.hoverMode = hoverMode; - return this; - } - - public LayoutBuilder hoverDistance(int distance) { - this.hoverDistance = distance; - return this; - } - - public LayoutBuilder showLegend(boolean showLegend) { - this.showLegend = showLegend; - return this; - } - - public LayoutBuilder height(int height) { - this.height = height; - this.heightSet = true; - return this; - } - - public LayoutBuilder width(int width) { - this.width = width; - this.widthSet = true; - return this; - } - - public LayoutBuilder autosize(boolean autosize) { - this.autoSize = autosize; - return this; - } - - public LayoutBuilder xAxis(Axis axis) { - this.xAxis = axis; - return this; - } - - public LayoutBuilder yAxis(Axis axis) { - this.yAxis = axis; - return this; - } - - public LayoutBuilder yAxis2(Axis axis) { - this.yAxis2 = axis; - return this; - } - - public LayoutBuilder yAxis3(Axis axis) { - this.yAxis3 = axis; - return this; - } - - public LayoutBuilder yAxis4(Axis axis) { - this.yAxis4 = axis; - return this; - } - - public LayoutBuilder zAxis(Axis axis) { - this.zAxis = axis; - return this; - } - - public LayoutBuilder plotBgColor(String color) { - this.plotBgColor = color; - return this; - } - - public LayoutBuilder paperBgColor(String color) { - this.paperBgColor = color; - return this; - } - - public LayoutBuilder grid(Grid grid) { - this.grid = grid; - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Line.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Line.java deleted file mode 100644 index 2b1f331f1..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Line.java +++ /dev/null @@ -1,158 +0,0 @@ -package tech.tablesaw.plotly.components; - -import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; - -public class Line extends Component { - - public enum Dash { - SOLID("solid"), - DASH("dash"), - DOT("dot"), - LONG_DASH("longdash"), - LONG_DASH_DOT("longdashdot"), - DASH_DOT("dashdot"); - - private final String value; - - Dash(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - private final String color; - private final double width; - private final double smoothing; - private final Shape shape; - private final Dash dash; - private final boolean simplify; - - private Line(LineBuilder builder) { - this.color = builder.color; - this.shape = builder.shape; - this.smoothing = builder.smoothing; - this.dash = builder.dash; - this.simplify = builder.simplify; - this.width = builder.width; - } - - @Override - public Map getContext() { - Map context = new HashMap<>(); - context.put("color", color); - context.put("width", width); - context.put("shape", shape); - context.put("smoothing", smoothing); - context.put("dash", dash); - context.put("simplify", simplify); - return context; - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - @Override - public String asJavascript() { - return asJSON(); - } - - /** - * Determines the shape of the line Linear (i.e. straight lines) is the default. With "spline" the - * lines are drawn using spline interpolation. The other available values correspond to step-wise - * line shapes. - */ - public enum Shape { - LINEAR("linear"), - SPLINE("spline"), - HV("hv"), - VH("vh"), - HVH("hvh"), - VHV("vhv"); - - private final String value; - - Shape(String value) { - this.value = value; - } - - @JsonValue - @Override - public String toString() { - return value; - } - } - - public static LineBuilder builder() { - return new LineBuilder(); - } - - public static class LineBuilder { - private String color; - private double width = 2; - private double smoothing = 1; - private Shape shape = Shape.LINEAR; - private Dash dash = Dash.SOLID; - private boolean simplify = true; - - /** Sets the line color */ - public LineBuilder color(String color) { - this.color = color; - return this; - } - - public LineBuilder width(double width) { - Preconditions.checkArgument(width >= 0, "Line width must be >= 0."); - this.width = width; - return this; - } - - /** - * Sets the smoothing parameter - * - * @param smoothing a value between 0 and 1.3, inclusive - */ - public LineBuilder smoothing(double smoothing) { - Preconditions.checkArgument( - smoothing >= 0 && smoothing <= 1.3, - "Smoothing parameter must be between 0 and 1.3, inclusive."); - this.smoothing = smoothing; - return this; - } - - public LineBuilder dash(Dash dash) { - this.dash = dash; - return this; - } - - /** - * Simplifies lines by removing nearly-collinear points. When transitioning lines, it may be - * desirable to disable this so that the number of points along the resulting SVG path is - * unaffected. - * - * @param b true if you want to simplify. True is the default - */ - public LineBuilder simplify(boolean b) { - this.simplify = b; - return this; - } - - public LineBuilder shape(Shape shape) { - this.shape = shape; - return this; - } - - public Line build() { - return new Line(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Margin.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Margin.java deleted file mode 100644 index 8bcfdfecc..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Margin.java +++ /dev/null @@ -1,115 +0,0 @@ -package tech.tablesaw.plotly.components; - -import java.util.HashMap; -import java.util.Map; - -/** The margin for the plot */ -public class Margin extends Component { - - /** The left margin, in px */ - private final int left; - - /** The right margin, in px */ - private final int right; - - /** The top margin, in px */ - private final int top; - - /** The bottom margin, in px */ - private final int bottom; - - /** The amount of padding between the plotting area and the axis lines, in px */ - private final int pad; - - private final boolean autoExpand; - - public static MarginBuilder builder() { - return new MarginBuilder(); - } - - private Margin(MarginBuilder builder) { - this.left = builder.left; - this.right = builder.right; - this.top = builder.top; - this.bottom = builder.bottom; - this.pad = builder.pad; - this.autoExpand = builder.autoExpand; - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("t", top); - context.put("b", bottom); - context.put("r", right); - context.put("l", left); - context.put("pad", pad); - context.put("autoexpand", autoExpand); - return context; - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - public static class MarginBuilder { - /** The left margin, in px */ - private int left = 80; - - /** The right margin, in px */ - private int right = 80; - - /** The top margin, in px */ - private int top = 100; - - /** The bottom margin, in px */ - private int bottom = 80; - - /** The amount of padding between the plotting area and the axis lines, in px */ - private int pad = 0; - - private boolean autoExpand = true; - - private MarginBuilder() {} - - public MarginBuilder top(int top) { - this.top = top; - return this; - } - - public MarginBuilder bottom(int bottom) { - this.bottom = bottom; - return this; - } - - public MarginBuilder left(int left) { - this.left = left; - return this; - } - - public MarginBuilder right(int right) { - this.right = right; - return this; - } - - public MarginBuilder padding(int padding) { - this.pad = padding; - return this; - } - - public MarginBuilder autoExpand(boolean autoExpand) { - this.autoExpand = autoExpand; - return this; - } - - public Margin build() { - return new Margin(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Marker.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Marker.java deleted file mode 100644 index de1beab36..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Marker.java +++ /dev/null @@ -1,322 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static tech.tablesaw.plotly.components.Marker.SizeMode.DIAMETER; - -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.plotly.Utils; - -public class Marker extends Component { - - public enum SizeMode { - AREA("area"), - DIAMETER("diameter"); - - private final String value; - - SizeMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** Predefined palettes */ - public enum Palette { - GREYS("Greys"), - GREENS("Greens"), - YL_GN_BU("YlGnBu"), - YL_OR_RD("YlOrRd"), - BLUE_RED("Bluered"), - RD_BU("RdBu"), - REDS("Reds"), - BLUES("Blues"), - PICNIC("Picnic"), - RAINBOW("Rainbow"), - PORTLAND("Portland"), - JET("Jet"), - HOT("Hot"), - BLACKBODY("Blackbody"), - EARTH("Earth"), - ELECTRIC("Electric"), - VIRIDIS("Viridis"), - CIVIDIS("Cividis"); - - private final String value; - - Palette(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - private static final boolean DEFAULT_C_AUTO = true; - private static final boolean DEFAULT_AUTO_COLOR_SCALE = true; - private static final boolean DEFAULT_SHOW_SCALE = false; - private static final boolean DEFAULT_REVERSE_SCALE = false; - private static final double DEFAULT_OPACITY = 1.0; - private static final SizeMode DEFAULT_SIZE_MODE = DIAMETER; - - private final double[] size; - private final Line line; - private final String[] color; - private final Palette colorScalePalette; - private final boolean cAuto; - private final double cMin; - private final double cMax; - private final boolean autoColorScale; - private final boolean showScale; - private final boolean reverseScale; - private final double opacity; - private final Symbol symbol; - private final SizeMode sizeMode; - private final Gradient gradient; - private final double[] colorArray; - private final ColorBar colorBar; - - public static MarkerBuilder builder() { - return new MarkerBuilder(); - } - - private Marker(MarkerBuilder builder) { - symbol = builder.symbol; - line = builder.line; - size = builder.size; - color = builder.color; - colorArray = builder.colorArray; - gradient = builder.gradient; - colorScalePalette = builder.colorScalePalette; - cAuto = builder.cAuto; - cMin = builder.cMin; - cMax = builder.cMax; - autoColorScale = builder.autoColorScale; - showScale = builder.showScale; - reverseScale = builder.reverseScale; - opacity = builder.opacity; - sizeMode = builder.sizeMode; - colorBar = builder.colorBar; - } - - @Override - public String asJavascript() { - return asJavascript("marker_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("size", size.length == 1 ? size[0] : Utils.dataAsString(size)); - if (colorScalePalette != null) { - context.put("colorScale", colorScalePalette); - } - if (cAuto != DEFAULT_C_AUTO) context.put("cAuto", cAuto); - if (color != null && color.length > 0) { - if (color.length > 1) { - context.put("color", Utils.dataAsString(color)); - context.put("cMin", cMin); - context.put("cMax", cMax); - } else { - context.put("color", Utils.quote(color[0])); - } - } else if (colorArray != null) { - context.put("color", Utils.dataAsString(colorArray)); - } - if (line != null) context.put("line", line.asJavascript()); - if (autoColorScale != DEFAULT_AUTO_COLOR_SCALE) context.put("autoColorScale", autoColorScale); - if (showScale != DEFAULT_SHOW_SCALE) context.put("showScale", showScale); - if (reverseScale != DEFAULT_REVERSE_SCALE) context.put("reverseScale", reverseScale); - if (opacity != DEFAULT_OPACITY) context.put("opacity", opacity); - if (sizeMode != DEFAULT_SIZE_MODE) context.put("sizeMode", sizeMode); - if (gradient != null) context.put("gradient", gradient); - if (colorBar != null) context.put("colorBar", colorBar.asJavascript()); - context.put("symbol", symbol); - return context; - } - - public static class MarkerBuilder { - - private double[] size = {6}; - - // Note, a marker can have a color, or color array, but not both - private String[] color; - private double[] colorArray; - - private Gradient gradient; - private Palette colorScalePalette; - private boolean cAuto = DEFAULT_C_AUTO; - private double cMin; - private double cMax; - private Line line; - private boolean autoColorScale = DEFAULT_AUTO_COLOR_SCALE; - private boolean showScale = DEFAULT_SHOW_SCALE; - private boolean reverseScale = DEFAULT_REVERSE_SCALE; - private double opacity = DEFAULT_OPACITY; - private Symbol symbol; - private SizeMode sizeMode = DEFAULT_SIZE_MODE; - private ColorBar colorBar; - - public MarkerBuilder size(double... size) { - String errorMessage = "All sizes in size array must be greater than 0."; - for (double d : size) { - Preconditions.checkArgument(d > 0, errorMessage); - } - this.size = size; - return this; - } - - public MarkerBuilder size(NumericColumn size) { - return size(size.asDoubleArray()); - } - - /** - * Has an effect only if `marker.color` is set to a numerical array and `cmin`, `cmax` are also - * set. In this case, it controls whether the range of colors in `colorscale` is mapped to the - * range of values in the `color` array (`cauto: True`), or the `cmin`/`cmax` values (`cauto: - * False`). - * - *

Defaults to `False` when `cmin`, `cmax` are set by the user. - */ - public MarkerBuilder cAuto(boolean b) { - this.cAuto = b; - return this; - } - - /** - * Has an effect only if `marker.color` is set to a numerical array. Reverses the color mapping - * if True (`cmin` will correspond to the last color in the array and `cmax` will correspond to - * the first color). - */ - public MarkerBuilder reverseScale(boolean b) { - this.reverseScale = b; - return this; - } - - /** Sets an outline around the marker */ - public MarkerBuilder line(Line line) { - this.line = line; - return this; - } - - /** Sets a gradient for the marker */ - public MarkerBuilder gradient(Gradient gradient) { - this.gradient = gradient; - return this; - } - - /** Sets the ColorBar to display the scale for the marker */ - public MarkerBuilder colorBar(ColorBar colorBar) { - this.colorBar = colorBar; - return this; - } - - /** - * Has an effect only if `marker.color` is set to a numerical array. Determines whether the - * colorscale is a default palette (`autocolorscale: True`) or the palette determined by - * `marker.colorscale`. In case `colorscale` is unspecified or `autocolorscale` is True, the - * default palette will be chosen according to whether numbers in the `color` array are all - * positive, all negative or mixed. - * - *

Defaults to true - */ - public MarkerBuilder autoColorScale(boolean b) { - this.autoColorScale = b; - return this; - } - - /** - * Has an effect only if `marker.color` is set to a numerical array. Sets the lower and upper - * bound of the color domain. Values should be associated to the `marker.color` array index - */ - public MarkerBuilder cMinAndMax(double min, double max) { - this.cMin = min; - this.cMax = max; - return this; - } - - /** - * Has an effect only if `marker.color` is set to a numerical array. Determines whether or not a - * colorbar is displayed. - */ - public MarkerBuilder showScale(boolean b) { - this.showScale = b; - return this; - } - - /** - * Sets the colorscale and only has an effect if `marker.color` is set to a numerical array. The - * colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, - * hex, hsl, hsv, or named color string. - * - *

At minimum, a mapping for the lowest (0) and highest (1) values are required. For example, - * `[[0, 'rgb(0,0,255)', [1, 'rgb(255,0,0)']]`. - * - *

To control the bounds of the colorscale in color space, use `marker.cmin` and - * `marker.cmax`. - */ - public MarkerBuilder colorScale(Palette palette) { - this.colorScalePalette = palette; - return this; - } - - /** Sets the opacity. Value must be between 0 and 1 inclusive */ - public MarkerBuilder opacity(double opacity) { - Preconditions.checkArgument(opacity >= 0 && opacity <= 1); - this.opacity = opacity; - return this; - } - - /** Sets the marker color to a single value */ - public MarkerBuilder color(String color) { - this.color = new String[1]; - this.color[0] = color; - this.colorArray = null; - return this; - } - - /** Sets the marker color to an array of color values */ - public MarkerBuilder color(String[] color) { - this.color = color; - this.colorArray = null; - return this; - } - - /** - * Sets the marker color to an array of numeric values for use when a color scale is provided - */ - public MarkerBuilder color(double[] color) { - this.colorArray = color; - this.color = null; - return this; - } - - /** Sets the symbol for the marker */ - public MarkerBuilder symbol(Symbol symbol) { - this.symbol = symbol; - return this; - } - - /** - * Sets the size mode for the marker - * - *

Has an effect only if `marker.size` is set to a numerical array. Sets the rule for which - * the data in `size` is converted to pixels, either as area or the diameter - */ - public MarkerBuilder sizeMode(SizeMode sizeMode) { - this.sizeMode = sizeMode; - return this; - } - - public Marker build() { - return new Marker(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Page.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Page.java deleted file mode 100644 index 77d518306..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Page.java +++ /dev/null @@ -1,60 +0,0 @@ -package tech.tablesaw.plotly.components; - -import java.util.HashMap; -import java.util.Map; - -/** Represents an entire html page that contains a figure */ -public class Page extends Component { - - private final Figure figure; - private final String divName; - - private final String plotlyJsLocation; - - private Page(PageBuilder builder) { - this.figure = builder.figure; - this.divName = builder.divName; - this.plotlyJsLocation = builder.plotlyJsLocation; - } - - @Override - public String asJavascript() { - return asJavascript("page_template.html"); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("figureScript", figure.asJavascript(divName)); - context.put("targetDiv", figure.divString(divName)); - context.put("figureTitle", figure.getLayout() != null ? figure.getLayout().getTitle() : null); - context.put("plotlyJsLocation", plotlyJsLocation); - return context; - } - - public static PageBuilder pageBuilder(Figure figure, String divName) { - return new PageBuilder(figure, divName); - } - - public static class PageBuilder { - - private final Figure figure; - private final String divName; - - private String plotlyJsLocation = null; - - public PageBuilder(Figure figure, String divName) { - this.figure = figure; - this.divName = divName; - } - - public Page build() { - return new Page(this); - } - - public PageBuilder plotlyJsLocation(String location) { - this.plotlyJsLocation = location; - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/Symbol.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/Symbol.java deleted file mode 100644 index 7186c4dd0..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/Symbol.java +++ /dev/null @@ -1,102 +0,0 @@ -package tech.tablesaw.plotly.components; - -/** - * symbol ( "circle-open" | "circle-dot" | "circle-open-dot" "square-open" | "square-dot" | - * "square-open-dot" "diamond-open" | "diamond-dot" | "diamond-open-dot" "cross-open" | "cross-dot" - * | "cross-open-dot" "x-open" | "x-dot" | "x-open-dot" "triangle-up-open" | "triangle-up-dot" | - * "triangle-up-open-dot" "triangle-down-open" | "triangle-down-dot" | "triangle-down-open-dot" - * "triangle-left-open" | "triangle-left-dot" | "triangle-left-open-dot" "triangle-right-open" | - * "triangle-right-dot" | "triangle-right-open-dot" "triangle-ne-open" | "triangle-ne-dot" | - * "triangle-ne-open-dot" "triangle-se-open" | "triangle-se-dot" | "triangle-se-open-dot" - * "triangle-sw-open" | "triangle-sw-dot" | "triangle-sw-open-dot" "triangle-nw-open" | - * "triangle-nw-dot" | "triangle-nw-open-dot" - * - *

"pentagon-open" | "pentagon-dot | "pentagon-open-dot" "hexagon-open" | "hexagon-dot" | - * "hexagon-open-dot" "hexagon2-open" | "hexagon2-dot" | "hexagon2-open-dot" "octagon-open" | - * "octagon-dot" | "octagon-open-dot" "star-open" | "star-dot" | "star-open-dot" "hexagram-open" | - * "hexagram-dot" | "hexagram-open-dot" "star-triangle-up-open" | "star-triangle-up-dot" | - * "star-triangle-up-open-dot" "star-triangle-down-open" | "star-triangle-down-dot" | - * "star-triangle-down-open-dot" "star-square-open" | "star-square-dot" | "star-square-open-dot" - * "star-diamond-open" | "star-diamond-dot" | "star-diamond-open-dot" - * - *

"diamond-tall-open" | "diamond-tall-dot" | "diamond-tall-open-dot" "diamond-wide-open" | - * "diamond-wide-dot" | "diamond-wide-open-dot" "hourglass-open" "bowtie-open" "circle-cross-open" - * "circle-x-open" "square-cross-open" "square-x-open" "diamond-cross-open" "diamond-x-open" - * - *

"cross-thin-open" "x-thin-open" "asterisk-open" "hash-open" "hash-dot" "hash-open-dot" - * - *

"y-up-open" "y-down-open" "y-left-open" "y-right-open" - * - *

"line-ew-open" "line-ns-open" "line-ne-open" "line-nw-open" - * - *

default: "circle" - * - *

Sets the marker symbol type. Adding 100 is equivalent to appending "-open" to a symbol name. - * Adding 200 is equivalent to appending "-dot" to a symbol name. Adding 300 is equivalent to - * appending "-open-dot" or "dot-open" to a symbol name. - */ -public enum Symbol { - CIRCLE("circle"), - SQUARE("square"), - DIAMOND("diamond"), - CROSS("cross"), - X("x"), - TRIANGLE_UP("triangle-up"), - TRIANGLE_DOWN("triangle-down"), - TRIANGLE_LEFT("triangle-left"), - TRIANGLE_RIGHT("triangle-right"), - TRIANGLE_NE("triangle-ne"), - TRIANGLE_SE("triangle-se"), - TRIANGEL_SW("triangle-sw"), - TRIANGLE_NW("triangle-nw"), - - PENTAGON("pentagon"), - HEXAGON("hexagon"), - HEXAGON2("hexagon2"), - OCTAGON("octagon"), - STAR("star"), - HEXAGRAM("hexagram"), - - STAR_TRIANGLE_UP("star-triangle-up"), - STAR_TRIANGLE_DOWN("star-triangle-down"), - STAR_SQUARE("star-square"), - STAR_DIAMOND("star-diamond"), - - DIAMOND_TALL("diamond-tall"), - DIAMOND_WIDE("diamond-wide"), - HOURGLASS("hourglass"), - BOWTIE("bowtie"), - - CIRCLE_CROSS("circle-cross"), - CIRCLE_X("circle-x"), - SQUARE_CROSS("square-cross"), - SQUARE_X("square-x"), - DIAMOND_CROSS("diamond-cross"), - DIAMOND_X("diamond-x"), - - CROSS_THIN("cross-thin"), - X_THIN("x-thin"), - ASTERISK("asterisk"), - HASH("hash"), - - Y_UP("y-up"), - Y_DOWN("y-down"), - Y_LEFT("y-left"), - Y_RIGHT("y-right"), - - LINE_EW("line-ew"), - LINE_NS("line-ns"), - LINE_NE("line-ne"), - LINE_NW("line-sw"); - - private final String value; - - Symbol(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java deleted file mode 100644 index 7a85336e4..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/TemplateUtils.java +++ /dev/null @@ -1,45 +0,0 @@ -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 java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class TemplateUtils { - - private TemplateUtils() {} - - private static Collection templateLocations = new ArrayList<>(); - - public static void setTemplateLocations(String... locations) { - templateLocations = Arrays.asList(locations); - } - - public static PebbleEngine getNewEngine() { - PebbleEngine engine; - try { - Loader loader = new ClasspathLoader(); - if (templateLocations != null && !templateLocations.isEmpty()) { - List> loaders = new ArrayList<>(); - for (String templateLocation : templateLocations) { - FileLoader fileLoader = new FileLoader(); - fileLoader.setPrefix(templateLocation); - loaders.add(fileLoader); - } - // add this one last, so it is shadowed - loaders.add(loader); - loader = new DelegatingLoader(loaders); - } - engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build(); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } - return engine; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/TickSettings.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/TickSettings.java deleted file mode 100644 index c39c2bf24..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/TickSettings.java +++ /dev/null @@ -1,454 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static tech.tablesaw.plotly.components.TickSettings.DisplayRules.ALL; -import static tech.tablesaw.plotly.components.TickSettings.ExponentFormat.B; - -import com.google.common.base.Preconditions; -import java.util.Map; -import tech.tablesaw.plotly.Utils; - -public class TickSettings { - - /** - * Sets the tick mode for this axis. If "auto", the number of ticks is set via `nticks`. If - * "linear", the placement of the ticks is determined by a starting position `tick0` and a tick - * step `dtick` If "array", the placement of the ticks is set via `tickvals` and the tick text is - * `ticktext`. - */ - public enum TickMode { - AUTO("auto"), - LINEAR("linear"), - ARRAY("array"); - - private final String value; - - TickMode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** Determines whether and where ticks are drawn */ - public enum TickPlacement { - OUTSIDE("outside"), - INSIDE("inside"), - NONE(""); - private final String value; - - TickPlacement(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** Controls the display of prefixes, suffixes, and exponents on ticks */ - public enum DisplayRules { - ALL("outside"), - FIRST("first"), - LAST("last"), - NONE("none"); - private final String value; - - DisplayRules(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** Controls the display of prefixes on ticks */ - public enum Mirror { - TRUE("true"), - FALSE("false"), - TICKS("ticks"), - ALL("all"), - ALL_TICKS("allticks"); - private final String value; - - Mirror(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - /** Controls the display of prefixes on ticks */ - public enum ExponentFormat { - NONE("none"), - e("e"), - E("E"), - POWER("power"), - SI("SI"), - B("B"); - private final String value; - - ExponentFormat(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - private final TickMode tickMode; - - private final int nTicks; // >= 0 - - private final Object tick0; - private final Object dTick; - - private final int - length; // (number greater than or equal to 0) default: 5 Sets the tick length (in px). - private final int - width; // (number greater than or equal to 0) default: 1 , Sets the tick width (in px). - private final String color; // (color) default: "#444" Sets the tick color. - private final boolean - showLabels; // (boolean) default: True Determines whether or not the tick labels are drawn. - - private final TickPlacement placement; - private final Font tickFont; - - // the values and labels to use when TickMode is ARRAY - private final Object[] tickText; - private final double[] tickValues; - - private final Mirror mirror; - private final int angle; - private final String prefix; - private final String suffix; - private final boolean autoMargin; - private final DisplayRules showPrefix; - private final DisplayRules showSuffix; - private final DisplayRules showExponent; - private final ExponentFormat exponentFormat; - - private final boolean separateThousands; - - private TickSettings(TickSettingsBuilder builder) { - this.tickMode = builder.tickMode; - this.nTicks = builder.nTicks; - - this.color = builder.tickColor; - this.length = builder.tickLength; - this.width = builder.tickWidth; - this.showLabels = builder.showTickLabels; - this.tickFont = builder.font; - this.placement = builder.placement; - - tickText = builder.tickText; - tickValues = builder.tickValues; - - tick0 = builder.tick0; - dTick = builder.dTick; - - showPrefix = builder.showPrefix; - showSuffix = builder.showSuffix; - showExponent = builder.showExponent; - exponentFormat = builder.exponentFormat; - - autoMargin = builder.autoMargin; - - angle = builder.angle; - prefix = builder.prefix; - suffix = builder.suffix; - mirror = builder.mirror; - separateThousands = builder.separateThousands; - } - - protected void updateContext(Map context) { - context.put("showTickLabels", showLabels); - context.put("tickLength", length); - context.put("tickWidth", width); - context.put("tickColor", color); - context.put("tickFont", tickFont); - context.put("ticks", placement); - if (tickText != null) { - context.put("tickText", Utils.dataAsString(tickText)); - } - if (nTicks != 0) { - context.put("nTicks", nTicks); - } - if (dTick != null) { - context.put("dTick", dTick); - } - if (tick0 != null) { - context.put("tick0", tick0); - } - if (showExponent != ALL) { - context.put("showExponent", showExponent); - } - if (exponentFormat != B) { - context.put("exponentFormat", exponentFormat); - } - if (tickValues != null) { - context.put("tickValues", Utils.dataAsString(tickValues)); - } - context.put("mirror", mirror); - context.put("prefix", prefix); - context.put("suffix", suffix); - context.put("showPrefix", showPrefix); - context.put("showSuffix", showSuffix); - context.put("angle", angle); - context.put("autoMargin", autoMargin); - context.put("tickMode", tickMode); - context.put("separateThousands", separateThousands); - } - - public static TickSettingsBuilder builder() { - return new TickSettingsBuilder(); - } - - public static class TickSettingsBuilder { - - private DisplayRules showExponent = ALL; - private ExponentFormat exponentFormat = B; - private Object tick0; - private Object dTick; - - private TickMode tickMode = TickMode.LINEAR; - private Object[] tickText; - private double[] tickValues; - - private int tickLength = 5; - private int tickWidth = 1; - private String tickColor = "#444"; - private boolean showTickLabels = true; - private Font font; - private TickPlacement placement = TickPlacement.INSIDE; - private int nTicks = 0; - - private int angle = 0; - private String prefix; - private String suffix; - private boolean autoMargin = true; - private DisplayRules showPrefix = ALL; - private DisplayRules showSuffix = ALL; - private Mirror mirror; - private boolean separateThousands; - - private TickSettingsBuilder() {} - - /** - * @param tickValues Sets the values at which ticks on this axis appear. Only has an effect if - * `tickmode` is set to "array". Used with `ticktext`. - * @param tickText Sets the text displayed at the ticks position via `tickvals`. Only has an - * effect if `tickmode` is set to "array". Used with `tickvals`. - */ - public TickSettings.TickSettingsBuilder arrayTicks(double[] tickValues, String[] tickText) { - this.tickValues = tickValues; - this.tickText = tickText; - return this; - } - - public TickSettings.TickSettingsBuilder arrayTicks(double[] tickValues) { - this.tickValues = tickValues; - return this; - } - - public TickSettings.TickSettingsBuilder placement(TickPlacement placement) { - this.placement = placement; - return this; - } - - /** - * Specifies the maximum number of ticks for the particular axis. The actual number of ticks - * will be chosen automatically to be less than or equal to `nticks`. Has an effect only if - * `tickmode` is set to "auto". - * - * @param nTicks a non-negative int - * @return this builder - */ - public TickSettings.TickSettingsBuilder nTicks(int nTicks) { - Preconditions.checkArgument(nTicks >= 0); - this.nTicks = nTicks; - return this; - } - - public TickSettings.TickSettingsBuilder tickMode(TickMode tickMode) { - this.tickMode = tickMode; - return this; - } - - /** Determines whether or not the tick labels are drawn. */ - public TickSettings.TickSettingsBuilder showTickLabels(boolean showTickLabels) { - this.showTickLabels = showTickLabels; - return this; - } - - /** Sets the tick color */ - public TickSettings.TickSettingsBuilder color(String tickColor) { - this.tickColor = tickColor; - return this; - } - - /** Sets the tick font */ - public TickSettings.TickSettingsBuilder font(Font font) { - this.font = font; - return this; - } - - /** - * Sets the tick width (in px). - * - * @param tickWidth number greater than or equal to 0 - */ - public TickSettings.TickSettingsBuilder width(int tickWidth) { - Preconditions.checkArgument(tickWidth >= 0); - this.tickWidth = tickWidth; - return this; - } - - /** - * Sets the tick length (in px). - * - * @param tickLength number greater than or equal to 0 - */ - public TickSettings.TickSettingsBuilder length(int tickLength) { - Preconditions.checkArgument(tickLength >= 0); - this.tickLength = tickLength; - return this; - } - - /** Determines whether long tick labels automatically grow the figure margins. */ - public TickSettings.TickSettingsBuilder autoMargin(boolean adjust) { - this.autoMargin = adjust; - return this; - } - - public TickSettings.TickSettingsBuilder separateThousands(boolean separate) { - this.separateThousands = separate; - return this; - } - - /** */ - public TickSettings.TickSettingsBuilder showSuffix(DisplayRules showSuffix) { - this.showSuffix = showSuffix; - return this; - } - - /** */ - public TickSettings.TickSettingsBuilder showExponent(DisplayRules showExponent) { - this.showExponent = showExponent; - return this; - } - - /** - * If "all", all exponents are shown besides their significands. If "first", only the exponent - * of the first tick is shown. If "last", only the exponent of the last tick is shown. If - * "none", no exponents appear. - */ - public TickSettings.TickSettingsBuilder exponentFormat(ExponentFormat format) { - this.exponentFormat = format; - return this; - } - - /** - * If "all", all tick labels are displayed with a prefix. If "first", only the first tick is - * displayed with a prefix. If "last", only the last tick is displayed with a prefix. If "none", - * tick prefixes are hidden. - */ - public TickSettings.TickSettingsBuilder showPrefix(DisplayRules showPrefix) { - this.showPrefix = showPrefix; - return this; - } - - /** - * Determines if the axis lines or/and ticks are mirrored to the opposite side of the plotting - * area. If "True", the axis lines are mirrored. If "ticks", the axis lines and ticks are - * mirrored. If "False", mirroring is disable. If "all", axis lines are mirrored on all - * shared-axes subplots. If "allticks", axis lines and ticks are mirrored on all shared-axes - * subplots. - */ - public TickSettings.TickSettingsBuilder mirror(Mirror mirror) { - this.mirror = mirror; - return this; - } - - /** - * Sets the angle of the tick labels with respect to the horizontal. For example, a `tickangle` - * of -90 draws the tick labels vertically. - */ - public TickSettings.TickSettingsBuilder angle(int angle) { - this.angle = angle; - return this; - } - - public TickSettings.TickSettingsBuilder prefix(String prefix) { - this.prefix = prefix; - return this; - } - - public TickSettings.TickSettingsBuilder suffix(String suffix) { - this.suffix = suffix; - return this; - } - - /** - * TODO: this is pretty hack-y. Add a separate method for dealing with dates and maybe clean up - * logs too - * - *

Sets the placement of the first tick on this axis. Use with `dtick`. - * - *

If the axis `type` is "log", then you must take the log of your starting tick (e.g. to set - * the starting tick to 100, set the `tick0` to 2) except when `dtick`="L<f>" (see `dtick` - * for more info). - * - *

If the axis `type` is "date", it should be a date string, like date data. - * - *

If the axis `type` is "category", it should be a number, using the scale where each - * category is assigned a serial number from zero in the order it appears. - */ - public TickSettings.TickSettingsBuilder tick0(Object tick0) { - this.tick0 = tick0; - return this; - } - - /** - * TODO: this is pretty hack-y. Add a separate method for dealing with dates and maybe clean up - * logs too - * - *

Sets the step in-between ticks on this axis. Use with `tick0`. Must be a positive number, - * or special strings available to "log" and "date" axes. - * - *

If the axis `type` is "log", then ticks are set every 10^(n"dtick) where n is the tick - * number. For example, to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1. To set tick - * marks at 1, 100, 10000, ... set dtick to 2. To set tick marks at 1, 5, 25, 125, 625, 3125, - * ... set dtick to log_10(5), or 0.69897000433. "log" has several special values; "L<f>", - * where `f` is a positive number, gives ticks linearly spaced in value (but not position). - * - *

For example `tick0` = 0.1, `dtick` = "L0.5" will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To - * show powers of 10 plus small digits between, use "D1" (all digits) or "D2" (only 2 and 5). - * `tick0` is ignored for "D1" and "D2". - * - *

If the axis `type` is "date", then you must convert the time to milliseconds. For example, - * to set the interval between ticks to one day, set `dtick` to 86400000.0. "date" also has - * special values "M<n>" gives ticks spaced by a number of months. `n` must be a positive - * integer. To set ticks on the 15th of every third month, set `tick0` to "2000-01-15" and - * `dtick` to "M3". To set ticks every 4 years, set `dtick` to "M48" - */ - public TickSettings.TickSettingsBuilder dTick(Object dTick) { - this.dTick = dTick; - return this; - } - - public TickSettings build() { - return new TickSettings(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Change.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Change.java deleted file mode 100644 index 737e86a2c..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Change.java +++ /dev/null @@ -1,52 +0,0 @@ -package tech.tablesaw.plotly.components.change; - -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.plotly.components.Component; - -public abstract class Change extends Component { - - // private static final ChangeLine DEFAULT_CHANGE_LINE = new LineBuilder().build(); - - private final ChangeLine changeLine; - private final String fillColor; - - @Override - public String asJavascript() { - return asJSON(); - } - - Change(ChangeBuilder builder) { - this.changeLine = builder.changeLine; - this.fillColor = builder.fillColor; - } - - @Override - protected Map getJSONContext() { - Map context = new HashMap<>(); - if (changeLine != null) context.put("line", changeLine.getJSONContext()); - if (fillColor != null) context.put("fillcolor", fillColor); - return context; - } - - @Override - protected Map getContext() { - return getJSONContext(); - } - - public static class ChangeBuilder { - - protected String fillColor; - protected ChangeLine changeLine; - - public ChangeBuilder fillColor(String color) { - this.fillColor = color; - return this; - } - - public ChangeBuilder changeLine(ChangeLine line) { - this.changeLine = line; - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/ChangeLine.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/change/ChangeLine.java deleted file mode 100644 index 672caaf7d..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/ChangeLine.java +++ /dev/null @@ -1,69 +0,0 @@ -package tech.tablesaw.plotly.components.change; - -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.plotly.components.Component; - -public class ChangeLine extends Component { - - private static final int DEFAULT_WIDTH = 2; - private static final String DEFAULT_COLOR = "#3D9970"; - - private final String color; - private final int width; - - private ChangeLine(LineBuilder lineBuilder) { - color = lineBuilder.color; - width = lineBuilder.width; - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getJSONContext() { - Map context = new HashMap<>(); - if (!color.equals(DEFAULT_COLOR)) context.put("color", color); - if (width != DEFAULT_WIDTH) context.put("width", width); - return context; - } - - @Override - protected Map getContext() { - return getJSONContext(); - } - - public static LineBuilder builder() { - return new LineBuilder(); - } - - public static class LineBuilder { - - private String color = DEFAULT_COLOR; - private int width = DEFAULT_WIDTH; - - /** Sets the color of line bounding the box(es). */ - public LineBuilder color(String color) { - this.color = color; - return this; - } - - /** - * Sets the width (in px) of line bounding the box(es). - * - * @param width greater than or equal to 0 - */ - public LineBuilder width(int width) { - Preconditions.checkArgument(width >= 0); - this.width = width; - return this; - } - - public ChangeLine build() { - return new ChangeLine(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Decreasing.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Decreasing.java deleted file mode 100644 index d6035a719..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Decreasing.java +++ /dev/null @@ -1,31 +0,0 @@ -package tech.tablesaw.plotly.components.change; - -public class Decreasing extends Change { - - private Decreasing(DecreasingBuilder builder) { - super(builder); - } - - public static DecreasingBuilder builder() { - return new DecreasingBuilder(); - } - - public static class DecreasingBuilder extends ChangeBuilder { - - @Override - public DecreasingBuilder fillColor(String color) { - this.fillColor = color; - return this; - } - - @Override - public DecreasingBuilder changeLine(ChangeLine line) { - this.changeLine = line; - return this; - } - - public Decreasing build() { - return new Decreasing(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Increasing.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Increasing.java deleted file mode 100644 index 4f0b5e6d5..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/change/Increasing.java +++ /dev/null @@ -1,31 +0,0 @@ -package tech.tablesaw.plotly.components.change; - -public class Increasing extends Change { - - private Increasing(IncreasingBuilder builder) { - super(builder); - } - - public static IncreasingBuilder builder() { - return new IncreasingBuilder(); - } - - public static class IncreasingBuilder extends ChangeBuilder { - - @Override - public Increasing.IncreasingBuilder fillColor(String color) { - this.fillColor = color; - return this; - } - - @Override - public Increasing.IncreasingBuilder changeLine(ChangeLine line) { - this.changeLine = line; - return this; - } - - public Increasing build() { - return new Increasing(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Camera.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Camera.java deleted file mode 100644 index bb66d3d79..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Camera.java +++ /dev/null @@ -1,62 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.plotly.components.Component; - -public class Camera extends Component { - - private final Center center; - private final Up up; - private final Eye eye; - - private Camera(CameraBuilder builder) { - this.eye = builder.eye; - this.up = builder.up; - this.center = builder.center; - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("up", up); - context.put("eye", eye); - context.put("center", center); - return context; - } - - @Override - public String asJavascript() { - return asJavascript("camera_template.html"); - } - - public CameraBuilder cameraBuilder() { - return new CameraBuilder(); - } - - public static class CameraBuilder { - - private Center center; - private Up up; - private Eye eye; - - public CameraBuilder xAxis(Center center) { - this.center = center; - return this; - } - - public CameraBuilder yAxis(Up up) { - this.up = up; - return this; - } - - public CameraBuilder zAxis(Eye eye) { - this.eye = eye; - return this; - } - - public Camera build() { - return new Camera(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/CameraComponent.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/CameraComponent.java deleted file mode 100644 index 9c872eed1..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/CameraComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -import java.util.HashMap; -import java.util.Map; -import tech.tablesaw.plotly.components.Component; - -class CameraComponent extends Component { - - private final double x; - private final double y; - private final double z; - - CameraComponent(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public String asJavascript() { - return asJSON(); - } - - @Override - protected Map getJSONContext() { - return getContext(); - } - - @Override - protected Map getContext() { - Map context = new HashMap<>(); - context.put("x", x); - context.put("y", y); - context.put("z", z); - return context; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Center.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Center.java deleted file mode 100644 index 5b8be49b2..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Center.java +++ /dev/null @@ -1,29 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -class Center extends CameraComponent { - - private Center(CenterBuilder builder) { - super(builder.x, builder.y, builder.z); - } - - public static CenterBuilder centerBuilder(double x, double y, double z) { - return new CenterBuilder(x, y, z); - } - - public static class CenterBuilder { - - private final double x; - private final double y; - private final double z; - - private CenterBuilder(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Center build() { - return new Center(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Eye.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Eye.java deleted file mode 100644 index 48194ee68..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Eye.java +++ /dev/null @@ -1,29 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -public class Eye extends CameraComponent { - - private Eye(EyeBuilder builder) { - super(builder.x, builder.y, builder.z); - } - - public static EyeBuilder eyeBuilder(double x, double y, double z) { - return new EyeBuilder(x, y, z); - } - - public static class EyeBuilder { - - private final double x; - private final double y; - private final double z; - - private EyeBuilder(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Eye build() { - return new Eye(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java deleted file mode 100644 index 9041853e3..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Scene.java +++ /dev/null @@ -1,101 +0,0 @@ -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; -import tech.tablesaw.plotly.components.Component; - -public class Scene extends Component { - - private final Axis xAxis; - - private final Axis yAxis; - - private final Axis zAxis; - - private final Camera camera; - - private Scene(SceneBuilder builder) { - this.xAxis = builder.xAxis; - this.yAxis = builder.yAxis; - this.zAxis = builder.zAxis; - this.camera = builder.camera; - } - - protected Map getContext() { - Map context = new HashMap<>(); - if (xAxis != null) { - context.put("xAxis", xAxis); - } - if (yAxis != null) { - context.put("yAxis", yAxis); - } - if (zAxis != null) { - context.put("zAxis", zAxis); - } - if (camera != null) { - context.put("camera", camera); - } - return context; - } - - 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); - } - return writer.toString(); - } - - public static class SceneBuilder { - - private Axis xAxis; - - private Axis yAxis; - - private Axis zAxis; - - private Camera camera; - - public SceneBuilder xAxis(Axis axis) { - this.xAxis = axis; - return this; - } - - public SceneBuilder yAxis(Axis axis) { - this.yAxis = axis; - return this; - } - - public SceneBuilder zAxis(Axis axis) { - this.zAxis = axis; - return this; - } - - public SceneBuilder camera(Camera camera) { - this.camera = camera; - return this; - } - - public Scene build() { - return new Scene(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Up.java b/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Up.java deleted file mode 100644 index a58ec5600..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/components/threeD/Up.java +++ /dev/null @@ -1,31 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -public class Up extends CameraComponent { - - public static final Up DEFAULT = Up.upBuilder(0, 0, 1).build(); - - private Up(UpBuilder builder) { - super(builder.x, builder.y, builder.z); - } - - public static UpBuilder upBuilder(double x, double y, double z) { - return new UpBuilder(x, y, z); - } - - public static class UpBuilder { - - private final double x; - private final double y; - private final double z; - - private UpBuilder(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Up build() { - return new Up(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/display/Browser.java b/jsplot/src/main/java/tech/tablesaw/plotly/display/Browser.java deleted file mode 100644 index 5cc4e47ce..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/display/Browser.java +++ /dev/null @@ -1,25 +0,0 @@ -package tech.tablesaw.plotly.display; - -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import java.net.URI; - -public class Browser { - - public static void main(String[] args) throws Exception { - - if (Desktop.isDesktopSupported()) { - Desktop.getDesktop().browse(new URI("http://www.example.com")); - } - } - - public void browse(File file) throws IOException { - if (Desktop.isDesktopSupported()) { - - Desktop.getDesktop().browse(file.toURI()); - } else { - throw new UnsupportedOperationException("Browser not supported."); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandler.java b/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandler.java deleted file mode 100644 index 835797c2c..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package tech.tablesaw.plotly.event; - -public interface EventHandler { - - /** - * Returns a string of Javascript code that implements a plotly event handler - * - * @param targetName name of the target document - * @param divName target document id - * @return A string that can be rendered in javascript - */ - String asJavascript(String targetName, String divName); -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandlerBody.java b/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandlerBody.java deleted file mode 100644 index 5d2567ecb..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/event/EventHandlerBody.java +++ /dev/null @@ -1,14 +0,0 @@ -package tech.tablesaw.plotly.event; - -public interface EventHandlerBody { - - /** - * Returns a string of Javascript code that implements a plotly event handler - * - * @param targetName name of the target document - * @param divName target document id - * @param eventData name of the event data variable - * @return A string that can be rendered in javascript - */ - String asJavascript(String targetName, String divName, String eventData); -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverBroadcastBody.java b/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverBroadcastBody.java deleted file mode 100644 index 2d8580b31..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverBroadcastBody.java +++ /dev/null @@ -1,69 +0,0 @@ -package tech.tablesaw.plotly.event; - -public class HoverBroadcastBody implements EventHandlerBody { - - private final String[] subPlots; - private final int nTraces; - - public static HoverBroadcastBuilder builder() { - return new HoverBroadcastBuilder(); - } - - private HoverBroadcastBody(HoverBroadcastBuilder builder) { - this.subPlots = builder.subPlots; - this.nTraces = builder.nTraces; - } - - @Override - public String asJavascript(String targetName, String divName, String eventData) { - StringBuilder builder = new StringBuilder(); - - builder.append(String.format("\tvar pointIndex = %s.points[0].pointNumber;", eventData)); - builder.append(System.lineSeparator()); - builder.append(String.format("\tPlotly.Fx.hover('%s',[ ", divName)); - builder.append(System.lineSeparator()); - - for (int i = 0; i < nTraces; i++) { - builder.append(String.format("\t\t{ curveNumber: %d, pointNumber: pointIndex }", i)); - if (i < nTraces - 1) { - builder.append(", "); - } - builder.append(System.lineSeparator()); - } - builder.append("\t\t]"); - - if (subPlots.length > 0) { - builder.append(", ["); - for (int i = 0; i < subPlots.length; i++) { - builder.append(String.format("'%s'", subPlots[i])); - if (i < subPlots.length - 1) { - builder.append(", "); - } - } - builder.append("]"); - builder.append(System.lineSeparator()); - } - builder.append("\t);"); - builder.append(System.lineSeparator()); - return builder.toString(); - } - - public static class HoverBroadcastBuilder { - private String[] subPlots; - private int nTraces; - - public HoverBroadcastBuilder subPlots(String[] subPlots) { - this.subPlots = subPlots; - return this; - } - - public HoverBroadcastBuilder numTraces(int nTraces) { - this.nTraces = nTraces; - return this; - } - - public HoverBroadcastBody build() { - return new HoverBroadcastBody(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverEventHandler.java b/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverEventHandler.java deleted file mode 100644 index a03ef2b80..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/event/HoverEventHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package tech.tablesaw.plotly.event; - -public class HoverEventHandler implements EventHandler { - - private final EventHandlerBody body; - private final String eventDataVarName = "eventData"; - - public static HoverEventHanlderBuilder builder() { - return new HoverEventHanlderBuilder(); - } - - private HoverEventHandler(HoverEventHanlderBuilder builder) { - this.body = builder.body; - } - - /** - * Returns a string of Javascript code that implements a plotly hover event handler - * - * @param targetName name of the target document - * @param divName target document id - * @return A string that can be rendered in javascript - */ - @Override - public String asJavascript(String targetName, String divName) { - StringBuilder builder = new StringBuilder(); - - builder.append( - String.format("%s.on('plotly_hover', function(%s){", targetName, eventDataVarName)); - builder.append(System.lineSeparator()); - - builder.append(body.asJavascript(targetName, divName, eventDataVarName)); - - builder.append("});"); - builder.append(System.lineSeparator()); - - return builder.toString(); - } - - public static class HoverEventHanlderBuilder { - private EventHandlerBody body; - - public HoverEventHanlderBuilder body(EventHandlerBody body) { - this.body = body; - return this; - } - - public HoverEventHandler build() { - return new HoverEventHandler(this); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java deleted file mode 100644 index 0c4baebbd..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/AbstractTrace.java +++ /dev/null @@ -1,143 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import com.mitchellbosecke.pebble.PebbleEngine; -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.HoverLabel; -import tech.tablesaw.plotly.components.TemplateUtils; - -public abstract class AbstractTrace implements Trace { - - protected static final double DEFAULT_OPACITY = 1.0; - protected static final Visibility DEFAULT_VISIBILITY = Visibility.TRUE; - - protected final PebbleEngine engine = TemplateUtils.getNewEngine(); - - public enum Visibility { - TRUE("True"), - FALSE("False"), - LEGEND_ONLY("legendonly"); - - private final String value; - - Visibility(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - protected final String type; - - private final Visibility visible; - - /** Determines whether or not an item corresponding to this trace is shown in the legend. */ - private final Boolean showLegend; - - /** - * 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 opacity of the trace. */ - private final double opacity; // number between or equal to 0 and 1 - - /** Sets the trace name. The trace name appear as the legend item and on hover. */ - private final String name; - - /** - * Assigns id labels to each datum. These ids for object constancy of data points during - * animation. Should be an array of strings, not numbers or any other type. - */ - private final String[] ids; - - /** - * Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If *x* , the x - * coordinates refer to `layout.xaxis`. If *x2*, the x coordinates refer to `layout.xaxis2`, and - * so on. - */ - private final String xAxis; - /** - * Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If *y* , the y - * coordinates refer to `layout.yaxis`. If *y2*, the y coordinates refer to `layout.yaxis2`, and - * so on. - */ - private final String yAxis; - - private final HoverLabel hoverLabel; - - public AbstractTrace(TraceBuilder builder) { - this.type = builder.getType(); - this.name = builder.name; - this.showLegend = builder.showLegend; - this.legendGroup = builder.legendGroup; - this.visible = builder.visible; - this.ids = builder.ids; - this.hoverLabel = builder.hoverLabel; - this.opacity = builder.opacity; - this.xAxis = builder.xAxis; - this.yAxis = builder.yAxis; - } - - @Override - public String name() { - return name; - } - - @Override - public String toString() { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - protected Map getContext() { - Map context = new HashMap<>(); - context.put("type", type); - context.put("name", name); - if (showLegend != null) { - context.put("showLegend", showLegend); - } - - context.put("legendGroup", legendGroup); - - if (!visible.equals(DEFAULT_VISIBILITY)) { - context.put("visible", visible); - } - context.put("ids", ids); - context.put("hoverLable", hoverLabel); - if (opacity != DEFAULT_OPACITY) { - context.put("opacity", opacity); - } - context.put("xAxis", xAxis); - context.put("yAxis", yAxis); - return context; - } - - public HoverLabel hoverLabel() { - return hoverLabel; - } - - public boolean showLegend() { - return showLegend; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java deleted file mode 100644 index 36f54ce2e..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/BarTrace.java +++ /dev/null @@ -1,161 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -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.Map; -import tech.tablesaw.api.CategoricalColumn; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.plotly.components.Marker; - -public class BarTrace extends AbstractTrace { - - private final Object[] x; - private final double[] y; - private final Orientation orientation; - private final Marker marker; - - private BarTrace(BarBuilder builder) { - super(builder); - this.orientation = builder.orientation; - this.x = builder.x; - this.y = builder.y; - this.marker = builder.marker; - } - - public static BarBuilder builder(Object[] x, double[] y) { - return new BarBuilder(x, y); - } - - public static BarBuilder builder(CategoricalColumn x, NumericColumn y) { - return new BarBuilder(x, y); - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - if (orientation == Orientation.HORIZONTAL) { - context.put("x", dataAsString(y)); - context.put("y", dataAsString(x)); - } else { - context.put("y", dataAsString(y)); - context.put("x", dataAsString(x)); - } - context.put("orientation", orientation.value); - if (marker != null) { - context.put("marker", marker); - } - return context; - } - - public enum Orientation { - VERTICAL("v"), - HORIZONTAL("h"); - - private final String value; - - Orientation(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public static class BarBuilder extends TraceBuilder { - - private final String type = "bar"; - private final Object[] x; - private final double[] y; - private Orientation orientation = Orientation.VERTICAL; - private Marker marker; - - BarBuilder(Object[] x, double[] y) { - this.x = x; - this.y = y; - } - - BarBuilder(CategoricalColumn x, NumericColumn y) { - - this.x = TraceBuilder.columnToStringArray(x); - this.y = y.asDoubleArray(); - } - - public BarTrace build() { - return new BarTrace(this); - } - - /** - * Sets the orientation of the bars. With "v" ("h"), the value of the each bar spans along the - * vertical (horizontal). - */ - public BarBuilder orientation(Orientation orientation) { - this.orientation = orientation; - return this; - } - - @Override - public BarBuilder opacity(double opacity) { - super.opacity(opacity); - return this; - } - - @Override - public BarBuilder name(String name) { - super.name(name); - return this; - } - - @Override - public BarBuilder showLegend(boolean b) { - super.showLegend(b); - return this; - } - - public BarBuilder marker(Marker marker) { - this.marker = marker; - return this; - } - - @Override - public BarBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public BarBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java deleted file mode 100644 index dd2d3db0d..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/BoxTrace.java +++ /dev/null @@ -1,110 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -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.Map; -import tech.tablesaw.api.CategoricalColumn; -import tech.tablesaw.api.NumericColumn; - -public class BoxTrace extends AbstractTrace { - - private final Object[] x; - private final double[] y; - - private BoxTrace(BoxBuilder builder) { - super(builder); - this.x = builder.x; - this.y = builder.y; - } - - public static BoxBuilder builder(Object[] x, double[] y) { - return new BoxBuilder(x, y); - } - - public static BoxBuilder builder(CategoricalColumn x, NumericColumn y) { - return new BoxBuilder(x, y); - } - - public static BoxBuilder builder(double[] x, double[] y) { - Double[] xObjs = new Double[x.length]; - for (int i = 0; i < x.length; i++) { - xObjs[i] = x[i]; - } - return new BoxBuilder(xObjs, y); - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("y", dataAsString(y)); - context.put("x", dataAsString(x)); - return context; - } - - public static class BoxBuilder extends TraceBuilder { - - private static final String type = "box"; - private final Object[] x; - private final double[] y; - - BoxBuilder(Object[] x, double[] y) { - this.x = x; - this.y = y; - } - - @Override - public BoxBuilder name(String name) { - super.name(name); - return this; - } - - BoxBuilder(CategoricalColumn x, NumericColumn y) { - this.x = columnToStringArray(x); - this.y = y.asDoubleArray(); - } - - public BoxTrace build() { - return new BoxTrace(this); - } - - @Override - public BoxBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public BoxBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java deleted file mode 100644 index aebee67c1..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ContourTrace.java +++ /dev/null @@ -1,95 +0,0 @@ -package tech.tablesaw.plotly.traces; - -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.Map; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -public class ContourTrace extends AbstractTrace { - - private final Object[] x; - private final Object[] y; - private final double[][] z; - private final String type; - - public ContourTrace(ContourBuilder builder) { - super(builder); - this.x = builder.x; - this.y = builder.y; - this.z = builder.z; - this.type = builder.getType(); - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - @Override - protected Map getContext() { - - Map context = super.getContext(); - context.put("variableName", "trace0"); - context.put("x", dataAsString(x)); - context.put("y", dataAsString(y)); - context.put("z", dataAsString(z)); - context.put("type", type); - return context; - } - - public static ContourTrace.ContourBuilder builder(Object[] x, Object[] y, double[][] z) { - return new ContourTrace.ContourBuilder(x, y, z); - } - - public static class ContourBuilder extends TraceBuilder { - - private static final String type = "contour"; - private final Object[] x; - private final Object[] y; - private final double[][] z; - - ContourBuilder(Object[] x, Object[] y, double[][] z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public ContourTrace.ContourBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public ContourTrace.ContourBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - public ContourTrace build() { - return new ContourTrace(this); - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java deleted file mode 100644 index 6aea6b76a..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/HeatmapTrace.java +++ /dev/null @@ -1,94 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -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.Map; - -public class HeatmapTrace extends AbstractTrace { - - private final Object[] x; - private final Object[] y; - private final double[][] z; - private final String type; - - private HeatmapTrace(HeatmapBuilder builder) { - super(builder); - this.x = builder.x; - this.y = builder.y; - this.z = builder.z; - this.type = builder.getType(); - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext()); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - @Override - protected Map getContext() { - - Map context = super.getContext(); - context.put("variableName", "trace0"); - context.put("x", dataAsString(x)); - context.put("y", dataAsString(y)); - context.put("z", dataAsString(z)); - context.put("type", type); - return context; - } - - public static HeatmapBuilder builder(Object[] x, Object[] y, double[][] z) { - return new HeatmapBuilder(x, y, z); - } - - public static class HeatmapBuilder extends TraceBuilder { - - private static final String type = "heatmap"; - private final Object[] x; - private final Object[] y; - private final double[][] z; - - HeatmapBuilder(Object[] x, Object[] y, double[][] z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public HeatmapBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public HeatmapBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - public HeatmapTrace build() { - return new HeatmapTrace(this); - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java deleted file mode 100644 index 82c30c6a9..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Histogram2DTrace.java +++ /dev/null @@ -1,105 +0,0 @@ -package tech.tablesaw.plotly.traces; - -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.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.plotly.Utils; - -public class Histogram2DTrace extends AbstractTrace { - - private final double[] x; - private final double[] y; - - public static Histogram2DBuilder builder(double[] x, double[] y) { - return new Histogram2DBuilder(x, y); - } - - public static Histogram2DBuilder builder( - NumericColumn x, NumericColumn y) { - return new Histogram2DBuilder(x.asDoubleArray(), y.asDoubleArray()); - } - - private Histogram2DTrace(Histogram2DBuilder builder) { - super(builder); - this.x = builder.x; - this.y = builder.y; - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("x", Utils.dataAsString(x)); - context.put("y", Utils.dataAsString(y)); - return context; - } - - public static class Histogram2DBuilder extends TraceBuilder { - - private final String type = "histogram2d"; - /* - private int bins; - private String barMode; - private String histFunction; - private String histNorm; - */ - private final double[] x; - private final double[] y; - - private Histogram2DBuilder(double[] x, double[] y) { - this.x = x; - this.y = y; - } - - /* - public Histogram2DBuilder setBins(int bins) { - this.bins = bins; - return this; - } - - public Histogram2DBuilder barMode(String barMode) { - this.barMode = barMode; - return this; - } - - public Histogram2DBuilder histFunction(String histFunction) { - this.histFunction = histFunction; - return this; - } - - public Histogram2DBuilder histNorm(String histNorm) { - this.histNorm = histNorm; - return this; - } - */ - public Histogram2DTrace build() { - return new Histogram2DTrace(this); - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java deleted file mode 100644 index fc8e476a2..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/HistogramTrace.java +++ /dev/null @@ -1,293 +0,0 @@ -package tech.tablesaw.plotly.traces; - -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.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.columns.Column; -import tech.tablesaw.plotly.Utils; -import tech.tablesaw.plotly.components.Marker; - -public class HistogramTrace extends AbstractTrace { - - private final Object[] x; - private final Object[] y; - private final double opacity; - private final int nBinsX; - private final int nBinsY; - private final boolean autoBinX; - private final boolean autoBinY; - private final Marker marker; - private final HistNorm histNorm; - private final HistFunc histFunc; - - public enum HistNorm { - NONE(""), - PERCENT("percent"), - PROBABILITY("probability"), - DENSITY("density"), - PROBABILITY_DENSITY("probability density"); - - private final String value; - - HistNorm(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum HistFunc { - COUNT("count"), - SUM("sum"), - AVG("avg"), - MIN("min"), - MAX("max"); - - private final String value; - - HistFunc(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public static HistogramBuilder builder(double[] values) { - return new HistogramBuilder(values); - } - - public static HistogramBuilder builder(NumericColumn values) { - return new HistogramBuilder(values.asDoubleArray()); - } - - public static HistogramBuilder builder( - Column xValues, NumericColumn values) { - return new HistogramBuilder(xValues.asObjectArray(), values.asDoubleArray()); - } - - private HistogramTrace(HistogramBuilder builder) { - super(builder); - if (builder.horizontal) { - this.x = builder.y; - this.y = builder.x; - } else { - this.x = builder.x; - this.y = builder.y; - } - this.histNorm = builder.histNorm; - this.histFunc = builder.histFunc; - this.nBinsX = builder.nBinsX; - this.nBinsY = builder.nBinsY; - this.autoBinX = builder.autoBinX; - this.autoBinY = builder.autoBinY; - this.opacity = builder.opacity; - this.marker = builder.marker; - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - if (x != null) { - context.put("x", Utils.dataAsString(x)); - } - if (y != null) { - context.put("y", Utils.dataAsString(y)); - } - context.put("opacity", opacity); - context.put("nBinsX", nBinsX); - context.put("nBinsY", nBinsY); - context.put("autoBinX", autoBinX); - context.put("autoBinY", autoBinY); - context.put("histnorm", histNorm); - context.put("histfunc", histFunc); - if (marker != null) { - context.put("marker", marker); - } - - return context; - } - - public static class HistogramBuilder extends TraceBuilder { - - private final String type = "histogram"; - private int nBinsX; - private int nBinsY; - private boolean autoBinX; - private boolean autoBinY; - private boolean horizontal = false; - private Object[] x; - private Object[] y; - private Marker marker; - private HistNorm histNorm = HistNorm.NONE; - private HistFunc histFunc = HistFunc.COUNT; - - private HistogramBuilder(double[] values) { - this.x = doublesToObjects(values); - } - - private HistogramBuilder(Object[] xValues, double[] yValues) { - this.x = xValues; - this.y = doublesToObjects(yValues); - } - - /** - * Specifies the maximum number of desired bins. This value will be used in an algorithm that - * will decide the optimal bin size such that the histogram best visualizes the distribution of - * the data. - */ - public HistogramBuilder nBinsX(int bins) { - this.nBinsX = bins; - return this; - } - - public HistogramBuilder nBinsY(int bins) { - this.nBinsY = bins; - return this; - } - - /** - * Determines whether or not the x axis bin attributes are picked by an algorithm. Note that - * this should be set to False if you want to manually set the number of bins using the - * attributes in xbins. - * - *

Note also that this should be true (default) to use nbinsx to suggest a bin count - */ - public HistogramBuilder autoBinX(boolean autoBinX) { - this.autoBinX = autoBinX; - return this; - } - - public HistogramBuilder autoBinY(boolean autoBinY) { - this.autoBinY = autoBinY; - return this; - } - - public HistogramBuilder marker(Marker marker) { - this.marker = marker; - return this; - } - - @Override - public HistogramBuilder opacity(double opacity) { - super.opacity(opacity); - return this; - } - - public HistogramBuilder horizontal(boolean horizontal) { - this.horizontal = horizontal; - return this; - } - - @Override - public HistogramBuilder showLegend(boolean b) { - super.showLegend(b); - return this; - } - - /** - * Specifies the type of normalization used for this histogram trace. If "", the span of each - * bar corresponds to the number of occurrences (i.e. the number of data points lying inside the - * bins). If "percent" / "probability", the span of each bar corresponds to the percentage / - * fraction of occurrences with respect to the total number of sample points (here, the sum of - * all bin HEIGHTS equals 100% / 1). If "density", the span of each bar corresponds to the - * number of occurrences in a bin divided by the size of the bin interval (here, the sum of all - * bin AREAS equals the total number of sample points). If "probability density", the area of - * each bar corresponds to the probability that an event will fall into the corresponding bin - * (here, the sum of all bin AREAS equals 1). - * - * @param histNorm The normalization type for the histogram - * @return This HistogramBuilder - */ - public HistogramBuilder histNorm(HistNorm histNorm) { - this.histNorm = histNorm; - return this; - } - - /** - * Specifies the binning function used for this histogram trace. If "count", the histogram - * values are computed by counting the number of values lying inside each bin. If "sum", "avg", - * "min", "max", the histogram values are computed using the sum, the average, the minimum or - * the maximum of the values lying inside each bin respectively. - * - * @param histFunc The function type - * @return This HistogramBuilder - */ - public HistogramBuilder histFunc(HistFunc histFunc) { - this.histFunc = histFunc; - return this; - } - - @Override - public HistogramBuilder name(String name) { - super.name(name); - return this; - } - - @Override - public HistogramBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public HistogramBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - public HistogramBuilder y(double[] y) { - this.y = doublesToObjects(y); - return this; - } - - public HistogramBuilder y(NumericColumn values) { - this.y = values.asObjectArray(); - return this; - } - - public HistogramTrace build() { - return new HistogramTrace(this); - } - - @Override - protected String getType() { - return type; - } - } - - private static Object[] doublesToObjects(double[] doubles) { - Object[] objects = new Object[doubles.length]; - for (int i = 0; i < doubles.length; i++) { - objects[i] = doubles[i]; - } - return objects; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java deleted file mode 100644 index 02af6ad2d..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/PieTrace.java +++ /dev/null @@ -1,98 +0,0 @@ -package tech.tablesaw.plotly.traces; - -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.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.columns.Column; -import tech.tablesaw.plotly.Utils; -import tech.tablesaw.plotly.components.Domain; - -public class PieTrace extends AbstractTrace { - - private final double[] values; - private final Object[] labels; - private final Domain domain; - - private PieTrace(PieBuilder builder) { - super(builder); - this.values = builder.values; - this.labels = builder.labels; - this.domain = builder.domain; - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("pie_trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("values", Utils.dataAsString(values)); - if (labels != null) { - context.put("labels", Utils.dataAsString(labels)); - } - if (domain != null) { - context.put("domain", domain.asJavascript()); - } - return context; - } - - public static PieBuilder builder(Object[] labels, double[] values) { - return new PieBuilder(labels, values); - } - - public static PieBuilder builder(Column labels, NumericColumn values) { - return new PieBuilder(TraceBuilder.columnToStringArray(labels), values.asDoubleArray()); - } - - public static class PieBuilder extends TraceBuilder { - - private final String type = "pie"; - private final double[] values; - private final Object[] labels; - private Domain domain; - - private PieBuilder(Object[] labels, double[] values) { - this.labels = labels; - this.values = values; - } - - public PieBuilder domain(Domain domain) { - this.domain = domain; - return this; - } - - public PieTrace build() { - return new PieTrace(this); - } - - @Override - protected String getType() { - return type; - } - - @Override - public PieTrace.PieBuilder showLegend(boolean b) { - super.showLegend(b); - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java deleted file mode 100644 index 7ce39c2f6..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Scatter3DTrace.java +++ /dev/null @@ -1,192 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -import com.google.common.base.Preconditions; -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.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.plotly.components.HoverLabel; -import tech.tablesaw.plotly.components.Marker; - -public class Scatter3DTrace extends AbstractTrace { - - private final double[] y; - private final double[] x; - private final double[] z; - private final String[] text; - private final Mode mode; - private final HoverLabel hoverLabel; - private final Marker marker; - - public static Scatter3DBuilder builder(double[] x, double[] y, double[] z) { - return new Scatter3DBuilder(x, y, z); - } - - public static Scatter3DBuilder builder( - NumericColumn x, - NumericColumn y, - NumericColumn z) { - return new Scatter3DBuilder(x, y, z); - } - - private Scatter3DTrace(Scatter3DBuilder builder) { - super(builder); - this.mode = builder.mode; - this.y = builder.y; - this.x = builder.x; - this.z = builder.z; - this.text = builder.text; - this.hoverLabel = builder.hoverLabel; - this.marker = builder.marker; - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("mode", mode); - context.put("y", dataAsString(y)); - context.put("x", dataAsString(x)); - context.put("z", dataAsString(z)); - if (marker != null) { - context.put("marker", marker); - } - if (hoverLabel != null) { - context.put("hoverlabel", hoverLabel.asJavascript()); - } - if (text != null) { - context.put("text", dataAsString(text)); - } - return context; - } - - @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 enum Mode { - LINE("line"), - MARKERS("markers"), - LINE_AND_MARKERS("line + markers"), - LINE_AND_TEXT("line + text"), - TEXT_AND_MARKERS("text + text"), - LINE_TEXT_AND_MARKERS("line + text + markers"), - TEXT("text"), - NONE("none"); - - final String value; - - Mode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public static class Scatter3DBuilder extends TraceBuilder { - - private String type = "scatter3d"; - private Mode mode = Mode.MARKERS; - private final double[] x; - private final double[] y; - private final double[] z; - private String[] text; - private Marker marker; - - private Scatter3DBuilder(double[] x, double[] y, double[] z) { - this.x = x; - this.y = y; - this.z = z; - } - - private Scatter3DBuilder( - NumericColumn x, - NumericColumn y, - NumericColumn z) { - this.x = x.asDoubleArray(); - this.y = y.asDoubleArray(); - this.z = z.asDoubleArray(); - } - - public Scatter3DBuilder mode(Mode mode) { - this.mode = mode; - return this; - } - - public Scatter3DBuilder type(String kind) { - this.type = kind; - return this; - } - - public Scatter3DBuilder text(String[] text) { - this.text = text; - return this; - } - - public Scatter3DTrace build() { - return new Scatter3DTrace(this); - } - - protected String getType() { - return type; - } - - @Override - public Scatter3DBuilder name(String name) { - return (Scatter3DBuilder) super.name(name); - } - - @Override - public Scatter3DBuilder opacity(double n) { - Preconditions.checkArgument(n >= 0 && n <= 1); - return (Scatter3DBuilder) super.opacity(n); - } - - @Override - public Scatter3DBuilder legendGroup(String group) { - return (Scatter3DBuilder) super.legendGroup(group); - } - - public Scatter3DBuilder marker(Marker marker) { - this.marker = marker; - return this; - } - - @Override - public Scatter3DBuilder showLegend(boolean showLegend) { - return (Scatter3DBuilder) super.showLegend(showLegend); - } - - @Override - public Scatter3DBuilder visible(Visibility visibility) { - return (Scatter3DBuilder) super.visible(visibility); - } - - @Override - public Scatter3DBuilder hoverLabel(HoverLabel hoverLabel) { - return (Scatter3DBuilder) super.hoverLabel(hoverLabel); - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java deleted file mode 100644 index 0a3eb7df5..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ScatterTrace.java +++ /dev/null @@ -1,411 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -import com.google.common.base.Preconditions; -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.Map; -import tech.tablesaw.api.NumericColumn; -import tech.tablesaw.columns.Column; -import tech.tablesaw.plotly.components.HoverLabel; -import tech.tablesaw.plotly.components.Line; -import tech.tablesaw.plotly.components.Marker; -import tech.tablesaw.plotly.components.change.Decreasing; -import tech.tablesaw.plotly.components.change.Increasing; - -public class ScatterTrace extends AbstractTrace { - - private static final Fill DEFAULT_FILL = Fill.NONE; - private static final double DEFAULT_WHISKER_WIDTH = 0; - - public enum Fill { - NONE("none"), - TO_ZERO_Y("tozeroy"), - TO_ZERO_X("tozerox"), - TO_NEXT_Y("tonexty"), - TO_NEXT_X("tonextx"), - TO_SELF("toself"), - TO_NEXT("tonext"); - - private final String value; - - Fill(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public enum YAxis { - Y("y"), // DEFAULT - Y2("y2"), - Y3("y3"), - Y4("y4"); - - private final String value; - - YAxis(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - private final Fill fill; - private final String fillColor; - private final Object[] y; - private final Object[] x; - private final String[] text; - private final Mode mode; - private final HoverLabel hoverLabel; - private final Marker marker; - private final Line line; - private final YAxis yAxis; - - private final double[] open; - private final double[] high; - private final double[] low; - private final double[] close; - private final double whiskerWidth; - private final Increasing increasing; - private final Decreasing decreasing; - - public static ScatterBuilder builder(double[] x, double[] y) { - return new ScatterBuilder(x, y); - } - - public static ScatterBuilder builder(Column x, Column y) { - return new ScatterBuilder(x, y); - } - - public static ScatterBuilder builder( - Column x, - NumericColumn open, - NumericColumn high, - NumericColumn low, - NumericColumn close) { - return new ScatterBuilder(x, open, high, low, close); - } - - private ScatterTrace(ScatterBuilder builder) { - super(builder); - this.mode = builder.mode; - this.y = builder.y; - this.x = builder.x; - this.text = builder.text; - this.marker = builder.marker; - this.hoverLabel = builder.hoverLabel; - this.line = builder.line; - this.fill = builder.fill; - this.fillColor = builder.fillColor; - this.yAxis = builder.yAxis; - this.open = builder.open; - this.high = builder.high; - this.low = builder.low; - this.close = builder.close; - this.whiskerWidth = builder.whiskerWidth; - this.increasing = builder.increasing; - this.decreasing = builder.decreasing; - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("mode", mode); - if (x != null) { - context.put("x", dataAsString(x)); - } - if (y != null) { - context.put("y", dataAsString(y)); - } - - // for pricing data (candlesticks and OHLC) - if (open != null) { - context.put("open", dataAsString(open)); - } - if (high != null) { - context.put("high", dataAsString(high)); - } - if (low != null) { - context.put("low", dataAsString(low)); - } - if (close != null) { - context.put("close", dataAsString(close)); - } - if (whiskerWidth != DEFAULT_WHISKER_WIDTH) { - context.put("whiskerWidth", whiskerWidth); - } - if (increasing != null) { - context.put("increasing", increasing); - } - if (decreasing != null) { - context.put("decreasing", decreasing); - } - if (yAxis != null) { - context.put("yAxis", yAxis); - } - - context.put("marker", marker); - - if (!fill.equals(DEFAULT_FILL)) { - context.put("fill", fill); - } - if (fillColor != null) { - context.put("fillColor", fillColor); - } - if (hoverLabel != null) { - context.put("hoverlabel", hoverLabel.asJavascript()); - } - if (line != null) { - context.put("line", line.asJavascript()); - } - if (text != null) { - context.put("text", dataAsString(text)); - } - return context; - } - - @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 enum Mode { - LINE("lines"), - MARKERS("markers"), - LINE_AND_MARKERS("lines+markers"), - LINE_AND_TEXT("lines+text"), - TEXT_AND_MARKERS("markers+text"), - LINE_TEXT_AND_MARKERS("lines+markers+text"), - TEXT("text"), - NONE("none"); - - final String value; - - Mode(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - - public static class ScatterBuilder extends TraceBuilder { - - private String type = "scatter"; - private Mode mode = Mode.MARKERS; - private final Object[] x; - private Object[] y; - private String[] text; - private Marker marker; - private YAxis yAxis; - private Line line; - private double[] open; - private double[] close; - private double[] high; - private double[] low; - private Increasing increasing; - private Decreasing decreasing; - - /** - * Sets the area to fill with a solid color. Use with `fillcolor` if not "none". "tozerox" and - * "tozeroy" fill to x=0 and y=0 respectively. "tonextx" and "tonexty" fill between the - * endpoints of this trace and the endpoints of the trace before it, connecting those endpoints - * with straight lines (to make a stacked area graph); if there is no trace before it, they - * behave like "tozerox" and "tozeroy". "toself" connects the endpoints of the trace (or each - * segment of the trace if it has gaps) into a closed shape. "tonext" fills the space between - * two traces if one completely encloses the other (eg consecutive contour lines), and behaves - * like "toself" if there is no trace before it. "tonext" should not be used if one trace does - * not enclose the other. - */ - private ScatterTrace.Fill fill = DEFAULT_FILL; - - /** - * Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, - * or marker line color, whichever is available. - */ - private String fillColor; - - /** - * Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers - * are as wide as the box(es). - */ - private double whiskerWidth = DEFAULT_WHISKER_WIDTH; - - private ScatterBuilder(double[] x, double[] y) { - Double[] x1 = new Double[x.length]; - Double[] y1 = new Double[y.length]; - for (int i = 0; i < x1.length; i++) { - x1[i] = x[i]; - y1[i] = y[i]; - } - this.x = x1; - this.y = y1; - } - - private ScatterBuilder(Column x, Column y) { - this.x = x.asObjectArray(); - this.y = y.asObjectArray(); - } - - private ScatterBuilder( - Column x, - NumericColumn open, - NumericColumn high, - NumericColumn low, - NumericColumn close) { - this.x = x.asObjectArray(); - this.open = open.asDoubleArray(); - this.high = high.asDoubleArray(); - this.low = low.asDoubleArray(); - this.close = close.asDoubleArray(); - } - - public ScatterBuilder mode(Mode mode) { - this.mode = mode; - return this; - } - - /** - * Sets a specific yAxis to this trace when you want to display more than one yAxis in a plot. - * This can be ignored if only one y axis is desired for the whole plot, and need not be set if - * this trace should get the default y-axis. - * - *

There must be a corresponding Y Axis defined in the layout, e.g., if you specify YAxis.Y2 - * here, you must provide a value for yAxis2 in the layout - * - * @param axis The Axis to use for this trace - * @return this ScatterBuilder - */ - public ScatterBuilder yAxis(YAxis axis) { - this.yAxis = axis; - return this; - } - - public ScatterBuilder line(Line line) { - this.line = line; - return this; - } - - /** For candlestick plots */ - public ScatterBuilder whiskerWidth(double width) { - Preconditions.checkArgument(width >= 0 && width <= 1); - this.whiskerWidth = width; - return this; - } - - public ScatterBuilder marker(Marker marker) { - this.marker = marker; - return this; - } - - public ScatterBuilder type(String kind) { - this.type = kind; - return this; - } - - public ScatterBuilder text(String[] text) { - this.text = text; - return this; - } - - /** For candlestick plots */ - public ScatterBuilder increasing(Increasing increasing) { - this.increasing = increasing; - return this; - } - - /** For candlestick plots */ - public ScatterBuilder decreasing(Decreasing decreasing) { - this.decreasing = decreasing; - return this; - } - - public ScatterBuilder fill(ScatterTrace.Fill fill) { - this.fill = fill; - return this; - } - - public ScatterBuilder fillColor(String fillColor) { - this.fillColor = fillColor; - return this; - } - - public ScatterTrace build() { - return new ScatterTrace(this); - } - - protected String getType() { - return type; - } - - @Override - public ScatterBuilder name(String name) { - return (ScatterBuilder) super.name(name); - } - - @Override - public ScatterBuilder opacity(double n) { - Preconditions.checkArgument(n >= 0 && n <= 1); - return (ScatterBuilder) super.opacity(n); - } - - @Override - public ScatterBuilder legendGroup(String group) { - return (ScatterBuilder) super.legendGroup(group); - } - - @Override - public ScatterBuilder showLegend(boolean showLegend) { - return (ScatterBuilder) super.showLegend(showLegend); - } - - @Override - public ScatterBuilder visible(Visibility visibility) { - return (ScatterBuilder) super.visible(visibility); - } - - @Override - public ScatterBuilder hoverLabel(HoverLabel hoverLabel) { - return (ScatterBuilder) super.hoverLabel(hoverLabel); - } - - @Override - public ScatterBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public ScatterBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Trace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/Trace.java deleted file mode 100644 index aade7efd9..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/Trace.java +++ /dev/null @@ -1,20 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import tech.tablesaw.plotly.components.HoverLabel; - -public interface Trace { - - /** - * Returns a string of Javascript code that can be used to display the trace in a browser - * - * @param i A unique number for this trace in the enclosing figure - * @return A string that can be rendered in javascript - */ - String asJavascript(int i); - - String name(); - - HoverLabel hoverLabel(); - - boolean showLegend(); -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/TraceBuilder.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/TraceBuilder.java deleted file mode 100644 index 4c40791a7..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/TraceBuilder.java +++ /dev/null @@ -1,101 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import com.google.common.base.Preconditions; -import tech.tablesaw.columns.Column; -import tech.tablesaw.plotly.components.HoverLabel; - -public abstract class TraceBuilder { - - protected AbstractTrace.Visibility visible = AbstractTrace.DEFAULT_VISIBILITY; - - /** Determines whether or not an item corresponding to this trace is shown in the legend. */ - protected Boolean showLegend = null; - - /** - * Sets the legend group for this trace. Traces part of the same legend group hide/show at the - * same time when toggling legend items. - */ - protected String legendGroup = ""; - - /** Sets the opacity of the trace. */ - protected double opacity = AbstractTrace.DEFAULT_OPACITY; // number between or equal to 0 and 1 - - /** Sets the trace name. The trace name appear as the legend item and on hover. */ - protected String name; - - /** - * Assigns id labels to each datum. These ids for object constancy of data points during - * animation. Should be an array of strings, not numbers or any other type. - */ - protected String[] ids; - - protected HoverLabel hoverLabel; - - /** - * Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If *x* (the - * default value), the x coordinates refer to `layout.xaxis`. If *x2*, the x coordinates refer to - * `layout.xaxis2`, and so on. - */ - protected String xAxis = "x"; - /** - * Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If *y* (the - * default value), the y coordinates refer to `layout.yaxis`. If *y2*, the y coordinates refer to - * `layout.yaxis2`, and so on. - */ - protected String yAxis = "y"; - - TraceBuilder() {} - - protected abstract String getType(); - - public TraceBuilder name(String name) { - this.name = name; - return this; - } - - public TraceBuilder opacity(double n) { - Preconditions.checkArgument(n >= 0 && n <= 1); - this.opacity = n; - return this; - } - - public TraceBuilder legendGroup(String group) { - this.legendGroup = group; - return this; - } - - protected TraceBuilder showLegend(boolean showLegend) { - this.showLegend = showLegend; - return this; - } - - protected TraceBuilder visible(AbstractTrace.Visibility visibility) { - this.visible = visibility; - return this; - } - - protected TraceBuilder hoverLabel(HoverLabel hoverLabel) { - this.hoverLabel = hoverLabel; - return this; - } - - protected static String[] columnToStringArray(Column column) { - String[] x = new String[column.size()]; - for (int i = 0; i < column.size(); i++) { - x[i] = column.getString(i); - } - return x; - } - - public TraceBuilder xAxis(String xAxis) { - Preconditions.checkArgument(xAxis.matches("^x[0-9]*$")); - this.xAxis = xAxis; - return this; - } - - public TraceBuilder yAxis(String yAxis) { - Preconditions.checkArgument(yAxis.matches("^y[0-9]*$")); - this.yAxis = yAxis; - return this; - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java b/jsplot/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java deleted file mode 100644 index a9a545bfa..000000000 --- a/jsplot/src/main/java/tech/tablesaw/plotly/traces/ViolinTrace.java +++ /dev/null @@ -1,132 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static tech.tablesaw.plotly.Utils.dataAsString; - -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.Map; -import tech.tablesaw.api.CategoricalColumn; -import tech.tablesaw.api.NumericColumn; - -public class ViolinTrace extends AbstractTrace { - - private final Object[] x; - private final double[] y; - private final boolean showBoxPlot; - private final boolean showMeanLine; - - private ViolinTrace(ViolinBuilder builder) { - super(builder); - this.x = builder.x; - this.y = builder.y; - this.showMeanLine = builder.showMeanLine; - this.showBoxPlot = builder.showBoxPlot; - } - - public static ViolinBuilder builder(Object[] x, double[] y) { - return new ViolinBuilder(x, y); - } - - public static ViolinBuilder builder(CategoricalColumn x, NumericColumn y) { - return new ViolinBuilder(x, y); - } - - public static ViolinBuilder builder(double[] x, double[] y) { - Double[] xObjs = new Double[x.length]; - for (int i = 0; i < x.length; i++) { - xObjs[i] = x[i]; - } - return new ViolinBuilder(xObjs, y); - } - - @Override - public String asJavascript(int i) { - Writer writer = new StringWriter(); - PebbleTemplate compiledTemplate; - - try { - compiledTemplate = engine.getTemplate("trace_template.html"); - compiledTemplate.evaluate(writer, getContext(i)); - } catch (PebbleException e) { - throw new IllegalStateException(e); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return writer.toString(); - } - - private Map getContext(int i) { - - Map context = super.getContext(); - context.put("variableName", "trace" + i); - context.put("y", dataAsString(y)); - context.put("x", dataAsString(x)); - if (showBoxPlot){ - context.put("box", "{visible: true}"); - } - if (showMeanLine){ - context.put("meanLine", "{visible: true}"); - } - return context; - } - - public static class ViolinBuilder extends TraceBuilder { - - private static final String type = "violin"; - private final Object[] x; - private final double[] y; - private boolean showBoxPlot; - private boolean showMeanLine; - - ViolinBuilder(Object[] x, double[] y) { - this.x = x; - this.y = y; - } - - @Override - public ViolinBuilder name(String name) { - super.name(name); - return this; - } - - ViolinBuilder(CategoricalColumn x, NumericColumn y) { - this.x = columnToStringArray(x); - this.y = y.asDoubleArray(); - } - - public ViolinBuilder boxPlot(boolean show) { - this.showBoxPlot = show; - return this; - } - - public ViolinBuilder meanLine(boolean show) { - this.showMeanLine = show; - return this; - } - - public ViolinTrace build() { - return new ViolinTrace(this); - } - - @Override - public ViolinBuilder xAxis(String xAxis) { - super.xAxis(xAxis); - return this; - } - - @Override - public ViolinBuilder yAxis(String yAxis) { - super.yAxis(yAxis); - return this; - } - - @Override - protected String getType() { - return type; - } - } -} diff --git a/jsplot/src/main/java/tech/tablesaw/plotly/wrappers/TraceWrapper.java b/jsplot/src/main/java/tech/tablesaw/plotly/wrappers/TraceWrapper.java new file mode 100644 index 000000000..505752851 --- /dev/null +++ b/jsplot/src/main/java/tech/tablesaw/plotly/wrappers/TraceWrapper.java @@ -0,0 +1,14 @@ +package tech.tablesaw.plotly.wrappers; + +import tech.tablesaw.columns.Column; + +public class TraceWrapper { + + protected static String[] columnToStringArray(Column column) { + String[] x = new String[column.size()]; + for (int i = 0; i < column.size(); i++) { + x[i] = column.getString(i); + } + return x; + } +} diff --git a/jsplot/src/test/java/tech/tablesaw/components/AnnotationTest.java b/jsplot/src/test/java/tech/tablesaw/components/AnnotationTest.java deleted file mode 100644 index 2577a4461..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/AnnotationTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package tech.tablesaw.components; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Annotation; -import tech.tablesaw.plotly.components.Font; - -@Disabled -public class AnnotationTest { - @Test - public void asJavascript() { - Annotation annotation = Annotation.builder().xref("paper"). - yref("paper") - .x(0) - .y(0) - .yanchor(Annotation.Yanchor.BOTTOM). - bordercolor("#c7c7c7") - .font(Font.builder().build()) - .text("X asis label") - .showarrow(false).build(); - System.out.println(annotation.asJavascript()); - } - - @Test - public void asJavascript2() { - Annotation annotation = Annotation.builder() - .xref("x") - .yref("y") - .x(0) - .y(0) - .yanchor(Annotation.Yanchor.BOTTOM) - .bordercolor("#c7c7c7") - .font(Font.builder().family(Font.Family.SANS_SERIF).size(16).color("#ffffff").build()) - .text("max=5").align(Annotation.Align.CENTER).arrowhead(2).arrowsize(1).arrowwidth(2).ax(20).ay(-30) - .font(Font.builder().color("rgba(0,0,0,0)").build()) - .showarrow(true).build(); - System.out.println(annotation.asJavascript()); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/AxisTest.java b/jsplot/src/test/java/tech/tablesaw/components/AxisTest.java deleted file mode 100644 index 1b1218452..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/AxisTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package tech.tablesaw.components; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Axis; -import tech.tablesaw.plotly.components.Font; - -@Disabled -public class AxisTest { - - @Test - public void asJavascript() { - Axis x = - Axis.builder() - .title("x Axis 1") - .visible(true) - .type(Axis.Type.DEFAULT) - .titleFont(Font.builder().family(Font.Family.ARIAL).size(8).color("red").build()) - .build(); - - System.out.println(x); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/GridTest.java b/jsplot/src/test/java/tech/tablesaw/components/GridTest.java deleted file mode 100644 index ac886b6b3..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/GridTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package tech.tablesaw.components; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Grid; - -public class GridTest { - - @Test - public void asJavascript() { - Grid x = - Grid.builder() - .rows(10) - .columns(5) - .rowOrder(Grid.RowOrder.BOTTOM_TO_TOP) - .pattern(Grid.Pattern.INDEPENDENT) - .build(); - - String asJavascript = x.asJavascript(); - assertTrue(asJavascript.contains("rows")); - assertTrue(asJavascript.contains("columns")); - assertTrue(asJavascript.contains("roworder")); - assertTrue(asJavascript.contains("pattern")); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/HoverLabelTest.java b/jsplot/src/test/java/tech/tablesaw/components/HoverLabelTest.java deleted file mode 100644 index dbffc7d36..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/HoverLabelTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package tech.tablesaw.components; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Font; -import tech.tablesaw.plotly.components.HoverLabel; - -@Disabled -public class HoverLabelTest { - - @Test - public void asJavascript() { - HoverLabel x = - HoverLabel.builder() - .nameLength(10) - .bgColor("blue") - .borderColor("green") - .font(Font.builder().family(Font.Family.ARIAL).size(8).color("red").build()) - .build(); - - System.out.println(x); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/LayoutTest.java b/jsplot/src/test/java/tech/tablesaw/components/LayoutTest.java deleted file mode 100644 index a9ca6d496..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/LayoutTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package tech.tablesaw.components; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Axis; -import tech.tablesaw.plotly.components.Grid; -import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.components.Margin; - -public class LayoutTest { - - private static final String LINE_END = System.lineSeparator(); - - // @Test - public void asJavascript() { - - Axis x = Axis.builder().title("x axis").build(); - Axis y = Axis.builder().title("y axis").build(); - - Layout layout = - Layout.builder() - .title("foobar") - .xAxis(x) - .yAxis(y) - .showLegend(true) - .margin(Margin.builder().top(100).bottom(100).left(200).right(200).build()) - .build(); - System.out.println(layout.asJavascript()); - } - - // @Test - public void asJavascriptForGrid() { - - Axis x = Axis.builder().title("x axis").build(); - Axis y = Axis.builder().title("y axis").build(); - Grid grid = Grid.builder().rows(2).columns(2).build(); - Layout layout = - Layout.builder() - .title("foobar") - .xAxis(x) - .yAxis(y) - .grid(grid) - .showLegend(true) - .margin(Margin.builder().top(100).bottom(100).left(200).right(200).build()) - .build(); - String asJavascript = layout.asJavascript(); - assertTrue(asJavascript.contains("rows")); - assertTrue(asJavascript.contains("columns")); - assertTrue(asJavascript.contains("rows")); - assertTrue(asJavascript.contains("xAxis")); - } - - @Test - public void testAutosize() { - { - Layout layout = Layout.builder().autosize(true).build(); - assertEquals( - "var layout = {" - + LINE_END - + " autosize: true," - + LINE_END - + LINE_END - + LINE_END - + "};" - + LINE_END, - layout.asJavascript()); - } - { - Layout layout = Layout.builder().autosize(true).width(800).build(); - assertEquals( - "var layout = {" - + LINE_END - + " width: 800," - + LINE_END - + " autosize: true," - + LINE_END - + LINE_END - + LINE_END - + "};" - + LINE_END, - layout.asJavascript()); - } - { - Layout layout = Layout.builder().autosize(true).height(600).width(800).build(); - assertEquals( - "var layout = {" - + LINE_END - + " height: 600," - + LINE_END - + " width: 800," - + LINE_END - + " autosize: true," - + LINE_END - + LINE_END - + LINE_END - + "};" - + LINE_END, - layout.asJavascript()); - } - { - // see if 700x450 - Layout layout = Layout.builder().autosize(false).height(600).build(); - assertEquals( - "var layout = {" - + LINE_END - + " height: 600," - + LINE_END - + " width: 700," - + LINE_END - + LINE_END - + LINE_END - + "};" - + LINE_END, - layout.asJavascript()); - } - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/MarkerTest.java b/jsplot/src/test/java/tech/tablesaw/components/MarkerTest.java deleted file mode 100644 index d7a64dc02..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/MarkerTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package tech.tablesaw.components; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Marker; -import tech.tablesaw.plotly.components.Symbol; - -public class MarkerTest { - - @Test - public void asJavascript() { - Marker x = Marker.builder().size(12.0).symbol(Symbol.DIAMOND_TALL).color("#c68486").build(); - - assertTrue(x.asJavascript().contains("color")); - assertTrue(x.asJavascript().contains("symbol")); - assertTrue(x.asJavascript().contains("size")); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/components/TemplateUtilsTest.java b/jsplot/src/test/java/tech/tablesaw/components/TemplateUtilsTest.java deleted file mode 100644 index 53c90c56c..000000000 --- a/jsplot/src/test/java/tech/tablesaw/components/TemplateUtilsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package tech.tablesaw.components; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.File; -import java.net.URL; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Page; -import tech.tablesaw.plotly.components.Page.PageBuilder; -import tech.tablesaw.plotly.components.TemplateUtils; -import tech.tablesaw.plotly.traces.ScatterTrace; -import tech.tablesaw.plotly.traces.Trace; - -public class TemplateUtilsTest { - - private double[] x = {1, 2, 3, 4, 5}; - private double[] y = {1, 4, 9, 16, 25}; - - private String customTemplateString = ""; - - @Test - public void testDefaultTemplateLocation() { - TemplateUtils.setTemplateLocations(); - String html = createPageHtml(); - assertTrue(html.indexOf(customTemplateString) < 0); - } - - @Test - public void testCustomTemplateLocation() { - URL url = this.getClass().getResource(this.getClass().getSimpleName() + ".class"); - assertNotNull(url, "Couldn't locate class (as resource), where template is also found"); - String path = url.getPath(); - assertTrue(path.lastIndexOf('/') >= 0); - String folderPath = path.substring(0, path.lastIndexOf('/')); - File templateFile = new File(folderPath + "/page_template.html"); - assertTrue(templateFile.exists(), templateFile + " doesn't exist"); - TemplateUtils.setTemplateLocations(folderPath); - String html = createPageHtml(); - assertTrue(html.indexOf(customTemplateString) >= 0); - } - - private String createPageHtml() { - Trace trace = ScatterTrace.builder(x, y).build(); - Figure figure = new Figure(trace); - Page page = new PageBuilder(figure, "plot").build(); - String html = page.asJavascript(); - return html; - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/examples/BarExample.java b/jsplot/src/test/java/tech/tablesaw/examples/BarExample.java index 8f27ff875..d9f8e9099 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/BarExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/BarExample.java @@ -74,7 +74,9 @@ public static void main(String[] args) throws Exception { for (int i = 0; i < 2; i++) { String name = numberColNames[i]; BarTrace trace = - BarTrace.builder(summaryTable.categoricalColumn("scale"), summaryTable.numberColumn(name)) + BarTrace.builder( + summaryTable.categoricalColumn("scale").asObjectArray(), + summaryTable.numberColumn(name).asDoubleArray()) .orientation(BarTrace.Orientation.VERTICAL) .marker(Marker.builder().color(colors[i]).build()) .showLegend(true) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/BarPieAndParetoExample.java b/jsplot/src/test/java/tech/tablesaw/examples/BarPieAndParetoExample.java index e13d3967d..327b380b5 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/BarPieAndParetoExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/BarPieAndParetoExample.java @@ -55,7 +55,10 @@ public static void main(String[] args) throws Exception { t2 = t2.sortDescendingOn(t2.column(1).name()); Layout layout = Layout.builder().title("Tornado Fatalities by State").build(); - BarTrace trace = BarTrace.builder(t2.categoricalColumn(0), t2.numberColumn(1)).build(); + BarTrace trace = + BarTrace.builder( + t2.categoricalColumn(0).asObjectArray(), t2.numberColumn(1).asDoubleArray()) + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/BoxExample.java b/jsplot/src/test/java/tech/tablesaw/examples/BoxExample.java index b3c35ff25..e3898ada3 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/BoxExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/BoxExample.java @@ -32,7 +32,10 @@ public static void main(String[] args) throws Exception { Layout layout = Layout.builder().title("Tornado Injuries by Scale").build(); BoxTrace trace = - BoxTrace.builder(table.categoricalColumn("scale"), table.nCol("injuries")).build(); + BoxTrace.builder( + table.categoricalColumn("scale").asObjectArray(), + table.nCol("injuries").asDoubleArray()) + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/BubbleExample.java b/jsplot/src/test/java/tech/tablesaw/examples/BubbleExample.java index 574f5eb18..8786e6b0c 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/BubbleExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/BubbleExample.java @@ -34,8 +34,10 @@ public static void main(String[] args) throws IOException { NumericColumn data = sub.nCol("Market_Share"); Layout layout = Layout.builder().title("Market Share").build(); - Marker marker = Marker.builder().size(data).sizeMode(Marker.SizeMode.AREA).build(); - ScatterTrace trace = ScatterTrace.builder(x, y).marker(marker).build(); + Marker marker = + Marker.builder().size(data.asDoubleArray()).sizeMode(Marker.SizeMode.AREA).build(); + ScatterTrace trace = + ScatterTrace.builder(x.asDoubleArray(), y.asDoubleArray()).marker(marker).build(); Plot.show(new Figure(layout, trace)); } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/DistributionVisualizations.java b/jsplot/src/test/java/tech/tablesaw/examples/DistributionVisualizations.java index bb62d55d2..421255c1d 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/DistributionVisualizations.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/DistributionVisualizations.java @@ -28,7 +28,7 @@ public static void main(String[] args) throws Exception { Layout layout = Layout.builder().title("Distribution of property sizes").build(); HistogramTrace trace = - HistogramTrace.builder(property.numberColumn("sq__ft")) + HistogramTrace.builder(property.numberColumn("sq__ft").asDoubleArray()) .marker(Marker.builder().color("#B10DC9").opacity(.70).build()) .build(); Plot.show(new Figure(layout, trace)); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/DotPlotExample.java b/jsplot/src/test/java/tech/tablesaw/examples/DotPlotExample.java index ed5e75214..2e1f6e79c 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/DotPlotExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/DotPlotExample.java @@ -6,6 +6,7 @@ import tech.tablesaw.api.NumericColumn; import tech.tablesaw.api.Table; import tech.tablesaw.plotly.Plot; +import tech.tablesaw.plotly.Utils; import tech.tablesaw.plotly.components.Figure; import tech.tablesaw.plotly.components.Layout; import tech.tablesaw.plotly.components.Marker; @@ -23,7 +24,10 @@ public static void main(String[] args) throws Exception { Layout layout = Layout.builder().title("Approval ratings by agency").build(); - ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.MARKERS).build(); + ScatterTrace trace = + ScatterTrace.builder(x.asObjectArray(), Utils.dataAsArrayofStrings(y.asObjectArray())) + .mode(ScatterTrace.Mode.MARKERS) + .build(); Plot.show(new Figure(layout, trace)); // A more complex example involving two traces @@ -41,14 +45,18 @@ public static void main(String[] args) throws Exception { Table year1 = summary.where(summary.intColumn("year").isEqualTo(2001)); Table year2 = summary.where(summary.intColumn("year").isEqualTo(2002)); ScatterTrace trace2 = - ScatterTrace.builder(year1.nCol("Mean [approval]"), year1.stringColumn("who")) + ScatterTrace.builder( + year1.nCol("Mean [approval]").asObjectArray(), + Utils.dataAsArrayofStrings(year1.stringColumn("who").asObjectArray())) .name("2001") .mode(ScatterTrace.Mode.MARKERS) .marker(Marker.builder().symbol(Symbol.DIAMOND).color("red").size(10).build()) .build(); ScatterTrace trace3 = - ScatterTrace.builder(year2.nCol("Mean [approval]"), year2.stringColumn("who")) + ScatterTrace.builder( + year2.nCol("Mean [approval]").asObjectArray(), + Utils.dataAsArrayofStrings(year2.stringColumn("who").asObjectArray())) .name("2002") .mode(ScatterTrace.Mode.MARKERS) .marker(Marker.builder().symbol(Symbol.STAR).size(10).color("blue").build()) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HistogramExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HistogramExample.java index 4e903e87a..b18b4a408 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HistogramExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HistogramExample.java @@ -27,7 +27,7 @@ public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Layout layout = Layout.builder().title("Distribution of team batting averages").build(); - HistogramTrace trace = HistogramTrace.builder(baseball.nCol("BA")).build(); + HistogramTrace trace = HistogramTrace.builder(baseball.nCol("BA").asDoubleArray()).build(); Plot.show(new Figure(layout, trace)); } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HistogramFuncExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HistogramFuncExample.java index 75cda5661..86c7a2b57 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HistogramFuncExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HistogramFuncExample.java @@ -14,6 +14,8 @@ package tech.tablesaw.examples; +import static tech.tablesaw.plotly.traces.HistogramTrace.HistFunc.*; + import tech.tablesaw.api.IntColumn; import tech.tablesaw.api.StringColumn; import tech.tablesaw.api.Table; @@ -22,28 +24,34 @@ import tech.tablesaw.plotly.components.Layout; import tech.tablesaw.plotly.traces.HistogramTrace; -import static tech.tablesaw.plotly.traces.HistogramTrace.HistFunc.*; - /** */ public class HistogramFuncExample { public static void main(String[] args) { - Table test = Table.create( - StringColumn.create("type").append("apples").append("apples").append("apples").append("oranges").append("bananas"), + Table test = + Table.create( + StringColumn.create("type") + .append("apples") + .append("apples") + .append("apples") + .append("oranges") + .append("bananas"), IntColumn.create("num").append(5).append(10).append(3).append(10).append(5)); Layout layout1 = Layout.builder().title("Histogram COUNT Test (team batting averages)").build(); - HistogramTrace trace = HistogramTrace. - builder(test.stringColumn("type"), test.intColumn("num")) + HistogramTrace trace = + HistogramTrace.builder( + test.stringColumn("type").asObjectArray(), test.intColumn("num").asDoubleArray()) .histFunc(COUNT) .build(); Plot.show(new Figure(layout1, trace)); Layout layout2 = Layout.builder().title("Hist SUM Test (team batting averages)").build(); - HistogramTrace trace2 = HistogramTrace. - builder(test.stringColumn("type"), test.intColumn("num")) + HistogramTrace trace2 = + HistogramTrace.builder( + test.stringColumn("type").asObjectArray(), test.intColumn("num").asDoubleArray()) .histFunc(SUM) .build(); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HistogramHorizontalExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HistogramHorizontalExample.java index 5afa75bc1..f990e480a 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HistogramHorizontalExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HistogramHorizontalExample.java @@ -41,7 +41,7 @@ public static void main(String[] args) throws Exception { Table t2 = groups.get(1).asTable(); HistogramTrace trace1 = - HistogramTrace.builder(t1.nCol("BA")) + HistogramTrace.builder(t1.nCol("BA").asDoubleArray()) .name("American League") .opacity(.75) .nBinsY(24) @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception { .build(); HistogramTrace trace2 = - HistogramTrace.builder(t2.nCol("BA")) + HistogramTrace.builder(t2.nCol("BA").asDoubleArray()) .name("National League") .opacity(.75) .nBinsY(24) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HistogramOverlayExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HistogramOverlayExample.java index a38d6c6ae..498e0ada5 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HistogramOverlayExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HistogramOverlayExample.java @@ -39,7 +39,7 @@ public static void main(String[] args) throws Exception { Table t1 = groups.get(0).asTable(); HistogramTrace trace1 = - HistogramTrace.builder(t1.nCol("BA")) + HistogramTrace.builder(t1.nCol("BA").asDoubleArray()) .name("American Leage") .opacity(.75) .nBinsX(24) @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception { Table t2 = groups.get(1).asTable(); HistogramTrace trace2 = - HistogramTrace.builder(t2.nCol("BA")) + HistogramTrace.builder(t2.nCol("BA").asDoubleArray()) .name("National League") .opacity(.75) .nBinsX(24) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HistogramProbabilityExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HistogramProbabilityExample.java index 8c9774fdd..36418bf3a 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HistogramProbabilityExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HistogramProbabilityExample.java @@ -26,9 +26,10 @@ public class HistogramProbabilityExample { public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); - Layout layout = Layout.builder().title("Probability Histogram of team batting averages").build(); - HistogramTrace trace = HistogramTrace. - builder(baseball.nCol("BA")) + Layout layout = + Layout.builder().title("Probability Histogram of team batting averages").build(); + HistogramTrace trace = + HistogramTrace.builder(baseball.nCol("BA").asDoubleArray()) .histNorm(HistogramTrace.HistNorm.PROBABILITY) .build(); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HorizontalBarExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HorizontalBarExample.java index 9d3e1dcc1..9ce455116 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HorizontalBarExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HorizontalBarExample.java @@ -30,7 +30,7 @@ public static void main(String[] args) throws Exception { Table s = table.summarize("fatalities", count).by("State"); BarTrace trace = - BarTrace.builder(s.categoricalColumn(0), s.numberColumn(1)) + BarTrace.builder(s.categoricalColumn(0).asObjectArray(), s.numberColumn(1).asDoubleArray()) .orientation(BarTrace.Orientation.HORIZONTAL) .build(); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/HoverBroadcastExample.java b/jsplot/src/test/java/tech/tablesaw/examples/HoverBroadcastExample.java index 54f551bb7..617915a56 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/HoverBroadcastExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/HoverBroadcastExample.java @@ -39,7 +39,7 @@ public static void main(String[] args) throws Exception { IntColumn y1 = IntColumn.create("volume", volumes); ScatterTrace trace0 = - ScatterTrace.builder(x, y2) + ScatterTrace.builder(x.asObjectArray(), y2.asObjectArray()) .showLegend(true) .name("Price") .mode(ScatterTrace.Mode.LINE) @@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception { .build(); ScatterTrace trace1 = - ScatterTrace.builder(x, y1) + ScatterTrace.builder(x.asObjectArray(), y1.asObjectArray()) .showLegend(true) .name("Volume") .mode(ScatterTrace.Mode.LINE) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/LineOptionsExample.java b/jsplot/src/test/java/tech/tablesaw/examples/LineOptionsExample.java index 9eff5ca47..b76148ac3 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/LineOptionsExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/LineOptionsExample.java @@ -33,7 +33,10 @@ public static void main(String[] args) throws Exception { private void showDefaultLines() { Layout layout = Layout.builder().title("Default Line Style").build(); - ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); Plot.show(new Figure(layout, trace)); } @@ -41,7 +44,7 @@ private void showDefaultLines() { private void showWideLines() { Layout layout = Layout.builder().title("Wide lines").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().width(4).build()) .build(); @@ -51,7 +54,7 @@ private void showWideLines() { private void showRedLines() { Layout layout = Layout.builder().title("Red Lines").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().color("red").build()) .build(); @@ -62,7 +65,7 @@ private void showRedLines() { private void showSmoothedLines() { Layout layout = Layout.builder().title("Smoothed lines").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().shape(Line.Shape.SPLINE).smoothing(1.2).build()) .build(); @@ -73,7 +76,7 @@ private void showSmoothedLines() { private void showSteppedLines() { Layout layout = Layout.builder().title("Stepped lines using HV shape").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().shape(Line.Shape.HV).build()) .build(); @@ -84,7 +87,7 @@ private void showSteppedLines() { private void showSteppedLines2() { Layout layout = Layout.builder().title("Stepped lines using VHV shape").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().shape(Line.Shape.VHV).build()) .build(); @@ -95,7 +98,7 @@ private void showSteppedLines2() { private void showDashedLine() { Layout layout = Layout.builder().title("Dashed lines").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().dash(Line.Dash.LONG_DASH).build()) .build(); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExample.java b/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExample.java index 092137de6..53f1509e0 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExample.java @@ -30,7 +30,10 @@ public static void main(String[] args) throws Exception { Layout layout = Layout.builder().title("Monthly Boston Armed Robberies Jan. 1966 - Oct. 1975").build(); - ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.LINE).build(); + ScatterTrace trace = + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .mode(ScatterTrace.Mode.LINE) + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExampleWithSmoothing.java b/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExampleWithSmoothing.java index ca988a1a1..c81d32356 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExampleWithSmoothing.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/LinePlotExampleWithSmoothing.java @@ -34,7 +34,7 @@ public static void main(String[] args) throws Exception { Layout.builder().title("Monthly Boston Armed Robberies Jan. 1966 - Oct. 1975").build(); ScatterTrace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().shape(Line.Shape.SPLINE).smoothing(1.2).build()) .build(); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/MarkerOptionsExample.java b/jsplot/src/test/java/tech/tablesaw/examples/MarkerOptionsExample.java index 2c216db2b..64b182d90 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/MarkerOptionsExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/MarkerOptionsExample.java @@ -21,7 +21,7 @@ public class MarkerOptionsExample { private final NumericColumn x; private final NumericColumn y; - private MarkerOptionsExample() throws Exception { + private MarkerOptionsExample() { this.baseball = Table.read().csv("../data/baseball.csv"); this.x = baseball.nCol("BA"); this.y = baseball.nCol("W"); @@ -53,7 +53,10 @@ private void showRedMarkers() { .yAxis(Axis.builder().title("Wins").build()) .build(); - Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().color("red").build()).build(); + Trace trace = + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().color("red").build()) + .build(); Plot.show(new Figure(layout, trace)); } @@ -73,7 +76,7 @@ private void showColorScale() { IntColumn wins = baseball.intColumn("W"); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker( Marker.builder() .color(wins.asDoubleArray()) @@ -100,7 +103,7 @@ private void showColorScaleWithBar() { IntColumn wins = baseball.intColumn("W"); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker( Marker.builder() .color(wins.asDoubleArray()) @@ -128,7 +131,7 @@ private void showColorScaleWithCustomBar() { IntColumn wins = baseball.intColumn("W"); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker( Marker.builder() .color(wins.asDoubleArray()) @@ -166,7 +169,7 @@ private void showMarkerGradient() { .build(); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker( Marker.builder() .size(10) @@ -187,7 +190,7 @@ private void showCustomLine() { .build(); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker( Marker.builder() .line(Line.builder().color("rgb(231, 99, 250)").width(1).build()) @@ -209,7 +212,9 @@ private void showBowTieSymbol() { .build(); Trace trace = - ScatterTrace.builder(x, y).marker(Marker.builder().symbol(Symbol.BOWTIE).build()).build(); + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().symbol(Symbol.BOWTIE).build()) + .build(); Plot.show(new Figure(layout, trace)); } @@ -222,7 +227,10 @@ private void show50PctOpacity() { .yAxis(Axis.builder().title("Wins").build()) .build(); - Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().opacity(.5).build()).build(); + Trace trace = + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().opacity(.5).build()) + .build(); Plot.show(new Figure(layout, trace)); } @@ -235,7 +243,10 @@ private void showLargeMarkers() { .yAxis(Axis.builder().title("Wins").build()) .build(); - Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().size(9).build()).build(); + Trace trace = + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().size(9).build()) + .build(); Plot.show(new Figure(layout, trace)); } @@ -249,7 +260,7 @@ private void showRGBColor() { .build(); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .marker(Marker.builder().color("rgb(17, 157, 255)").build()) .build(); Plot.show(new Figure(layout, trace)); @@ -264,7 +275,7 @@ private void showDefault() { .yAxis(Axis.builder().title("Wins").build()) .build(); - Trace trace = ScatterTrace.builder(x, y).build(); + Trace trace = ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()).build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/MultiPlotExample.java b/jsplot/src/test/java/tech/tablesaw/examples/MultiPlotExample.java index 081ef4f03..e7ef55e7d 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/MultiPlotExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/MultiPlotExample.java @@ -89,8 +89,8 @@ public static void main(String[] args) throws Exception { .build(); // 5. Create the traces for each plot - Trace trace1 = ScatterTrace.builder(x1, y1).build(); - Trace trace2 = ScatterTrace.builder(x2, y2).build(); + Trace trace1 = ScatterTrace.builder(x1.asObjectArray(), y1.asObjectArray()).build(); + Trace trace2 = ScatterTrace.builder(x2.asObjectArray(), y2.asObjectArray()).build(); // 6. Build a Figure for each plot from the layout and trace Figure figure1 = new Figure(layout1, trace1); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/ParetoExample.java b/jsplot/src/test/java/tech/tablesaw/examples/ParetoExample.java index 821473fb3..55ecd3a49 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/ParetoExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/ParetoExample.java @@ -32,7 +32,10 @@ public static void main(String[] args) throws Exception { t2 = t2.sortDescendingOn(t2.column(1).name()); Layout layout = Layout.builder().title("Tornado Fatalities by State").build(); - BarTrace trace = BarTrace.builder(t2.categoricalColumn(0), t2.numberColumn(1)).build(); + BarTrace trace = + BarTrace.builder( + t2.categoricalColumn(0).asObjectArray(), t2.numberColumn(1).asDoubleArray()) + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/PieExample.java b/jsplot/src/test/java/tech/tablesaw/examples/PieExample.java index a68a70056..48b45bdc1 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/PieExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/PieExample.java @@ -29,7 +29,10 @@ public static void main(String[] args) throws Exception { Table t2 = table.countBy(table.categoricalColumn("Scale")); PieTrace trace = - PieTrace.builder(t2.categoricalColumn("Category"), t2.numberColumn("Count")).build(); + PieTrace.builder( + t2.categoricalColumn("Category").asObjectArray(), + t2.numberColumn("Count").asDoubleArray()) + .build(); Layout layout = Layout.builder().title("Total fatalities by scale").build(); Plot.show(new Figure(layout, trace)); diff --git a/jsplot/src/test/java/tech/tablesaw/examples/ScatterLegendExample.java b/jsplot/src/test/java/tech/tablesaw/examples/ScatterLegendExample.java index f6e086f12..06b8fc08b 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/ScatterLegendExample.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/ScatterLegendExample.java @@ -26,7 +26,10 @@ public static void main(String[] args) throws Exception { .showLegend(true) .build(); Trace trace = - ScatterTrace.builder(x, y).marker(Marker.builder().size(1).build()).name("lat/lon").build(); + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().size(1).build()) + .name("lat/lon") + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithSpecificAxisRange.java b/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithSpecificAxisRange.java index 5e125017a..b3d65782e 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithSpecificAxisRange.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithSpecificAxisRange.java @@ -40,7 +40,10 @@ public static void main(String[] args) throws Exception { .yAxis(Axis.builder().range(20, 60).build()) .build(); Trace trace = - ScatterTrace.builder(x, y).marker(Marker.builder().size(1).build()).name("lat/lon").build(); + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) + .marker(Marker.builder().size(1).build()) + .name("lat/lon") + .build(); Plot.show(new Figure(layout, trace)); } } diff --git a/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithTwoYAxes.java b/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithTwoYAxes.java index 5315b237b..b404718e8 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithTwoYAxes.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/ScatterplotWithTwoYAxes.java @@ -56,13 +56,13 @@ public static void main(String[] args) throws Exception { .build(); Trace trace = - ScatterTrace.builder(x, y) + ScatterTrace.builder(x.asObjectArray(), y.asObjectArray()) .name("Batting avg.") .marker(Marker.builder().opacity(.7).color("#01FF70").build()) .build(); Trace trace2 = - ScatterTrace.builder(x, y2) + ScatterTrace.builder(x.asObjectArray(), y2.asObjectArray()) .yAxis(ScatterTrace.YAxis.Y2) .name("Slugging pct.") .marker(Marker.builder().opacity(.7).color("rgb(17, 157, 255)").build()) diff --git a/jsplot/src/test/java/tech/tablesaw/examples/TimeSeriesVisualizations.java b/jsplot/src/test/java/tech/tablesaw/examples/TimeSeriesVisualizations.java index 2e3f8f20b..18ab5e0d2 100644 --- a/jsplot/src/test/java/tech/tablesaw/examples/TimeSeriesVisualizations.java +++ b/jsplot/src/test/java/tech/tablesaw/examples/TimeSeriesVisualizations.java @@ -33,7 +33,9 @@ public static void main(String[] args) throws Exception { Layout.builder("Boston Robberies by month: Jan 1966-Oct 1975", "year", "robberies").build(); ScatterTrace trace = - ScatterTrace.builder(robberies.numberColumn("Record"), robberies.numberColumn("Robberies")) + ScatterTrace.builder( + robberies.numberColumn("Record").asDoubleArray(), + robberies.numberColumn("Robberies").asDoubleArray()) .mode(ScatterTrace.Mode.LINE) .marker(Marker.builder().color("#3D9970").build()) .fill(ScatterTrace.Fill.TO_NEXT_Y) diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/BarTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/BarTest.java deleted file mode 100644 index 64026a413..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/BarTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package tech.tablesaw.plotly; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.traces.BarTrace; - -@Disabled -public class BarTest { - - private final Object[] x = {"sheep", "cows", "fish", "tree sloths"}; - private final double[] y = {1, 4, 9, 16}; - - @Test - public void testAsJavascript() { - BarTrace trace = BarTrace.builder(x, y).build(); - System.out.println(trace.asJavascript(1)); - } - - @Test - public void show() { - - BarTrace trace = BarTrace.builder(x, y).build(); - Figure figure = new Figure(trace); - Plot.show(figure, "target"); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/BoxTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/BoxTest.java deleted file mode 100644 index 59fcda4f5..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/BoxTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.traces.BoxTrace; - -@Disabled -class BoxTest { - - private final Object[] x = { - "sheep", - "cows", - "fish", - "tree sloths", - "sheep", - "cows", - "fish", - "tree sloths", - "sheep", - "cows", - "fish", - "tree sloths" - }; - private final double[] y = {1, 4, 9, 16, 3, 6, 8, 8, 2, 4, 7, 11}; - - @Test - void testAsJavascript() { - BoxTrace trace = BoxTrace.builder(x, y).build(); - assertNotNull(trace.asJavascript(1)); - } - - @Test - void show() { - BoxTrace trace = BoxTrace.builder(x, y).build(); - Figure figure = new Figure(trace); - assertNotNull(figure); - Plot.show(figure, "target"); - } - - /** Test ensures that the name() method returns a BoxTraceBuilder as expected. */ - @Test - void name() { - BoxTrace trace = BoxTrace.builder(x, y).name("my name").build(); - assertNotNull(trace); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/BubbleTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/BubbleTest.java deleted file mode 100644 index e3457a22d..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/BubbleTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package tech.tablesaw.plotly; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Marker; -import tech.tablesaw.plotly.components.Symbol; -import tech.tablesaw.plotly.traces.ScatterTrace; - -@Disabled -public class BubbleTest { - - private final double[] x = {1, 2, 3, 4, 5, 6}; - private final double[] y = {0, 1, 6, 14, 25, 39}; - private final double[] size = {10, 33, 21, 40, 28, 16}; - - @Test - public void testAsJavascript() { - ScatterTrace trace = - ScatterTrace.builder(x, y).marker(Marker.builder().size(size).build()).build(); - System.out.println(trace.asJavascript(1)); - } - - @Test - public void showScatter() { - ScatterTrace trace = - ScatterTrace.builder(x, y) - .mode(ScatterTrace.Mode.MARKERS) - .marker( - Marker.builder() - .size(size) - .colorScale(Marker.Palette.CIVIDIS) - .opacity(.5) - .showScale(true) - .symbol(Symbol.DIAMOND_TALL) - .build()) - .build(); - - Plot.show(new Figure(trace)); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/ContourTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/ContourTest.java deleted file mode 100644 index f4a4e585f..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/ContourTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package tech.tablesaw.plotly; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.api.StringColumn; -import tech.tablesaw.api.Table; -import tech.tablesaw.plotly.api.ContourPlot; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.traces.ContourTrace; - -import java.io.IOException; - -@Disabled -public class ContourTest { - - private final Object[] x = {-9, -6, -5, -3, -1}; - private final Object[] y = {0, 1, 4, 5, 7}; - private final double[][] z = { - {10, 10.625, 12.5, 15.625, 20}, - {5.625, 6.25, 8.125, 11.25, 15.625}, - {2.5, 3.125, 5.0, 8.125, 12.5}, - {0.625, 1.25, 3.125, 6.25, 10.625}, - {0, 0.625, 2.5, 5.625, 10} - }; - - @Test - public void testAsJavascript() { - ContourTrace trace = ContourTrace.builder(x, y, z).build(); - System.out.println(trace.asJavascript(1)); - } - - @Test - public void testContourTrace() { - ContourTrace trace = ContourTrace.builder(x, y, z).build(); - Figure figure = new Figure(trace); - Plot.show(figure); - } - - @Test - public void testContourPlot() throws IOException { - Table table = Table.read().csv("../data/bush.csv"); - StringColumn yearsMonth = table.dateColumn("date").yearMonth(); - String name = "Year and month"; - yearsMonth.setName(name); - table.addColumns(yearsMonth); - - Figure figure = ContourPlot.create("Polls conducted by year and month", table, name, "who"); - Plot.show(figure); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/HistogramTraceTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/HistogramTraceTest.java deleted file mode 100644 index 4e88b84ca..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/HistogramTraceTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package tech.tablesaw.plotly; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.traces.HistogramTrace; - -@Disabled -public class HistogramTraceTest { - - private final double[] y1 = {1, 4, 9, 16, 11, 4, -1, 20, 4, 7, 9, 12, 8, 6, 28, 12}; - private final double[] y2 = {3, 11, 19, 14, 11, 14, 5, 24, -4, 10, 15, 6, 5, 18}; - - @Test - public void testAsJavascript() { - HistogramTrace trace1 = HistogramTrace.builder(y1).build(); - System.out.println(trace1.asJavascript(1)); - } - - @Test - public void show() { - Layout layout = Layout.builder().barMode(Layout.BarMode.OVERLAY).build(); - HistogramTrace trace1 = HistogramTrace.builder(y1).opacity(.75).build(); - HistogramTrace trace2 = HistogramTrace.builder(y2).opacity(.75).build(); - Plot.show(new Figure(layout, trace1, trace2)); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/PageTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/PageTest.java deleted file mode 100644 index f81319969..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/PageTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Page; -import tech.tablesaw.plotly.traces.BarTrace; - -public class PageTest { - - private final Object[] x = {"sheep", "cows", "fish", "tree sloths"}; - private final double[] y = {1, 4, 9, 16}; - - @Test - public void testDefaultPlotlyJsLocation() { - BarTrace trace = BarTrace.builder(x, y).build(); - Page page = Page.pageBuilder(new Figure(trace), "plot").build(); - String html = page.asJavascript(); - assertTrue(html.indexOf("\"" + "https://cdn.plot.ly/plotly-latest.min.js" + "\"") > 0); - } - - @Test - public void testCustomPlotlyJsLocation() { - BarTrace trace = BarTrace.builder(x, y).build(); - String location = - this.getClass().getResource(this.getClass().getSimpleName() + ".class").toString(); - Page page = Page.pageBuilder(new Figure(trace), "plot").plotlyJsLocation(location).build(); - String html = page.asJavascript(); - assertTrue(html.indexOf("\"" + location + "\"") > 0); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/PieTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/PieTest.java deleted file mode 100644 index c7d26d513..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/PieTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package tech.tablesaw.plotly; - -import java.io.File; -import java.nio.file.Paths; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.traces.PieTrace; - -@Disabled -public class PieTest { - - private final Object[] x = {"sheep", "cows", "fish", "tree sloths"}; - private final double[] y = {1, 4, 9, 16}; - - @Test - public void testAsJavascript() { - PieTrace trace = PieTrace.builder(x, y).build(); - System.out.println(trace.asJavascript(1)); - } - - @Test - public void show() { - PieTrace trace = PieTrace.builder(x, y).build(); - Figure figure = new Figure(trace); - File outputFile = Paths.get("testoutput/output.html").toFile(); - Plot.show(figure, "target", outputFile); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/PlotTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/PlotTest.java deleted file mode 100644 index 1a13b970e..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/PlotTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.File; -import java.nio.file.Paths; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@Disabled -class PlotTest { - - @Test - void show() { - String html = "

Hello World

"; - File file = Paths.get("testoutput", "myfile.html").toFile(); - Plot.show(html, file); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/Scatter3DTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/Scatter3DTest.java deleted file mode 100644 index e5632b3e5..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/Scatter3DTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.api.DoubleColumn; -import tech.tablesaw.api.Table; -import tech.tablesaw.plotly.api.Scatter3DPlot; -import tech.tablesaw.plotly.components.Axis; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.traces.Scatter3DTrace; - -@Disabled -public class Scatter3DTest { - - private final double[] x = {1, 2, 3, 4, 5, 6}; - private final double[] y = {0, 1, 6, 14, 25, 39}; - private final double[] z = {-23, 11, -2, -7, 0.324, -11}; - - private final String[] labels = {"apple", "bike", "car", "dog", "elephant", "fox"}; - - @Test - public void testAsJavascript() { - Scatter3DTrace trace = Scatter3DTrace.builder(x, y, z).text(labels).build(); - assertNotNull(trace.asJavascript(1)); - } - - @Test - public void showScatter() { - - Scatter3DTrace trace = - Scatter3DTrace.builder(x, y, z).mode(Scatter3DTrace.Mode.MARKERS).text(labels).build(); - - Layout layout = Layout.builder().xAxis(Axis.builder().title("x title").build()).build(); - assertEquals("x title", layout.getTitle()); - Plot.show(new Figure(layout, trace)); - } - - @Test - public void showLineAndMarkers() { - - Scatter3DTrace trace = - Scatter3DTrace.builder(x, y, z).mode(Scatter3DTrace.Mode.LINE_AND_MARKERS).build(); - Layout layout = Layout.builder().xAxis(Axis.builder().title("x title").build()).build(); - - Plot.show(new Figure(layout, trace)); - } - - @Test - public void showText() { - - Scatter3DTrace trace = - Scatter3DTrace.builder(x, y, z).mode(Scatter3DTrace.Mode.TEXT).text(labels).build(); - - Plot.show(new Figure(trace)); - } - - @Test - void createScatter3D() { - DoubleColumn xData = DoubleColumn.create("x", new double[] {2, 2, 1}); - DoubleColumn yData = DoubleColumn.create("y", new double[] {1, 2, 3}); - DoubleColumn zData = DoubleColumn.create("z", new double[] {1, 4, 1}); - - Table data = Table.create().addColumns(xData, yData, zData); - assertNotNull(Scatter3DPlot.create("3D plot", data, "x", "y", "z")); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/ScatterTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/ScatterTest.java deleted file mode 100644 index effca216a..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/ScatterTest.java +++ /dev/null @@ -1,148 +0,0 @@ -package tech.tablesaw.plotly; - -import java.io.File; -import java.nio.file.Paths; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Axis; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Font; -import tech.tablesaw.plotly.components.HoverLabel; -import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.components.Marker; -import tech.tablesaw.plotly.components.Symbol; -import tech.tablesaw.plotly.components.TickSettings; -import tech.tablesaw.plotly.traces.ScatterTrace; - -@Disabled -public class ScatterTest { - - private final String[] text = {"acc", "dnax", "lc", "hc", "seq"}; - private final double[] vals = {1, 6, 14, 25, 39}; - - private final double[] x = {1, 2, 3, 4, 5, 6}; - private final double[] y = {0, 1, 6, 14, 25, 39}; - - private final String[] labels = {"a", "b", "c", "d", "e", "f"}; - - @Test - public void testAsJavascript() { - ScatterTrace trace = ScatterTrace.builder(x, y).text(labels).build(); - - System.out.println(trace.asJavascript(1)); - } - - @Test - public void showScatter() { - - ScatterTrace trace = - ScatterTrace.builder(x, y) - .marker( - Marker.builder().size(12.0).symbol(Symbol.DIAMOND_TALL).color("#c68486").build()) - .mode(ScatterTrace.Mode.MARKERS) - .text(labels) - .build(); - - Figure figure = new Figure(trace); - File outputFile = Paths.get("testoutput/output.html").toFile(); - Plot.show(figure, "target", outputFile); - } - - @Test - public void showLine() { - Layout layout = - Layout.builder() - .title("test") - .titleFont(Font.builder().size(32).color("green").build()) - .showLegend(true) - .height(700) - .width(1200) - .build(); - - ScatterTrace trace = - ScatterTrace.builder(x, y) - .mode(ScatterTrace.Mode.LINE) - .hoverLabel( - HoverLabel.builder().bgColor("red").font(Font.builder().size(24).build()).build()) - .showLegend(true) - .build(); - - Figure figure = new Figure(layout, trace); - File outputFile = Paths.get("testoutput/output.html").toFile(); - - Plot.show(figure, "target", outputFile); - } - - @Test - public void showLineWithArrayTicks() { - - final double[] x1 = {13, 14, 15, 16, 17, 18}; - final double[] y1 = {0, 1, 6, 14, 25, 39}; - - final double[] x2 = {7, 9, 11, 13}; - final double[] y2 = {0, 1, 6, 14}; - - Axis.Spikes spikes = Axis.Spikes.builder().color("blue").dash("solid").thickness(1).build(); - - TickSettings tickSettings = - TickSettings.builder() - .tickMode(TickSettings.TickMode.ARRAY) - .showTickLabels(true) - .arrayTicks(vals, text) - .build(); - - Axis yAxis = - Axis.builder() - .title("stages") - .tickSettings(tickSettings) - .autoRange(Axis.AutoRange.REVERSED) - .gridWidth(1) - .gridColor("grey") - .spikes(spikes) - .build(); - - Layout layout = - Layout.builder() - .title("train time") - .yAxis(yAxis) - .xAxis(Axis.builder().spikes(spikes).build()) - .height(700) - .width(1200) - .hoverMode(Layout.HoverMode.CLOSEST) - .build(); - - ScatterTrace trace1 = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.LINE).build(); - - ScatterTrace trace3 = ScatterTrace.builder(x1, y1).mode(ScatterTrace.Mode.LINE).build(); - - ScatterTrace trace2 = ScatterTrace.builder(x2, y2).mode(ScatterTrace.Mode.LINE).build(); - - Figure figure = new Figure(layout, trace1, trace2, trace3); - File outputFile = Paths.get("testoutput/output.html").toFile(); - Plot.show(figure, "target", outputFile); - } - - @Test - public void showLineAndMarkers() { - - ScatterTrace trace = - ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.LINE_AND_MARKERS).build(); - - Figure figure = new Figure(trace); - File outputFile = Paths.get("testoutput/output.html").toFile(); - - Plot.show(figure, "target", outputFile); - } - - @Test - public void showText() { - - ScatterTrace trace = - ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.TEXT).text(labels).build(); - - Figure figure = new Figure(trace); - File outputFile = Paths.get("testoutput/output.html").toFile(); - - Plot.show(figure, "target", outputFile); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/TimeSeriesTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/TimeSeriesTest.java deleted file mode 100644 index 17cc4f69c..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/TimeSeriesTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.io.IOException; -import org.junit.jupiter.api.Test; -import tech.tablesaw.api.Table; -import tech.tablesaw.plotly.api.TimeSeriesPlot; -import tech.tablesaw.plotly.components.Figure; - -class TimeSeriesTest { - - @Test - void testWithInstant() throws IOException { - - Table dateTable = Table.read().csv("../data/dateTimeTestFile.csv"); - dateTable.addColumns(dateTable.dateTimeColumn(0).asInstantColumn().setName("Instant")); - Figure figure = - TimeSeriesPlot.create( - "Value over time", - "time", - dateTable.instantColumn("Instant"), - "values", - dateTable.numberColumn("Value")); - assertNotNull(figure); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/UtilsTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/UtilsTest.java deleted file mode 100644 index 2e1df5dcc..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/UtilsTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class UtilsTest { - - @Test - public void testEscapeQuote() { - String s = Utils.dataAsString(new String[] {"Bobby\"s tables"}); - assertTrue(s.contains("\\"), s); - String s2 = Utils.dataAsString(new String[] {"Hello\\"}); - assertEquals("[\"Hello\\\\\"]", s2); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/ViolinTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/ViolinTest.java deleted file mode 100644 index 794fe3b88..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/ViolinTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package tech.tablesaw.plotly; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.traces.ViolinTrace; - -@Disabled -class ViolinTest { - - private final Object[] x = { - "sheep", - "cows", - "fish", - "tree sloths", - "sheep", - "cows", - "fish", - "tree sloths", - "sheep", - "cows", - "fish", - "tree sloths" - }; - private final double[] y = {1, 4, 9, 16, 3, 6, 8, 8, 2, 4, 7, 11}; - - @Test - void testAsJavascriptWithBoxPlot() { - ViolinTrace trace = ViolinTrace.builder(x, y).boxPlot(true).build(); - assertNotNull(trace.asJavascript(1)); - } - - @Test - void showWithMeanLine() { - ViolinTrace trace = ViolinTrace.builder(x, y).meanLine(true).build(); - Figure figure = new Figure(trace); - assertNotNull(figure); - Plot.show(figure, "target"); - } - - @Test - void showWithBoxPlot() { - ViolinTrace trace = ViolinTrace.builder(x, y).boxPlot(true).build(); - Figure figure = new Figure(trace); - assertNotNull(figure); - Plot.show(figure, "target"); - } - - /** Test ensures that the name() method returns a ViolinTraceBuilder as expected. */ - @Test - void name() { - ViolinTrace trace = ViolinTrace.builder(x, y).name("my name").build(); - assertNotNull(trace); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/ChangeTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/ChangeTest.java deleted file mode 100644 index 8b90e8f8d..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/ChangeTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.components.change.ChangeLine; -import tech.tablesaw.plotly.components.change.Increasing; - -public class ChangeTest { - - @Test - public void testJavascript() { - - Increasing increasing = - Increasing.builder() - .changeLine(ChangeLine.builder().width(3).color("blue").build()) - .fillColor("444") - .build(); - - assertTrue(increasing.asJavascript().contains("line")); - assertTrue(increasing.asJavascript().contains("color")); - assertTrue(increasing.asJavascript().contains("width")); - assertTrue(increasing.asJavascript().contains("fillcolor")); - } - - @Test - public void testJavascript2() { - - ChangeLine line = ChangeLine.builder().width(4).color("444").build(); - - assertTrue(line.asJavascript().contains("color")); - assertTrue(line.asJavascript().contains("width")); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/ConfigTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/ConfigTest.java deleted file mode 100644 index 3b71d1ac2..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/ConfigTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class ConfigTest { - - @Test - public void testJavascript() { - { - Config config = Config.builder().build(); - assertTrue(config.asJavascript().startsWith("var config")); - } - { - Config config = Config.builder().displayModeBar(true).build(); - assertTrue(config.asJavascript().contains("\"displayModeBar\" : true")); - } - { - Config config = Config.builder().displayModeBar(false).build(); - assertTrue(config.asJavascript().contains("\"displayModeBar\" : false")); - } - { - Config config = Config.builder().build(); - assertFalse(config.asJavascript().contains("displayModeBar")); - } - { - Config config = Config.builder().responsive(true).build(); - assertTrue(config.asJavascript().contains("\"responsive\" : true")); - } - { - Config config = Config.builder().responsive(false).build(); - assertTrue(config.asJavascript().contains("\"responsive\" : false")); - } - { - Config config = Config.builder().build(); - assertFalse(config.asJavascript().contains("responsive")); - } - { - Config config = Config.builder().displayLogo(true).build(); - assertTrue(config.asJavascript().contains("\"displaylogo\" : true")); - } - { - Config config = Config.builder().displayLogo(false).build(); - assertTrue(config.asJavascript().contains("\"displaylogo\" : false")); - } - { - Config config = Config.builder().build(); - assertFalse(config.asJavascript().contains("displaylogo")); - } - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/FigureTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/FigureTest.java deleted file mode 100644 index 8fced2023..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/FigureTest.java +++ /dev/null @@ -1,179 +0,0 @@ -package tech.tablesaw.plotly.components; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; -import tech.tablesaw.plotly.traces.ScatterTrace; -import tech.tablesaw.plotly.traces.Trace; - -class FigureTest { - - private static final String LINE_END = System.lineSeparator(); - private String divName = "target"; - - private double[] x = {1, 2, 3, 4, 5}; - private double[] y = {1, 4, 9, 16, 25}; - - @Test - void asJavascript() { - - Trace trace = ScatterTrace.builder(x, y).build(); - Figure figure = new Figure(trace); - - assertEquals( - " " - + LINE_END, - figure.asJavascript(divName)); - } - - @Test - void asJavascript2() { - - Trace trace = ScatterTrace.builder(x, y).build(); - - Layout layout = - Layout.builder() - .title("A test title") - .xAxis( - Axis.builder() - .title("x Axis 1") - .visible(true) - .type(Axis.Type.DEFAULT) - .titleFont( - Font.builder().family(Font.Family.ARIAL).size(8).color("red").build()) - .build()) - .margin(Margin.builder().top(200).left(200).build()) - .showLegend(true) - .build(); - - Figure figure = new Figure(layout, trace); - - assertEquals( - " " - + LINE_END, - figure.asJavascript(divName)); - } - - @Test - void builder() { - String title = "A test title"; - Layout layout = Layout.builder().title(title).showLegend(true).build(); - - Trace trace = ScatterTrace.builder(x, y).build(); - - Figure figure = Figure.builder().layout(layout).addTraces(trace).build(); - - assertEquals(layout, figure.getLayout()); - - figure.asJavascript(divName); // force the context to get created - assertTrue(String.valueOf(figure.getContext().get("figure")).contains(title)); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/CenterTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/CenterTest.java deleted file mode 100644 index c34082b2e..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/CenterTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -public class CenterTest { - - private static final String javaScript = - "{" - + System.lineSeparator() - + " \"x\" : 1.0," - + System.lineSeparator() - + " \"y\" : 2.0," - + System.lineSeparator() - + " \"z\" : 3.0" - + System.lineSeparator() - + "}"; - - @Test - public void centerBuilder() { - assertEquals(javaScript, Center.centerBuilder(1, 2, 3).build().asJavascript()); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/EyeTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/EyeTest.java deleted file mode 100644 index 0622fec0f..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/EyeTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -public class EyeTest { - - private static final String javaScript = - "{" - + System.lineSeparator() - + " \"x\" : 1.0," - + System.lineSeparator() - + " \"y\" : 2.0," - + System.lineSeparator() - + " \"z\" : 3.0" - + System.lineSeparator() - + "}"; - - @Test - public void eyeBuilder() { - assertEquals(javaScript, Eye.eyeBuilder(1, 2, 3).build().asJavascript()); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/UpTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/UpTest.java deleted file mode 100644 index a27d71679..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/components/threeD/UpTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package tech.tablesaw.plotly.components.threeD; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -public class UpTest { - - private static final String javaScript = - "{" - + System.lineSeparator() - + " \"x\" : 1.0," - + System.lineSeparator() - + " \"y\" : 2.0," - + System.lineSeparator() - + " \"z\" : 3.0" - + System.lineSeparator() - + "}"; - - @Test - public void upBuilder() { - assertEquals(javaScript, Up.upBuilder(1, 2, 3).build().asJavascript()); - } -} diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/traces/TraceBuilderTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/traces/TraceBuilderTest.java deleted file mode 100644 index a8f3898f3..000000000 --- a/jsplot/src/test/java/tech/tablesaw/plotly/traces/TraceBuilderTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package tech.tablesaw.plotly.traces; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.Test; - -public class TraceBuilderTest { - - @Test - public void shouldFailPreconditionTest() { - TraceBuilder traceBuilder = - new TraceBuilder() { - @Override - protected String getType() { - return "dummy"; - } - }; - - assertThrows( - IllegalArgumentException.class, - () -> { - traceBuilder.xAxis("xa"); - }); - assertThrows( - IllegalArgumentException.class, - () -> { - traceBuilder.yAxis("yy"); - }); - } - - @Test - public void shouldBeAbleToSetAxis() { - String xAxis = "x1"; - String yAxis = "y"; - TraceBuilder traceBuilder = - new TraceBuilder() { - @Override - protected String getType() { - return "dummy"; - } - }; - traceBuilder.xAxis(xAxis).yAxis(yAxis); - assertEquals(xAxis, traceBuilder.xAxis); - assertEquals(yAxis, traceBuilder.yAxis); - } -}