Skip to content
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

Added Cell level control for Table Borders #1285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kaustbh
Copy link

@Kaustbh Kaustbh commented Oct 15, 2024

Fixes : #1192

Implemented a new feature that allows granular, cell-level control over table borders. With this update, users can now define specific borders (left, right, top, bottom) for individual cells, offering greater customization when generating tables in PDFs.

Checklist:

  • The GitHub pipeline is OK (green),
    meaning that both pylint (static code analyzer) and black (code formatter) are happy with the changes of this PR.

  • A unit test is covering the code added / modified by this PR

  • This PR is ready to be merged

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@Kaustbh
Copy link
Author

Kaustbh commented Oct 15, 2024

Hi @Lucas-C, I have made a PR to know if I am doing it correctly it is not a complete implementation, please see the code change and give me suggestions.

@@ -849,6 +872,7 @@ class Cell:
rowspan: int
padding: Optional[Union[int, tuple, type(None)]]
link: Optional[Union[str, int]]
border: Optional[Union[str, int, CellBordersLayout]]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
border: Optional[Union[str, int, CellBordersLayout]]
border: Optional[CellBordersLayout]

@@ -819,6 +840,7 @@ def cell(
rowspan,
padding,
link,
border,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
border,
CellBordersLayout.coerce(border),

It's better to check if the value provided is valid early, and to always store an instance of CellBordersLayout.

def get_cell_border(self, i, j, cell):
"""
Defines which cell borders should be drawn.
Returns a string containing some or all of the letters L/R/T/B,
to be passed to `fpdf.FPDF.multi_cell()`.
Can be overriden to customize this logic
"""

if hasattr(cell, "border"):
border = CellBordersLayout.coerce(cell.border)
Copy link
Member

Choose a reason for hiding this comment

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

Not needed if you perform the call to .coerce() in Row.cell()

border = CellBordersLayout.coerce(cell.border)

if border != CellBordersLayout.INHERIT:
border2 = []
Copy link
Member

@Lucas-C Lucas-C Oct 16, 2024

Choose a reason for hiding this comment

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

Suggested change
border2 = []
return str(border)

I think it would be best to put this conversion-to-string logic in a method CellBordersLayout.__str__

@Lucas-C
Copy link
Member

Lucas-C commented Oct 16, 2024

Hi @Lucas-C, I have made a PR to know if I am doing it correctly it is not a complete implementation, please see the code change and give me suggestions.

Nice, thank you for creating a PR 🙂

I made a few comments.

On thing that should come next is to add unit tests! 🙂

@Kaustbh
Copy link
Author

Kaustbh commented Oct 19, 2024

Hi, I made the suggested changes, now how can I fix this pylint warning,
fpdf/table.py:255:4: R0911: Too many return statements (7/6) (too-many-return-statements)
which is caused because of additional return str(border).

And please tell me where I should add the unit tests.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 21, 2024

Hi, I made the suggested changes, now how can I fix this pylint warning, fpdf/table.py:255:4: R0911: Too many return statements (7/6) (too-many-return-statements) which is caused because of additional return str(border).

It now seems to be passing, but you have however 27 failing tests.

And please tell me where I should add the unit tests.

You can add them to test/table/test_table.py.

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.

Add Cell Level Controll for Table Borders
2 participants