willdale / SwiftUICharts

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.
MIT License
843 stars 105 forks source link

Bug in 2.9.8? #174

Closed gesabo closed 2 years ago

gesabo commented 2 years ago

I'm not sure if its just me or the cause but this same chart which looked fine in 2.9.7, now in 2.9.8 the Legend (the word "Trend") is overlapping the xAxis values, see below, 2.9.7 is on the bottom. IMG_4117 IMG_4118

willdale commented 2 years ago

This should be fixed in v2.9.9.

Thanks

sai-manoj-kumar commented 2 years ago

@gesabo I am working on fixing this issue after including the reverted fix. I am not able to repro this issue with MutliLineChart. Can you please share the code you used to create this chart? In specific, I want to understand which chart type you are using.

gesabo commented 2 years ago

@sai-manoj-kumar after checking my code I realized I was actually adding my own custom "legend" for the word Trend in the screenshot, so whatever changed in version 2.9.8 somehow made my Text view overlap the chart:


     VStack(alignment: .leading, spacing: -20) {

                    BarChart(chartData: unwrappedData)
                            .extraLine(chartData: unwrappedData, legendTitle: "") {
                                makeTrendData(data: athlyticDataStore.past60DaysOr6MonthsRecoveryScoreObjects?.suffix(60).compactMap { Double($0.recoveryScore)})
                            } style: {
                                showWeeklyAverageChart ? extraLineHiddenStyle : extraLineStyle
                            }
                        .touchOverlay(chartData: unwrappedData) //to be able to tab to see points need both .touchOverlay and .floatingInfoBox
                        .floatingInfoBox(chartData: unwrappedData)
                        .xAxisLabels(chartData: unwrappedData)
                        .yAxisLabels(chartData: unwrappedData)
                        .id(unwrappedData.id)
                        .animation(nil) //this prevents any of the chart from animating
                        .unredacted()
                    if !showWeeklyAverageChart {
                        if makeTrendData(data: athlyticDataStore.past60DaysOr6MonthsRecoveryScoreObjects?.suffix(60).compactMap { Double($0.recoveryScore)}).count > 1 {

                            HStack {
                                RoundedRectangle(cornerRadius: 2.0)
                                    .foregroundColor( colorScheme == .dark ? Color(.label) : TrackerConstants.trendLineColor)
                                    .frame(width: 8.0, height: 8.0)
                                Text("Trend")
                                    .font(.footnote)
                                    .unredacted()
                            }
                        }
                 }

             }
sai-manoj-kumar commented 2 years ago

@gesabo, Thanks for sharing the code. I think it is happening because of the spacing of -20 in your VStack. I was able to repro the issue along with the PR. After removing the spacing: -20, the issue is gone. Please confirm if this works or not.

gesabo commented 2 years ago

@sai-manoj-kumar thank you yes it seems like removing spacing of -20 solves the issue using version 2.9.8 and 2.9.9 as well. 👍

sai-manoj-kumar commented 2 years ago

@gesabo Thanks for confirming it quickly.

@willdale Can you please revert the reverted PR again? Thanks