Skip to content

Commit

Permalink
Merge branch 'master' into BugFix
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscb authored May 30, 2022
2 parents b6e0cd1 + c1f65d6 commit f162517
Show file tree
Hide file tree
Showing 23 changed files with 9,500 additions and 8,790 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/webviz-subsurface-components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ jobs:
- name: 📦 Install build dependencies
# The deckgl types package runs a postscript to setup, but since we ignore scripts, we need to set it up manually.
run: |
# In https://github.com/equinor/webviz-subsurface-components/pull/1010 we
# loosened up npm constraint to include npm version using lockfileVersion: 1
# for downstream users. However in the development of this repository we
# want to limit ourselves to lockfileVersion: 2.
# While waiting for dropping node 14 and npm 6 support, we include this manual
# check:
grep -q '"lockfileVersion": 2,' ./react/package-lock.json
npm ci --ignore-scripts --prefix ./react
npm run setup-deckgl-types --prefix ./react
npm run copy-package-json --prefix ./react
Expand Down
2 changes: 1 addition & 1 deletion react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
module.exports = {
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|scss)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
},
Expand Down
17,339 changes: 8,653 additions & 8,686 deletions react/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"webpack-dev-server": "^3.11.2"
},
"engines": {
"node": ">=16",
"npm": ">=7"
"node": ">=14.17",
"npm": ">=6.14"
}
}
16 changes: 8 additions & 8 deletions react/src/demo/example-data/deckgl-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"visible": true,
"incrementValue": 100,
"widthPerUnit": 100,
"position": [
10,
10
]
"cssStyle": {
"left": 10,
"top": 10
}
},
"legend": {
"visible": true,
"position": [
80,
10
],
"cssStyle": {
"right": 10,
"top": 10
},
"horizontal": false
},
"toolbar": {
Expand Down
12 changes: 6 additions & 6 deletions react/src/lib/components/DeckGLMap/DeckGLMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export interface DeckGLMapProps {
visible?: boolean | null;
incrementValue?: number | null;
widthPerUnit?: number | null;
position?: number[] | null;
cssStyle?: Record<string, unknown> | null;
};
coordinateUnit?: string;
toolbar?: {
visible?: boolean | null;
};
legend?: {
visible?: boolean | null;
position?: number[] | null;
cssStyle?: Record<string, unknown> | null;
horizontal?: boolean | null;
};
colorTables?: colorTablesArray;
Expand Down Expand Up @@ -245,9 +245,9 @@ DeckGLMap.propTypes = {
*/
widthPerUnit: PropTypes.number,
/**
* Scale bar position in pixels.
* Scale bar css style can be used for positioning.
*/
position: PropTypes.arrayOf(PropTypes.number.isRequired),
cssStyle: PropTypes.objectOf(PropTypes.any),
}),

/**
Expand Down Expand Up @@ -275,9 +275,9 @@ DeckGLMap.propTypes = {
*/
visible: PropTypes.bool,
/**
* Legend position in pixels.
* Legend css style can be used for positioning.
*/
position: PropTypes.arrayOf(PropTypes.number.isRequired),
cssStyle: PropTypes.objectOf(PropTypes.any),
/**
* Orientation of color legend
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ exports[`Test Map component snapshot test 1`] = `
style="left: 0px; top: 0px; width: 100%; position: absolute; height: 100%;"
/>
</div>
<div
style="bottom: 10px; left: 10px; position: relative;"
>
<label>
100
</label>
m
<div
style="width: 99.27470534904805px; height: 4px; border: 2px solid gray; display: inline-block; margin-left: 3px; margin-right: 3px; right: 0px; bottom: 0px;"
/>
</div>
<div>
<svg
aria-valuemax="100"
Expand Down Expand Up @@ -88,17 +77,6 @@ exports[`Test Map component snapshot test with edited data 1`] = `
style="left: 0px; top: 0px; width: 100%; position: absolute; height: 100%;"
/>
</div>
<div
style="bottom: 10px; left: 10px; position: relative;"
>
<label>
100
</label>
m
<div
style="width: 99.27470534904805px; height: 4px; border: 2px solid gray; display: inline-block; margin-left: 3px; margin-right: 3px; right: 0px; bottom: 0px;"
/>
</div>
<div>
<svg
aria-valuemax="100"
Expand Down
11 changes: 4 additions & 7 deletions react/src/lib/components/DeckGLMap/components/ColorLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {
import { colorTablesArray } from "@emerson-eps/color-tables/";

interface ColorLegendProps {
position?: number[] | null;
// Pass additional css style to the parent color legend container
cssStyle?: Record<string, unknown> | null;
horizontal?: boolean | null;
layers: Layer<unknown>[];
colorTables: colorTablesArray;
}

// Todo: Adapt it for other layers too
const ColorLegend: React.FC<ColorLegendProps> = ({
position,
cssStyle,
horizontal,
layers,
}: ColorLegendProps) => {
Expand Down Expand Up @@ -87,9 +88,8 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
style={{
position: "absolute",
display: "flex",
right: position ? position[0] : " ",
top: position ? position[1] : " ",
zIndex: 999,
...cssStyle,
}}
>
{legendProps.map(
Expand All @@ -101,7 +101,6 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
discreteData={legend.metadata}
dataObjectName={legend.title}
colorName={legend.colorName}
position={position}
horizontal={horizontal}
/>
)}
Expand All @@ -111,7 +110,6 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
max={legend.valueRange[1]}
dataObjectName={legend.title}
colorName={legend.colorName}
position={position}
horizontal={horizontal}
/>
)}
Expand All @@ -123,7 +121,6 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
};

ColorLegend.defaultProps = {
position: [5, 10],
horizontal: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Test Color Legend", () => {
zoom={0}
incrementValue={0}
widthPerUnit={0}
position={[0, 0]}
cssStyle={{ top: 0, left: 0 }}
scaleUnit="m"
/>
);
Expand All @@ -27,7 +27,7 @@ describe("Test Color Legend", () => {
zoom={1}
incrementValue={100}
widthPerUnit={100}
position={[10, 10]}
cssStyle={{ top: 10, left: 10 }}
scaleUnit="m"
/>
);
Expand Down
23 changes: 10 additions & 13 deletions react/src/lib/components/DeckGLMap/components/DistanceScale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface scaleProps {
incrementValue?: number | null;
// Scale bar width in pixels per unit value
widthPerUnit?: number | null;
// positioning the scale ruler based on x and y values
position?: number[] | null;
// additional css style to position the component
cssStyle?: Record<string, unknown> | null;
// default unit for the scale ruler
scaleUnit?: string;
}
Expand All @@ -23,10 +23,10 @@ const DistanceScale: React.FC<scaleProps> = ({
zoom,
incrementValue,
widthPerUnit,
position,
cssStyle,
scaleUnit,
}: scaleProps) => {
if (!zoom || !widthPerUnit || !incrementValue || !position) return null;
if (!zoom || !widthPerUnit || !incrementValue) return null;

const [rulerWidth, setRulerWidth] = React.useState<number>(0);
const widthInUnits = widthPerUnit / Math.pow(2, zoom);
Expand All @@ -37,9 +37,6 @@ const DistanceScale: React.FC<scaleProps> = ({
borderTop: "none",
display: "inline-block",
marginLeft: "3px",
marginRight: "3px",
right: 0,
bottom: 0,
};

const scaleValue =
Expand All @@ -57,13 +54,14 @@ const DistanceScale: React.FC<scaleProps> = ({
return (
<div
style={{
bottom: position[0],
left: position[1],
position: "relative",
position: "absolute",
...cssStyle,
}}
>
<label>{convertedValue.toFixed(0)}</label>
{convertedUnit}
<label>
{convertedValue.toFixed(0)}
{convertedUnit}
</label>
<div style={scaleRulerStyle}></div>
</div>
);
Expand All @@ -73,7 +71,6 @@ DistanceScale.defaultProps = {
zoom: -3,
incrementValue: 100,
widthPerUnit: 100,
position: [10, 10],
scaleUnit: "m",
};

Expand Down
3 changes: 3 additions & 0 deletions react/src/lib/components/DeckGLMap/components/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const useStyles = makeStyles({
borderRadius: "5px",
position: "absolute",
bottom: 0,
left: 0,
marginLeft: "3px",
marginBottom: "3px",
},
},
icon_style: {
Expand Down
31 changes: 18 additions & 13 deletions react/src/lib/components/DeckGLMap/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export interface MapProps {
visible?: boolean | null;
incrementValue?: number | null;
widthPerUnit?: number | null;
position?: number[] | null;
cssStyle?: Record<string, unknown> | null;
};

coordinateUnit?: string;
Expand All @@ -159,7 +159,7 @@ export interface MapProps {

legend?: {
visible?: boolean | null;
position?: number[] | null;
cssStyle?: Record<string, unknown> | null;
horizontal?: boolean | null;
};

Expand Down Expand Up @@ -236,10 +236,16 @@ const Map: React.FC<MapProps> = ({
setViewState({ ...viewState, zoom: vs.zoom });
}, [zoom]);

// react on bounds prop change
useEffect(() => {
const vs = getViewState(bounds, zoom, deckRef.current?.deck);
setViewState({ ...viewState, target: vs.target });
}, [bounds]);

// calculate view state on deckgl context load (based on viewport size)
const onLoad = useCallback(() => {
setViewState(getViewState(bounds, zoom, deckRef.current?.deck));
}, []);
}, [bounds, zoom]);

// state for views prop of DeckGL component
const [viewsProps, setViewsProps] = useState<ViewProps[]>([]);
Expand Down Expand Up @@ -372,7 +378,7 @@ const Map: React.FC<MapProps> = ({
// validate layers data
const [errorText, setErrorText] = useState<string>();
useEffect(() => {
const layers = deckRef.current?.deck.props.layers;
const layers = deckRef.current?.deck.props.layers as Layer<unknown>[];
// this ensures to validate the schemas only once
if (checkDatafileSchema && layers && isLoaded) {
try {
Expand Down Expand Up @@ -465,11 +471,13 @@ const Map: React.FC<MapProps> = ({
{...legend}
layers={[
getLayersByType(
deckRef.current?.deck.props.layers,
deckRef.current?.deck.props
.layers as Layer<unknown>[],
"WellsLayer"
)?.[0],
getLayersByType(
deckRef.current?.deck.props.layers,
deckRef.current?.deck.props
.layers as Layer<unknown>[],
"ColormapLayer"
)?.[0],
]}
Expand Down Expand Up @@ -497,10 +505,8 @@ const Map: React.FC<MapProps> = ({

{scale?.visible ? (
<DistanceScale
{...scale}
zoom={viewState?.zoom}
incrementValue={scale.incrementValue}
widthPerUnit={scale.widthPerUnit}
position={scale.position}
scaleUnit={coordinateUnit}
/>
) : null}
Expand Down Expand Up @@ -534,14 +540,14 @@ Map.defaultProps = {
visible: true,
incrementValue: 100,
widthPerUnit: 100,
position: [10, 10],
cssStyle: { top: 10, left: 10 },
},
toolbar: {
visible: false,
},
legend: {
visible: true,
position: [5, 10],
cssStyle: { top: 5, right: 10 },
horizontal: false,
},
coordinateUnit: "m",
Expand Down Expand Up @@ -596,8 +602,7 @@ function getViewState(
height = deck.height;
}

const padding = 20;
const fitted_bound = fitBounds({ width, height, bounds, padding });
const fitted_bound = fitBounds({ width, height, bounds });
const view_state: ViewStateType = {
target: [fitted_bound.x, fitted_bound.y, 0],
zoom: zoom ?? fitted_bound.zoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

exports[`Test Color Legend snapshot test 1`] = `
<div
style="position: absolute; display: flex; right: 5px; top: 10px; z-index: 999;"
style="position: absolute; display: flex; z-index: 999;"
/>
`;
Loading

0 comments on commit f162517

Please sign in to comment.