fix #33 - issues with same event names
This commit is contained in:
@@ -22,7 +22,6 @@ export function ReportChartTooltip({
|
|||||||
payload,
|
payload,
|
||||||
}: ReportLineChartTooltipProps) {
|
}: ReportLineChartTooltipProps) {
|
||||||
const { unit, interval } = useChartContext();
|
const { unit, interval } = useChartContext();
|
||||||
const getLabel = useMappings();
|
|
||||||
const formatDate = useFormatDateInterval(interval);
|
const formatDate = useFormatDateInterval(interval);
|
||||||
const number = useNumber();
|
const number = useNumber();
|
||||||
if (!active || !payload) {
|
if (!active || !payload) {
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ export function ReportLineChart({ data }: ReportLineChartProps) {
|
|||||||
)}
|
)}
|
||||||
</defs>
|
</defs>
|
||||||
<Line
|
<Line
|
||||||
dot={false}
|
dot={isAreaStyle}
|
||||||
type={lineType}
|
type={lineType}
|
||||||
name={serie.id}
|
name={serie.id}
|
||||||
isAnimationActive={false}
|
isAnimationActive={false}
|
||||||
@@ -229,6 +229,7 @@ export function ReportLineChart({ data }: ReportLineChartProps) {
|
|||||||
/>
|
/>
|
||||||
{isAreaStyle && (
|
{isAreaStyle && (
|
||||||
<Area
|
<Area
|
||||||
|
dot={false}
|
||||||
name={`${serie.id}:area:noTooltip`}
|
name={`${serie.id}:area:noTooltip`}
|
||||||
dataKey={`${serie.id}:count`}
|
dataKey={`${serie.id}:count`}
|
||||||
fill={`url(#color${color})`}
|
fill={`url(#color${color})`}
|
||||||
@@ -265,11 +266,9 @@ export function ReportLineChart({ data }: ReportLineChartProps) {
|
|||||||
<Line
|
<Line
|
||||||
type={lineType}
|
type={lineType}
|
||||||
name={`${serie.id}:prev`}
|
name={`${serie.id}:prev`}
|
||||||
isAnimationActive={false}
|
isAnimationActive
|
||||||
strokeWidth={1}
|
|
||||||
dot={false}
|
dot={false}
|
||||||
strokeDasharray={'1 1'}
|
strokeOpacity={0.3}
|
||||||
strokeOpacity={0.5}
|
|
||||||
dataKey={`${serie.id}:prev:count`}
|
dataKey={`${serie.id}:prev:count`}
|
||||||
stroke={color}
|
stroke={color}
|
||||||
// Use for legend
|
// Use for legend
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export type IRechartPayloadItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
names: string[];
|
names: string[];
|
||||||
color: string;
|
color: string;
|
||||||
event: { id: string; name: string };
|
event: { id?: string; name: string };
|
||||||
count: number;
|
count: number;
|
||||||
date: string;
|
date: string;
|
||||||
previous?: {
|
previous?: {
|
||||||
|
|||||||
@@ -118,17 +118,14 @@ export const alphabetIds = [
|
|||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const deprecated_timeRanges = {
|
export const deprecated_timeRanges = {
|
||||||
'30min': '30min',
|
|
||||||
'1h': '1h',
|
'1h': '1h',
|
||||||
today: 'today',
|
|
||||||
'24h': '24h',
|
'24h': '24h',
|
||||||
'7d': '7d',
|
|
||||||
'14d': '14d',
|
'14d': '14d',
|
||||||
'1m': '1m',
|
'1m': '1m',
|
||||||
'3m': '3m',
|
'3m': '3m',
|
||||||
'6m': '6m',
|
'6m': '6m',
|
||||||
'1y': '1y',
|
'1y': '1y',
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
export const metrics = {
|
export const metrics = {
|
||||||
sum: 'sum',
|
sum: 'sum',
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
subYears,
|
subYears,
|
||||||
} from 'date-fns';
|
} from 'date-fns';
|
||||||
import * as mathjs from 'mathjs';
|
import * as mathjs from 'mathjs';
|
||||||
import { repeat, reverse } from 'ramda';
|
import { pluck, repeat, reverse, uniq } from 'ramda';
|
||||||
import { escape } from 'sqlstring';
|
import { escape } from 'sqlstring';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -47,7 +47,7 @@ import type {
|
|||||||
} from '@openpanel/validation';
|
} from '@openpanel/validation';
|
||||||
|
|
||||||
function getEventLegend(event: IChartEvent) {
|
function getEventLegend(event: IChartEvent) {
|
||||||
return event.displayName ?? event.name;
|
return event.displayName || event.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withFormula(
|
export function withFormula(
|
||||||
@@ -481,6 +481,7 @@ export async function getChartSerie(payload: IGetChartDataInput) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IGetChartSerie = Awaited<ReturnType<typeof getChartSeries>>[number];
|
||||||
export async function getChartSeries(input: IChartInputWithDates) {
|
export async function getChartSeries(input: IChartInputWithDates) {
|
||||||
const series = (
|
const series = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@@ -501,6 +502,9 @@ export async function getChartSeries(input: IChartInputWithDates) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getChart(input: IChartInput) {
|
export async function getChart(input: IChartInput) {
|
||||||
|
const includeEventName =
|
||||||
|
uniq(pluck('name', input.events)).length !==
|
||||||
|
pluck('name', input.events).length;
|
||||||
const currentPeriod = getChartStartEndDate(input);
|
const currentPeriod = getChartStartEndDate(input);
|
||||||
const previousPeriod = getChartPrevStartEndDate({
|
const previousPeriod = getChartPrevStartEndDate({
|
||||||
range: input.range,
|
range: input.range,
|
||||||
@@ -518,6 +522,8 @@ export async function getChart(input: IChartInput) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSerieId = (serie: IGetChartSerie) =>
|
||||||
|
[slug(serie.name.join('-')), serie.event.id].filter(Boolean).join('-');
|
||||||
const result = await Promise.all(promises);
|
const result = await Promise.all(promises);
|
||||||
const series = result[0]!;
|
const series = result[0]!;
|
||||||
const previousSeries = result[1];
|
const previousSeries = result[1];
|
||||||
@@ -526,7 +532,7 @@ export async function getChart(input: IChartInput) {
|
|||||||
const final: FinalChart = {
|
const final: FinalChart = {
|
||||||
series: series.map((serie) => {
|
series: series.map((serie) => {
|
||||||
const previousSerie = previousSeries?.find(
|
const previousSerie = previousSeries?.find(
|
||||||
(item) => item.name.join('-') === serie.name.join('-')
|
(prevSerie) => getSerieId(prevSerie) === getSerieId(serie)
|
||||||
);
|
);
|
||||||
const metrics = {
|
const metrics = {
|
||||||
sum: sum(serie.data.map((item) => item.count)),
|
sum: sum(serie.data.map((item) => item.count)),
|
||||||
@@ -534,14 +540,20 @@ export async function getChart(input: IChartInput) {
|
|||||||
min: min(serie.data.map((item) => item.count)),
|
min: min(serie.data.map((item) => item.count)),
|
||||||
max: max(serie.data.map((item) => item.count)),
|
max: max(serie.data.map((item) => item.count)),
|
||||||
};
|
};
|
||||||
|
const event = {
|
||||||
|
id: serie.event.id,
|
||||||
|
name: serie.event.displayName || serie.event.name,
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: slug(serie.name.join('-')),
|
id: getSerieId(serie),
|
||||||
names: serie.name,
|
names: includeEventName
|
||||||
event: {
|
? [
|
||||||
id: serie.event.id!,
|
`(${event.id || event.name}) ${serie.name[0]}`,
|
||||||
name: serie.event.displayName ?? serie.event.name,
|
...serie.name.slice(1),
|
||||||
},
|
]
|
||||||
|
: serie.name,
|
||||||
|
event,
|
||||||
metrics: {
|
metrics: {
|
||||||
...metrics,
|
...metrics,
|
||||||
...(input.previous
|
...(input.previous
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const reportRouter = createTRPCRouter({
|
|||||||
lineType: report.lineType,
|
lineType: report.lineType,
|
||||||
range: report.range === 'custom' ? '30d' : report.range,
|
range: report.range === 'custom' ? '30d' : report.range,
|
||||||
formula: report.formula,
|
formula: report.formula,
|
||||||
|
previous: report.previous ?? false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -55,6 +56,7 @@ export const reportRouter = createTRPCRouter({
|
|||||||
lineType: report.lineType,
|
lineType: report.lineType,
|
||||||
range: report.range === 'custom' ? '30d' : report.range,
|
range: report.range === 'custom' ? '30d' : report.range,
|
||||||
formula: report.formula,
|
formula: report.formula,
|
||||||
|
previous: report.previous ?? false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export type IChartSerie = {
|
|||||||
id: string;
|
id: string;
|
||||||
names: string[];
|
names: string[];
|
||||||
event: {
|
event: {
|
||||||
id: string;
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
metrics: Metrics;
|
metrics: Metrics;
|
||||||
|
|||||||
Reference in New Issue
Block a user