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

LF-4699(1): Display sensor readings on the UI #3714

Open
wants to merge 37 commits into
base: integration
Choose a base branch
from

Conversation

SayakaOno
Copy link
Collaborator

@SayakaOno SayakaOno commented Mar 14, 2025

Description

  • Add LineChart component and stories.
    • Supports both timely data and general data.
    • The default hover behaviour (example) of displaying tooltips and dots for all x-axis points is overridden using state.
    • Dots are displayed when the data length is 12 or fewer, to ensure tooltips are easily accessible, especially on mobile.
  • Add getTicks function and tests (pnpm test chartUtils)
    • Returns monthly ticks if the range spans over two or more days at the start of a month; otherwise, returns daily ticks.
    • Limits the number of ticks to 7.

Jira link: https://lite-farm.atlassian.net/browse/LF-4699

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@SayakaOno SayakaOno added the enhancement New feature or request label Mar 14, 2025
@SayakaOno SayakaOno self-assigned this Mar 14, 2025
@SayakaOno SayakaOno changed the base branch from LF-4698-create-endpoints-to-get-sensor-array-readings-from-ensemble to integration March 14, 2025 20:50
@SayakaOno SayakaOno force-pushed the LF-4699/Display_sensor_readings_on_the_UI branch from 874f2d7 to 45613cf Compare March 14, 2025 21:52
@SayakaOno SayakaOno changed the title [WIP] LF-4699(1): Display sensor readings on the UI LF-4699(1): Display sensor readings on the UI Mar 17, 2025
@SayakaOno SayakaOno marked this pull request as ready for review March 17, 2025 19:00
@SayakaOno SayakaOno requested review from a team as code owners March 17, 2025 19:00
@SayakaOno SayakaOno requested review from antsgar and kathyavini and removed request for a team March 17, 2025 19:00
Copy link
Collaborator

@antsgar antsgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The charts look amazing! ❤️ I left a couple of small comments, but this looks great. I assume there'll be a follow up PR for showing these on the sensor detail view, correct?

Comment on lines +54 to +59
'--Colors-Accent---singles-Blue-full': '#0669e1',
'--Colors-Accent---singles-Red-full': '#d02620',
'--Colors-Accent-Accent-yellow-600': '#e8a700',
'--Colors-Primary-Primary-teal-700': '#266f68',
'--Colors-Accent---singles-Purple-full': '#8f26f0',
'--Colors-Accent---singles-Brown-full': '#aa5f04',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we follow the format of the other colors in the theme here instead of the "CSS variable" format? So something like accentYellow600? I also wonder if these colors are only going to be used for charts, in which case it might be good to make that explicit in the naming and call them something like chartBlue, chartRed. Perhaps we could check that with Loïc?

Comment on lines +104 to +125
const CustomTooltip = ({ active, payload, label }: TooltipProps<ValueType, NameType>) => {
if (active && payload?.length && activeLine) {
const data = payload.find(({ dataKey }) => dataKey === activeLine);

if (data) {
const { color } = lineConfig.find(({ id }) => id === activeLine)!;
const xAxisData = isTimeScaleProps(props)
? getDateTime(label, props.language, props.truncPeriod, t)
: label;
const value = formatTooltipValue?.(label, data.value) || data.value;

return (
<dl className={styles.tooltip} style={{ '--tooltipColor': color } as React.CSSProperties}>
<dt>{xAxisData}</dt>
<dd>{value}</dd>
</dl>
);
}
}

return null;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this component outside of LineChart and pass any props needed from LineChart to it? It's best not to declare a component inside another one, because it will be re-created on every render. I also think it's harder to figure out which data the component needs to function when it's declared inside another one and uses some of its props/state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants