Skip to content

Bar chart titles disappearing depending on other titles reserved space #2078

@Enurian

Description

@Enurian

In my app I encountered a bug with horizontal bar charts that I want to fix.
What is the bug?
When rotating a bar chart to make it horizontal, the top titles (original "left titles") will completely disappear, as soon as the left titles (original "bottom titles") have more reserved space than the height of the chart.

EDIT: I just realized this is not only affecting horizontal/rotated charts, but vertical charts too. It´s just less likely to have so thin charts / large reserved space there! So basically all charts should be affected?

Luckily, it´s easy to reproduce, even in your examples. Here is the original:

Image

Since the aspect ratio is pretty evened out, I need to put in a lot of reserved space to provoke it:

Image

But if I change the aspect ratio and along with it the height of the widget, the issue appears much earlier:

Image

Since in my app, I need very slim charts with just two bars, I get this issue very, very early, with a reserved space of 60 already. This is really annoying to work around.

As far as I see, the titles disappear in side_title_widget.dart line 183:
axisPositions = _getPositionsWithinChartRange(axisPositions, side);
axisPositions has 0 items after the call of _getPositionsWithinChartRange.
The issue is this bit:

final chartSize = Size(
      widget.parentSize.width - thisSidePaddingTotal,
      widget.parentSize.height - thisSidePaddingTotal,
    ).rotateByQuarterTurns(widget.axisChartData.rotationQuarterTurns);

The this side padding is subtracted from both sides and with rotation, the other side (that the padding is not for) is checked against. As soon as this gets negative, the titles are thrown out.

I can try to fix this and make a PR, if you want.

Versions
1.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions