Skip to content

Commit

Permalink
bug fixes (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
tracyhenry committed Sep 20, 2020
1 parent d72a077 commit 6dee30c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
27 changes: 27 additions & 0 deletions back-end/src/main/java/index/Indexer.java
Expand Up @@ -7,6 +7,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -15,10 +16,12 @@
import jdk.nashorn.api.scripting.JSObject;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import main.Config;
import main.DbConnector;
import main.Main;
import project.Canvas;
import project.Layer;
import project.Placement;
import project.SSV;

/** Created by wenbo on 12/30/18. */
public abstract class Indexer implements Serializable {
Expand Down Expand Up @@ -91,6 +94,30 @@ else if (Config.indexingScheme == Config.indexingScheme.TILE_INDEX)
l.setIndexer(indexer);
l.setIndexerType(indexer.getClass().getSimpleName());

// for geo ssv layers, add kyrix_geo_x/kyrix_geo_y columns first
// so that getTransform().getColumnNames() below can find them
if (!l.getSSVId().isEmpty()) {
int ssvIndex =
Integer.valueOf(l.getSSVId().substring(0, l.getSSVId().indexOf("_")));
SSV curSSV = Main.getProject().getSsvs().get(ssvIndex);
// check if geo component is specified
if (curSSV.getGeoInitialLevel() >= 0) {
String rawTable = curSSV.getRawTable();
String db = curSSV.getDb();
Statement rawDbStmt = DbConnector.getStmtByDbName(db);
String sql =
"ALTER TABLE "
+ rawTable
+ " ADD COLUMN IF NOT EXISTS kyrix_geo_x float;";
rawDbStmt.executeUpdate(sql);
sql =
"ALTER TABLE "
+ rawTable
+ " ADD COLUMN IF NOT EXISTS kyrix_geo_y float;";
rawDbStmt.executeUpdate(sql);
}
}

// pre-run getColumnNames, see issue #84: github.com/tracyhenry/kyrix/issues/84
l.getTransform().getColumnNames();
}
Expand Down
18 changes: 11 additions & 7 deletions back-end/src/main/java/index/SSVInMemoryIndexer.java
Expand Up @@ -161,9 +161,6 @@ public void createMV(Canvas c, int layerId) throws Exception {
// set common variables
setCommonVariables();

// transform geo to screen coordinates if needed
if (!ssv.getGeoLatCol().isEmpty()) getGeoCoords();

// compute cluster aggregations
long st = System.nanoTime();
computeClusterAggs();
Expand Down Expand Up @@ -198,6 +195,9 @@ private void setCommonVariables() throws Exception {
overlappingThreshold = Math.max(overlappingThreshold, ssv.getOverlap());
System.out.println("Overlapping threshold: " + overlappingThreshold);

// transform geo to screen coordinates if needed
if (!ssv.getGeoLatCol().isEmpty()) getGeoCoords();

// store raw query results into memory
rawRows = DbConnector.getQueryResult(ssv.getDb(), ssv.getQuery());
for (int i = 0; i < rawRows.size(); i++)
Expand All @@ -220,7 +220,7 @@ private void getGeoCoords() throws Exception {
System.out.println(sql);
rawDbStmt.executeUpdate(sql);

sql = "DROP FUNCTION get_coord";
sql = "DROP FUNCTION IF EXISTS get_coord;";
System.out.println(sql);
rawDbStmt.executeUpdate(sql);

Expand Down Expand Up @@ -249,7 +249,11 @@ private void getGeoCoords() throws Exception {
sql =
"UPDATE "
+ ssv.getRawTable()
+ " SET kyrix_geo_x = ((get_coord(latitude::float, longitude::float)->>'x')::float),"
+ " SET kyrix_geo_x = ((get_coord("
+ ssv.getGeoLatCol()
+ "::float, "
+ ssv.getGeoLonCol()
+ "::float)->>'x')::float),"
+ " kyrix_geo_y = ((get_coord(latitude::float, longitude::float)->>'y')::float);";
System.out.println(sql);
rawDbStmt.executeUpdate(sql);
Expand Down Expand Up @@ -479,8 +483,8 @@ private void calculateBGRP(RTreeData[] rds, int level)

private void cleanUp() throws SQLException {
// commit & close connections
rawDbStmt.close();
bboxStmt.close();
if (rawDbStmt != null) rawDbStmt.close();
if (bboxStmt != null) bboxStmt.close();
DbConnector.closeConnection(ssv.getDb());
DbConnector.closeConnection(Config.databaseName);

Expand Down
1 change: 1 addition & 0 deletions back-end/src/main/java/server/IndexHandler.java
Expand Up @@ -51,6 +51,7 @@ else if (path.contains(".jpg"))
e.printStackTrace();
System.out.println("\n\n" + e.getMessage() + "\n");
Server.printServingErrorMessage();
Server.sendResponse(httpExchange, HttpsURLConnection.HTTP_NO_CONTENT, "");
}
}
}
2 changes: 2 additions & 0 deletions compiler/src/index.js
Expand Up @@ -593,6 +593,8 @@ function saveProject() {
throw new Error(
"Auto drill down for MySQL is not supported right now."
);
if (this.views.length == 0)
throw new Error("No view object specified in the project.");
for (var i = 0; i < this.canvases.length; i++) {
// a canvas should have at least one layer
if (this.canvases[i].layers.length == 0)
Expand Down
16 changes: 9 additions & 7 deletions compiler/src/template-api/SSV.js
Expand Up @@ -1662,7 +1662,9 @@ function getMapRenderer() {
var vy = args["viewportY"];
var vw = args["viewportW"];
var vh = args["viewportH"];
var level = args["pyramidLevel"];
var topLevelWidth = params.hiX - params.loX;
var topLevelHeight = params.hiY - params.loY;
var level = +args.ssvId.substring(args.ssvId.indexOf("_") + 1);
var initialLon = params.geoInitialCenterLon;
var initialLat = params.geoInitialCenterLat;
var initialLevel = params.geoInitialLevel;
Expand All @@ -1672,16 +1674,16 @@ function getMapRenderer() {

// note: vw/3 because dynamic boxes fetch a box slightly larger than viewport
var minTileX = Math.floor(
(cx - (vw * (1 << level)) / 2 + vx - vw / 3) / 256
(cx - (topLevelWidth * (1 << level)) / 2 + vx - vw / 3) / 256
);
var maxTileX = Math.floor(
(cx - (vw * (1 << level)) / 2 + vx + vw + vw / 3) / 256
(cx - (topLevelWidth * (1 << level)) / 2 + vx + vw + vw / 3) / 256
);
var minTileY = Math.floor(
(cy - (vh * (1 << level)) / 2 + vy - vh / 3) / 256
(cy - (topLevelHeight * (1 << level)) / 2 + vy - vh / 3) / 256
);
var maxTileY = Math.floor(
(cy - (vh * (1 << level)) / 2 + vy + vh + vh / 3) / 256
(cy - (topLevelHeight * (1 << level)) / 2 + vy + vh + vh / 3) / 256
);
var tiles = [];
for (var i = minTileX; i <= maxTileX; i++)
Expand Down Expand Up @@ -1712,10 +1714,10 @@ function getMapRenderer() {
);
})
.attr("x", function(d) {
return d[0] * 256 - (cx - (vw * (1 << level)) / 2);
return d[0] * 256 - (cx - (topLevelWidth * (1 << level)) / 2);
})
.attr("y", function(d) {
return d[1] * 256 - (cy - (vh * (1 << level)) / 2);
return d[1] * 256 - (cy - (topLevelHeight * (1 << level)) / 2);
})
.attr("width", 256)
.attr("height", 256);
Expand Down
6 changes: 4 additions & 2 deletions front-end/js/jump.js
@@ -1,12 +1,14 @@
function removePopovers(viewId) {
var selector = ".popover,.kyrixtooltip";
var selector = ".popover";
if (viewId != null) selector += ".view_" + viewId;
selector += ",.kyrixtooltip";
d3.selectAll(selector).remove();
}

function removePopoversSmooth(viewId) {
var selector = ".popover,.kyrixtooltip";
var selector = ".popover";
if (viewId != null) selector += ".view_" + viewId;
selector += ",.kyrixtooltip";
d3.selectAll(selector)
.transition()
.duration(param.popoverOutDuration)
Expand Down
6 changes: 5 additions & 1 deletion front-end/js/jumpAnimation.js
Expand Up @@ -42,7 +42,11 @@ function animateSemanticZoom(viewId, jump, newVpX, newVpY, tuple) {

// get client dx & dy
var thisBox = this.getBoundingClientRect();
var ancestorBox = ancestor.getBoundingClientRect();
var ancestorBox = d3
.select(ancestor)
.select("rect")
.node()
.getBoundingClientRect();
var dx = thisBox.x - ancestorBox.x;
var dy = thisBox.y - ancestorBox.y;

Expand Down

0 comments on commit 6dee30c

Please sign in to comment.