Skip to content

Conversation

@Ishankoradia
Copy link
Contributor

@Ishankoradia Ishankoradia commented Oct 27, 2025

Summary by CodeRabbit

  • New Features

    • Added Percentage Threshold control for pie chart data labels, allowing you to specify the minimum percentage (0-100%, adjustable in 0.1 increments) for labels to display in the Data Labels section.
  • Improvements

    • Enhanced chart configuration processing for consistent label visibility handling across all chart types.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

The changes introduce a percentage threshold control for pie chart labels. A new utility function processes chart configurations to dynamically compute label visibility and formatting based on a labelThreshold property. This processor is integrated across six chart rendering components and a new UI control is added to the pie chart customizations panel.

Changes

Cohort / File(s) Summary
UI Control
components/charts/ChartCustomizations.tsx
Adds a labelThreshold numeric input (0–100, step 0.1) to the Data Labels section of PieChartCustomizations, bound to customizations.labelThreshold with a default of 5.
Config Processor Utility
lib/chart-config-processor.ts
Introduces processChartConfig() and needsProcessing() functions. The processor creates a deep copy of the chart config, applies dynamic per-item label visibility and formatters for pie series based on labelThreshold and total series values, and cleans up custom properties before returning the processed config.
Chart Rendering Components
components/charts/ChartExport.tsx, components/charts/ChartExportDropdownForList.tsx, components/charts/ChartPreview.tsx, components/charts/MiniChart.tsx, components/dashboard/chart-element-v2.tsx, components/dashboard/chart-element-view.tsx
Each component imports processChartConfig and applies it to the chart configuration before passing to setOption(), introducing a preprocessing step to enable label threshold features.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as ChartCustomizations
    participant Store as State/Customizations
    participant Renderer as Chart Component<br/>(e.g., ChartPreview)
    participant Processor as processChartConfig
    participant ECharts as ECharts Instance

    User->>UI: Set labelThreshold value
    UI->>Store: updateCustomization(labelThreshold)
    Store->>Renderer: Pass config with labelThreshold
    Renderer->>Processor: processChartConfig(config)
    Note over Processor: Compute per-item label<br/>visibility based on threshold
    Processor-->>Renderer: Return processedConfig
    Renderer->>ECharts: setOption(processedConfig)
    ECharts-->>User: Render chart with<br/>filtered labels
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas requiring attention:

  • lib/chart-config-processor.ts: The core logic for deep-copying config, iterating series, computing totals, and dynamically assigning formatters should be verified for correctness, especially edge cases (empty series, null values, non-pie series).
  • Integration consistency: Verify that all six chart components apply the processor correctly and that the preprocessing doesn't conflict with existing styling or margin logic (particularly in ChartPreview which already modifies grid.containLabel).
  • Backward compatibility: Confirm that the cleanup of custom properties (labelThreshold, labelFormat) doesn't inadvertently affect existing chart configs or downstream consumers.

Possibly related PRs

  • PR UX Fixes for dashboard and app #117: Modifies PieChartCustomizations in components/charts/ChartCustomizations.tsx, overlapping with the labelThreshold UI control addition in this PR.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Threshold percentage on labels for pie charts" directly and specifically describes the main change in the pull request. The changeset introduces a new percentage threshold control for pie chart labels (implemented via a labelThreshold numeric input in PieChartCustomizations, a new processChartConfig utility function to apply the threshold logic, and integration across multiple chart rendering components). The title is concise, clear, and uses specific terminology that accurately conveys the primary feature being added without vagueness or unnecessary embellishment.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/label-threshold

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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: 0

🧹 Nitpick comments (4)
lib/chart-config-processor.ts (3)

11-17: Consider using structuredClone or a proper deep clone library.

JSON.parse(JSON.stringify()) has several limitations:

  • Loses function references (though you add them back later)
  • Cannot handle circular references
  • Drops undefined, Symbol, and non-JSON types
  • Performance overhead for large configs

For modern environments, use structuredClone(config) or a library like lodash.cloneDeep for better reliability.

-  // Create a deep copy to avoid mutating the original
-  const processedConfig = JSON.parse(JSON.stringify(config));
+  // Create a deep copy to avoid mutating the original
+  const processedConfig = structuredClone(config);

34-59: Simplify nested ternary for better readability.

The deeply nested ternary operator (lines 44-52) is difficult to read and maintain. Consider extracting this logic into a helper function or using a switch statement.

function getFormatterString(labelFormat: string): string {
  switch (labelFormat) {
    case 'percentage':
      return '{d}%';
    case 'value':
      return '{c}';
    case 'name_percentage':
      return '{b}\n{d}%';
    case 'name_value':
      return '{b}\n{c}';
    default:
      return '{d}%';
  }
}

Then use: formatter: showLabel ? getFormatterString(labelFormat) : ''


63-79: Eliminate duplicate formatter logic.

The formatter logic appears twice: once as template strings (lines 44-52) and again in the series-level formatter function (lines 67-77). This duplication increases maintenance burden and risk of inconsistency.

Consider extracting a shared helper function that both code paths can use, or rely solely on per-item formatters when threshold is active.

components/charts/ChartCustomizations.tsx (1)

477-498: LGTM! Consider clarifying the default value in the UI.

The percentage threshold control is well-implemented with proper validation. The default value of 5 is reasonable, but users might benefit from seeing this explicitly indicated in the UI (e.g., via placeholder text or help text) rather than only when the field is empty.

Optional enhancement:

              <Input
                id="labelThreshold"
                type="number"
                min="0"
                max="100"
                step="0.1"
                value={customizations.labelThreshold ?? 5}
+               placeholder="5 (default)"
                onChange={(e) => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e6147a7 and 933525b.

📒 Files selected for processing (8)
  • components/charts/ChartCustomizations.tsx (1 hunks)
  • components/charts/ChartExport.tsx (2 hunks)
  • components/charts/ChartExportDropdownForList.tsx (2 hunks)
  • components/charts/ChartPreview.tsx (2 hunks)
  • components/charts/MiniChart.tsx (2 hunks)
  • components/dashboard/chart-element-v2.tsx (2 hunks)
  • components/dashboard/chart-element-view.tsx (2 hunks)
  • lib/chart-config-processor.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
{components,app}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

{components,app}/**/*.{ts,tsx}: Use Tailwind utility-first styling, CVA for component variants, and the cn() utility for class merging
Guard browser-only APIs with typeof window !== 'undefined' in client-side code

Files:

  • components/charts/ChartCustomizations.tsx
  • components/dashboard/chart-element-view.tsx
  • components/charts/ChartExportDropdownForList.tsx
  • components/charts/ChartPreview.tsx
  • components/dashboard/chart-element-v2.tsx
  • components/charts/MiniChart.tsx
  • components/charts/ChartExport.tsx
components/charts/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Implement charts following existing patterns in components/charts/, selecting the appropriate library (ECharts/Nivo/Recharts) and supporting PNG/PDF export

Files:

  • components/charts/ChartCustomizations.tsx
  • components/charts/ChartExportDropdownForList.tsx
  • components/charts/ChartPreview.tsx
  • components/charts/MiniChart.tsx
  • components/charts/ChartExport.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Define TypeScript interfaces/types for API responses to ensure type safety
Use the @/* path alias for imports instead of deep relative paths

Files:

  • components/charts/ChartCustomizations.tsx
  • components/dashboard/chart-element-view.tsx
  • components/charts/ChartExportDropdownForList.tsx
  • components/charts/ChartPreview.tsx
  • lib/chart-config-processor.ts
  • components/dashboard/chart-element-v2.tsx
  • components/charts/MiniChart.tsx
  • components/charts/ChartExport.tsx
🧠 Learnings (1)
📚 Learning: 2025-10-13T07:21:21.746Z
Learnt from: CR
PR: DalgoT4D/webapp_v2#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-13T07:21:21.746Z
Learning: Applies to components/charts/**/*.{ts,tsx} : Implement charts following existing patterns in components/charts/, selecting the appropriate library (ECharts/Nivo/Recharts) and supporting PNG/PDF export

Applied to files:

  • components/charts/ChartExportDropdownForList.tsx
  • components/charts/ChartPreview.tsx
  • components/dashboard/chart-element-v2.tsx
  • components/charts/MiniChart.tsx
  • components/charts/ChartExport.tsx
🧬 Code graph analysis (6)
components/dashboard/chart-element-view.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
components/charts/ChartExportDropdownForList.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
components/charts/ChartPreview.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
components/dashboard/chart-element-v2.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
components/charts/MiniChart.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
components/charts/ChartExport.tsx (1)
lib/chart-config-processor.ts (1)
  • processChartConfig (11-96)
🔇 Additional comments (6)
components/charts/ChartExportDropdownForList.tsx (1)

14-14: LGTM!

The integration of processChartConfig is clean and well-documented with a clear comment explaining its purpose.

Also applies to: 118-120

components/charts/ChartExport.tsx (1)

21-21: LGTM!

The integration properly processes the config before export and includes a helpful comment. Disabling animation for export is a good practice.

Also applies to: 90-95

components/charts/MiniChart.tsx (1)

14-14: LGTM!

Clean integration with clear documentation. The processing step is consistently applied before setting options.

Also applies to: 84-86

components/dashboard/chart-element-v2.tsx (1)

41-41: LGTM!

The config processing is correctly applied after grid modifications and before setting the chart options. Documentation is clear.

Also applies to: 654-658

components/dashboard/chart-element-view.tsx (1)

39-39: LGTM!

The processing is correctly positioned after applying styled config and before setting chart options. The implementation is consistent with other chart components.

Also applies to: 894-900

components/charts/ChartPreview.tsx (1)

8-8: LGTM!

The preprocessing step is correctly integrated after modifying the config for proper margins and before setting the chart option.

Also applies to: 66-70

@himanshudube97
Copy link
Member

a. threshold is 1.5% -> labels are seen
image

b. threshold is now 3% -> labels are hidden
image

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.

3 participants