TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Charts last two x labels overlap

Forums > SwiftUI

@konic  

I have chart with dynamic number of values: it could be large or few.
In the code I hide intermediate ones like

value.index % numsToShow == 0

but always add the last point.
In this case I may get two x labes at the end of chart - right side, which overlap.
Labels are displayed like this:

if (value.index % numsToShow == 0 || value.index == xValues.count - 1) {
      AxisValueLabel {
          if let day = value.as(String.self) {
              Text(day)
              ....
          }
      }
}

Is there anyway to check if two Text views are visibly overlapping?
I tried to use GeometryReader for the Text, but rect shows width and height only, origin is always (0, 0).

Text(day)
  .background(
          GeometryReader { (geom) -> AnyView in
              let rect = geom.frame(in: .global)
              DispatchQueue.main.async {
                  self.aRects.append(rect) // save 'rect' for further usage
              }
              return AnyView(Color.clear)
          }
  )

   

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.