Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Feat: Localize x-axis in timeseries.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon committed May 15, 2020
1 parent e627618 commit ef1858c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
3 changes: 2 additions & 1 deletion all_locales.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,5 +809,6 @@
"Open Sourced on GitHub": "Open Sourced on GitHub",
"Crowdsourced Patient Database": "Crowdsourced Patient Database",
"View updates on Twitter": "View updates on Twitter",
"Join Telegram to Collaborate!": "Join Telegram to Collaborate!"
"Join Telegram to Collaborate!": "Join Telegram to Collaborate!",
"Back": "Back"
}
6 changes: 0 additions & 6 deletions missing_locales.json
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
{
"Open Sourced on GitHub": "Open Sourced on GitHub",
"Crowdsourced Patient Database": "Crowdsourced Patient Database",
"View updates on Twitter": "View updates on Twitter",
"Join Telegram to Collaborate!": "Join Telegram to Collaborate!"
}
2 changes: 1 addition & 1 deletion src/components/mapexplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function MapExplorer({
className="button back-button"
onClick={() => switchMapToState('India')}
>
Back
{t('Back')}
</div>
) : null}

Expand Down
19 changes: 5 additions & 14 deletions src/components/row.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import {
STATE_ROW_STATISTICS,
DISTRICT_ROW_STATISTICS,
LOCALE_SHORTHANDS,
} from '../constants';
import {STATE_ROW_STATISTICS, DISTRICT_ROW_STATISTICS} from '../constants';
import {
formatDate,
formatNumber,
formatLastUpdated,
capitalize,
abbreviate,
} from '../utils/commonfunctions';

import classnames from 'classnames';
import {formatDistance} from 'date-fns';
import equal from 'fast-deep-equal';
import i18n from 'i18next';
import React, {useState, useCallback, useMemo} from 'react';
import * as Icon from 'react-feather';
import {useTranslation} from 'react-i18next';
Expand Down Expand Up @@ -309,12 +304,8 @@ function Row({
<p>
{isNaN(Date.parse(formatDate(state.lastupdatedtime)))
? ''
: `${t('Last updated')} ${formatDistance(
new Date(formatDate(state.lastupdatedtime)),
new Date(),
{
locale: LOCALE_SHORTHANDS[i18n.language],
}
: `${t('Last updated')} ${formatLastUpdated(
state.lastupdatedtime
)} ${t('ago')}`}
</p>
{sortedDistricts?.Unknown && (
Expand All @@ -332,7 +323,7 @@ function Row({
history.push(`state/${state.statecode}`);
}}
>
{t('See more details on {{state}}', {state: state.state})}
{t('See more details on {{state}}', {state: t(state.state)})}
</td>
</tr>

Expand Down
10 changes: 9 additions & 1 deletion src/components/timeseries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
sliceTimeseriesFromEnd,
formatNumber,
formatTimeseriesDate,
formatTimeseriesTickX,
} from '../utils/commonfunctions';
import {useResizeObserver} from '../utils/hooks';

Expand Down Expand Up @@ -86,7 +87,14 @@ function TimeSeries({timeseriesProp, chartType, mode, logMode, isTotal}) {
const numTicksX = width < 480 ? 4 : 7;

const xAxis = (g) =>
g.attr('class', 'x-axis').call(d3.axisBottom(xScale).ticks(numTicksX));
g.attr('class', 'x-axis').call(
d3
.axisBottom(xScale)
.ticks(numTicksX)
.tickFormat((tick) => {
return formatTimeseriesTickX(tick);
})
);

const xAxis2 = (g, yScale) => {
g.attr('class', 'x-axis2')
Expand Down
6 changes: 6 additions & 0 deletions src/utils/commonfunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export const formatTimeseriesDate = (unformattedDate) => {
});
};

export const formatTimeseriesTickX = (unformattedDate) => {
return format(unformattedDate, 'd MMM', {
locale: LOCALE_SHORTHANDS[i18n.language],
});
};

const validateCTS = (data = []) => {
const dataTypes = [
'dailyconfirmed',
Expand Down

0 comments on commit ef1858c

Please sign in to comment.