diff --git a/src/components/dialog/observation-chart.js b/src/components/dialog/observation-chart.js index 07b55621..1be97e52 100644 --- a/src/components/dialog/observation-chart.js +++ b/src/components/dialog/observation-chart.js @@ -1,6 +1,6 @@ -import React, {Fragment} from 'react'; -import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts'; +import React from 'react'; import axios from 'axios'; +import { LineChart, Line, XAxis, YAxis, CartesianGrid, Legend, ResponsiveContainer, Tooltip } from 'recharts'; import { useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query'; const queryClient = new QueryClient(); @@ -57,16 +57,16 @@ function CreateObsChart(url) { // render the chart return ( - + { status === 'pending' ? ( - 'Loading...' +
Loading...
) : status === 'error' ? ( - Error: {error.message} +
Error: {error.message}
) : ( - + - - + + @@ -75,7 +75,7 @@ function CreateObsChart(url) { )} -
+ ); } @@ -118,10 +118,27 @@ function csvToJSON(csvData) { // remove the timezone from the time value ret_val.map(function (e){ e.time = e.time.substring(0, e.time.split(':', 2).join(':').length); - if (e["APS Nowcast"]) e["APS Nowcast"] = +parseFloat(e["APS Nowcast"]).toFixed(4); - if (e["Observations"]) e["Observations"] = +parseFloat(e["Observations"]).toFixed(4); - if (e["NOAA Tidal Predictions"]) e["NOAA Tidal Predictions"] = +parseFloat(e["NOAA Tidal Predictions"]).toFixed(3); - if (e["Difference (APS-OBS)"]) e["Difference (APS-OBS)"] = +parseFloat(e["Difference (APS-OBS)"]).toFixed(3); + + // data that is missing a value will not result in plotting + if (e["APS Nowcast"]) + e["APS Nowcast"] = +parseFloat(e["APS Nowcast"]).toFixed(4); + else + e["APS Nowcast"] = null; + + if (e["Observations"]) + e["Observations"] = +parseFloat(e["Observations"]).toFixed(4); + else + e["Observations"] = null; + + if (e["NOAA Tidal Predictions"]) + e["NOAA Tidal Predictions"] = +parseFloat(e["NOAA Tidal Predictions"]).toFixed(3); + else + e["NOAA Tidal Predictions"] = null; + + if (e["Difference (APS-OBS)"]) + e["Difference (APS-OBS)"] = +parseFloat(e["Difference (APS-OBS)"]).toFixed(3); + else + e["Difference (APS-OBS)"] = null; }); // return the json data representation