Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #96 from openghg/scatter
Browse files Browse the repository at this point in the history
Replace the CH4 density map with scatter
  • Loading branch information
gareth-j authored Nov 8, 2021
2 parents 2a1ba8a + e3a8f3a commit d87797c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/components/LiveData/LiveData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import LeafletMap from "../LeafletMap/LeafletMap";
import styles from "../../Dashboard.module.css";
import ObsBox from "../ObsBox/ObsBox";
import ObsExplainer from "../ObsExplainer/ObsExplainer";
import DensityMap from "../DensityMap/DensityMap";
import GraphContainer from "../GraphContainer/GraphContainer";
import MobileExplainer from "../MobileExplainer/MobileExplainer";
import ScatterMap from "../ScatterMap/ScatterMap";

class LiveData extends React.Component {
createMapExplainer() {
Expand Down Expand Up @@ -67,9 +67,9 @@ class LiveData extends React.Component {
siteInfoOverlay={this.props.setSiteOverlay}
/>
</div>
<div className={styles.mobileMap} >
<div className={styles.mobileMap}>
<GraphContainer divName="densityMapContent">
<DensityMap />
<ScatterMap />
</GraphContainer>
</div>
<div className={styles.mobileExplainer} id="densityMapContent">
Expand Down
1 change: 1 addition & 0 deletions src/components/MobileExplainer/MobileExplainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MobileExplainer extends React.Component {
<div className={styles.intro}>
This map shows methane detected by a mobile study completed in August, 2021.
Methane was measured using a car-mounted instrument which was driven 350km around Glasgow to gather this data.
The diameter of the circles on the map is related to the size of the methane emissions measured.
<br />
<br />
<a
Expand Down
6 changes: 0 additions & 6 deletions src/components/ObsBox/ObsBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class ObsBox extends React.Component {
for (const [site, sectorData] of Object.entries(networkData)) {
for (const [sector, value] of Object.entries(sectorData)) {
if (value) {
// if (!speciesEmissions.hasOwnProperty(site)) {
// speciesEmissions[site] = {};
// }

// speciesEmissions[network][site][sector] = data;

const data = processedData[selectedSpecies][network][site][sector];
set(speciesEmissions, `${network}.${site}.${sector}`, data);

Expand Down
84 changes: 84 additions & 0 deletions src/components/ScatterMap/ScatterMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from "react";
import Plot from "react-plotly.js";

import styles from "./ScatterMap.module.css";

import ch4MobileGlasgow from "../../data/ch4_mobile_glasgow.json";

class ScatterMap extends React.Component {
constructor(props) {
super(props);

const ch4Data = ch4MobileGlasgow["ch4"]["data"];

const measurements = ch4Data["z"];
const latitude = ch4Data["lat"];
const longitude = ch4Data["lon"];

const hovertemplate =
"<b>Latitude</b>: %{lat:.5f}<br>" +
"<b>Longitude</b>: %{lon:.5f}<br><br>" +
"<b>Concentration: </b>: %{text:.2f} ppb <br>" +
"(enhancement over background)" +
"<extra></extra>";

const sizeVals = [];
const divisor = 125;
for (var i = 0; i < measurements.length; i++) {
sizeVals.push(measurements[i] / divisor);
}

const dataObj = {
type: "scattermapbox",
mode: "markers",
coloraxis: "coloraxis",
hovertemplate: hovertemplate,
text: measurements,
lon: longitude,
lat: latitude,
marker: {
color: measurements,
colorscale: "Viridis",
cmin: Math.min(measurements),
cmax: Math.max(measurements),
reversescale: false,
size: sizeVals,
colorbar: {
thickness: 10,
titleside: "right",
outlinecolor: "rgba(68,68,68,0)",
ticks: "outside",
ticklen: 3,
shoticksuffix: "last",
title: { side: "right", text: "Methane (ppb)", font: { size: 16 } },
},
},
};

this.state = { plotData: [dataObj] };
}

render() {
const height = 400;
const width = this.props.width;
const plotData = this.state.plotData;

const layout = {
mapbox: { center: { lon: -4.212836, lat: 55.843658 }, style: "open-street-map", zoom: 10 },
coloraxis: {
colorscale: "Viridis",
colorbar: { title: { side: "right", text: "Methane (ppb)", font: { size: 16 } } },
},
margin: { t: 30, b: 30, l: 30, r: 30 },
width: width,
height: height,
};
return (
<div className={styles.content}>
<Plot data={plotData} layout={layout} />
</div>
);
}
}

export default ScatterMap;
4 changes: 4 additions & 0 deletions src/components/ScatterMap/ScatterMap.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.content {
width: 100%;
height: 100%;
}

0 comments on commit d87797c

Please sign in to comment.