Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Sources/SPGlassData/Data/GlassTrend.swift8// Module : SPGlassData9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import SPGlassCore4344/// Direction of a change. Always shown with a symbol and a word, never with colour alone.45public enum GlassTrend: String, CaseIterable, Sendable {46 case up, down, flat4748 /// The direction of a signed change. Changes whose magnitude is at most `tolerance`, and values that are49 /// not finite, are flat.50 public static func of(change: Double, tolerance: Double = 0) -> GlassTrend {51 guard change.isFinite, abs(change) > max(tolerance, 0) else { return .flat }52 return change > 0 ? .up : .down53 }5455 /// SF Symbol that depicts the direction.56 public var systemImage: String {57 switch self {58 case .up: "arrow.up.right"59 case .down: "arrow.down.right"60 case .flat: "arrow.right"61 }62 }6364 /// Localised word for the direction ("Up", "Down", "Unchanged").65 public var label: String { GlassL10n.string(key) }6667 /// The word in a specific localisation, for tests and language previews.68 public func label(localization: String) -> String { GlassL10n.string(key, localization: localization) }6970 private var key: GlassL10n.Key {71 switch self {72 case .up: .trendUp73 case .down: .trendDown74 case .flat: .trendFlat75 }76 }77}78