Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Dec 20, 2024
1 parent 502e30b commit 7000e7a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { ViewAnnotation } from "./components/ViewAnnotation";
function mapAnnotation(annotationContainers: React.ReactNode) {
return React.Children.map(annotationContainers, (annotationContainer) => {
let viewId = (annotationContainer as React.ReactElement).props.id;
if (React.isValidElement(annotationContainer) && (annotationContainer.type === ViewAnnotation || (annotationContainer.props instanceof Object && Object.keys(annotationContainer.props).includes("_dashprivate_layout")))) {
if (
React.isValidElement(annotationContainer) &&
(annotationContainer.type === ViewAnnotation ||
(annotationContainer.props instanceof Object &&
Object.keys(annotationContainer.props).includes(
"_dashprivate_layout"
)))
) {
viewId = annotationContainer.props._dashprivate_layout.props.id;
}
if (!viewId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { PickingInfo, Viewport } from "@deck.gl/core";
import { DeckGLRef } from "@deck.gl/react";
import { ExtendedLayerProps, MapMouseEvent, PropertyDataType } from "../../";
import type { DeckGLRef } from "@deck.gl/react";
import type {
ExtendedLayerProps,
MapMouseEvent,
PropertyDataType,
} from "../../";

export type LayerPickingInfo = {
layerId: string;
Expand All @@ -16,12 +20,16 @@ export type PickingInfoPerView = Record<
}
>;

function hasPropertiesArray(obj: any): obj is { properties: PropertyDataType[] } {
function hasPropertiesArray(
obj: any

Check failure on line 24 in typescript/packages/subsurface-viewer/src/hooks/useMultiViewPicking/MultiViewPickingInfoAssembler.ts

View workflow job for this annotation

GitHub Actions / typescript

Unexpected any. Specify a different type
): obj is { properties: PropertyDataType[] } {
return obj && Array.isArray(obj.properties);
}

function hasSingleProperty(obj: any): obj is { propertyValue: number } {

Check failure on line 29 in typescript/packages/subsurface-viewer/src/hooks/useMultiViewPicking/MultiViewPickingInfoAssembler.ts

View workflow job for this annotation

GitHub Actions / typescript

Unexpected any. Specify a different type
return obj && "propertyValue" in obj && typeof obj.propertyValue === "number";
return (
obj && "propertyValue" in obj && typeof obj.propertyValue === "number"
);
}

export type MultiViewPickingInfoAssemblerOptions = {
Expand All @@ -36,11 +44,15 @@ export interface MultiViewPickingInfoAssemblerSubscriberCallback {
export class MultiViewPickingInfoAssembler {
private _deckGl: DeckGLRef | null = null;
private _options: MultiViewPickingInfoAssemblerOptions;
private _subscribers: Set<MultiViewPickingInfoAssemblerSubscriberCallback> = new Set();
private _subscribers: Set<MultiViewPickingInfoAssemblerSubscriberCallback> =
new Set();

constructor(
deckGL: DeckGLRef | null,
options: MultiViewPickingInfoAssemblerOptions = { multiPicking: false, pickDepth: 1 }
options: MultiViewPickingInfoAssemblerOptions = {
multiPicking: false,
pickDepth: 1,
}
) {
this._deckGl = deckGL;
this._options = options;
Expand All @@ -50,7 +62,9 @@ export class MultiViewPickingInfoAssembler {
this._deckGl = deckGL;
}

subscribe(callback: MultiViewPickingInfoAssemblerSubscriberCallback): () => void {
subscribe(
callback: MultiViewPickingInfoAssemblerSubscriberCallback
): () => void {
this._subscribers.add(callback);

return () => {
Expand Down Expand Up @@ -84,9 +98,16 @@ export class MultiViewPickingInfoAssembler {
return;
}

const eventScreenCoordinate: [number, number] = [hoverEvent.infos[0].x, hoverEvent.infos[0].y];
const eventScreenCoordinate: [number, number] = [
hoverEvent.infos[0].x,
hoverEvent.infos[0].y,
];

this.assembleMultiViewPickingInfo(eventScreenCoordinate, activeViewportId, viewports).then((info) => {
this.assembleMultiViewPickingInfo(
eventScreenCoordinate,
activeViewportId,
viewports
).then((info) => {
this.publish(info, activeViewportId);
});
}
Expand All @@ -102,7 +123,9 @@ export class MultiViewPickingInfoAssembler {
reject("DeckGL not initialized");
return;
}
const activeViewport = viewports.find((el) => el.id === activeViewportId);
const activeViewport = viewports.find(
(el) => el.id === activeViewportId
);
if (!activeViewport) {
reject("Active viewport not found");
return;
Expand All @@ -113,11 +136,14 @@ export class MultiViewPickingInfoAssembler {
eventScreenCoordinate[1] - activeViewport.y,
];

const worldCoordinate = activeViewport.unproject(activeViewportRelativeScreenCoordinates);
const worldCoordinate = activeViewport.unproject(
activeViewportRelativeScreenCoordinates
);

const collectedPickingInfo: PickingInfoPerView = {};
for (const viewport of viewports) {
const [relativeScreenX, relativeScreenY] = viewport.project(worldCoordinate);
const [relativeScreenX, relativeScreenY] =
viewport.project(worldCoordinate);

let pickingInfo: PickingInfo[] = [];
if (this._options.multiPicking) {
Expand Down Expand Up @@ -150,22 +176,33 @@ export class MultiViewPickingInfoAssembler {
continue;
}

if (collectedLayerPickingInfo.find((el) => el.layerId === info.layer?.id)) {
if (
collectedLayerPickingInfo.find(
(el) => el.layerId === info.layer?.id
)
) {
continue;
}

const layerId = info.layer.id;
const layerName = (info.layer.props as unknown as ExtendedLayerProps).name;
const layerName = (
info.layer.props as unknown as ExtendedLayerProps
).name;

let layerPickingInfo = collectedLayerPickingInfo.find((el) => el.layerId === layerId);
let layerPickingInfo = collectedLayerPickingInfo.find(
(el) => el.layerId === layerId
);

if (!layerPickingInfo) {
collectedLayerPickingInfo.push({
layerId,
layerName,
properties: [],
});
layerPickingInfo = collectedLayerPickingInfo[collectedLayerPickingInfo.length - 1];
layerPickingInfo =
collectedLayerPickingInfo[
collectedLayerPickingInfo.length - 1
];
}

if (hasOneProperty) {
Expand Down Expand Up @@ -205,4 +242,4 @@ export class MultiViewPickingInfoAssembler {
resolve(collectedPickingInfo);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CompositeLayer, DefaultProps } from "@deck.gl/core";
import { CompositeLayer } from "@deck.gl/core";
import { IconLayer } from "@deck.gl/layers";

import type { DefaultProps } from "@deck.gl/core";

function makeCrossHairSvg(color: [number, number, number, number]): string {
return `<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="150px" height="150px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Tab from "@mui/material/Tab";
import Tabs from "@mui/material/Tabs";

import type { SubsurfaceViewerProps } from "../../SubsurfaceViewer";
import SubsurfaceViewer, { ViewStateType } from "../../SubsurfaceViewer";
import SubsurfaceViewer from "../../SubsurfaceViewer";
import type { ViewStateType } from "../../SubsurfaceViewer";
import type { MapMouseEvent, ViewsType } from "../../components/Map";
import { ViewFooter } from "../../components/ViewFooter";

Expand All @@ -33,7 +34,7 @@ import {
redAxes2DLayer,
subsufaceProps,
} from "../sharedSettings";
import { DeckGLRef } from "@deck.gl/react";
import type { DeckGLRef } from "@deck.gl/react";

const stories: Meta = {
component: SubsurfaceViewer,
Expand Down

0 comments on commit 7000e7a

Please sign in to comment.