Skip to content

Commit

Permalink
Customize chart display names (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeShi42 authored Jan 5, 2024
1 parent b04ee14 commit a7647ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
21 changes: 14 additions & 7 deletions packages/app/src/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const seriesDisplayName = (
} = {},
) => {
if (s.type === 'time' || s.type === 'table') {
if (s.displayName != null) {
return s.displayName;
}

const displayField =
s.aggFn !== 'count'
? s.table === 'metrics'
Expand Down Expand Up @@ -113,13 +117,16 @@ export function seriesColumns({
? [
{
dataKey: `series_0.data`,
displayName: `${seriesDisplayName(series[0], {
showField,
showWhere,
})}/${seriesDisplayName(series[1], {
showField,
showWhere,
})}`,
displayName:
'displayName' in series[0] && series[0].displayName != null
? series[0].displayName
: `${seriesDisplayName(series[0], {
showField,
showWhere,
})}/${seriesDisplayName(series[1], {
showField,
showWhere,
})}`,
sortOrder:
'sortOrder' in series[0] ? series[0].sortOrder : undefined,
},
Expand Down
25 changes: 7 additions & 18 deletions packages/app/src/HDXMultiSeriesTableChart.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
import { memo, useCallback, useRef } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/router';
import cx from 'classnames';
import { Anchor, Flex, Text } from '@mantine/core';
import { Flex, Text } from '@mantine/core';
import {
flexRender,
getCoreRowModel,
Expand All @@ -22,7 +20,6 @@ import {
} from './ChartUtils';
import { UNDEFINED_WIDTH } from './tableUtils';
import type { ChartSeries, NumberFormat } from './types';
import { AggFn } from './types';
import { formatNumber } from './utils';

const Table = ({
Expand Down Expand Up @@ -135,8 +132,6 @@ const Table = ({
<div
className="overflow-auto h-100 fs-8 bg-inherit"
ref={tableContainerRef}
// Fixes flickering scroll bar: https://github.com/TanStack/virtual/issues/426#issuecomment-1403438040
// style={{ overflowAnchor: 'none' }}
>
<table className="w-100 bg-inherit" style={{ tableLayout: 'fixed' }}>
<thead
Expand Down Expand Up @@ -203,13 +198,6 @@ const Table = ({
? 'isResizing'
: ''
}`}
// style={{
// position: 'absolute',
// right: 4,
// top: 0,
// bottom: 0,
// width: 12,
// }}
>
<i className="bi bi-three-dots-vertical" />
</div>
Expand Down Expand Up @@ -287,10 +275,9 @@ const HDXMultiSeriesTableChart = memo(
config: {
series,
seriesReturnType = 'column',
// numberFormat,
dateRange,
sortOrder,
numberFormat,
groupColumnName,
},
onSettled,
onSortClick,
Expand All @@ -302,6 +289,7 @@ const HDXMultiSeriesTableChart = memo(
seriesReturnType: 'ratio' | 'column';
sortOrder: 'asc' | 'desc';
numberFormat?: NumberFormat;
groupColumnName?: string;
};
onSettled?: () => void;
onSortClick?: (seriesIndex: number) => void;
Expand Down Expand Up @@ -346,9 +334,10 @@ const HDXMultiSeriesTableChart = memo(
<Table
data={data?.data ?? []}
groupColumnName={
series[0].type === 'table'
groupColumnName ??
(series[0].type === 'table'
? series[0].groupBy.join(' ') || 'Group'
: 'Group'
: 'Group')
}
columns={seriesMeta}
numberFormat={numberFormat}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type AggFn =
export type SourceTable = 'logs' | 'rrweb' | 'metrics';

export type TimeChartSeries = {
displayName?: string;
table: SourceTable;
type: 'time';
aggFn: AggFn; // TODO: Type
Expand All @@ -193,6 +194,7 @@ export type TimeChartSeries = {
};

export type TableChartSeries = {
displayName?: string;
type: 'table';
table: SourceTable;
aggFn: AggFn;
Expand Down

0 comments on commit a7647ea

Please sign in to comment.