Skip to content

Commit

Permalink
Use transpiled react components for generating dash components (equin…
Browse files Browse the repository at this point in the history
…or#497)

* Change name for setup deckgl types to follow convention

* Add ts transpiling

* Update examples + add well logs example

* Add propTypes to wellLogViewer

* Remove size limit
  • Loading branch information
alexandruandrei91 authored and Havard Bjerke committed Nov 29, 2021
1 parent edb1c18 commit 4735ca2
Show file tree
Hide file tree
Showing 20 changed files with 961,099 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/webviz-subsurface-components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
# The deckgl types package runs a postscript to setup, but since we ignore scripts, we need to set it up manually.
run: |
npm ci --ignore-scripts --prefix ./react
npm run setup_deckgl_types --prefix ./react
npm run setup-deckgl-types --prefix ./react
npm run copy-package-json --prefix ./react
pip install .[dependencies]
pip install dash[dev]
Expand All @@ -50,7 +50,7 @@ jobs:
run: |
echo "NPM_PUBLISH_TAG=next" >> $GITHUB_ENV
npm install --ignore-scripts @webviz/core-components@next
npm run setup_deckgl_types
npm run setup-deckgl-types
- name: 🏗️ Build JavaScript part
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dash built code

react/webviz_subsurface_components/**/*
webviz_subsurface_components/**/*
!webviz_subsurface_components/__init__.py

Expand Down
13 changes: 11 additions & 2 deletions examples/example_deckgl_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def array2d_to_png(z_array):
"https://raw.githubusercontent.com/equinor/webviz-subsurface-components/"
"master/react/src/demo/example-data/volve_wells.json"
)
LOGS = (
"https://raw.githubusercontent.com/equinor/webviz-subsurface-components/"
"master/react/src/demo/example-data/volve_logs.json"
)

bounds = [432205, 6475078, 437720, 6481113] # left, bottom, right, top
width = bounds[2] - bounds[0] # right - left
Expand All @@ -151,7 +155,6 @@ def array2d_to_png(z_array):
id="deckgl-map",
resources={
"propertyMap": map_data,
"wells": WELLS,
},
deckglSpecBase={
"initialViewState": {
Expand Down Expand Up @@ -185,11 +188,17 @@ def array2d_to_png(z_array):
{
"@@type": "WellsLayer",
"id": "wells-layer",
"data": "@@#resources.wells",
"data": WELLS,
"logData": LOGS,
"opacity": 1.0,
"lineWidthScale": 5,
"pointRadiusScale": 8,
"outline": True,
"logRadius": 6,
"logrunName": "BLOCKING",
"logName": "ZONELOG",
"logCurves": True,
"refine": True,
},
],
"views": [
Expand Down
2 changes: 1 addition & 1 deletion examples/example_well_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import webviz_subsurface_components

with open("../src/demo/example-data/well-completions-with-attr.json", "r") as json_file:
with open("./react/src/demo/example-data/well-completions.json", "r") as json_file:
data = json.load(json_file)

app = dash.Dash(__name__)
Expand Down
31 changes: 31 additions & 0 deletions examples/example_well_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2020 - Equinor ASA.

import json

import dash
import dash_html_components as html

import webviz_subsurface_components

with open("./react/src/demo/example-data/L898MUD.json", "r") as json_file:
logs = json.load(json_file)

with open("./react/src/demo/example-data/welllog_template_1.json", "r") as json_file:
template = json.load(json_file)

app = dash.Dash(__name__)

app.layout = html.Div(
children=[
webviz_subsurface_components.WellLogViewer(
id="well_completions", welllog=logs, template=template
),
],
)

if __name__ == "__main__":
app.run_server(debug=True)
9 changes: 6 additions & 3 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
"scripts": {
"start": "webpack serve --mode development --devtool inline-source-map --entry ./src/demo/index.js --open",
"copy-package-json": "copyfiles ./package.json ../webviz_subsurface_components/",
"transpile": "tsc && npm run copy-files",
"transpile:dash": "tsc && rimraf ./dist/components/*/**/",
"tidy-up": "rimraf ./dist ./webviz_subsurface_components",
"build:js": "webpack --mode production",
"build:js-dev": "webpack --mode development",
"build:js-demo": "webpack --mode production --entry ./src/demo/index.js",
"build:py": "mv ../webviz_subsurface_components . && dash-generate-components ./src/lib/components webviz_subsurface_components -p package-info.json --ignore \"(.js|.stories.jsx)$\" && mv webviz_subsurface_components ..",
"build": "npm run build:js && npm run build:js-dev && npm run build:py",
"build:py": "npm run transpile:dash && copyfiles -a ../webviz_subsurface_components/. ./webviz_subsurface_components/ && copyfiles ./package.json ./webviz_subsurface_components/ && dash-generate-components ./dist/components webviz_subsurface_components -p package.json --ignore '(^index.js|.stories.js)$' && copyfiles -a -f ./webviz_subsurface_components/* ../webviz_subsurface_components/",
"build": "npm run transpile && npm run build:js && npm run build:js-dev && npm run tidy-up && npm run build:py && npm run tidy-up",
"typecheck": "tsc --noEmit",
"format": "eslint --fix *.js *json \"src/**/*.+(ts|tsx|js|jsx|json|css)\"",
"lint": "eslint *.js *.json \"src/**/*.+(ts|tsx|js|jsx|json|css)\"",
"validate": "npm run typecheck && npm run lint",
"setup_deckgl_types": "cd ./node_modules/@danmarshall/deckgl-typings/ && indefinitely-typed --folder deck.gl__aggregation-layers --folder deck.gl__core --folder deck.gl__extensions --folder deck.gl__geo-layers --folder deck.gl__google-maps --folder deck.gl__json --folder deck.gl__layers --folder deck.gl__mapbox --folder deck.gl__mesh-layers --folder deck.gl__react --folder deck.gl --folder luma.gl__constants --folder luma.gl__core --folder luma.gl__gltools --folder luma.gl__webgl-state-tracker --folder luma.gl__webgl --folder math.gl__core --folder math.gl",
"setup-deckgl-types": "cd ./node_modules/@danmarshall/deckgl-typings/ && indefinitely-typed --folder deck.gl__aggregation-layers --folder deck.gl__core --folder deck.gl__extensions --folder deck.gl__geo-layers --folder deck.gl__google-maps --folder deck.gl__json --folder deck.gl__layers --folder deck.gl__mapbox --folder deck.gl__mesh-layers --folder deck.gl__react --folder deck.gl --folder luma.gl__constants --folder luma.gl__core --folder luma.gl__gltools --folder luma.gl__webgl-state-tracker --folder luma.gl__webgl --folder math.gl__core --folder math.gl",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"test": "jest --coverage",
Expand Down
1 change: 1 addition & 0 deletions react/src/demo/WellLogViewerDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class WellLogViewerDemo extends Component {
</div>
<div style={{ width: "80%", flex: 1 }}>
<WellLogViewer
id="WellLogViewer"
welllog={this.getData(this.state.example)}
template={JSON.parse(this.state.text)}
/>
Expand Down
960,961 changes: 960,960 additions & 1 deletion react/src/demo/example-data/volve_logs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/src/lib/components/DeckGLMap/DeckGLMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as jsonpatch from "fast-json-patch";
import { cloneDeep } from "lodash";
import PropTypes from "prop-types";
import * as React from "react";
import Map from "./Map";
import Map from "./components/Map";

function _idsToIndices(doc, path) {
// The path looks something like this: `/layers/[layer-id]/property`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { Operation } from "fast-json-patch";
import { Feature } from "geojson";
import React from "react";
import { Provider as ReduxProvider } from "react-redux";
import Settings from "./components/settings/Settings";
import JSON_CONVERTER_CONFIG from "./configuration";
import { setSpec } from "./redux/actions";
import { createStore } from "./redux/store";
import { WellsPickInfo } from "./layers/wells/wellsLayer";
import InfoCard from "./components/InfoCard";
import Settings from "./settings/Settings";
import JSON_CONVERTER_CONFIG from "../utils/configuration";
import { setSpec } from "../redux/actions";
import { createStore } from "../redux/store";
import { WellsPickInfo } from "../layers/wells/wellsLayer";
import InfoCard from "./InfoCard";

export interface MapProps {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { EditableGeoJsonLayer } from "@nebula.gl/layers";
import { registerLoaders } from "@loaders.gl/core";
import GL from "@luma.gl/constants";

import * as CustomLayers from "./layers";
import * as CustomLayers from "../layers";

// Note: deck already registers JSONLoader...
registerLoaders([]);
Expand Down
2 changes: 1 addition & 1 deletion react/src/lib/components/LeafletMap/LeafletMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "./layers/L.tileWebGLLayer";
// Components
import Controls from "./components/Controls";
import CompositeMapLayers from "./components/CompositeMapLayers";
import Context from "./context";
import Context from "./utils/context";

// Utils
import { onSizeChange } from "./utils/element";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Component } from "react";
import PropTypes from "prop-types";
import Context from "../context";
import Context from "../utils/context";

// Leaflet
import L from "leaflet";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { useState, useEffect, useContext } from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
import Context from "../../../context";
import Context from "../../../utils/context";

// Leaflet
import L from "leaflet";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { Component } from "react";
import PropTypes from "prop-types";
import "leaflet-draw/dist/leaflet.draw.css";
import L from "leaflet";
import Context from "../../../context";
import Context from "../../../utils/context";

import { getShapeType } from "../../../utils/leaflet";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "leaflet-draw/dist/leaflet.draw.css";
import L from "leaflet";

// Context
import Context from "../../../context";
import Context from "../../../utils/context";

// Constants

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { useState, useEffect, useContext } from "react";
import PropTypes from "prop-types";
import Context from "../../../context";
import Context from "../../../utils/context";

import L from "leaflet";

Expand Down
116 changes: 70 additions & 46 deletions react/src/lib/components/WellLogViewer/WellLogViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component, ReactNode } from "react";

import PropTypes from "prop-types";
import WellLogView from "./components/WellLogView";
import InfoPanel from "./components/InfoPanel";
import AxisSelector from "./components/AxisSelector";
Expand Down Expand Up @@ -45,6 +46,8 @@ interface State {
}

class WellLogViewer extends Component<Props, State> {
public static propTypes: Record<string, unknown>;

controller?: WellLogController;

constructor(props: Props) {
Expand Down Expand Up @@ -142,56 +145,77 @@ class WellLogViewer extends Component<Props, State> {
return (
<div>
<table style={{ height: "100%", width: "100%" }}>
<tr>
<td>
<WellLogView
welllog={this.props.welllog}
template={this.props.template}
primaryAxis={this.state.primaryAxis}
axisTitles={axisTitles}
axisMnemos={axisMnemos}
maxTrackNum={7}
setInfo={this.setInfo.bind(this)}
setController={this.setController.bind(this)}
setScrollPos={this.setScrollPos.bind(this)}
/>{" "}
{/*scroll={this.state.scroll}*/}
</td>
<td valign="top" style={{ width: "250px" }}>
<AxisSelector
header="Primary scale"
axes={this.state.axes}
axisLabels={axisTitles}
value={this.state.primaryAxis}
onChange={this.onChangePrimaryAxis.bind(this)}
/>
<InfoPanel
header="Readout"
infos={this.state.infos}
/>
<div>
<br />
<button
id="buttonUp"
type="button"
onClick={this.onScrollUp.bind(this)}
>
{"\u25C4"}
</button>
<button
id="buttonDown"
type="button"
onClick={this.onScrollDown.bind(this)}
>
{"\u25BA"}
</button>
</div>
</td>
</tr>
<tbody>
<tr>
<td>
<WellLogView
welllog={this.props.welllog}
template={this.props.template}
primaryAxis={this.state.primaryAxis}
axisTitles={axisTitles}
axisMnemos={axisMnemos}
maxTrackNum={7}
setInfo={this.setInfo.bind(this)}
setController={this.setController.bind(
this
)}
setScrollPos={this.setScrollPos.bind(this)}
/>{" "}
{/*scroll={this.state.scroll}*/}
</td>
<td valign="top" style={{ width: "250px" }}>
<AxisSelector
header="Primary scale"
axes={this.state.axes}
axisLabels={axisTitles}
value={this.state.primaryAxis}
onChange={this.onChangePrimaryAxis.bind(
this
)}
/>
<InfoPanel
header="Readout"
infos={this.state.infos}
/>
<div>
<br />
<button
id="buttonUp"
type="button"
onClick={this.onScrollUp.bind(this)}
>
{"\u25C4"}
</button>
<button
id="buttonDown"
type="button"
onClick={this.onScrollDown.bind(this)}
>
{"\u25BA"}
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
);
}
}

WellLogViewer.propTypes = {
/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string.isRequired,

// TODO: Add doc
welllog: PropTypes.array,

// TODO: Add doc
template: PropTypes.object,
};

export default WellLogViewer;
2 changes: 2 additions & 0 deletions react/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Morris from "./components/Morris";
import PriorPosteriorDistribution from "./components/PriorPosteriorDistribution";
import VectorSelector from "./components/VectorSelector";
import WellCompletions from "./components/WellCompletions";
import WellLogViewer from "./components/WellLogViewer";

export {
HistoryMatch,
Expand All @@ -26,4 +27,5 @@ export {
VectorSelector,
WellCompletions,
GroupTree,
WellLogViewer,
};

0 comments on commit 4735ca2

Please sign in to comment.