Skip to content

Commit

Permalink
apply cr feedback (#29077)
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev authored Oct 7, 2021
1 parent b0cdf67 commit 2bb85c6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion static/app/components/charts/barChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type ChartProps = React.ComponentProps<typeof BaseChart>;
export type BarChartSeries = Series & Omit<EChartOption.SeriesBar, 'data' | 'name'>;

type Props = Omit<ChartProps, 'series'> & {
stacked?: boolean;
series: BarChartSeries[];
stacked?: boolean;
};

class BarChart extends React.Component<Props> {
Expand Down
7 changes: 7 additions & 0 deletions static/app/components/charts/baseChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ type Props = {
) => string;
valueFormatter?: (value: number, label?: string) => string | number;
nameFormatter?: (name: string) => string;
/**
* Array containing seriesNames that need to be indented
*/
indentLabels?: string[];
};
/**
* DataZoom (allows for zooming of chart)
Expand Down Expand Up @@ -456,6 +460,9 @@ const ChartContainer = styled('div')`
font-weight: normal;
color: ${p => p.theme.white};
}
.tooltip-label-indent {
margin-left: ${space(3)};
}
.tooltip-series > div {
display: flex;
justify-content: space-between;
Expand Down
27 changes: 22 additions & 5 deletions static/app/components/charts/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ type TooltipFormatters =
| 'nameFormatter';

type FormatterOptions = Pick<NonNullable<ChartProps['tooltip']>, TooltipFormatters> &
Pick<ChartProps, NeededChartProps>;
Pick<ChartProps, NeededChartProps> & {
/**
* Array containing seriesNames that need to be indented
*/
indentLabels?: string[];
};

function getFormatter({
filter,
Expand All @@ -93,6 +98,7 @@ function getFormatter({
bucketSize,
valueFormatter = defaultValueFormatter,
nameFormatter = defaultNameFormatter,
indentLabels = [],
}: FormatterOptions) {
const getFilter = (seriesParam: EChartOption.Tooltip.Format) => {
// Series do not necessarily have `data` defined, e.g. releases don't have `data`, but rather
Expand Down Expand Up @@ -140,10 +146,14 @@ function getFormatter({
seriesParamsOrParam.name
);

const className = indentLabels.includes(seriesParamsOrParam.name ?? '')
? 'tooltip-label tooltip-label-indent'
: 'tooltip-label';

return [
'<div class="tooltip-series">',
`<div>
<span class="tooltip-label"><strong>${seriesParamsOrParam.name}</strong></span>
<span class="${className}"><strong>${seriesParamsOrParam.name}</strong></span>
${truncatedName}: ${formattedValue}
</div>`,
'</div>',
Expand All @@ -163,7 +173,7 @@ function getFormatter({
? seriesParams[0].axisValue
: getSeriesValue(seriesParams[0], 0);

const label =
const date =
seriesParams.length &&
axisFormatterOrDefault(
timestamp,
Expand All @@ -182,11 +192,16 @@ function getFormatter({
truncationFormatter(s.seriesName ?? '', truncate)
);
const value = valueFormatter(getSeriesValue(s, 1), s.seriesName);
return `<div><span class="tooltip-label">${s.marker} <strong>${formattedLabel}</strong></span> ${value}</div>`;

const className = indentLabels.includes(formattedLabel)
? 'tooltip-label tooltip-label-indent'
: 'tooltip-label';

return `<div><span class="${className}">${s.marker} <strong>${formattedLabel}</strong></span> ${value}</div>`;
})
.join(''),
'</div>',
`<div class="tooltip-date">${label}</div>`,
`<div class="tooltip-date">${date}</div>`,
`<div class="tooltip-arrow"></div>`,
].join('');
};
Expand All @@ -208,6 +223,7 @@ export default function Tooltip({
valueFormatter,
nameFormatter,
hideDelay,
indentLabels,
...props
}: Props = {}): EChartOption.Tooltip {
formatter =
Expand All @@ -222,6 +238,7 @@ export default function Tooltip({
formatAxisLabel,
valueFormatter,
nameFormatter,
indentLabels,
});

return {
Expand Down
3 changes: 2 additions & 1 deletion static/app/components/charts/miniBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MiniBarChart extends React.Component<Props> {
let chartSeries: BarChartSeries[] = [];

// Ensure bars overlap and that empty values display as we're disabling the axis lines.
if (series && series.length) {
if (!!series?.length) {
chartSeries = series.map((original, i: number) => {
const updated = {
...original,
Expand Down Expand Up @@ -222,6 +222,7 @@ class MiniBarChart extends React.Component<Props> {
animation: false,
},
};

return <BarChart series={chartSeries} {...chartOptions} {...barChartProps} />;
}
}
Expand Down
19 changes: 10 additions & 9 deletions static/app/components/charts/series/barSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ type BarChartDataObject = Omit<EChartOption.SeriesBar.DataObject, 'value'> & {
value: (string | number) | (string | number)[];
};

export default function barSeries(
props: Omit<EChartOption.SeriesBar, 'data'> & {
data?:
| (string | number | void | BarChartDataObject | (string | number)[])[]
| (string | number | void | BarChartDataObject)[][]
| undefined;
} = {}
): EChartOption.SeriesBar {
const {data, ...rest} = props;
type Props = Omit<EChartOption.SeriesBar, 'data'> & {
data?:
| (string | number | void | BarChartDataObject | (string | number)[])[]
| (string | number | void | BarChartDataObject)[][]
| undefined;
};

function barSeries({data, ...rest}: Props): EChartOption.SeriesBar {
return {
...rest,
data: data as EChartOption.SeriesBar['data'],
type: 'bar',
};
}

export default barSeries;

1 comment on commit 2bb85c6

@evanpurkhiser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, somehow this got merged as just the last commit for the message 😨

Please sign in to comment.