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

fix(ui): better experience for analytics charts #12462

Merged
Merged
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 @@ -84,6 +84,38 @@
return returnLines;
}

const formatAxisDate = (value: number, chartData: TimeSeriesChartType) => {
const date = new Date(value);

switch (chartData.interval) {
case 'MONTH':
return date.toLocaleDateString('en-US', {
month: 'short',
year: 'numeric',
timeZone: 'UTC',
});
case 'WEEK':
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
timeZone: 'UTC',
});
case 'DAY':
return date.toLocaleDateString('en-US', {
weekday: 'short',
day: 'numeric',
timeZone: 'UTC',
});
default:
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
timeZone: 'UTC',
});
}
};

Check warning on line 117 in datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx#L88-L117

Added lines #L88 - L117 were not covered by tests

export const TimeSeriesChart = ({
chartData,
width,
Expand Down Expand Up @@ -117,6 +149,7 @@
strokeWidth={style?.axisWidth}
tickLabelProps={{ fill: 'black', fontFamily: 'inherit', fontSize: 10 }}
numTicks={3}
tickFormat={(value) => formatAxisDate(value, chartData)}

Check warning on line 152 in datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx#L152

Added line #L152 was not covered by tests
/>
<Axis
orientation="right"
Expand Down Expand Up @@ -151,9 +184,7 @@
tooltipData?.nearestDatum && (
<div>
<div>
{new Date(
Number(accessors.xAccessor(tooltipData.nearestDatum.datum)),
).toDateString()}
{formatAxisDate(accessors.xAccessor(tooltipData.nearestDatum.datum), chartData)}

Check warning on line 187 in datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/analyticsDashboard/components/TimeSeriesChart.tsx#L187

Added line #L187 was not covered by tests
</div>
<div>{accessors.yAccessor(tooltipData.nearestDatum.datum)}</div>
</div>
Expand Down
Loading