Bug 159462 - chart: best fit algorithm should be able to "shrink" text width to fit into "vertical" slices
Summary: chart: best fit algorithm should be able to "shrink" text width to fit into "...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Chart (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: OOXML-Chart
  Show dependency treegraph
 
Reported: 2024-01-30 18:35 UTC by Justin L
Modified: 2024-03-05 18:31 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
bestFitVertical.xlsx: MSO bestFit inconsistency demo (12.76 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2024-01-30 18:35 UTC, Justin L
Details
bestFitVertical_mso2010.pdf: how it looks in the program that created the file (261.12 KB, application/pdf)
2024-01-30 18:40 UTC, Justin L
Details
insideWrapping.xlsx: text attempts to fit into slice also with center placement (12.81 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2024-01-30 18:55 UTC, Justin L
Details
insideWrapping_mso2010.pdf: how it looks in the program that created it (261.09 KB, application/pdf)
2024-01-30 18:59 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin L 2024-01-30 18:35:03 UTC
Created attachment 192268 [details]
bestFitVertical.xlsx: MSO bestFit inconsistency demo

Slices near the Y-axis are best suited for well-wrapped text. Unfortunately, LO's algorithm has no ability to look for the "best width". So it cannot place as many labels inside the slice as needed for compatibility documents.

However, there are other cases where LO's algorithm is able to bestFit content where MSO fails, and as this document shows, MSO isn't very predictable in determining whether content should bestFit or not.

Fixing this will require adding a significant amount of intelligence to the bestFit algorithm. It will need to loop and try three or four different widths.

Due to 3D manipulation, simple tricks like comparing the slice area to the text area will not work - unless your area formula takes into account the 3D rotation.
Comment 1 Justin L 2024-01-30 18:40:00 UTC
Created attachment 192269 [details]
bestFitVertical_mso2010.pdf: how it looks in the program that created the file
Comment 2 Justin L 2024-01-30 18:55:15 UTC
Created attachment 192270 [details]
insideWrapping.xlsx: text attempts to fit into slice also with center placement

The bestFit shrinking algorithm should also be applied to center/inside-edge placements.
Comment 3 Justin L 2024-01-30 18:59:38 UTC
Created attachment 192271 [details]
insideWrapping_mso2010.pdf: how it looks in the program that created it

Granted, this is not a "nice" example. It was designed to show how MS handles a somewhat bizarre situation, compared to how LO does it.

LO ends up looking somewhat OK in this example because it ALWAYS limits the width to 80% of the radius. For a very large pie, LO wouldn't wrap which might cause it to spill out of the slice if it doesn't bestFit. As can be seen here, MSO can sometimes not bother to bestFit and just spill outside of the pie chart too.
Comment 4 Justin L 2024-01-30 19:06:51 UTC
(In reply to Justin L from comment #2)
> The bestFit shrinking algorithm should also be applied to center/inside-edge
I'd like to retract this statement. A bit more playing around suggests this is not actually true. I'm not sure what is going on here...
Comment 5 Justin L 2024-01-31 15:39:27 UTC
I think in the ideal case that ALL inside placements should also try to bestFit the text content into the slice, regardless of what MSO does. (I mean, how bad could it be if we DO NOT spill out of the slice - just less aesthetic hyphen-splits in specific contexts?)

IIUC, our current bestFit algorithm simply tries to find the best POSITION for the text: center or edge basically. In order to do that, it does some brilliant calculations, which I would HOPE could be fairly easily adapted to compare to the area of the current text bounding box.
    // get label b.b. width and height
    basegfx::B2IRectangle aBb( lcl_getRect( rPieLabelInfo.xLabelGroupShape ) );

If the guessed best width doesn't fit, [but the area fits into the slices' available text area,] then reduce the maximum width to this width and check if the new height is OK.
[Area isn't a great predictive test though, since almost half of it could be empty space.]
    rPieLabelInfo.xTextShape->SvxShape::setPropertyValue("TextMaximumFrameWidth", nMaxBestFitWidth);

That is an expensive task, so don't want to do that flippantly. However, the only way to actually know if it fits is to force the text to re-layout with a new width.
Comment 6 Buovjaga 2024-03-05 18:31:54 UTC
Ok, let's set to NEW.