Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admins can preview pollen calendar #101

Merged
merged 27 commits into from
May 5, 2024
Merged

Conversation

arnard76
Copy link
Contributor

@arnard76 arnard76 commented Apr 30, 2024

Task ⛳

#74 > #100

Solution 🫠

After inputting valid excel spreadsheet (previous two tasks), the admin can click the preview button to see how the pollen calendar would look & verify that their data is parsed (understood) correctly.

image

Stuff included in the pollen calendar

  • a bar chart (directed downwards) 📊
    to compare pollen types on a single day

  • a line chart (directed upwards) 📉
    to see the trend of a pollen type over multiple days

  • tooltip
    to see what the easily see what the pollen value was & at which date

  • pollen type filter
    to narrow down to the pollen types that user/admin is interested in
    e.g. they are researching grass pollen or their health is heavily effected by plantain pollen more than other types

    image
  • date filter
    narrows down chart to show a specific time period
    e.g. just summer, the entire year, multiple years, this week, last week, today etc.

NOTE: Update button doesn't do anything yet, part of the separate task (check #74)

Code changes 🤓🧑‍💻

Summary + explanation of code changes

Don't need to read if you don't want to. Or you can take a look at 'Files changed' tab if that is more readable.

  • MultiChart.tsx is a component that shows a bar chart and line chart on the same axis

  • updated parseExcel.ts to include sorting of all pollen values so that the array is ordered by the date (of the pollen measurement)

  • formatData.ts is different to parseExcel.ts! formatData is to get the already parsed PollenData object into a format that is ready to be displayed

  • add 2 visual tests for the preview
    soo..... the pollen calendar has a chart on it from the module chart.js and chart.js uses HTML <canvas> elements. This is great for very visual components like a graph that have to render effeciently 😀. However it is unfortunate for testing purposes because all the browser sees is a canvas element (no child elements) as seen below 👇

    image

    so visual tests compare what the pollen calendar looks like with the screenshot I took before this PR e.g. cypress/snapshots/base/pollenCalendar.cy.ts/editPollenCalendarPreview.png

    so can test visual elements like canvas by differences in screenshots. I've added one test for the pollen calendar as is & one for when user hovers over a bar on the chart & tooltip is shown (check snapshots folder to see how it looks)

    i've used this library to compare the screenshots (snapshots) but there are lots more if we need alternatives 😇

  • fix annoying bug:
    on brave, the chart would start shrinking & lagging when hovering over a data point.
    it worked perfectly fine a few days ago (on brave) and still works fine on other chromium based browsers..

    fix for it 🛠️🛠️
    All chart examples are decreasing in size when pixelRatio is non-terminating value chartjs/Chart.js#11224
    set a height on the chart and set maintainAspectRatio to false
    no idea why this works but no more weird lagging on chart 😇

plus refactor code a bit
- only show assumptions if there are errors related to parsing.
no valid sheets would result in app crashing, somade  e2e test for that and fixed it
e.g. if pollen calendar looks drastically different, then test will fail.

for this example, the way to solve it would fix bug that was ruining calendar OR if it is an improvement to calendar, update the snapshots in `cypress/snapshots/base/<testfilename>/<snapshotname>`

followed the `readme` of the package to setup ☝️
https://github.com/cypress-visual-regression/cypress-visual-regression
- can be used for the pollen calendar on `/pollen` page that user sees too
why?
0 has boolean value false so formatting data function was getting rid of those values

fix 🛠️
only get rid of undefined values (as on those dates, no pollen value was recorded)
- noticeable when clicking the filter buttons, the multichart would keep refreshing even tho the data hasn't changed yet
when changing the date period using the date filter, the last bar or line points on the chart is offsetted by 50%.

why?
when changing the date period using the date filter, the timestamp generated for the date would have time midday.

fix 🧑‍⚕️🧑‍⚕️
changing the date timestamp to have time of 00:00:00 (which is either midnight at the start of day or midnight at the end, idk)

no more weird offset
using the stack property to stack the bars only not the lines.

this is great because we don't have to manually set the max and min for each axis. and when

setting suggested min and max because if there is pollen values are all at 0, it should be obvious that the chart can go higher than 0 but the value was low. SORRY soooper confusing explanation, definitely easier to show.
…ontal line

it looked really weird and was especially noticeable for the dailyTotal because the horizontal line was around 40 on the y-axis

fix 🛠️: chart.js connects the points based on the order they appear in the array, not based on their x-axis value (in this case the date of the pollen measurement)

so sorting the parsed pollen data based on the date fixed this issue 👌👌👌😃😃😃
@arnard76 arnard76 self-assigned this Apr 30, 2024
@arnard76 arnard76 added type: feature an issue that involves a new feature or enhancements project: frontend an issue in the frontend app labels Apr 30, 2024
@arnard76 arnard76 changed the base branch from dev to 74-pollen-data-standard-format April 30, 2024 11:01
it should look as it does right now (50% difference is tolerated). but if it is not there, the test will let us know 😃🧪👌
@arnard76 arnard76 added the pr: pending review the PR is pending review label Apr 30, 2024
@arnard76 arnard76 force-pushed the 100-show-pollen-calendar-preview branch from fb365a0 to ea257b8 Compare April 30, 2024 23:47
@arnard76 arnard76 linked an issue May 1, 2024 that may be closed by this pull request
@arnard76 arnard76 force-pushed the 74-pollen-data-standard-format branch from 0536d5a to 18bbce9 Compare May 1, 2024 10:26
Base automatically changed from 74-pollen-data-standard-format to dev May 1, 2024 10:51
@arnard76 arnard76 marked this pull request as ready for review May 1, 2024 11:22
@arnard76 arnard76 force-pushed the 100-show-pollen-calendar-preview branch from f038107 to 9b60714 Compare May 1, 2024 11:50
@arnard76 arnard76 marked this pull request as draft May 1, 2024 12:25
@arnard76 arnard76 removed the pr: pending review the PR is pending review label May 1, 2024
@arnard76 arnard76 force-pushed the 100-show-pollen-calendar-preview branch 2 times, most recently from f0c1d46 to e036797 Compare May 2, 2024 02:11
even if errors, show any preview of any parsed data

update the types
@arnard76 arnard76 force-pushed the 100-show-pollen-calendar-preview branch from e036797 to 6a0b6ce Compare May 2, 2024 02:23
@arnard76 arnard76 marked this pull request as ready for review May 2, 2024 02:43
frontend/app/components/pollenCalendar/index.tsx Outdated Show resolved Hide resolved
frontend/app/components/pollenCalendar/index.tsx Outdated Show resolved Hide resolved
frontend/app/components/pollenCalendar/index.tsx Outdated Show resolved Hide resolved
frontend/app/components/pollenCalendar/index.tsx Outdated Show resolved Hide resolved
frontend/app/components/pollenCalendar/index.tsx Outdated Show resolved Hide resolved
@HuzzNZ
Copy link
Contributor

HuzzNZ commented May 2, 2024

Consider:

@/components/pollenCalendar -> @/components/PollenCalendar (capitalize the directory)

@arnard76
Copy link
Contributor Author

arnard76 commented May 2, 2024

Consider:

@/components/pollenCalendar -> @/components/PollenCalendar (capitalize the directory)

weird I tried to do this. and locally it shows it renamed but on github it doesn't and i don't have any changes 🤔
lemme see what is happening lol

@arnard76
Copy link
Contributor Author

arnard76 commented May 2, 2024

Consider:
@/components/pollenCalendar -> @/components/PollenCalendar (capitalize the directory)

weird I tried to do this. and locally it shows it renamed but on github it doesn't and i don't have any changes 🤔 lemme see what is happening lol

nvm figured it out: git config core.ignorecase false

@arnard76
Copy link
Contributor Author

arnard76 commented May 2, 2024

Consider:

@/components/pollenCalendar -> @/components/PollenCalendar (capitalize the directory)

npm run build throws a weird error to this:
https://github.com/uoa-compsci399-s1-2024/capstone-project-2024-s1-team-15/actions/runs/8922754394/job/24505571378

feel free to give it a go if u want, but it would also make it the only directory in the project with a capital letter 😁

@arnard76 arnard76 force-pushed the 100-show-pollen-calendar-preview branch from ae71145 to be0cdcf Compare May 2, 2024 11:14
@arnard76 arnard76 requested a review from HuzzNZ May 2, 2024 11:18
@HuzzNZ HuzzNZ merged commit 68afb64 into dev May 5, 2024
2 checks passed
@HuzzNZ HuzzNZ deleted the 100-show-pollen-calendar-preview branch May 5, 2024 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: frontend an issue in the frontend app type: feature an issue that involves a new feature or enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Frontend: Show Pollen Calendar preview in CMS
2 participants