mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
- graph bugfixes [skip ci]
This commit is contained in:
@@ -13,14 +13,16 @@ import Cocoa
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
struct ChartVisibilityItem {
|
||||
var title: String
|
||||
var color: GColor
|
||||
|
||||
static func generateItemsFrames(for chartWidth: CGFloat, items: [ChartVisibilityItem]) -> [CGRect] {
|
||||
public struct ChartVisibilityItem {
|
||||
public var title: String
|
||||
public var color: GColor
|
||||
public init(title: String, color: GColor) {
|
||||
self.title = title
|
||||
self.color = color
|
||||
}
|
||||
public static func generateItemsFrames(for chartWidth: CGFloat, items: [ChartVisibilityItem]) -> [CGRect] {
|
||||
var previousPoint = CGPoint(x: ChatVisibilityItemConstants.insets.left, y: ChatVisibilityItemConstants.insets.top)
|
||||
var frames: [CGRect] = []
|
||||
|
||||
for item in items {
|
||||
let labelSize = textSize(with: item.title, font: ChatVisibilityItemConstants.textFont)
|
||||
let width = (labelSize.width + ChatVisibilityItemConstants.labelTextApproxInsets).rounded(.up)
|
||||
|
||||
@@ -128,6 +128,7 @@ public class BaseChartController: ChartThemeContainer {
|
||||
return ChartVisibilityItem(title: value.name, color: value.color)
|
||||
}
|
||||
let frames = ChartVisibilityItem.generateItemsFrames(for: width, items: items)
|
||||
|
||||
guard let lastFrame = frames.last else { return height }
|
||||
|
||||
height += lastFrame.maxY
|
||||
|
||||
@@ -26,11 +26,13 @@ extension NSAttributedString {
|
||||
}
|
||||
|
||||
func textSize(with string: String, font: NSFont) -> CGSize {
|
||||
|
||||
let attributedString:NSAttributedString = NSAttributedString(string: string, attributes: [.font : font])
|
||||
let layout = LabelNode.layoutText(attributedString, CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude))
|
||||
var size:CGSize = layout.0.size
|
||||
size.width = ceil(size.width)
|
||||
size.height = ceil(size.height)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user