Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
usfalami committed Aug 27, 2024
1 parent 8199e14 commit b6fa61e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 50 deletions.
18 changes: 4 additions & 14 deletions src/main/java/org/usf/jquery/core/AsciiResultMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,10 @@ public Void map(ResultSet rs) throws SQLException {
}

private static boolean isNumer(int type) {
switch (type) {
case BOOLEAN:
case BIT:
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
case REAL:
case FLOAT:
case DOUBLE:
case NUMERIC:
case DECIMAL: return true;
default: return false;
}
return switch (type) {
case BOOLEAN, BIT, TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, NUMERIC, DECIMAL: yield true;
default: yield false;
};
}

private static Object[] array(int size, String v) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/usf/jquery/web/view/Chart2DView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static java.lang.System.lineSeparator;
import static java.nio.file.Files.readString;
import static java.util.Map.ofEntries;
import static java.util.stream.Collectors.toList;
import static org.usf.jquery.core.SqlStringBuilder.doubleQuote;
import static org.usf.jquery.web.view.WebViewMapper.DataTable.fromMetaData;
import static org.usf.jquery.web.view.WebViewMapper.WebType.NUMBER;
Expand Down Expand Up @@ -54,7 +53,7 @@ public Void map(ResultSet rs) throws SQLException {
var sb1 = new StringBuilder();
var xAxis = dt.getXAxis();
sb1.append("[").append(doubleQuote(xAxis.getType().typeName())).append(",").append(doubleQuote(xAxis.getName())).append("]");
var cols = dt.getRows().stream().flatMap(c-> c.stream().skip(1)).map(Entry::getKey).distinct().sorted().collect(toList());
var cols = dt.getRows().stream().flatMap(c-> c.stream().skip(1)).map(Entry::getKey).distinct().sorted().toList();
if(cols.isEmpty()) { //no data
for(var c : dt.getYAxis()) {
sb1.append(",[").append(doubleQuote(NUMBER.typeName())).append(",").append(doubleQuote(c.getName())).append("]");
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/usf/jquery/web/view/ChartMappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
public final class ChartMappers {

public static WebViewMapper webChart(String view, Writer w) {
switch (view) {
case "table" : return new TableView(w);
case "pie" : return new PieChartView(w);
case "column" : return columnChart(w);
case "bar" : return barChart(w);
case "area" : return areaChart(w);
case "combo" : return comboChart(w);
case "line" : return lineChart(w);
case "timeline" : return new TimelineChartView(w);
case "calendar" : return new CalendarView(w);
case "sankey" : return new SankeyView(w);
return switch (view) {
case "table" : yield new TableView(w);
case "pie" : yield new PieChartView(w);
case "column" : yield columnChart(w);
case "bar" : yield barChart(w);
case "area" : yield areaChart(w);
case "combo" : yield comboChart(w);
case "line" : yield lineChart(w);
case "timeline" : yield new TimelineChartView(w);
case "calendar" : yield new CalendarView(w);
case "sankey" : yield new SankeyView(w);
default : throw new IllegalArgumentException(view);
}
};
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/web/view/PieChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Void map(ResultSet rs) throws SQLException { //scroll.
var bg = currentTimeMillis();
var rw = 0;
var cols = TableColumn.columns(rs.getMetaData());
var numb = Stream.of(cols).filter(c-> c.getType() == NUMBER).collect(toList());
var numb = Stream.of(cols).filter(c-> c.getType() == NUMBER).toList();
if(numb.isEmpty()) {
throw new IllegalArgumentException("require number column");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/usf/jquery/web/view/SankeyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.lang.System.currentTimeMillis;
import static java.lang.System.lineSeparator;
import static java.nio.file.Files.readString;
import static java.util.stream.Collectors.toList;
import static org.usf.jquery.web.view.WebViewMapper.TableColumn.columns;
import static org.usf.jquery.web.view.WebViewMapper.WebType.NUMBER;
import static org.usf.jquery.web.view.WebViewMapper.WebType.STRING;
Expand Down Expand Up @@ -46,7 +45,7 @@ public Void map(ResultSet rs) throws SQLException {
var bg = currentTimeMillis();
var rw = 0;
var cols = columns(rs.getMetaData());
var xAxis = Stream.of(cols).filter(c-> c.getType() == STRING).collect(toList());
var xAxis = Stream.of(cols).filter(c-> c.getType() == STRING).toList();
if(xAxis.size() != 2) {
throw new IllegalArgumentException("require [STRING, STRING, NUMBER] columns");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/usf/jquery/web/view/TimelineChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public Void map(ResultSet rs) throws SQLException {
var bg = currentTimeMillis();
var rw = 0;
var cols = columns(rs.getMetaData());
var numb = Stream.of(cols).filter(c-> c.getType() == NUMBER).collect(toList());
var numb = Stream.of(cols).filter(c-> c.getType() == NUMBER).toList();
if(numb.isEmpty()) {
numb = Stream.of(cols).filter(c-> c.getType().isDate()).collect(toList());
numb = Stream.of(cols).filter(c-> c.getType().isDate()).toList();
}
if(numb.isEmpty() || numb.size() != 2) {
throw new IllegalArgumentException("require NUMBER or DATE columns");
}
var yAxis = numb;
var xAxis = Stream.of(cols).filter(c-> yAxis.stream().noneMatch(v-> v.getName().equals(c.getName()))).collect(toList());
var xAxis = Stream.of(cols).filter(c-> yAxis.stream().noneMatch(v-> v.getName().equals(c.getName()))).toList();
if(xAxis.isEmpty()) {

}
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/org/usf/jquery/web/view/WebViewMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,14 @@ public String typeName() {
}

static WebType typeOf(int type) {
switch (type) {
case Types.BOOLEAN: return BOOLEAN;
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
case Types.NUMERIC:
case Types.DECIMAL: return NUMBER;
case Types.DATE: return DATE;
case Types.TIMESTAMP: return DATETIME;
return switch (type) {
case Types.BOOLEAN: yield BOOLEAN;
case Types.BIT, Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT, Types.REAL, Types.FLOAT, Types.DOUBLE, Types.NUMERIC, Types.DECIMAL: yield NUMBER;
case Types.DATE: yield DATE;
case Types.TIMESTAMP: yield DATETIME;
//case Types.TIME: //need explicit cast format !?
default: return STRING;
}
default: yield STRING;
};
}
}

Expand Down

0 comments on commit b6fa61e

Please sign in to comment.