diff --git a/src/components/App.tsx b/src/components/App.tsx index 4bbb746..b41c318 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -19,7 +19,7 @@ export const App: React.FC = () => { const [activeTab, setActiveTab] = useState<"location" | "simulation">("location"); const [latitude, setLatitude] = useState(""); const [longitude, setLongitude] = useState(""); - const [dayOfYear, setDayOfYear] = useState(171); + const [dayOfYear, /*setDayOfYear */] = useState(171); const [locations, setLocations] = useState([]); const [locationSearch, setLocationSearch] = useState(""); const [selectedAttrs, setSelectedAttributes] = useState(kDefaultOnAttributes); @@ -34,20 +34,21 @@ export const App: React.FC = () => { // of the sync process, when user select a row in CODAP and we want to update the day in the simulation tab. }; - const handleCaseSelectionInCodap = (_latitude: string, _longitude: string, day: number) => { - // Option 1. Update as much of the plugin state as we can when user selects a case in CODAP. I think this might - // be too much, as it'll clear all the inputs in all the tabs and the user will have to re-enter everything - // if they were in the middle of something. - // setDayOfYear(day); - // setLatitude(_latitude); - // setLongitude(_longitude); - // ...OR... - // Option 2. Update only the day of the year, as that's reasonably unobtrusive and useful. We can first check - // if user actually selected the case from the same location, and only then update the day of the year. - if (latitude === _latitude && longitude === _longitude) { - setDayOfYear(day); - } - } + // TODO: Handle case selection - sync sim tab with CODAP selection + // const handleCaseSelectionInCodap = (_latitude: string, _longitude: string, day: number) => { + // // Option 1. Update as much of the plugin state as we can when user selects a case in CODAP. I think this might + // // be too much, as it'll clear all the inputs in all the tabs and the user will have to re-enter everything + // // if they were in the middle of something. + // // setDayOfYear(day); + // // setLatitude(_latitude); + // // setLongitude(_longitude); + // // ...OR... + // // Option 2. Update only the day of the year, as that's reasonably unobtrusive and useful. We can first check + // // if user actually selected the case from the same location, and only then update the day of the year. + // if (latitude === _latitude && longitude === _longitude) { + // setDayOfYear(day); + // } + // } const { getUniqueLocationsInCodapData } = useCodapData(); // Store a ref to getUniqueLocationsInCodapData so we can call inside useEffect without triggering unnecessary re-runs diff --git a/src/utils/daylight-utils.ts b/src/utils/daylight-utils.ts index d8a1c52..c13ec71 100644 --- a/src/utils/daylight-utils.ts +++ b/src/utils/daylight-utils.ts @@ -28,13 +28,14 @@ function getDayLength(sunrise: Dayjs, sunset: Dayjs): number { return dayLength; } -function hasDST(latitude: number, longitude: number, year: number): boolean { - const timeZone = tzlookup(latitude, longitude); - const winterDate = dayjs.tz(`${year}-01-01`, timeZone); - const summerDate = dayjs.tz(`${year}-07-01`, timeZone); +// Uncomment this to use in the DST adjustment commented out below +// function hasDST(latitude: number, longitude: number, year: number): boolean { +// const timeZone = tzlookup(latitude, longitude); +// const winterDate = dayjs.tz(`${year}-01-01`, timeZone); +// const summerDate = dayjs.tz(`${year}-07-01`, timeZone); - return winterDate.utcOffset() !== summerDate.utcOffset(); -} +// return winterDate.utcOffset() !== summerDate.utcOffset(); +// } function getSeasonName(dayJsDay: Dayjs, latitude: number): string { const year = dayJsDay.year(); @@ -73,7 +74,7 @@ function getSeasonName(dayJsDay: Dayjs, latitude: number): string { return season; } -export function getSolarNoonIntensity(dayNum: number, latitude: number): number | null { +export function getSolarNoonIntensity(dayNum: number, latitude: number): number { const solarConstant = 1361; const latitudeRad = latitude * Math.PI / 180; const declination = 23.45 * Math.sin((360/365) * (dayNum - 81) * Math.PI / 180); @@ -87,7 +88,7 @@ export function getSolarNoonIntensity(dayNum: number, latitude: number): number return solarNoonIntensity; } -export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:number): number | null { +export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:number): number { const tiltAxisZRadians = 2 * Math.PI * (dayNum - kBasicSummerSolstice) / 365; const orbitalTiltDegrees = earthTilt ? earthTilt : 0; const effectiveTiltDegrees = -Math.cos(tiltAxisZRadians) * orbitalTiltDegrees;