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

Conditional and table formatting support for html #4412

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

Conversation

mikkokoo
Copy link

@mikkokoo mikkokoo commented Mar 19, 2025

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Why this change is needed?

Conditional and table formatting support for html writer were needed to provide better html output for processed files.

Fix #1375.

@mikkokoo mikkokoo marked this pull request as ready for review March 19, 2025 12:40
@oleibman
Copy link
Collaborator

Here is something like what I would like to see for HtmlTableFormatWithConditionalTest.
HtmlTableFormatWithConditionalTest.zip

@mikkokoo
Copy link
Author

I did some profiling and found out that the getHashCode functions in Style/ get called a lot. They make the conditional formatting pretty slow. I managed to cache the hash code so that the execution time dropped by 75%.

@oleibman Should I commit that to this PR (I think yes) or make another pull request after this one?

10 files changed, 242 insertions(+), 61 deletions(-)

@mikkokoo mikkokoo force-pushed the master branch 2 times, most recently from 4272f4d to d542036 Compare March 24, 2025 12:56
@oleibman
Copy link
Collaborator

Please make a separate PR for your HashCode improvements.

@@ -214,6 +215,15 @@ protected function processOperatorComparison(Conditional $conditional): bool
return $this->evaluateExpression($expression);
}

protected function processColorScale(Conditional $conditional): bool
{
if ($this->wrapCellValue() !== '' && is_float($this->wrapCellValue()) && $conditional->getColorScale() !== null && $conditional->getColorScale()->colorScaleReadyForUse()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand your code correctly your first 2 conditions conditions can be combined - if it's a float, then it's not equal to null-string. And I also believe the 3rd and 4th conditions can also be combined with a null-safe operator.

if (is_float($this->wrapCellValue()) && $conditional->getColorScale?->colorScaleReadyForUse())

However, I'm not entirely sure about is_float. It seems that wrapCellValue might also return int. If you don't want that to follow the same code path as float, then leave is_float as-is; however, if you do want int and float to follow the same path, you might use is_numeric instead.


public static function colourScaleProvider(): array
{
return [
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still an overwhelmingly large number of tests. Can you model it after the others and just test a few "interesting" cells in each row, and only for the data you're looking for (background color and value).

Copy link
Author

Choose a reason for hiding this comment

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

It is the test of different color scale formulas. There has to be quite a few data points to have meaningful results as the style is the only measurable data. They are all interesting. I'd say this is the bare minimum.


public function testConditionalFormattingRulesHtml(): void
{
$expectedMatches = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, this is just too many tests for me to absorb. Please just choose a representative sample. Maybe a couple from column 1 (all of this column seems to match whatever test it needs), the matching cell from column 2, one or two non-matching cells from column 2, and one or two cells from column 3 (these might be a little trickier because conditional formatting doesn't apply to them). It is not that the tests I'm asking you to remove aren't worthwhile - they most decidedly are. For that reason, I would suggest commenting them out rather than deleting them. I think the "missing" tests are better handled by also creating new samples, so that we can confirm visually that the html matches the original xlsx. I will add a comment to your ticket later on how that might be done.

@oleibman
Copy link
Collaborator

As discussed above, I would like you to use your xlsx files for both unit tests and samples. Here is how you might go about it.
htmlcondtosamples.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

PDF-Generation don't respect condtional formatting
2 participants