Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// ExamplesDefaults.swift
// SwiftCharts
//
import UIKit
import SwiftCharts
struct ExamplesDefaults {
static var chartSettings: ChartSettings {
if Env.iPad {
return iPadChartSettings
} else {
return iPhoneChartSettings
}
}
static var chartSettingsWithPanZoom: ChartSettings {
if Env.iPad {
return iPadChartSettingsWithPanZoom
} else {
return iPhoneChartSettingsWithPanZoom
}
}
fileprivate static var iPadChartSettings: ChartSettings {
var chartSettings = ChartSettings()
chartSettings.leading = 20
chartSettings.top = 20
chartSettings.trailing = 20
chartSettings.bottom = 20
chartSettings.labelsToAxisSpacingX = 10
chartSettings.labelsToAxisSpacingY = 10
chartSettings.axisTitleLabelsToLabelsSpacing = 5
chartSettings.axisStrokeWidth = 1
chartSettings.spacingBetweenAxesX = 15
chartSettings.spacingBetweenAxesY = 15
chartSettings.labelsSpacing = 0
return chartSettings
}
fileprivate static var iPhoneChartSettings: ChartSettings {
var chartSettings = ChartSettings()
chartSettings.leading = 0
chartSettings.top = 0
chartSettings.trailing = 0
chartSettings.bottom = 0
chartSettings.labelsToAxisSpacingX = 5
chartSettings.labelsToAxisSpacingY = 5
chartSettings.axisTitleLabelsToLabelsSpacing = 0
chartSettings.axisStrokeWidth = 0.2
chartSettings.spacingBetweenAxesX = 8
chartSettings.spacingBetweenAxesY = 0
chartSettings.labelsSpacing = 0
return chartSettings
}
fileprivate static var iPadChartSettingsWithPanZoom: ChartSettings {
var chartSettings = iPadChartSettings
chartSettings.zoomPan.panEnabled = true
chartSettings.zoomPan.zoomEnabled = true
return chartSettings
}
fileprivate static var iPhoneChartSettingsWithPanZoom: ChartSettings {
var chartSettings = iPhoneChartSettings
chartSettings.zoomPan.panEnabled = true
chartSettings.zoomPan.zoomEnabled = true
return chartSettings
}
static func chartFrame(_ containerBounds: CGRect) -> CGRect {
return CGRect(x: 0, y: 70, width: containerBounds.size.width, height: containerBounds.size.height - 70)
}
static var labelSettings: ChartLabelSettings {
return ChartLabelSettings(font: ExamplesDefaults.labelFont)
}
static var labelFont: UIFont {
return ExamplesDefaults.fontWithSize(fontSize)
}
static var labelFontSmall: UIFont {
return ExamplesDefaults.fontWithSize(Env.iPad ? 12 : 10)
}
static var labelTextColor: UIColor {
return #colorLiteral(red: 0.5607843137, green: 0.5607843137, blue: 0.5725490196, alpha: 1)
}
static func fontWithSize(_ size: CGFloat) -> UIFont {
return UIFont.systemFont(ofSize: size)
}
static var fontSize: CGFloat {
return Env.iPad ? 14 : 10
}
static var semiBoldFont: UIFont {
return UIFont.systemFont(ofSize: fontSize, weight: UIFontWeightSemibold)
}
// MARK: - Guidelines
static var guidelinesWidth: CGFloat {
return Env.iPad ? 0.8 : 0.8
}
static var guidelinesColor: UIColor {
return #colorLiteral(red: 0.8862745098, green: 0.8862745098, blue: 0.8862745098, alpha: 1)
}
static var minBarSpacing: CGFloat {
return Env.iPad ? 15 : 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment