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

WAITP-1290: Fix Chart pdf export styles #4727

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const CartesianChart = ({
}, 50);
}, []);

const isMobileSize = isMobile();
const isMobileSize = isMobile(isExporting);

const {
chartType: defaultChartType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const GaugeChart = ({
onItemClick = () => {},
}: GaugeChartProps) => {
const { data, color = BLUE, ...restOfConfigs } = viewContent;
const isMobileSize = isMobile();
const isMobileSize = isMobile(isExporting);

const generateElements = () => {
const denominator = 0.05;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const PieChart = ({
// eslint-disable-next-line no-unused-vars
const [_, setLoaded] = useState(false);

const isMobileSize = isMobile();
const isMobileSize = isMobile(isExporting);

// Trigger rendering of the chart to fix an issue with the legend overlapping the chart.
// This is a work around for a recharts bug. @see https://github.com/recharts/recharts/issues/511
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const getPieLegend = ({
legendPosition,
viewContent,
}: PieLegendProps) => ({ payload }: any) => {
const isMobileSize = isMobile();
const isMobileSize = isMobile(isExporting);
return (
<PieLegendContainer $position={legendPosition} $isExporting={isExporting}>
{payload.map(({ color, value, payload: item }: TooltipPayload) => {
Expand Down Expand Up @@ -189,7 +189,7 @@ export const getCartesianLegend = ({
isExporting,
legendPosition,
}: CartesianLegendProps) => ({ payload }: any) => {
const isMobileSize = isMobile();
const isMobileSize = isMobile(isExporting);
return (
<LegendContainer $position={legendPosition} $isExporting={isExporting}>
{payload.map(({ color, value, dataKey }: TooltipPayload) => {
Expand Down
8 changes: 7 additions & 1 deletion packages/ui-chart-components/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import { GRANULARITY_CONFIG } from '@tupaia/utils';
import { DataProps, ChartType, ViewContent, VizPeriodGranularity } from '../types';

// tupaia-web uses a responsive approach, so we need to check the window width
export const isMobile = () => {
export const isMobile = (isExporting: boolean = false) => {
const appType = process.env.REACT_APP_APP_TYPE;

// Always use the desktop styles when exporting
if (isExporting) {
return false;
}

return appType === 'mobile' || window.innerWidth < 900;
};

Expand Down