Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate tooltip #736

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { NextUIProvider } from "@nextui-org/react";
import Toolbar from "./toolbar.js";
import throttle from "lodash.throttle";
import SidePanel from "./sidepanel/index";
import { getTooltip } from "./tooltip/index.js";

await initParquetWasm();

Expand Down Expand Up @@ -242,6 +243,7 @@ function App() {
? layers.concat(bboxSelectPolygonLayer)
: layers
}
getTooltip={(showTooltip && getTooltip) || undefined}
getCursor={() => (isDrawingBBoxSelection ? "crosshair" : "grab")}
pickingRadius={pickingRadius}
onClick={onMapClickHandler}
Expand Down
30 changes: 30 additions & 0 deletions src/tooltip/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Set fonts based on jupyter defaults */
.lonboard-tooltip {
font-family: var(--jp-ui-font-family);
font-size: var(--jp-ui-font-size1);
}

/* Remove spaces between table cells */
.lonboard-tooltip table {
border-collapse: collapse;
}

/* Alternate row colors */
.lonboard-tooltip table tr:nth-child(odd) {
background-color: white;
}

.lonboard-tooltip table tr:nth-child(even) {
background-color: rgb(241, 241, 241);
}

/* Define table cell borders and padding */
.lonboard-tooltip td {
border: 1px solid rgb(204, 204, 204);
padding: 5px;
}

/* Make the first column bold */
.lonboard-tooltip td:first-child {
font-weight: 450;
}
66 changes: 66 additions & 0 deletions src/tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { TooltipContent } from "@deck.gl/core/dist/lib/tooltip";
import type { GeoArrowPickingInfo } from "@geoarrow/deck.gl-layers";

import "./index.css";

const rowIndexSymbol = Symbol.for("rowIndex");

function toHtmlTable(featureProperties: Record<string, unknown>): string {
return `<table>
<tbody>
${Object.keys(featureProperties)
.map((key) => {
const value = featureProperties[key];
return `<tr>
<td>${key}</td>
<td>${value}</td>
</tr>`;
})
.join("")}
</tbody>
</table>`;
}

export function getTooltip({ object }: GeoArrowPickingInfo): TooltipContent {
if (object) {
// If the row index is -1 or undefined, return
//
// Note that this is a private API, but this appears to be the only way to
// get this information
//
// Without this block, we end up showing a tooltip even when not hovering
// over a point
if (
object[rowIndexSymbol] === null ||
object[rowIndexSymbol] === undefined ||
(object[rowIndexSymbol] && object[rowIndexSymbol] < 0)
) {
return null;
}

const jsonObj = object.toJSON();

if (!jsonObj) {
return null;
}

delete jsonObj["geometry"];

if (Object.keys(jsonObj).length === 0) {
return null;
}

return {
className: "lonboard-tooltip",
html: toHtmlTable(jsonObj),
style: {
backgroundColor: "#fff",
boxShadow: "0 0 15px rgba(0, 0, 0, 0.1)",
color: "#000",
padding: "6px",
},
};
}

return null;
}
Loading