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..be604922b 100644 --- a/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java +++ b/jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java @@ -27,17 +27,17 @@ public static Figure create( NumericColumn low = table.numberColumn(lowCol); NumericColumn close = table.numberColumn(closeCol); ScatterTrace trace; - if (x.type() == ColumnType.LOCAL_DATE) { + if (ColumnType.LOCAL_DATE.equals(x.type())) { trace = ScatterTrace.builder(table.dateColumn(xCol), open, high, low, close) .type(plotType) .build(); - } else if (x.type() == ColumnType.LOCAL_DATE_TIME) { + } else if (ColumnType.LOCAL_DATE_TIME.equals(x.type())) { trace = ScatterTrace.builder(table.dateTimeColumn(xCol), open, high, low, close) .type(plotType) .build(); - } else if (x.type() == ColumnType.INSTANT) { + } else if (ColumnType.INSTANT.equals(x.type())) { trace = ScatterTrace.builder(table.instantColumn(xCol), open, high, low, close) .type(plotType) diff --git a/jsplot/src/test/java/tech/tablesaw/plotly/OchlTest.java b/jsplot/src/test/java/tech/tablesaw/plotly/OchlTest.java new file mode 100644 index 000000000..4f39011ea --- /dev/null +++ b/jsplot/src/test/java/tech/tablesaw/plotly/OchlTest.java @@ -0,0 +1,47 @@ +package tech.tablesaw.plotly; + +import org.junit.jupiter.api.Test; +import tech.tablesaw.api.DateTimeColumn; +import tech.tablesaw.api.DoubleColumn; +import tech.tablesaw.api.Table; +import tech.tablesaw.plotly.api.OHLCPlot; +import tech.tablesaw.plotly.components.Figure; + +import java.time.LocalDateTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class OchlTest { + + @Test + void ochlPlotDoesNotThrowIllegalArgumentException() { + // Test to fix bug reported at https://github.com/jtablesaw/tablesaw/issues/1237 + String timeTitle = "time"; + String openTitle = "open"; + String closeTitle = "close"; + String highTitle = "high"; + String lowTitle = "low"; + String graphTitle = "title"; + + LocalDateTime now = LocalDateTime.now(); + List time = List.of(now, now.plusSeconds(5), now.plusSeconds(10)); + List open = List.of(1d, 2d, 3d); + List close = List.of(1d, 2d, 3d); + List high = List.of(1d, 2d, 3d); + List low = List.of(1d, 2d, 3d); + + DateTimeColumn timeColumn = DateTimeColumn.create(timeTitle, time); + DoubleColumn openColumn = DoubleColumn.create(openTitle, open); + DoubleColumn closeColumn = DoubleColumn.create(closeTitle, close); + DoubleColumn highColumn = DoubleColumn.create(highTitle, high); + DoubleColumn lowColumn = DoubleColumn.create(lowTitle, low); + + Table priceTable = Table.create(timeColumn, openColumn, closeColumn, highColumn, lowColumn); + Figure figure = OHLCPlot.create(graphTitle, priceTable, timeTitle, openTitle, highTitle, lowTitle, closeTitle); + + assertNotNull(figure); + assertDoesNotThrow(() -> IllegalArgumentException.class); + } +}