Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/v4/app/(app)/charts/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const chartTypes = [
"pie",
"radar",
"radial",
"scatter",
"tooltip",
] as const
type ChartType = (typeof chartTypes)[number]
Expand Down Expand Up @@ -50,7 +51,7 @@ export default async function ChartPage({ params }: ChartPageProps) {
{type.charAt(0).toUpperCase() + type.slice(1)} Charts
</h2>
<div className="grid flex-1 scroll-mt-20 items-stretch gap-10 md:grid-cols-2 md:gap-6 lg:grid-cols-3 xl:gap-10">
{Array.from({ length: 12 }).map((_, index) => {
{Array.from({ length: 9 }).map((_, index) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed the array’s initial length from 12 to 9, but there’s no comment explaining the reason for this change.

If the value is meant to be dynamic, we could derive it from chartList.length instead of hard-coding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The change from 12 to 9 was intentional to better match our scatter chart collection.

Context:

  • This PR adds 6 new scatter chart variants

  • The page previously rendered 12 total slots (actual charts + empty placeholders)

  • With only 6 scatter charts, this created 6 empty placeholder boxes, which looked sparse

Why 9:

  • Changing to 9 gives us a cleaner 3×3 grid on larger screens

  • Shows 6 actual scatter charts + 3 empty placeholders

  • The empty placeholders indicate room for future chart additions

  • Your suggestion about deriving from chartList.length:

I considered this, but the current implementation intentionally shows a few empty slots to indicate that more charts can be added. However, I'm open to either approach:

  1. Keep it at 9 (current) - Shows intentional space for future charts

  2. Use chartList.length - Dynamically adjusts, no empty slots

  3. Use Math.max(chartList.length, 9) Shows charts + minimum 9 slots

Which approach would you prefer for consistency across the codebase?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You hit it!

I noticed before these empty zones and slots and I was wondering why they were there.

The core team can decide on that.

const chart = chartList[index]
return chart ? (
<ChartDisplay
Expand Down
21 changes: 21 additions & 0 deletions apps/v4/app/(app)/charts/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ import { ChartRadialShape } from "@/registry/new-york-v4/charts/chart-radial-sha
import { ChartRadialSimple } from "@/registry/new-york-v4/charts/chart-radial-simple"
import { ChartRadialStacked } from "@/registry/new-york-v4/charts/chart-radial-stacked"
import { ChartRadialText } from "@/registry/new-york-v4/charts/chart-radial-text"
import { ChartScatterBubble } from "@/registry/new-york-v4/charts/chart-scatter-bubble"
import { ChartScatterDefault } from "@/registry/new-york-v4/charts/chart-scatter-default"
import { ChartScatterLabel } from "@/registry/new-york-v4/charts/chart-scatter-label"
import { ChartScatterLegend } from "@/registry/new-york-v4/charts/chart-scatter-legend"
import { ChartScatterMultiple } from "@/registry/new-york-v4/charts/chart-scatter-multiple"
import { ChartScatterShape } from "@/registry/new-york-v4/charts/chart-scatter-shape"
import { ChartTooltipAdvanced } from "@/registry/new-york-v4/charts/chart-tooltip-advanced"
import { ChartTooltipDefault } from "@/registry/new-york-v4/charts/chart-tooltip-default"
import { ChartTooltipFormatter } from "@/registry/new-york-v4/charts/chart-tooltip-formatter"
Expand All @@ -86,6 +92,7 @@ interface ChartGroups {
pie: ChartItem[]
radar: ChartItem[]
radial: ChartItem[]
scatter: ChartItem[]
tooltip: ChartItem[]
}

Expand Down Expand Up @@ -178,6 +185,14 @@ export const charts: ChartGroups = {
{ id: "chart-radial-shape", component: ChartRadialShape },
{ id: "chart-radial-stacked", component: ChartRadialStacked },
],
scatter: [
{ id: "chart-scatter-default", component: ChartScatterDefault },
{ id: "chart-scatter-bubble", component: ChartScatterBubble },
{ id: "chart-scatter-multiple", component: ChartScatterMultiple },
{ id: "chart-scatter-shape", component: ChartScatterShape },
{ id: "chart-scatter-label", component: ChartScatterLabel },
{ id: "chart-scatter-legend", component: ChartScatterLegend },
],
tooltip: [
{ id: "chart-tooltip-default", component: ChartTooltipDefault },
{
Expand Down Expand Up @@ -263,6 +278,12 @@ export {
ChartRadialText,
ChartRadialShape,
ChartRadialStacked,
ChartScatterDefault,
ChartScatterBubble,
ChartScatterMultiple,
ChartScatterShape,
ChartScatterLabel,
ChartScatterLegend,
ChartTooltipDefault,
ChartTooltipIndicatorLine,
ChartTooltipIndicatorNone,
Expand Down
2 changes: 1 addition & 1 deletion apps/v4/components/chart-code-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function ChartCodeViewer({
}: {
chart: Chart
} & React.ComponentProps<"div">) {
const isDesktop = useMediaQuery("(min-width: 768px)")

const isDesktop = useMediaQuery("(min-width: 768px)")
const button = (
<Button
size="sm"
Expand Down
84 changes: 70 additions & 14 deletions apps/v4/components/chart-copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,76 @@ export function ChartCopyButton({
const [hasCopied, setHasCopied] = React.useState(false)

React.useEffect(() => {
setTimeout(() => {
setHasCopied(false)
}, 2000)
if (hasCopied) {
const timer = setTimeout(() => {
setHasCopied(false)
}, 2000)
return () => clearTimeout(timer)
}
}, [hasCopied])

/**
* Copies text to clipboard using the modern Clipboard API with fallback support.

* Modern approach (preferred):
* - Uses `navigator.clipboard.writeText()` which is async and secure
* - Only available in secure contexts (HTTPS, localhost, or file://)
* - Supported in all modern browsers (Chrome 63+, Firefox 53+, Safari 13.1+, Edge 79+)

* Fallback approach (legacy):
* - Uses `document.execCommand('copy')` for older browsers
* - Works in non-secure contexts (HTTP)
* - Note: This method is deprecated and may be removed in future browser versions
* - Used as a best-effort compatibility layer for legacy environments
* - Required for: IE 11, older Android browsers, and HTTP-served pages
*/
const copyToClipboard = React.useCallback(
async (text: string) => {
try {
// Prefer the modern async clipboard API when available in secure contexts (HTTPS)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text)
} else {
// Fallback for older browsers or non-secure contexts (e.g., HTTP, some iframes)
// This path handles:
// 1. Older browsers that don't support navigator. clipboard
// 2. Non-secure contexts (HTTP instead of HTTPS)
// 3. Browsers with clipboard API disabled
const textArea = document.createElement("textarea")
textArea.value = text
// Position off-screen to avoid visual flash
textArea.style.position = "fixed"
textArea.style. left = "-999999px"
textArea.style.top = "-999999px"
document.body.appendChild(textArea)
textArea.focus()
textArea.select()

try {
// Note: execCommand is deprecated but remains the only option for non-secure contexts
document.execCommand("copy")
textArea.remove()
} catch (err) {
console.error("Fallback: Could not copy text", err)
textArea.remove()
throw err
}
}

trackEvent({
name: event,
properties: {
name,
},
})
setHasCopied(true)
} catch (err) {
console.error("Failed to copy text: ", err)
}
},
[event, name]
)

return (
<Tooltip>
<TooltipTrigger asChild>
Expand All @@ -41,16 +106,7 @@ export function ChartCopyButton({
"[&_svg]-h-3.5 h-7 w-7 rounded-[6px] [&_svg]:w-3.5",
className
)}
onClick={() => {
navigator.clipboard.writeText(code)
trackEvent({
name: event,
properties: {
name,
},
})
setHasCopied(true)
}}
onClick={() => copyToClipboard(code)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this refactoring, please could you add more details about the older-browsers and the non-secure contexts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've added detailed documentation explaining both paths:

Modern path (navigator.clipboard):

  • Used in secure contexts (HTTPS, localhost)
  • Supported in all modern browsers (Chrome 63+, Firefox 53+, Safari 13.1+, Edge 79+)
  • Async and follows current web standards

Fallback path (execCommand):

  • Handles older browsers (IE 11, older Android browsers)
  • Works in non-secure contexts (HTTP-served pages)
  • Needed for environments where clipboard API is unavailable or disabled
  • Includes scenarios like certain iframe configurations

I've added inline comments explaining the use cases for each path.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, However execCommand is deprecated.

{...props}
>
<span className="sr-only">Copy</span>
Expand All @@ -60,4 +116,4 @@ export function ChartCopyButton({
<TooltipContent className="bg-black text-white">Copy code</TooltipContent>
</Tooltip>
)
}
}
9 changes: 9 additions & 0 deletions apps/v4/components/chart-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MousePointer2Icon,
PieChartIcon,
RadarIcon,
ScatterChartIcon,
} from "lucide-react"

import { cn } from "@/lib/utils"
Expand Down Expand Up @@ -94,6 +95,14 @@ function ChartTitle({ chart }: { chart: Chart }) {
)
}

if (chart.name.includes("chart-scatter")) {
return (
<>
<ScatterChartIcon /> Scatter Chart
</>
)
}

if (chart.name.includes("chart-tooltip")) {
return (
<>
Expand Down
4 changes: 4 additions & 0 deletions apps/v4/components/charts-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const links = [
name: "Radial Charts",
href: "/charts/radial#charts",
},
{
name: "Scatter Charts",
href: "/charts/scatter#charts",
},
{
name: "Tooltips",
href: "/charts/tooltip#charts",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM - Potentially fragile active link detection logic
Category: bug

Description:
The condition link.href.startsWith(pathname) works for the current use case where links contain hash fragments, but could be fragile if link structure changes or pathname includes query params.

Suggestion:
Consider using pathname.startsWith(link.href.split('#')[0]) for more robust route matching that handles edge cases.

Confidence: 60%
Rule: qual_inverted_logic_js

Expand Down
2 changes: 1 addition & 1 deletion apps/v4/public/r/styles/base-lyra/input-group-example.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/v4/public/r/styles/base-lyra/item-example.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/v4/public/r/styles/base-lyra/toggle-example.json

Large diffs are not rendered by default.

Loading
Loading