Skip to content
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
11 changes: 11 additions & 0 deletions .changeset/configurable-content-font-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@hyperdx/app': minor
---

feat: add a content font size preference

Small text in the log/trace table was not adjustable without browser zoom, which
also shrinks the surrounding chrome. User preferences now carry a **Content font
size** setting (small / medium / large) that scales the search results table,
data tables, expanded row JSON, and chart axes, legends, and tooltips. Small is
the default and matches the previous sizes, so nothing changes until you opt in.
18 changes: 18 additions & 0 deletions packages/app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { NextApiConfigResponseData } from '@/types';
import { ConfirmProvider } from '@/useConfirm';
import {
SystemColorSchemeScript,
useContentFontSize,
useResolvedColorScheme,
useUserPreferences,
} from '@/useUserPreferences';
Expand Down Expand Up @@ -98,6 +99,8 @@ function AppContent({
const { userPreferences } = useUserPreferences();
const resolvedColorScheme = useResolvedColorScheme();
const { themeName } = useAppTheme();
const { base: contentFontSize, compact: compactContentFontSize } =
useContentFontSize();

// ClickStack theme always uses Inter font - user preference is ignored
// HyperDX theme allows user to select font preference
Expand All @@ -115,6 +118,21 @@ function AppContent({
}
}, [effectiveFont]);

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 minor — Users with a non-default size see a flash of small text and a column reflow on every load

userPreferencesAtom is an atomWithStorage with no getOnInit, and the vars are only written in a post-mount useEffect. So the first paint always uses 12px and scale: 1, then the text and the default column widths jump. SystemColorSchemeScript in useUserPreferences.tsx already solves this for color mode by reading hdx-user-preferences in an inline script before React runs. Have it set --hdx-content-font-size and --hdx-content-font-size-compact from contentFontSize too.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

// Single write point for the content font size preference; tables and
// chart CSS read these vars (see styles/app.scss for the defaults).
if (typeof document !== 'undefined') {
document.documentElement.style.setProperty(
'--hdx-content-font-size',
`${contentFontSize}px`,
);
document.documentElement.style.setProperty(
'--hdx-content-font-size-compact',
`${compactContentFontSize}px`,
);
}
}, [contentFontSize, compactContentFontSize]);

const getLayout = Component.getLayout ?? (page => page);

return (
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/HDXMultiSeriesTableChart.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// .rowButtons pattern from LogTable.module.scss (lines 156-172),
// scoped down to a single icon. See HDX-4405.

.tableWrapper {
font-size: var(--hdx-content-font-size);
}

.tableHeader {
// Always-on 1px separator between the sticky header and the rows. An
// inset box-shadow rather than a border because the table sets
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/HDXMultiSeriesTableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export const Table = ({

return (
<div
className={cx('overflow-auto h-100 fs-8', className)}
className={cx('overflow-auto h-100', styles.tableWrapper, className)}
ref={tableContainerRef}
>
<table
Expand Down
38 changes: 28 additions & 10 deletions packages/app/src/HDXMultiSeriesTimeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
toStartOfInterval,
} from './ChartUtils';
import { useFormatTime } from './useFormatTime';
import { useContentFontSize } from './useUserPreferences';

import styles from '@styles/HDXLineChart.module.scss';

Expand Down Expand Up @@ -777,7 +778,12 @@ export function collectMemoChartGradientHexes(
// (NumberFormat.tsx), but 2 already distinguishes values >= 0.005 from 0.
const MAX_AXIS_MANTISSA = 2;

/** Base width ceiling for a bare signed number - see MAX_AXIS_MANTISSA's comment. */
/**
* Base width ceiling for a bare signed number - see MAX_AXIS_MANTISSA's
* comment. A character budget rather than a pixel one, which is why
* Y_AXIS_WIDTH scales with the content font size preference: the gutter has to
* grow with the tick font for this to keep holding at every setting.
*/
const AXIS_CHAR_BUDGET = 5;

// Flat, not suffix-length-scaled - IBM Plex Mono is monospace, so a longer
Expand Down Expand Up @@ -1351,6 +1357,12 @@ export const MemoChart = memo(function MemoChart({
const _id = useId();
const id = _id.replace(/:/g, '');

// The y-axis width budget is expressed in characters (see MAX_AXIS_MANTISSA),
// so it has to grow with the tick font or the widest labels clip.
const { compact: axisTickFontSize, scale: contentFontScale } =
useContentFontSize();
const yAxisWidth = Math.round(Y_AXIS_WIDTH * contentFontScale);

// recharts sync group, scoped via context (see chartSync).
const syncId = useChartSyncId();

Expand Down Expand Up @@ -1585,14 +1597,14 @@ export const MemoChart = memo(function MemoChart({
if (graphResults.length !== 1) return undefined;
const drawableWidth = Math.max(
0,
containerWidth - Y_AXIS_WIDTH - SINGLE_POINT_BAR_RIGHT_PADDING,
containerWidth - yAxisWidth - SINGLE_POINT_BAR_RIGHT_PADDING,
);
if (drawableWidth <= 0) return undefined;
return Math.max(
1,
Math.floor(drawableWidth * SINGLE_POINT_BAR_WIDTH_RATIO),
);
}, [displayType, graphResults.length, containerWidth]);
}, [displayType, graphResults.length, containerWidth, yAxisWidth]);

const formatTime = useFormatTime();
const xTickFormatter = useCallback(
Expand Down Expand Up @@ -1932,9 +1944,9 @@ export const MemoChart = memo(function MemoChart({
}
return layoutAnnotations(coloredAnnotations, {
domain: xAxisDomain,
plotWidth: Math.max(0, containerWidth - Y_AXIS_WIDTH),
plotWidth: Math.max(0, containerWidth - yAxisWidth),
});
}, [coloredAnnotations, xAxisDomain, containerWidth]);
}, [coloredAnnotations, xAxisDomain, containerWidth, yAxisWidth]);

const [hoveredAnnotation, setHoveredAnnotation] =
useState<HoveredAnnotation | null>(null);
Expand All @@ -1948,9 +1960,9 @@ export const MemoChart = memo(function MemoChart({
// Drawable width, so markers too close together share one label. Zero on
// the first paint (before ResponsiveContainer measures), which the
// renderer treats as "label everything".
plotWidth: Math.max(0, containerWidth - Y_AXIS_WIDTH),
plotWidth: Math.max(0, containerWidth - yAxisWidth),
});
}, [coloredAnnotations, xAxisDomain, containerWidth]);
}, [coloredAnnotations, xAxisDomain, containerWidth, yAxisWidth]);

return (
<div
Expand Down Expand Up @@ -2063,13 +2075,19 @@ export const MemoChart = memo(function MemoChart({
type="number"
tickFormatter={xTickFormatter}
minTickGap={100}
tick={{ fontSize: 11, fontFamily: 'IBM Plex Mono, monospace' }}
tick={{
fontSize: axisTickFontSize,
fontFamily: 'IBM Plex Mono, monospace',
}}
/>
<YAxis
width={Y_AXIS_WIDTH}
width={yAxisWidth}
minTickGap={25}
tickFormatter={yAxisTickFormatter}
tick={{ fontSize: 11, fontFamily: 'IBM Plex Mono, monospace' }}
tick={{
fontSize: axisTickFontSize,
fontFamily: 'IBM Plex Mono, monospace',
}}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
domain={yAxisDomain}
ticks={yAxisTicks}
/>
Expand Down
25 changes: 24 additions & 1 deletion packages/app/src/UserPreferencesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ import {
} from '@mantine/core';
import { IconFlask } from '@tabler/icons-react';

import { OPTIONS_FONTS } from './config/fonts';
import {
isContentFontSize,
OPTIONS_CONTENT_FONT_SIZE,
OPTIONS_FONTS,
} from './config/fonts';
import { useAppTheme } from './theme/ThemeProvider';
import { isValidThemeName, themes } from './theme';
import {
DEFAULT_ROW_CLICK_ACTION,
RowClickAction,
useContentFontSize,
UserPreferences,
useUserPreferences,
} from './useUserPreferences';
Expand Down Expand Up @@ -72,6 +77,7 @@ export const UserPreferencesModal = ({
onClose: () => void;
}) => {
const { userPreferences, setUserPreference } = useUserPreferences();
const { contentFontSize } = useContentFontSize();
const { themeName, setTheme, isDev } = useAppTheme();

return (
Expand Down Expand Up @@ -168,6 +174,23 @@ export const UserPreferencesModal = ({
/>
</SettingContainer>

<SettingContainer
label="Content font size"
description="Text size for log tables, data tables, and charts"
>
<Select
data-testid="content-font-size-select"
value={contentFontSize}
onChange={value =>
value &&
isContentFontSize(value) &&
setUserPreference({ contentFontSize: value })
}
data={OPTIONS_CONTENT_FONT_SIZE}
allowDeselect={false}
/>
</SettingContainer>

{/*
Brand Theme Selector - DEV MODE ONLY

Expand Down
110 changes: 110 additions & 0 deletions packages/app/src/__tests__/useContentFontSize.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { Provider } from 'jotai';
import { act, renderHook } from '@testing-library/react';

import { CONTENT_FONT_SIZES } from '@/config/fonts';
import { useContentFontSize, useUserPreferences } from '@/useUserPreferences';

const STORAGE_KEY = 'hdx-user-preferences';

const renderContentFontSize = () =>
renderHook(
() => ({
resolved: useContentFontSize(),
preferences: useUserPreferences(),
}),
{ wrapper: Provider },
);

describe('useContentFontSize', () => {
beforeEach(() => {
window.localStorage.clear();
});

// The `sm` scale is what every content surface had hardcoded before the
// preference existed, so it has to stay the default.
it('defaults to the small scale', () => {
const { result } = renderContentFontSize();

expect(CONTENT_FONT_SIZES.sm).toEqual({ base: 12, compact: 11 });
expect(result.current.resolved).toEqual({
contentFontSize: 'sm',
...CONTENT_FONT_SIZES.sm,
scale: 1,
});
});

it('falls back to the default for preferences stored before the setting existed', () => {
window.localStorage.setItem(
STORAGE_KEY,
JSON.stringify({
isUTC: true,
timeFormat: '24h',
colorMode: 'dark',
font: 'Inter',
}),
);

const { result } = renderContentFontSize();

expect(result.current.resolved.contentFontSize).toBe('sm');
});

it('loads a non-default preference saved in a previous session', () => {
window.localStorage.setItem(
STORAGE_KEY,
JSON.stringify({
isUTC: false,
timeFormat: '12h',
colorMode: 'dark',
font: 'IBM Plex Mono',
contentFontSize: 'md',
}),
);

const { result } = renderContentFontSize();

expect(result.current.resolved).toEqual({
contentFontSize: 'md',
...CONTENT_FONT_SIZES.md,
scale: CONTENT_FONT_SIZES.md.base / CONTENT_FONT_SIZES.sm.base,
});
});

it('falls back to the default when the stored size is not one we ship', () => {
window.localStorage.setItem(
STORAGE_KEY,
JSON.stringify({
isUTC: false,
timeFormat: '12h',
colorMode: 'dark',
font: 'IBM Plex Mono',
contentFontSize: 'xl',
}),
);

const { result } = renderContentFontSize();

expect(result.current.resolved).toEqual({
contentFontSize: 'sm',
...CONTENT_FONT_SIZES.sm,
scale: 1,
});
});

it('resolves the stored preference', () => {
const { result } = renderContentFontSize();

act(() =>
result.current.preferences.setUserPreference({ contentFontSize: 'lg' }),
);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

expect(result.current.resolved).toEqual({
contentFontSize: 'lg',
...CONTENT_FONT_SIZES.lg,
scale: CONTENT_FONT_SIZES.lg.base / CONTENT_FONT_SIZES.sm.base,
});
expect(
JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '{}'),
).toEqual(expect.objectContaining({ contentFontSize: 'lg' }));
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 minor — The px-budget scaling — the part most likely to regress — has no test

The only new test covers the hook's resolved numbers; nothing exercises getResolvedColumnSize's scaled() defaults or the derived axis widths, so a future edit that drops contentFontScale from columnSizeOpts or reverts width={yAxisWidth} stays green. packages/app/src/components/__tests__/DBRowTable.test.tsx already has a "Column width persistence" harness asserting th inline widths — add a case there rendering with contentFontSize: 'lg' and asserting the timestamp column is 227px while a stored width stays untouched.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

});
24 changes: 20 additions & 4 deletions packages/app/src/components/DBBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { Flex } from '@mantine/core';

import type { NumberFormat } from '@/types';
import { useContentFontSize } from '@/useUserPreferences';
import { formatNumber } from '@/utils';

import {
Expand All @@ -24,6 +25,7 @@ import { ChartTooltipContainer, ChartTooltipItem } from './charts/ChartTooltip';

const MAX_BAR_LABEL_LENGTH = 14;
const BAR_LABEL_AXIS_HEIGHT = 80; // increased height to accommodate rotated + truncated labels
const Y_AXIS_WIDTH = 40;

const truncateBarLabel = (value: string) =>
value.length > MAX_BAR_LABEL_LENGTH
Expand Down Expand Up @@ -71,6 +73,14 @@ export const DBBarChart = (props: CategoricalChartProps) => {
chartData,
responseFormatError,
} = useCategoricalChart(props);
// Both axis allocations are character budgets at the default tick font, so
// they scale with it rather than clipping the labels.
const { base: axisTickFontSize, scale: contentFontScale } =
useContentFontSize();
const barLabelAxisHeight = Math.round(
BAR_LABEL_AXIS_HEIGHT * contentFontScale,
);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
const yAxisWidth = Math.round(Y_AXIS_WIDTH * contentFontScale);

return (
<ChartContainer title={props.title} toolbarItems={toolbarItems}>
Expand Down Expand Up @@ -113,12 +123,15 @@ export const DBBarChart = (props: CategoricalChartProps) => {
interval={0}
angle={-45}
textAnchor="end"
height={BAR_LABEL_AXIS_HEIGHT}
height={barLabelAxisHeight}
tickFormatter={truncateBarLabel}
tick={{ fontSize: 12, fontFamily: 'IBM Plex Mono, monospace' }}
tick={{
fontSize: axisTickFontSize,
fontFamily: 'IBM Plex Mono, monospace',
}}
/>
<YAxis
width={40}
width={yAxisWidth}
minTickGap={25}
tickFormatter={(value: number) =>
resolvedNumberFormat
Expand All @@ -128,7 +141,10 @@ export const DBBarChart = (props: CategoricalChartProps) => {
compactDisplay: 'short',
}).format(value)
}
tick={{ fontSize: 12, fontFamily: 'IBM Plex Mono, monospace' }}
tick={{
fontSize: axisTickFontSize,
fontFamily: 'IBM Plex Mono, monospace',
}}
/>
<Bar dataKey="value">
{chartData.map(entry => (
Expand Down
Loading
Loading