Skip to content

Commit

Permalink
Stats & charts: horizontal axis improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed Dec 18, 2024
1 parent 3a400a1 commit 38fef05
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ui/shared/chart/ChartWidgetGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ const ChartWidgetGraph = ({
const axesConfig = React.useMemo(() => {
return {
x: {
ticks: isEnlarged ? 8 : 4,
ticks: isEnlarged && !isMobile ? 8 : 4,
},
y: {
ticks: isEnlarged ? 6 : 3,
nice: true,
},
};
}, [ isEnlarged ]);
}, [ isEnlarged, isMobile ]);

const {
ref,
Expand Down
12 changes: 5 additions & 7 deletions ui/shared/chart/utils/timeChartAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _unique from 'lodash/uniq';

import type { AxesConfig, AxisConfig, TimeChartData } from '../types';

import { WEEK, MONTH, YEAR } from 'lib/consts';
import { MONTH, YEAR } from 'lib/consts';

export const DEFAULT_MAXIMUM_SIGNIFICANT_DIGITS = 2;
export const DEFAULT_MAXIMUM_FRACTION_DIGITS = 3;
Expand Down Expand Up @@ -48,14 +48,12 @@ const tickFormatterX = (axis: d3.Axis<d3.NumberValue>) => (d: d3.AxisDomain) =>

const span = Number(extent[1]) - Number(extent[0]);

if (span > YEAR) {
if (span > 2 * YEAR) {
format = d3.timeFormat('%Y');
} else if (span > 2 * MONTH) {
format = d3.timeFormat('%b');
} else if (span > WEEK) {
format = d3.timeFormat('%b %d');
} else if (span > 4 * MONTH) {
format = d3.timeFormat('%b \'%y');
} else {
format = d3.timeFormat('%a %d');
format = d3.timeFormat('%d %b');
}

return format(d as Date);
Expand Down

0 comments on commit 38fef05

Please sign in to comment.