Skip to content

Commit

Permalink
Stats: Use hour digits for hourly view X-axis labels (#97118)
Browse files Browse the repository at this point in the history
* Use only hour digits for chart x-axis labels for hourly view

* Format hourly view tooltips label with hour digits for the StatsEmailDetail page

* Fix typo
  • Loading branch information
dognose24 authored Dec 6, 2024
1 parent 1bfef66 commit 0439ab9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions client/my-sites/stats/stats-email-chart-tabs/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function formatDate( date, period ) {
const momentizedDate = moment( date );
switch ( period ) {
case 'hour':
return momentizedDate.format( 'HH:mm' );
return momentizedDate.format( 'MMM D' );
case 'day':
return momentizedDate.format( 'LL' );
default:
Expand Down Expand Up @@ -57,10 +57,13 @@ export const buildChartData = memoizeLast( ( activeLegend, chartTab, data, perio
function addTooltipData( chartTab, item, period ) {
const tooltipData = [];
const label = ( () => {
const formattedDate = formatDate( item.data.period, period );

if ( 'hour' === period ) {
return item.label;
return `${ formattedDate } ${ item.label }`;
}
return formatDate( item.data.period, period );

return formattedDate;
} )();

tooltipData.push( {
Expand Down
2 changes: 1 addition & 1 deletion client/state/stats/lists/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function getChartLabels( unit, date, localizedDate ) {
const isWeekend = 'day' === unit && ( 6 === dayOfWeek || 0 === dayOfWeek );
const labelName = `label${ unit.charAt( 0 ).toUpperCase() + unit.slice( 1 ) }`;
const formats = {
hour: translate( 'MMM D HH:mm', {
hour: translate( 'HH:mm', {
context: 'momentjs format string (hour)',
comment: 'This specifies an hour for the stats x-axis label.',
} ),
Expand Down

0 comments on commit 0439ab9

Please sign in to comment.