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

fix: Fixed tooltip for Mobile Area Charts #1817

Merged
merged 11 commits into from
Nov 11, 2024
9 changes: 4 additions & 5 deletions app/charts/area/areas-state.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMediaQuery, useTheme } from "@mui/material";
import { extent, group, rollup, sum } from "d3-array";
import {
ScaleLinear,
Expand Down Expand Up @@ -59,6 +58,7 @@ import {
getSortingOrders,
makeDimensionValueSorters,
} from "@/utils/sorting-values";
import { useIsMobile } from "@/utils/use-is-mobile";

import { ChartProps } from "../shared/ChartProps";

Expand Down Expand Up @@ -353,8 +353,7 @@ const useAreasState = (
xScaleTimeRange.range([0, chartWidth]);
yScale.range([chartHeight, 0]);

const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
const isMobile = useIsMobile();

/** Tooltip */
const getAnnotationInfo = useCallback(
Expand All @@ -376,10 +375,10 @@ const useAreasState = (
formatNumber,
});
const xAnchor = xScale(getX(datum));
const yNormalized = normalize
const yDesktopAnchor = normalize
? yScale.range()[0] * 0.5
: yScale(sum(yValues) * (fields.segment ? 0.5 : 1));
const yAnchor = isMobile ? chartHeight : yNormalized;
const yAnchor = isMobile ? chartHeight : yDesktopAnchor;

return {
xAnchor,
Expand Down
7 changes: 7 additions & 0 deletions app/utils/use-is-mobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useMediaQuery, useTheme } from "@mui/material";

export const useIsMobile = () => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
return isMobile;
};
noahonyejese marked this conversation as resolved.
Show resolved Hide resolved