Skip to content

feat: github history chart + embed#27

Open
legions-developer wants to merge 26 commits into
mainfrom
feat/history-feature
Open

feat: github history chart + embed#27
legions-developer wants to merge 26 commits into
mainfrom
feat/history-feature

Conversation

@legions-developer
Copy link
Copy Markdown
Owner

Description

image

Type of Change

  • New chart component
  • Bug fix
  • Documentation update
  • Performance improvement
  • Other (please describe)

Screenshots

Checklist

  • Code follows the project's style guidelines
  • Tested in development mode (yarn dev)
  • Tested production build (yarn build)
  • Registry synced (yarn gen-cli)
  • Documentation added/updated

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evilcharts Ready Ready Preview, Comment May 19, 2026 6:49pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a complete GitHub Star History tool: package/deps, shared types/errors, GitHub token pool and client, Zod query schema and URL builders, a Next.js API route producing SVG (including error-card fallbacks), a full SVG rendering pipeline (line/bar/pie/radial), client state and URL helpers, React UI components (repo input, config panel, preview/embed, color/date pickers), and app integration.

Changes

Star History Tool Implementation

Layer / File(s) Summary
Dependencies & UI tweaks
package.json, src/components/ui/*, src/app/globals.css
Adds @tanstack/react-query, D3 deps/types; tweaks focus-visible ring/border opacity, popover sideOffset/padding, input sizing, and dark popover color.
Shared type definitions and error handling
src/lib/star-history/types.ts
Defines theme/axis/chart/fill/stroke/background unions, StarRecord/RepoSeries, StarHistoryOptions, and StarHistoryError subclasses.
Token pool & repo parsing
src/lib/star-history/token-pool.ts, src/lib/star-history/parse-repo.ts
In-memory round-robin GitHub token pool with benching and repo parsing/validation utilities.
GitHub API client & fetchStarRecords
src/lib/star-history/github.ts
Authenticated GitHub client with pagination sampling, error mapping, and record aggregation into cumulative series.
Query schema & URL builders
src/lib/star-history/query-schema.ts, src/app/docs/tools/star-history/_lib/url.ts
Zod query contract parsing/clamping (including chartType, ring/pie params), hex parsing, and preview/embed URL generation.
SVG element & animation utilities
src/lib/star-history/svg/el.ts, src/lib/star-history/svg/escape.ts, src/lib/star-history/svg/wordmark.ts
Typed SVG attribute serialization, XML escaping, SMIL animate helper with looping support, and embedded wordmark helpers.
SVG theme, scales & draw primitives
src/lib/star-history/svg/theme.ts, src/lib/star-history/svg/scales.ts, src/lib/star-history/svg/draw.ts
Palettes (including pattern color), default series colors, layout/scale projection, and core drawing utilities (defs, grid, axes, legend, series primitives, footer).
Background patterns & chart generators
src/lib/star-history/svg/backgrounds.ts, src/lib/star-history/svg/charts/*
Background pattern builders and chart-specific SVG generators (line, bar, pie, radial/full & half).
SVG entry & error card
src/lib/star-history/svg/index.ts, src/lib/star-history/svg/error-svg.ts
Dispatch to chart generators and error-card SVG generation.
API route
src/app/api/star-history/route.ts
Next.js GET handler parsing params, fetching series concurrently, building options, generating SVG (or error SVG), and returning 200 with CORS/cache headers.
Client state & URL helpers
src/app/docs/tools/star-history/_lib/state.ts, .../_lib/url.ts
Client config types, newRepoId/defaultColor/createDefaultConfig, PREVIEW_SURFACE and preview/embed URL builders.
Repo input & validation
src/app/docs/tools/star-history/_lib/repo-input.ts, .../_components/repo-input-list.tsx
Repo slug extraction/validation schema and RepoInputList component with ColorPicker, validation, duplicate/capacity checks, and badges.
ColorPicker & DateRangePicker
src/components/ui/color-picker.tsx, src/components/ui/date-range-picker.tsx
New ColorPicker controlled component and DateRangePicker split-button with calendar range selection.
ConfigPanel UI
src/app/docs/tools/star-history/_components/config-panel.tsx
Controls for chart type, theme, axis, labels, background, stroke/dot/fill, animation, and geometry params with conditional rows and update propagation.
Preview, embed snippets & actions
src/app/docs/tools/star-history/_components/preview-panel.tsx, .../embed-snippets.tsx, .../svg-actions.tsx
Preview with replay and tabs, embed snippet generators with copy-to-clipboard, and SVG copy/download actions.
Tool orchestration
src/app/docs/tools/star-history/_components/star-history-tool.tsx
Top-level StarHistoryTool using React Query for debounced preview fetch, export caching, theme sync, and composing picker/preview/config/actions.
Page & navigation integration
src/app/docs/tools/star-history/page.tsx, src/globals/constants/docs-sidebar.tsx, src/components/docs/sidebar/index.tsx, src/app/layout.tsx, src/app/docs/[[...slug]]/page.tsx
Adds docs page with metadata, "Tools" sidebar entry, mounts global Toaster in RootLayout, and minor docs styling update.

🎯 4 (Complex) | ⏱️ ~60 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/history-feature

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/app/docs/tools/star-history/_components/star-history-tool.tsx (1)

42-47: ⚡ Quick win

Move theme synchronization out of render.

Updating state during render is fragile and causes extra render churn. Sync this in an effect with a guarded functional update.

Proposed refactor
-import { useCallback, useState, useSyncExternalStore } from "react";
+import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
@@
-  const { resolvedTheme } = useTheme();
-  const [syncedSiteTheme, setSyncedSiteTheme] = useState<string | undefined>(undefined);
-  if (resolvedTheme && resolvedTheme !== syncedSiteTheme) {
-    setSyncedSiteTheme(resolvedTheme);
-    setConfig((prev) => ({ ...prev, theme: resolvedTheme === "dark" ? "dark" : "light" }));
-  }
+  const { resolvedTheme } = useTheme();
+  useEffect(() => {
+    if (!resolvedTheme) return;
+    const nextTheme = resolvedTheme === "dark" ? "dark" : "light";
+    setConfig((prev) => (prev.theme === nextTheme ? prev : { ...prev, theme: nextTheme }));
+  }, [resolvedTheme]);

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f67b310-893f-4d0b-b3ad-5c29e08e53c5

📥 Commits

Reviewing files that changed from the base of the PR and between 0cbd93c and 78bfa0e.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (42)
  • package.json
  • src/app/api/star-history/route.ts
  • src/app/docs/tools/star-history/_components/actions-bar.tsx
  • src/app/docs/tools/star-history/_components/config-panel.tsx
  • src/app/docs/tools/star-history/_components/embed-snippets.tsx
  • src/app/docs/tools/star-history/_components/preview-panel.tsx
  • src/app/docs/tools/star-history/_components/repo-input-list.tsx
  • src/app/docs/tools/star-history/_components/star-history-tool.tsx
  • src/app/docs/tools/star-history/_lib/repo-input.ts
  • src/app/docs/tools/star-history/_lib/state.ts
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/app/docs/tools/star-history/page.tsx
  • src/app/globals.css
  • src/app/layout.tsx
  • src/components/docs/sidebar/index.tsx
  • src/components/ui/badge.tsx
  • src/components/ui/button.tsx
  • src/components/ui/checkbox.tsx
  • src/components/ui/color-picker.tsx
  • src/components/ui/date-range-picker.tsx
  • src/components/ui/input.tsx
  • src/components/ui/item.tsx
  • src/components/ui/popover.tsx
  • src/components/ui/radio-group.tsx
  • src/components/ui/select.tsx
  • src/components/ui/switch.tsx
  • src/components/ui/textarea.tsx
  • src/components/ui/toggle.tsx
  • src/globals/constants/docs-sidebar.tsx
  • src/lib/star-history/github.ts
  • src/lib/star-history/parse-repo.ts
  • src/lib/star-history/query-schema.ts
  • src/lib/star-history/svg/draw.ts
  • src/lib/star-history/svg/el.ts
  • src/lib/star-history/svg/error-svg.ts
  • src/lib/star-history/svg/escape.ts
  • src/lib/star-history/svg/index.ts
  • src/lib/star-history/svg/scales.ts
  • src/lib/star-history/svg/theme.ts
  • src/lib/star-history/svg/wordmark.ts
  • src/lib/star-history/token-pool.ts
  • src/lib/star-history/types.ts

Comment thread src/app/tools/star-history/_components/repo-input-list.tsx
Comment thread src/app/docs/tools/star-history/_lib/url.ts Outdated
Comment thread src/components/ui/color-picker.tsx
Comment thread src/lib/star-history/github.ts Outdated
Comment thread src/lib/star-history/svg/draw.ts Outdated
…G export features

- Added support for background patterns and their opacity.
- Introduced stroke variants for customizable line styles.
- Implemented loop intervals for animation replay.
- Updated configuration panel and related components to accommodate new options.
- Removed obsolete ActionsBar component and integrated its functionality into EmbedSnippets and PreviewPanel.
- Adjusted styles and improved documentation for better usability.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a37265e7-6414-4af8-a7fb-b4a8b2f4c7ef

📥 Commits

Reviewing files that changed from the base of the PR and between 78bfa0e and 935421d.

📒 Files selected for processing (17)
  • src/app/api/star-history/route.ts
  • src/app/docs/[[...slug]]/page.tsx
  • src/app/docs/tools/star-history/_components/config-panel.tsx
  • src/app/docs/tools/star-history/_components/embed-snippets.tsx
  • src/app/docs/tools/star-history/_components/preview-panel.tsx
  • src/app/docs/tools/star-history/_components/star-history-tool.tsx
  • src/app/docs/tools/star-history/_components/svg-actions.tsx
  • src/app/docs/tools/star-history/_lib/state.ts
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/lib/star-history/query-schema.ts
  • src/lib/star-history/svg/backgrounds.ts
  • src/lib/star-history/svg/draw.ts
  • src/lib/star-history/svg/el.ts
  • src/lib/star-history/svg/index.ts
  • src/lib/star-history/svg/scales.ts
  • src/lib/star-history/svg/theme.ts
  • src/lib/star-history/types.ts
✅ Files skipped from review due to trivial changes (1)
  • src/app/docs/[[...slug]]/page.tsx
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/lib/star-history/svg/theme.ts
  • src/lib/star-history/svg/index.ts
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/lib/star-history/svg/scales.ts
  • src/app/api/star-history/route.ts
  • src/app/docs/tools/star-history/_components/star-history-tool.tsx

Comment thread src/app/tools/star-history/_components/embed-snippets.tsx
Comment thread src/lib/star-history/svg/draw.ts Outdated
…ry tool

- Introduced new chart types: line, bar, radial, radial-half, and pie.
- Updated configuration panel to allow selection of chart type with corresponding icons.
- Enhanced state management to include chart type and related properties like radial ring width and pie inner radius.
- Modified URL handling to support new chart type parameters.
- Improved SVG generation logic to dispatch to appropriate chart builders based on selected type.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 554bca5f-6018-4e8f-9d53-294f671d1cb9

📥 Commits

Reviewing files that changed from the base of the PR and between 935421d and 247db34.

📒 Files selected for processing (13)
  • src/app/api/star-history/route.ts
  • src/app/docs/tools/star-history/_components/config-panel.tsx
  • src/app/docs/tools/star-history/_lib/state.ts
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/lib/star-history/query-schema.ts
  • src/lib/star-history/svg/charts/bar.ts
  • src/lib/star-history/svg/charts/line.ts
  • src/lib/star-history/svg/charts/pie.ts
  • src/lib/star-history/svg/charts/radial.ts
  • src/lib/star-history/svg/draw.ts
  • src/lib/star-history/svg/index.ts
  • src/lib/star-history/svg/scales.ts
  • src/lib/star-history/types.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/app/api/star-history/route.ts
  • src/lib/star-history/types.ts
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/app/docs/tools/star-history/_lib/state.ts

Comment thread src/app/docs/tools/star-history/_components/config-panel.tsx Outdated
Comment thread src/lib/star-history/svg/charts/pie.ts Outdated
Comment thread src/lib/chart-svg/svg/draw.ts
- Added aria-describedby attribute to associate error messages with input field.
- Updated error message rendering to include an id and role for better screen reader support.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
src/lib/star-history/svg/draw.ts (2)

75-82: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Namespace <defs> IDs per render instance.

IDs are still global (sh-grad-*, sh-plot-clip), so multiple embedded charts can cross-reference the wrong defs/clip paths.

Proposed direction
-function seriesFillDef(
+function seriesFillDef(
+  idPrefix: string,
   pattern: FillPattern,
   index: number,
   color: string,
   opacity: number,
 ): { def: string; id: string } {
-  const id = `sh-grad-${index}`;
+  const id = `${idPrefix}-sh-grad-${index}`;
-export function plotClip(layout: Layout): string {
+export function plotClip(layout: Layout, idPrefix: string): string {
...
-    { id: "sh-plot-clip" },
+    { id: `${idPrefix}-sh-plot-clip` },
-fill: `url(`#sh-grad-`${index})`,
+fill: `url(#${idPrefix}-sh-grad-${index})`,

Also applies to: 170-176, 441-441


334-339: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Prevent legend badges from rendering off-canvas.

A single long label can still produce a badge wider than row width, which makes right-aligned x negative.

Proposed fix
-  const items = series.map((s, i) => ({
-    label: s.label,
-    color: seriesColor(colors, i),
-    width:
-      LEGEND.PAD_X * 2 + LEGEND.SWATCH + LEGEND.SWATCH_GAP + s.label.length * LEGEND_CHAR_W,
-  }));
-
-  // Greedy wrap into rows that fit within the chart's inner width.
-  const maxRowWidth = width - LEGEND.EDGE * 2;
+  const maxRowWidth = Math.max(1, width - LEGEND.EDGE * 2);
+  const maxTextWidth = Math.max(
+    0,
+    maxRowWidth - (LEGEND.PAD_X * 2 + LEGEND.SWATCH + LEGEND.SWATCH_GAP),
+  );
+  const maxChars = Math.max(1, Math.floor(maxTextWidth / LEGEND_CHAR_W));
+  const items = series.map((s, i) => {
+    const label = s.label.length > maxChars ? `${s.label.slice(0, maxChars - 1)}…` : s.label;
+    const width =
+      LEGEND.PAD_X * 2 + LEGEND.SWATCH + LEGEND.SWATCH_GAP + label.length * LEGEND_CHAR_W;
+    return { label, color: seriesColor(colors, i), width: Math.min(width, maxRowWidth) };
+  });

Also applies to: 341-367


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c4d51da-6098-4725-bf0a-638bcc43372c

📥 Commits

Reviewing files that changed from the base of the PR and between 247db34 and 5462243.

📒 Files selected for processing (5)
  • src/app/docs/tools/star-history/_components/repo-input-list.tsx
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/components/ui/color-picker.tsx
  • src/lib/star-history/github.ts
  • src/lib/star-history/svg/draw.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/app/docs/tools/star-history/_lib/url.ts
  • src/app/docs/tools/star-history/_components/repo-input-list.tsx

Comment thread src/components/ui/color-picker.tsx
Comment thread src/lib/star-history/github.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6e67c82-0c81-4092-b924-142518add316

📥 Commits

Reviewing files that changed from the base of the PR and between 5462243 and 62a1127.

📒 Files selected for processing (11)
  • src/app/docs/tools/star-history/_components/config-panel.tsx
  • src/app/docs/tools/star-history/_components/embed-snippets.tsx
  • src/app/docs/tools/star-history/_components/repo-input-list.tsx
  • src/lib/star-history/github.ts
  • src/lib/star-history/svg/backgrounds.ts
  • src/lib/star-history/svg/charts/bar.ts
  • src/lib/star-history/svg/charts/line.ts
  • src/lib/star-history/svg/charts/pie.ts
  • src/lib/star-history/svg/charts/radial.ts
  • src/lib/star-history/svg/draw.ts
  • src/lib/star-history/svg/ids.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/lib/star-history/svg/charts/radial.ts
  • src/app/docs/tools/star-history/_components/repo-input-list.tsx
  • src/lib/star-history/svg/charts/pie.ts
  • src/app/docs/tools/star-history/_components/embed-snippets.tsx
  • src/lib/star-history/svg/charts/bar.ts
  • src/app/docs/tools/star-history/_components/config-panel.tsx

Comment thread src/lib/chart-svg/svg/charts/line.ts
- Removed the transparent background option from the configuration and related components.
- Updated the SVG generation logic to ensure the chart is always rendered with a transparent background.
- Introduced a new fill fade feature for area fills, allowing for customizable opacity effects.
- Adjusted the configuration panel to include sliders for fill opacity and fill fade settings.
- Simplified URL handling for chart generation, merging preview and embed URLs into a single function.
- Improved error handling in SVG generation to ensure consistent output across different scenarios.
…port options

- Added the StarHistoryTool component to manage the star history visualization.
- Introduced a ConfigPanel for customizing chart settings, including chart type and theme.
- Implemented a PreviewPanel for displaying the generated SVG and embed snippets.
- Created reusable components for handling repository inputs and SVG actions.
- Enhanced state management for repository entries and chart configurations.
- Developed URL handling for generating chart previews and embeds based on user input.
- Moved the star history tool from the /docs path to a dedicated /tools route.
- Updated sitemap to include the new URL for the star history tool.
- Refactored the DocsLayout component to utilize the AppShell for improved layout management.
- Adjusted sidebar links to reflect the new routing structure.
- Added a new entry for the NPM downloads tool in the sitemap for better navigation.
- Updated the star history API to utilize a new chart generation method, improving SVG output.
- Refactored the state management in the star history tool to streamline data handling.
- Introduced new chart options and improved error handling for better user experience.
- Updated the title in the HTML shell and metadata to use consistent casing.
- Adjusted embed snippets and preview panel comments to reflect the new title casing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant