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

CombinedChartView half first/last bar in single bar case, and fitBars defect #3186

Open
liuxuan30 opened this issue Jan 16, 2018 · 6 comments

Comments

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 16, 2018

Currently, combined chart with single bar will cut half of first and last bar.
In bar chart, fitBars is not working as expected, it's default disabled, but somehow the bars are just showing correctly, while turning on, it have more space. buggy

Problem 1: fitBars conflict with xAxis.spaceMin/Max

see #3186 (comment)

Problem 2: combined chart bars being cut off

see #3186 (comment)

Solution

For Problem 1, we can fix the conflict and update tests
For Problem 2, so far I don't have a descent solution to unify them, as all sub chart data shares the same xAxis, and to align different charts together, tweaking the x values and axisMinimum/Maximum instead of xAxis's internal min/max values or use multiple matrix and shadow xAxis is a much lower cost.

@liuxuan30
Copy link
Member Author

liuxuan30 commented Jan 16, 2018

Problem 1: fitBars conflict with xAxis.spaceMin/Max

**I'm afraid all of our bar chart unit tests need update
fitBars eventually adjust

        var min = _customAxisMin ? _axisMinimum : (dataMin - spaceMin)
        var max = _customAxisMax ? _axisMaximum : (dataMax + spaceMax)

by reducing or increasing dataMin/Max here:

        if fitBars
        {
            _xAxis.calculate(
                min: data.xMin - data.barWidth / 2.0,
                max: data.xMax + data.barWidth / 2.0)
        }

So it's equivalent to setting spaceMin/Max here:

    internal override func initialize()
    {
        ...
        self.xAxis.spaceMin = 0.5
        self.xAxis.spaceMax = 0.5
    }

However, currently fitBars by default is false, some of the demos like another bar chart enabled it, and is walking through both spaceMin/Max and fitBars code path, which leads to over-offseted bars before and after first/last bar:
728a859a-91bc-4cd2-bea8-b419fd44d227

@liuxuan30
Copy link
Member Author

liuxuan30 commented Jan 17, 2018

Problem 2 combined chart bars being cut off

Before touching the core, there are some tricky things:

  1. lineData add 0.5 to its x value, so the line is shifted a little
[ChartDataEntry alloc] initWithX:index + 0.5;
  1. default demo uses multiple bars, which will recalculate x values in groupBars,
  2. default demo tweaks axisMinimum/Maximum like
xAxis.axisMinimum = 0.0;
_chartView.xAxis.axisMaximum = data.xMax + 0.25;
  1. bubble data and candle data also shift x value by 0.5 and 1 like in line data above
    so after doing all these modifications, the demo combined chart aligns perfectly.

if we only leave bar data and line data behind,

However, reducing that 0.5 from lineData x value, and use single bar data, we could reproduce it:
image

So far it looks like to align combined chart, we need to do the tricky x value shift calculation for each sub chart data. Not sure if we can find a unified solution, but so far it's the workaround.

@jonasfugedi
Copy link

jonasfugedi commented Mar 3, 2018

x-axis labels are not calculated correct as well as the issues with the bars being cut in half.

simulator screen shot - iphone 8 - 2018-03-03 at 17 09 27

And then there is the old bug with labels in stacked bars not fitting - I had a fix for this in the old version so I need to figure out how to backport the fix. Not related to to this issue but these two are blocking my release so I will dig through the code a bit and see if I can get them resolved.

simulator screen shot - iphone 8 - 2018-03-03 at 17 13 53

Got the labels in the stacked bars better but still some scenarios where labels may overlap

simulator screen shot - iphone 8 - 2018-03-03 at 23 33 12

@liuxuan30
Copy link
Member Author

please open another issue to track your label issues. For the first one, I already documented the reason and workaround so far.

@jonasfugedi
Copy link

jonasfugedi commented Mar 4, 2018

Cool, I guess I do not understand the workaround proposed, will re-read your comments and see if I can come to grips with it.

The other issue is #620 so my fix for the labels should go there as before.

@jonasfugedi
Copy link

For the x-axis labels issue, my current workaround is to rotate the labels -15 degrees.

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

No branches or pull requests

2 participants