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

feat: 🎸 [JIRA:IOSSDKBUG-5] add variables to ChartLabelAttribute #692

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/FioriCharts/Charts/Common/XAxisView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ struct XAxisView: View {
Group {
if isShowLabels[index] {
Text(labels[index].title)
.font(.fiori(fixedSize: axis.labels.fontSize))
.font(axis.labels.targetFont)
.foregroundColor(axis.labels.color)
.background(axis.labels.backgroundColor)
.frame(maxWidth: rect.size.width / 2)
.position(x: labels[index].pos.x, y: labelYPos)
} else {
Expand Down
3 changes: 2 additions & 1 deletion Sources/FioriCharts/Charts/Common/YAxisView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ struct YAxisView: View {
Group {
if isShowLabels[index] {
Text(labels[index].title)
.font(.fiori(fixedSize: axis.labels.fontSize))
.font(axis.labels.targetFont)
.foregroundColor(axis.labels.color)
.background(axis.labels.backgroundColor)
.position(x: labels[index].pos.x,
y: labels[index].pos.y)
.frame(maxWidth: rect.size.width)
Expand Down
51 changes: 45 additions & 6 deletions Sources/FioriCharts/Model/ChartLabelAttributes.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Combine
import FioriThemeManager
import Foundation
import SwiftUI

Expand All @@ -17,24 +19,59 @@ public class ChartLabelAttributes: ObservableObject, Identifiable, NSCopying {
/// True when the associated label(s) should be hidden.
@Published public var isHidden: Bool

/// Font for the label, has higher priority than fontSize.
@Published public var font: Font?
/// Backgroundcolor for the label.
@Published public var backgroundColor: Color?

/// When font not be configured, use .fiori(fixedSize: fontSize) as default;
var targetFont: Font {
if let font {
return font
} else {
return .fiori(fixedSize: self.fontSize)
}
}

public let id = UUID()

/// The constructor with color, fontSize, offset, isHidden and backgroundColor
public init(color: Color = .preferredColor(.tertiaryLabel),
fontSize: Double = 12,
offset: Double = 0,
isHidden: Bool = false)
isHidden: Bool = false,
backgroundColor: Color? = nil)
{
self._color = Published(initialValue: color)
self._fontSize = PublishedConstrainedValue(wrappedValue: CGFloat(fontSize), 0 ... 100)
self._offset = PublishedConstrainedValue(wrappedValue: CGFloat(offset), -10 ... 10)
self._isHidden = Published(initialValue: isHidden)
self._backgroundColor = Published(initialValue: backgroundColor)
}

/// The constructor with color, font, offset, isHidden and backgroundColor
public init(color: Color = .preferredColor(.tertiaryLabel),
font: Font?,
offset: Double = 0,
isHidden: Bool = false,
backgroundColor: Color? = nil)
{
self._color = Published(initialValue: color)
self._font = Published(initialValue: font)
self._offset = PublishedConstrainedValue(wrappedValue: CGFloat(offset), -10 ... 10)
self._isHidden = Published(initialValue: isHidden)
self._backgroundColor = Published(initialValue: backgroundColor)
}

public func copy(with zone: NSZone? = nil) -> Any {
ChartLabelAttributes(color: self.color,
fontSize: Double(self.fontSize),
offset: Double(self.offset),
isHidden: self.isHidden)
let chartLabelAttributes = ChartLabelAttributes(color: self.color,
fontSize: Double(self.fontSize),
offset: Double(self.offset),
isHidden: self.isHidden,
backgroundColor: self.backgroundColor)
// assign font property
chartLabelAttributes.font = self.font
return chartLabelAttributes
}
}

Expand All @@ -43,7 +80,9 @@ extension ChartLabelAttributes: Equatable {
lhs.color == rhs.color &&
lhs.fontSize == rhs.fontSize &&
lhs.offset == rhs.offset &&
lhs.isHidden == rhs.isHidden
lhs.isHidden == rhs.isHidden &&
lhs.font == rhs.font &&
lhs.backgroundColor == rhs.backgroundColor
}
}

Expand Down
Loading