Skip to content

Commit b8aec95

Browse files
committed
Refactor
1 parent ded1784 commit b8aec95

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/popup/components/chart/option.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
import { formatPeriodCommon, formatTime } from "@util/time"
1818
import { t } from "@popup/locale"
1919
import { getPrimaryTextColor, getSecondaryTextColor } from "@util/style"
20+
import { generateSiteLabel } from "@util/site"
2021

2122
type EcOption = ComposeOption<
2223
| PieSeriesOption
@@ -47,10 +48,7 @@ const toolTipFormatter = ({ type }: timer.popup.QueryResult, params: any) => {
4748
const { name, value, percent } = format
4849
const data = format.data as timer.stat.Row
4950
const host = data.host
50-
let dimensionName = name
51-
if (host && host !== name) {
52-
dimensionName = `${name} (${host})`
53-
}
51+
const dimensionName = generateSiteLabel(host, name)
5452
const valueText = type === 'time' ? value || 0 : formatPeriodCommon(typeof value === 'number' ? value as number : 0)
5553
return `${dimensionName}<br/>${valueText} (${percent}%)`
5654
}

src/util/site.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ export function extractSiteName(title: string, host?: string) {
3434
.filter(s => !INVALID_SITE_NAME.test(s))
3535
.sort((a, b) => a.length - b.length)[0]
3636
.trim()
37+
}
38+
39+
/**
40+
* Generate the label text with host and name
41+
*
42+
* @since 1.1.8
43+
*/
44+
export function generateSiteLabel(host: string, name?: string): string {
45+
if (host && host !== name) {
46+
return `${name} (${host})`
47+
} else {
48+
return host
49+
}
3750
}

0 commit comments

Comments
 (0)