Skip to content

Commit

Permalink
fixes erroneous use of == in PricePlot (issue #1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
francescopeloi committed Oct 18, 2023
1 parent 6d857b7 commit 2cc3b0c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jsplot/src/main/java/tech/tablesaw/plotly/api/PricePlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions jsplot/src/test/java/tech/tablesaw/plotly/OchlTest.java
Original file line number Diff line number Diff line change
@@ -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<LocalDateTime> time = List.of(now, now.plusSeconds(5), now.plusSeconds(10));
List<Double> open = List.of(1d, 2d, 3d);
List<Double> close = List.of(1d, 2d, 3d);
List<Double> high = List.of(1d, 2d, 3d);
List<Double> 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);
}
}

0 comments on commit 2cc3b0c

Please sign in to comment.