Skip to content

Commit

Permalink
Redesign toolbox. Closes #423 (#569)
Browse files Browse the repository at this point in the history
* Redesign toolbox

* Use default layer props when available

* Improved infocard to display layer name instead on layer id

Co-authored-by: Shadab Khan <[email protected]>
  • Loading branch information
shadab-skhan and Shadab Khan authored Oct 4, 2021
1 parent 870ca7b commit 00c2bde
Show file tree
Hide file tree
Showing 31 changed files with 719 additions and 107 deletions.
9 changes: 1 addition & 8 deletions react/src/demo/example-data/deckgl-map-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,8 @@
"id": "wells-layer",
"data": "https://raw.githubusercontent.com/equinor/webviz-subsurface-components/master/react/src/demo/example-data/volve_wells.json",
"logData": "https://raw.githubusercontent.com/equinor/webviz-subsurface-components/master/react/src/demo/example-data/volve_logs.json",
"opacity": 1.0,
"lineWidthScale": 5,
"logRadius": 6,
"logrunName": "BLOCKING",
"logName": "ZONELOG",
"pointRadiusScale": 8,
"outline": true,
"logCurves": true,
"refine": true
"logName": "ZONELOG"
},
{
"@@type": "FaultPolygonsLayer",
Expand Down
9 changes: 1 addition & 8 deletions react/src/demo/example-data/deckgl-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,8 @@
"id": "wells-layer",
"data": "https://raw.githubusercontent.com/equinor/webviz-subsurface-components/master/react/src/demo/example-data/volve_wells.json",
"logData": "https://raw.githubusercontent.com/equinor/webviz-subsurface-components/master/react/src/demo/example-data/volve_logs.json",
"opacity": 1.0,
"lineWidthScale": 5,
"logRadius": 6,
"logrunName": "BLOCKING",
"logName": "ZONELOG",
"pointRadiusScale": 8,
"outline": true,
"logCurves": true,
"refine": true
"logName": "ZONELOG"
},
{
"@@type": "FaultPolygonsLayer",
Expand Down
16 changes: 12 additions & 4 deletions react/src/lib/components/DeckGLMap/components/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import { Button, Icon } from "@equinor/eds-core-react";
import { arrow_drop_up, arrow_drop_down } from "@equinor/eds-icons";

import { PickInfo } from "@deck.gl/core/lib/deck";
import { LayerPickInfo, PropertyDataType } from "../layers/utils/layerTools";
import {
ExtendedLayerProps,
LayerPickInfo,
PropertyDataType,
} from "../layers/utils/layerTools";
import { PropertyMapPickInfo } from "../layers/utils/propertyMapTools";
import { rgb } from "d3-color";
import { FeatureCollection } from "geojson";

Icon.add({ arrow_drop_up, arrow_drop_down });

Expand Down Expand Up @@ -163,8 +168,11 @@ const InfoCard: React.FC<InfoCardProps> = (props: InfoCardProps) => {

props.pickInfos.forEach((info) => {
const layer_properties = (info as LayerPickInfo)?.properties;
const group_name = (
info.layer?.props as ExtendedLayerProps<FeatureCollection>
)?.name;
const parent = infoCardData.find(
(item) => item.layerName === info.layer?.id
(item) => item.layerName === group_name
);
if (parent) {
layer_properties?.forEach((layer_prop) => {
Expand All @@ -179,7 +187,7 @@ const InfoCard: React.FC<InfoCardProps> = (props: InfoCardProps) => {
});
} else {
infoCardData.push({
layerName: info.layer?.id || "unknown-layer",
layerName: group_name || "unknown-layer",
properties: layer_properties,
});
}
Expand All @@ -192,7 +200,7 @@ const InfoCard: React.FC<InfoCardProps> = (props: InfoCardProps) => {
if (property) {
property.value = zValue;
} else {
xy_properties.push({ name: info.layer.id, value: zValue });
xy_properties.push({ name: group_name, value: zValue });
}
}
});
Expand Down
66 changes: 59 additions & 7 deletions react/src/lib/components/DeckGLMap/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@ import { createStore } from "../redux/store";
import { WellsPickInfo } from "../layers/wells/wellsLayer";
import InfoCard from "./InfoCard";
import DistanceScale from "../components/DistanceScale";
import {
ColormapLayer,
Hillshading2DLayer,
WellsLayer,
FaultPolygonsLayer,
PieChartLayer,
DrawingLayer,
} from "../layers";

// update spec object to include default layer props
function getSpecWithDefaultProps(
deckglSpec: Record<string, unknown>
): Record<string, unknown> {
const modified_spec = Object.assign({}, deckglSpec);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const layers = [...(modified_spec["layers"] as any[])];
layers?.forEach((layer) => {
let default_props = undefined;
if (layer["@@type"] === ColormapLayer.name)
default_props = ColormapLayer.defaultProps;
else if (layer["@@type"] === Hillshading2DLayer.name)
default_props = Hillshading2DLayer.defaultProps;
else if (layer["@@type"] === WellsLayer.name)
default_props = WellsLayer.defaultProps;
else if (layer["@@type"] === FaultPolygonsLayer.name)
default_props = FaultPolygonsLayer.defaultProps;
else if (layer["@@type"] === PieChartLayer.name)
default_props = PieChartLayer.defaultProps;
else if (layer["@@type"] === DrawingLayer.name)
default_props = DrawingLayer.defaultProps;

if (default_props) {
Object.entries(default_props).forEach(([prop, value]) => {
const prop_type = typeof value;
if (["string", "boolean", "number"].includes(prop_type)) {
if (layer[prop] === undefined) layer[prop] = value;
}
});
}
});

modified_spec["layers"] = layers;
return modified_spec;
}

export interface MapProps {
/**
Expand Down Expand Up @@ -77,21 +121,27 @@ const Map: React.FC<MapProps> = ({
coordinateUnit,
children,
}: MapProps) => {
const [deckglSpecWithDefaultProps, setDeckglSpecWithDefaultProps] =
React.useState(deckglSpec);
React.useEffect(() => {
setDeckglSpecWithDefaultProps(getSpecWithDefaultProps(deckglSpec));
}, [deckglSpec]);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const store = React.useRef<EnhancedStore<any, AnyAction, any>>(
createStore(deckglSpec, setSpecPatch)
createStore(deckglSpecWithDefaultProps, setSpecPatch)
);

React.useEffect(() => {
store.current = createStore(deckglSpec, setSpecPatch);
store.current = createStore(deckglSpecWithDefaultProps, setSpecPatch);
}, [setSpecPatch]);

const [specObj, setSpecObj] = React.useState(null);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [viewState, setViewState] = React.useState<any>();
React.useEffect(() => {
if (!deckglSpec) {
if (!deckglSpecWithDefaultProps) {
return;
}

Expand All @@ -106,8 +156,8 @@ const Map: React.FC<MapProps> = ({
});
}
const jsonConverter = new JSONConverter({ configuration });
setSpecObj(jsonConverter.convert(deckglSpec));
}, [deckglSpec, resources]);
setSpecObj(jsonConverter.convert(deckglSpecWithDefaultProps));
}, [deckglSpecWithDefaultProps, resources]);

const refCb = React.useCallback(
(deckRef) => {
Expand All @@ -131,8 +181,10 @@ const Map: React.FC<MapProps> = ({
);

React.useEffect(() => {
store.current.dispatch(setSpec(specObj ? deckglSpec : {}));
}, [deckglSpec, specObj]);
store.current.dispatch(
setSpec(specObj ? deckglSpecWithDefaultProps : {})
);
}, [deckglSpecWithDefaultProps, specObj]);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [hoverInfo, setHoverInfo] = React.useState<any>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,37 @@ import DrawModeSelector from "./DrawModeSelector";
describe("Test draw-mode menu", () => {
it("snapshot test", () => {
const { container } = render(
Wrapper({ children: <DrawModeSelector layerId="drawing-layer" /> })
Wrapper({
children: (
<DrawModeSelector
layerId="drawing-layer"
label="Draw mode"
value="drawLineString"
/>
),
})
);
expect(container.firstChild).toMatchSnapshot();
});
it("select option to dispatch redux action", async () => {
render(
Wrapper({ children: <DrawModeSelector layerId="drawing-layer" /> })
Wrapper({
children: (
<DrawModeSelector
layerId="drawing-layer"
label="Draw mode"
value="drawLineString"
/>
),
})
);
expect(screen.getByLabelText(/draw mode/i)).toBeVisible();
expect(
screen.getByRole("combobox", { name: /draw mode/i })
).toHaveDisplayValue("drawLineString");
).toHaveDisplayValue("Create polyline");
userEvent.selectOptions(
screen.getByRole("combobox", { name: /draw mode/i }),
"view"
"View"
);
expect(testStore.dispatch).toHaveBeenCalledTimes(1);
expect(testStore.dispatch).toBeCalledWith({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
import { NativeSelect } from "@equinor/eds-core-react";
import React, { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useDispatch } from "react-redux";
import { updateDrawingMode } from "../../redux/actions";
import { MapState } from "../../redux/store";
import { DrawModes } from "../../redux/types";
import { getDrawMode } from "../../utils/specExtractor";
import { DrawMode, DrawModes } from "../../redux/types";

interface Props {
/**
* It defines the mode that are available for a particular layer based on layer ID.
*/
layerId: string;
/**
* Label for the component.
*/
label: string;
/**
* Initial state of the component.
*/
value: string;
}
const DrawModeSelector: React.FC<Props> = React.memo(({ layerId }: Props) => {
// Redux
const dispatch = useDispatch();

const drawMode = useSelector((st: MapState) =>
getDrawMode(st.spec, layerId)
);
// handlers
const handleSelectedItemChange = useCallback(
(event) => dispatch(updateDrawingMode([layerId, event.target.value])),
[dispatch]
);
return (
drawMode && (
const DrawModeSelector: React.FC<Props> = React.memo(
({ layerId, label, value }: Props) => {
// Redux
const dispatch = useDispatch();

// handlers
const handleSelectedItemChange = useCallback(
(event) => {
const selection = DrawModes.find(
(mode) => mode.displayName === event.target.value
);
dispatch(
updateDrawingMode([layerId, selection?.id as DrawMode])
);
},
[dispatch]
);
const cur_selection = DrawModes.find((mode) => mode.id === value);
return (
<NativeSelect
id={`${layerId}-mode-selector`}
label="Draw Mode"
value={drawMode}
label={label}
value={cur_selection?.displayName}
onChange={handleSelectedItemChange}
>
{DrawModes.map((mode) => (
<option key={mode}>{mode}</option>
<option key={mode.id}>{mode.displayName}</option>
))}
</NativeSelect>
)
);
});
);
}
);

DrawModeSelector.displayName = "DrawModeSelector";
export default DrawModeSelector;
Loading

0 comments on commit 00c2bde

Please sign in to comment.