Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 8, 2025

This PR implements font support for chart legends, allowing users to specify font properties such as family, size, color, bold, italic, underline, and strike for legend text.

Changes Made

Core Implementation

  • xmlChart.go: Added Font field to ChartLegend struct
  • drawing.go:
    • Initialize TxPr (text properties) when creating chart legends
    • Apply font settings using the existing drawChartFont function
  • chart.go: Updated documentation to include the new Font option

Testing

  • chart_test.go: Added comprehensive TestChartLegendFont test covering:
    • Normal legend with font settings
    • Legend with position: "none" (edge case)
    • Different font properties validation

Usage Example

err := f.AddChart("Sheet1", "E1", &excelize.Chart{
    Type: excelize.Col,
    Series: series,
    Title: []excelize.RichTextRun{{Text: "Chart Title"}},
    Legend: excelize.ChartLegend{
        Position: "bottom", 
        Font: excelize.Font{
            Family: "Aptos", 
            Color:  "#3E3E3E", 
            Size:   10,
            Bold:   true,
        },
    },
})

Implementation Details

The implementation follows the same pattern used for other chart text elements (data labels, axes) to ensure consistency:

  1. Text Properties Initialization: Legends now have proper TxPr structure with body properties and paragraph settings
  2. Font Application: Uses the existing drawChartFont function to apply font settings to the legend's text properties
  3. Edge Case Handling: Properly handles cases where legend position is "none" without errors

Testing Results

  • All existing tests pass
  • New test validates font functionality
  • Manual testing confirms font settings are applied correctly
  • Edge cases (no legend) handled properly

The changes are minimal and surgical, adding exactly the functionality requested without affecting existing behavior.

Fixes #2169.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Legends in charts do not support font settings Add font support for chart legends Jul 8, 2025
@Copilot Copilot AI requested a review from xuri July 8, 2025 14:30
Copilot finished work on behalf of xuri July 8, 2025 14:30
@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 9, 2025
@xuri xuri moved this to Features in Excelize v2.10.0 Jul 9, 2025
@xuri xuri marked this pull request as ready for review July 9, 2025 15:12
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.24%. Comparing base (f47b3df) to head (c4e063c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2171   +/-   ##
=======================================
  Coverage   99.23%   99.24%           
=======================================
  Files          32       32           
  Lines       30383    30404   +21     
=======================================
+ Hits        30152    30173   +21     
  Misses        153      153           
  Partials       78       78           
Flag Coverage Δ
unittests 99.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

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

LGTM.

@xuri xuri merged commit 249b593 into master Jul 10, 2025
29 checks passed
@xuri xuri deleted the copilot/fix-2169 branch July 10, 2025 00:15
@xuri xuri removed their assignment Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Features
Development

Successfully merging this pull request may close these issues.

Legends in charts do not support font settings
2 participants