Skip to content

Unify main graph icons #5339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/dashboard/stats/graph/interval-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function IntervalPicker({
shouldIgnoreWhen={[isModifierPressed, isTyping]}
/>
)}
<Popover className="relative inline-block pl-2">
<Popover className="relative inline-block">
{({ close: closeDropdown }) => (
<>
<BlurMenuButtonOnEscape targetRef={menuElement} />
Expand Down
45 changes: 45 additions & 0 deletions assets/js/dashboard/stats/graph/notices.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react'
import { Tooltip } from '../../util/tooltip'

export const NoticesIcon = ({ notices }: { notices: string[] }) => {
if (!notices.length) {
return null
}
return (
<Tooltip
info={
<div className="w-[200px] font-normal flex flex-col gap-y-2">
{notices.map((notice, id) => (
<p key={id}>{notice}</p>
))}
</div>
}
className="cursor-pointer w-4 h-4"
>
<svg
className="absolute w-4 h-4 dark:text-gray-300 text-gray-700"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</Tooltip>
)
}

export function getSamplingNotice(topStatData: { samplePercent?: number }) {
const samplePercent = topStatData?.samplePercent

if (samplePercent && samplePercent < 100) {
return `Stats based on a ${samplePercent}% sample of all visitors`
}

return null
}
31 changes: 0 additions & 31 deletions assets/js/dashboard/stats/graph/sampling-notice.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as api from '../../api'
import { getCurrentInterval } from './interval-picker'
import { useSiteContext } from '../../site-context'
import { useQueryContext } from '../../query-context'
import { Tooltip } from '../../util/tooltip'

export default function StatsExport() {
const site = useSiteContext()
Expand Down Expand Up @@ -56,7 +57,12 @@ export default function StatsExport() {
const endpoint = `/${encodeURIComponent(site.domain)}/export?${queryParams}`

return (
<a href={endpoint} download onClick={startExport}>
<a
className="block h-4 w-4"
href={endpoint}
download
onClick={startExport}
>
<svg
className="absolute text-gray-700 feather dark:text-gray-300 hover:text-indigo-600 dark:hover:text-indigo-600"
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -76,9 +82,12 @@ export default function StatsExport() {
}

return (
<div className="w-4 h-4 mx-2">
<Tooltip
info={<div className="font-normal truncate">Click to export stats</div>}
className="w-4 h-4"
>
{exporting && renderLoading()}
{!exporting && renderExportLink()}
</div>
</Tooltip>
)
}
30 changes: 14 additions & 16 deletions assets/js/dashboard/stats/graph/visitor-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import TopStats from './top-stats'
import { IntervalPicker, getCurrentInterval } from './interval-picker'
import StatsExport from './stats-export'
import WithImportedSwitch from './with-imported-switch'
import SamplingNotice from './sampling-notice'
import { getSamplingNotice, NoticesIcon } from './notices'
import FadeIn from '../../fade-in'
import * as url from '../../util/url'
import { isComparisonEnabled } from '../../query-time-periods'
import LineGraphWithRouter from './line-graph'
import { useQueryContext } from '../../query-context'
import { useSiteContext } from '../../site-context'
import { ExclamationCircleIcon } from '@heroicons/react/24/outline'

function fetchTopStats(site, query) {
const q = { ...query }
Expand Down Expand Up @@ -152,23 +151,18 @@ export default function VisitorGraph({ updateImportedDataInView }) {
)
}

function renderImportedIntervalUnsupportedWarning() {
function getImportedIntervalUnsupportedNotice() {
const unsupportedInterval = ['hour', 'minute'].includes(
getCurrentInterval(site, query)
)
const showingImported =
importedSwitchVisible() && query.with_imported === true

return (
<FadeIn
show={showingImported && unsupportedInterval}
className="h-6 mr-1"
>
<span tooltip={'Interval is too short to graph imported data'}>
<ExclamationCircleIcon className="w-6 h-6 text-gray-700 dark:text-gray-300" />
</span>
</FadeIn>
)
if (showingImported && unsupportedInterval) {
return 'Interval is too short to graph imported data'
}

return null
}

return (
Expand All @@ -194,10 +188,14 @@ export default function VisitorGraph({ updateImportedDataInView }) {
</div>
<div className="relative px-2">
{graphRefreshing && renderLoader()}
<div className="absolute right-4 -top-8 py-1 flex items-center">
{renderImportedIntervalUnsupportedWarning()}
<div className="absolute right-4 -top-8 py-1 flex items-center gap-x-4">
<NoticesIcon
notices={[
getImportedIntervalUnsupportedNotice(),
getSamplingNotice(topStatData)
].filter((n) => !!n)}
/>
{!isRealtime && <StatsExport />}
<SamplingNotice samplePercent={topStatData} />
{importedSwitchVisible() && (
<WithImportedSwitch
tooltipMessage={topStatData.with_imported_switch.tooltip_msg}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ import { BarsArrowUpIcon } from '@heroicons/react/20/solid'
import classNames from 'classnames'
import { useQueryContext } from '../../query-context'
import { AppNavigationLink } from '../../navigation/use-app-navigate'
import { Tooltip } from '../../util/tooltip'

export default function WithImportedSwitch({ tooltipMessage, disabled }) {
export default function WithImportedSwitch({
tooltipMessage,
disabled
}: {
tooltipMessage: string
disabled?: boolean
}) {
const { query } = useQueryContext()
const importsSwitchedOn = query.with_imported

const iconClass = classNames('mt-0.5', {
const iconClass = classNames({
'dark:text-gray-300 text-gray-700': importsSwitchedOn,
'dark:text-gray-500 text-gray-400': !importsSwitchedOn
})

return (
<div tooltip={tooltipMessage} className="w-4 h-4 mx-2">
<Tooltip
info={<div className="font-normal truncate">{tooltipMessage}</div>}
className="w-4 h-4"
>
<AppNavigationLink
search={
disabled
Expand All @@ -24,6 +34,6 @@ export default function WithImportedSwitch({ tooltipMessage, disabled }) {
>
<BarsArrowUpIcon className={iconClass} />
</AppNavigationLink>
</div>
</Tooltip>
)
}
Loading