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

feat(workflow): Align xAxis dates on team stats bar graphs #29499

Merged
merged 2 commits into from
Oct 22, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {t} from 'app/locale';
import space from 'app/styles/space';
import {Organization} from 'app/types';

import {convertDaySeriesToWeeks, convertDayValueObjectToSeries} from './utils';
import {
barAxisLabel,
convertDaySeriesToWeeks,
convertDayValueObjectToSeries,
} from './utils';

type AlertsTriggered = Record<string, number>;

Expand Down Expand Up @@ -86,9 +90,7 @@ class TeamAlertsTriggered extends AsyncComponent<Props, State> {
period="7d"
legend={{right: 0, top: 0}}
yAxis={{minInterval: 1}}
xAxis={{
type: 'time',
}}
xAxis={barAxisLabel(seriesData.length)}
series={[
{
seriesName: t('Alerts Triggered'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import space from 'app/styles/space';
import {Organization, Project} from 'app/types';
import {formatPercentage} from 'app/utils/formatters';

import {convertDaySeriesToWeeks, convertDayValueObjectToSeries} from './utils';
import {
barAxisLabel,
convertDaySeriesToWeeks,
convertDayValueObjectToSeries,
} from './utils';

type IssuesBreakdown = Record<string, Record<string, {reviewed: number; total: number}>>;

Expand Down Expand Up @@ -110,8 +114,12 @@ class TeamIssuesReviewed extends AsyncComponent<Props, State> {
}
}

const reviewedSeries = convertDayValueObjectToSeries(allReviewedByDay);
const notReviewedSeries = convertDayValueObjectToSeries(allNotReviewedByDay);
const reviewedSeries = convertDaySeriesToWeeks(
convertDayValueObjectToSeries(allReviewedByDay)
);
const notReviewedSeries = convertDaySeriesToWeeks(
convertDayValueObjectToSeries(allNotReviewedByDay)
);

return (
<Fragment>
Expand All @@ -122,17 +130,20 @@ class TeamIssuesReviewed extends AsyncComponent<Props, State> {
style={{height: 200}}
stacked
isGroupedByDate
useShortDate
legend={{right: 0, top: 0}}
xAxis={barAxisLabel(reviewedSeries.length)}
yAxis={{minInterval: 1}}
series={[
{
seriesName: t('Reviewed'),
data: convertDaySeriesToWeeks(reviewedSeries),
data: reviewedSeries,
silent: true,
// silent is not incldued in the type for BarSeries
} as any,
{
seriesName: t('Not Reviewed'),
data: convertDaySeriesToWeeks(notReviewedSeries),
data: notReviewedSeries,
silent: true,
},
]}
Expand Down
30 changes: 12 additions & 18 deletions static/app/views/organizationStats/teamInsights/teamReleases.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ComponentType, Fragment} from 'react';
import {withTheme} from '@emotion/react';
import styled from '@emotion/styled';
import chunk from 'lodash/chunk';
import isEqual from 'lodash/isEqual';
import round from 'lodash/round';
import moment from 'moment';
Expand All @@ -20,6 +19,8 @@ import space from 'app/styles/space';
import {Organization, Project} from 'app/types';
import {Color, Theme} from 'app/utils/theme';

import {barAxisLabel, convertDaySeriesToWeeks} from './utils';

type Props = AsyncComponent['props'] & {
theme: Theme;
organization: Organization;
Expand Down Expand Up @@ -171,20 +172,13 @@ class TeamReleases extends AsyncComponent<Props, State> {
const {projects, period, theme} = this.props;
const {periodReleases} = this.state;

const data = Object.entries(periodReleases?.release_counts ?? {})
.map(([bucket, count]) => ({
const data = Object.entries(periodReleases?.release_counts ?? {}).map(
([bucket, count]) => ({
value: Math.ceil(count),
name: new Date(bucket).getTime(),
}))
.sort((a, b) => a.name - b.name);

// Convert from days to 7 day groups
const seriesData = chunk(data, 7).map(week => {
return {
name: week[0].name,
value: week.reduce((total, currentData) => total + currentData.value, 0),
};
});
})
);
const seriesData = convertDaySeriesToWeeks(data);

const averageValues = Object.values(periodReleases?.project_avgs ?? {});
const projectAvgSum = averageValues.reduce(
Expand All @@ -203,20 +197,20 @@ class TeamReleases extends AsyncComponent<Props, State> {
period="7d"
legend={{right: 3, top: 0}}
yAxis={{minInterval: 1}}
xAxis={{
type: 'time',
}}
xAxis={barAxisLabel(seriesData.length)}
series={[
{
seriesName: t('This Period'),
// @ts-expect-error silent missing from type
silent: true,
data: seriesData,
markLine: MarkLine({
silent: true,
lineStyle: {color: theme.gray200, type: 'dashed', width: 1},
data: [{yAxis: totalPeriodAverage} as any],
// @ts-expect-error yAxis type not correct
data: [{yAxis: totalPeriodAverage}],
}),
} as any,
},
]}
tooltip={{
formatter: seriesParams => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import space from 'app/styles/space';
import {Organization} from 'app/types';
import {getDuration} from 'app/utils/formatters';

import {convertDaySeriesToWeeks} from './utils';
import {barAxisLabel, convertDaySeriesToWeeks} from './utils';

type TimeToResolution = Record<string, {count: number; avg: number}>;

Expand Down Expand Up @@ -90,9 +90,7 @@ class TeamResolutionTime extends AsyncComponent<Props, State> {
},
}}
legend={{right: 0, top: 0}}
xAxis={{
type: 'time',
}}
xAxis={barAxisLabel(seriesData.length)}
series={[
{
seriesName: t('Time to Resolution'),
Expand Down
19 changes: 19 additions & 0 deletions static/app/views/organizationStats/teamInsights/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import chunk from 'lodash/chunk';
import moment from 'moment';

import BaseChart from 'app/components/charts/baseChart';
import {SeriesDataUnit} from 'app/types/echarts';

/**
Expand Down Expand Up @@ -28,3 +30,20 @@ export function convertDayValueObjectToSeries(
name: new Date(bucket).getTime(),
}));
}

export const barAxisLabel = (
dataEntries: number
): React.ComponentProps<typeof BaseChart>['xAxis'] => {
return {
splitNumber: dataEntries,
type: 'category',
min: 0,
axisLabel: {
showMaxLabel: true,
showMinLabel: true,
formatter: (date: number) => {
return moment(new Date(date)).format('MMM D');
},
},
};
};