Skip to content

Commit 0672336

Browse files
author
Alam, Maksudul
committed
Updated to load the json file from the data folder
1 parent f9fe280 commit 0672336

File tree

5 files changed

+30
-56
lines changed

5 files changed

+30
-56
lines changed

viz/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ For example, with Texas 2000 bus synthetic data, executing the following `opflow
4646
opflow -netfile case_ACTIVSg2000.m -save_output -opflow_output_format JSON -gicfile ACTIVSg2000_GIC_data.gic
4747
```
4848

49-
Next, go to the `viz` folder and run the following python script `geninputfile.py` from the `viz` folder to load the JSON file (`path/to/opflowout/opflowout.json`) in the visualization script. It will copy the `json` file to the `viz/data` subdirectory and create/overwrite a file named `viz/src/module_casedata.js`. The `module_casedata.js` file is an application source file to load the data file `opflowout.json`. Note, the visualization tool expects the file (`opflowout.json`) to be present in `viz/data` forlder, so it is copied by this script.
50-
51-
```
52-
python geninputfile.py path/to/opflowout/opflowout.json
53-
```
49+
Next, you can put the `opflowout.json` file in the `viz/data` folder. When the visualization tool will be launched, it will find all `*.json` files in the `viz/data` folder and show a list of files in the top left corner. The first item in the list will be visualized as default. Users can change the selection and the visualization will be updated accordingly. In addition, users can upload a compatible `json` case file (generated via `opflow`) using the file upload button next to the selection list.
5450

5551
Now you are ready to launch the visualization now.
5652

57-
Note: If you have already created or have the JSON file externally without running the `opflow` command as instructed above, simply run the `geninputfile.py` script using the above command.
58-
5953
## Launch visualization
6054
To launch the visualization, run
6155

File renamed without changes.

viz/src/App.jsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,18 @@ function valuetext(value) {
138138
return `${value.toFixed(2)}`;
139139
}
140140

141-
142-
// 39.8283° N, 98.5795°
143-
144-
145141
const INITIAL_VIEW_STATE = {
146142
latitude: 39.8283,
147143
longitude: -98.5795,
148-
zoom: 5,
144+
zoom: 4,
149145
maxZoom: 16,
150146
pitch: 0,
151147
bearing: 0,
152148
};
153149

154-
155-
156-
const CASES = [
157-
{ label: "500", file: "opflowout-500.json" },
158-
{ label: "10K", file: "opflowout-10K.json" },
159-
{ label: "70K", file: "opflowout-70K.json" },
160-
];
150+
const DATA_FILES = Object.keys(import.meta.glob("../data/*.json", { eager: true })).map((path) =>
151+
path.split("/").pop()
152+
);
161153

162154
function App({ refdata, refflowdata, refflowdata_reactive, ggdata, gendata, generation, areas, zones, countyload, countyloaddata, countymaxPd, mapcenter, mapStyle = MAP_STYLE }) {
163155

@@ -225,6 +217,23 @@ function App({ refdata, refflowdata, refflowdata_reactive, ggdata, gendata, gene
225217

226218
const [tooltip, setTooltip] = useState();
227219

220+
221+
const GoHome = () => {
222+
223+
setInitialViewState((viewState) => ({
224+
...INITIAL_VIEW_STATE
225+
}));
226+
227+
mapRef.current?.flyTo({
228+
center: [mapcenter.longitude, mapcenter.latitude],
229+
zoom: INITIAL_VIEW_STATE.zoom,
230+
pitch: INITIAL_VIEW_STATE.pitch,
231+
duration: 1200,
232+
});
233+
234+
setShowPopup({ ...showPopup, display: false });
235+
}
236+
228237
useEffect(() => {
229238

230239
setGridData(refdata);
@@ -625,21 +634,7 @@ function App({ refdata, refflowdata, refflowdata_reactive, ggdata, gendata, gene
625634
}
626635
});
627636

628-
const GoHome = () => {
629-
630-
setInitialViewState((viewState) => ({
631-
...INITIAL_VIEW_STATE
632-
}));
633-
634-
mapRef.current?.flyTo({
635-
center: [mapcenter.longitude, mapcenter.latitude],
636-
zoom: INITIAL_VIEW_STATE.zoom,
637-
pitch: INITIAL_VIEW_STATE.pitch,
638-
duration: 1200,
639-
});
640-
641-
setShowPopup({ ...showPopup, display: false });
642-
}
637+
643638

644639
const [netlayeractive, setNetLayerActive] = useState(true);
645640

@@ -1585,6 +1580,7 @@ function App({ refdata, refflowdata, refflowdata_reactive, ggdata, gendata, gene
15851580
const response = await fetch(`/data/${filename}`);
15861581
const json = await response.json();
15871582
const case_data = setInputCaseData(json);
1583+
GoHome();
15881584
console.log("Loaded case data:", case_data);
15891585
}
15901586

@@ -1969,7 +1965,7 @@ const label = { color: "#222" };
19691965

19701966
function AppContainer() {
19711967

1972-
const [selected, setSelected] = useState(CASES[0].file);
1968+
const [selected, setSelected] = useState(DATA_FILES[0]);
19731969
const [casedata, setCasedata] = useState(null);
19741970
const [loading, setLoading] = useState(false);
19751971
const [err, setErr] = useState(null);
@@ -1985,6 +1981,7 @@ function AppContainer() {
19851981
if (!res.ok) throw new Error(`Failed to load ${selected}: ${res.status}`);
19861982
const json = await res.json();
19871983
if (!cancelled) setCasedata(json);
1984+
19881985
} catch (e) {
19891986
if (!cancelled) setErr(e);
19901987
} finally {
@@ -2062,11 +2059,12 @@ function AppContainer() {
20622059
return (
20632060
<>
20642061
<select value={selected} onChange={(e) => setSelected(e.target.value)}>
2065-
{CASES.map((c) => (
2066-
<option key={c.file} value={c.file}>{c.label}</option>
2062+
{DATA_FILES.map((c) => (
2063+
<option key={c} value={c}>{c}</option>
20672064
))}
20682065
</select>
20692066

2067+
Upload a JSON case file:
20702068
<input
20712069
type="file"
20722070
accept=".json"

viz/src/dataprocess.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import countydata from "../data/counties.json";
1+
import countydata from "../geo_data/counties.json";
22
import { center, convex, bbox } from "@turf/turf";
33
import us from "us";
44

viz/src/module_casedata.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)