-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
431 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { FC } from 'react' | ||
import { memo, useMemo } from 'react' | ||
import type { Options } from 'highcharts' | ||
import Highcharts from 'highcharts' | ||
import HighchartsExporting from 'highcharts/modules/exporting' | ||
import HighchartsReact from 'highcharts-react-official' | ||
import dayjs from 'dayjs' | ||
import { useMount } from 'react-use' | ||
import { theme } from '~/styles/chart.theme' | ||
|
||
if (typeof Highcharts === 'object') | ||
HighchartsExporting(Highcharts) | ||
|
||
interface MiniChartProps { | ||
type: '24h' | '14d' | ||
data?: { | ||
time: string | ||
count: number | ||
}[] | ||
title?: string | ||
} | ||
|
||
const MiniChart: FC<MiniChartProps> = memo(({ type, data, title }) => { | ||
useMount(() => { | ||
if (typeof Highcharts === 'object') | ||
Highcharts.setOptions(theme) | ||
}) | ||
|
||
const options = useMemo<Options>( | ||
() => ({ | ||
chart: { | ||
height: 60, | ||
spacingTop: 5, | ||
spacingBottom: 5, | ||
}, | ||
xAxis: { labels: { enabled: false } }, | ||
series: [ | ||
{ | ||
type: 'areaspline', | ||
data: data?.map(v => ({ | ||
name: v.time, | ||
y: v.count, | ||
})), | ||
lineWidth: 4, | ||
marker: { enabled: false }, | ||
tooltip: { | ||
headerFormat: '', | ||
pointFormatter() { | ||
const { name, y } = this | ||
if (type === '24h') | ||
return `<div style="text-align: center"><span>${dayjs(name).format('YYYY-MM-DD')}<br />${dayjs(name).format('h:00 A → h:59 A')}</span><br /><b>${y} events</b></div>` | ||
|
||
if (type === '14d') | ||
return `<div style="text-align: center"><span>${dayjs(name).format('YYYY-MM-DD')}</span><br /><b>${y} events</b></div>` | ||
|
||
return '' | ||
}, | ||
}, | ||
}, | ||
], | ||
}), | ||
[data, type], | ||
) | ||
|
||
return ( | ||
<div> | ||
{title && ( | ||
<div className="font-semibold"> | ||
<i /> | ||
{title} | ||
</div> | ||
)} | ||
<HighchartsReact | ||
highcharts={Highcharts} | ||
options={options} | ||
/> | ||
</div> | ||
) | ||
}) | ||
|
||
MiniChart.displayName = 'MiniChart' | ||
|
||
export default MiniChart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import type { serviceGetIssuesTrendsReturn } from '~/services/issues' | ||
import { serviceGetIssuesTrends } from '~/services/issues' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<serviceGetIssuesTrendsReturn[]>, | ||
) { | ||
const ids = req.query.ids as string | ||
const type = (req.query.type || '24h') as '24h' | '14d' | ||
const trends = await serviceGetIssuesTrends({ | ||
ids, | ||
type, | ||
}) | ||
res.status(200).json(trends) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const theme = { | ||
credits: { enabled: false }, | ||
colors: ['black'], | ||
title: { text: undefined }, | ||
chart: { | ||
spacingTop: 0, | ||
spacingBottom: 0, | ||
spacingLeft: 0, | ||
spacingRight: 0, | ||
backgroundColor: 'transparent', | ||
}, | ||
legend: { enabled: false }, | ||
xAxis: { | ||
title: { text: null }, | ||
tickWidth: 0, | ||
lineWidth: 0, | ||
}, | ||
yAxis: { | ||
title: { text: null }, | ||
labels: { enabled: false }, | ||
gridLineWidth: 0, | ||
}, | ||
tooltip: { | ||
useHTML: true, | ||
outside: true, | ||
animation: false, | ||
backgroundColor: 'white', | ||
borderWidth: 0, | ||
}, | ||
} |
Oops, something went wrong.