Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Data/GlassChartExample.swift8// Module : Examples9// 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 SwiftUI42import SPGlassKit4344public struct GlassChartExample: GlassExample {45 public static let componentID = "glass-chart"4647 // Fictitious data: energy produced by two imaginary sites.48 private static let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]49 private static let north: [Double] = [42, 48, 55, 61, 58, 70]50 private static let south: [Double] = [65, 60, 57, 52, 49, 44]5152 private static let production: [GlassChartPoint] =53 zip(months, north).map { GlassChartPoint(label: $0, value: $1, series: "North") }54 + zip(months, south).map { GlassChartPoint(label: $0, value: $1, series: "South") }5556 private static let visits: [GlassChartPoint] = {57 let start = Date(timeIntervalSince1970: 1_780_272_000)58 let values: [Double] = [120, 135, 128, 160, 190, 240, 210]59 return values.enumerated().map { GlassChartPoint(date: start.addingTimeInterval(Double($0.offset) * 86_400), value: $0.element) }60 }()6162 @State private var kind = GlassChartKind.line63 @State private var series = "All"6465 public init() {}6667 private var visibleProduction: [GlassChartPoint] {68 series == "All" ? Self.production : Self.production.filter { $0.series == series }69 }7071 public var body: some View {72 ScrollView {73 VStack(spacing: 16) {74 Picker("Mark", selection: $kind) {75 Text("Line").tag(GlassChartKind.line)76 Text("Bar").tag(GlassChartKind.bar)77 Text("Area").tag(GlassChartKind.area)78 }79 .pickerStyle(.segmented)8081 GlassChart("Energy produced", points: visibleProduction, kind: kind, xAxisTitle: "Month", yAxisTitle: "Energy", unit: "MWh") {82 Picker("Series", selection: $series) {83 Text("All").tag("All")84 ForEach(GlassChartLogic.seriesNames(Self.production), id: \.self) { Text(verbatim: $0).tag($0) }85 }86 .pickerStyle(.menu)87 }8889 GlassChart("Daily visits", points: Self.visits, kind: .area, xAxisTitle: "Day", yAxisTitle: "Visits")9091 GlassChart("Nothing measured yet", points: [])92 }93 .padding()94 }95 }96}9798#Preview("GlassChart") { GlassChartExample().glassTheme(.ocean) }99