SPB Git

Repository Public

Scores.swift 10.2 KB 234 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Lou-Ka iOS9// File             : LouKa/Design/Scores.swift10// Description      : scores de quartier — anneau, pastille, radar à cinq axes,11//                    barres.12// Module           : LouKa13// Repository       : https://git.spboucher.ai/lou-ka-ios-v314// Project Website  : https://www.lou-ka.com15// Created          : 2026-11-2516// Last Modified    : 2026-11-2817//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : None specified (no license file in this repository)83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192struct ScoreAxis: Identifiable, Sendable {93    let key: String94    let label: String95    let icon: String96    let hint: String97    var id: String { key }9899    static let all: [ScoreAxis] = [100        .init(key: "walk", label: "Marche", icon: "figure.walk", hint: "Commerces et services à pied"),101        .init(key: "transit", label: "Transport", icon: "tram.fill", hint: "Métro, bus, fréquence"),102        .init(key: "bike", label: "Vélo", icon: "bicycle", hint: "Réseau cyclable à proximité"),103        .init(key: "calme", label: "Calme", icon: "leaf.fill", hint: "Éloignement du bruit, parcs"),104        .init(key: "services", label: "Services", icon: "bag.fill", hint: "Écoles, santé, épiceries"),105    ]106}107108struct ScoreRing: View {109    let value: Double?110    var size: CGFloat = 56111    var lineWidth: CGFloat = 5112    @State private var shown = false113    @Environment(\.accessibilityReduceMotion) private var reduceMotion114115    var body: some View {116        let color = Theme.scoreColor(value)117        ZStack {118            Circle().stroke(Theme.surface3, lineWidth: lineWidth)119            Circle()120                .trim(from: 0, to: shown ? CGFloat(min(100, max(0, value ?? 0)) / 100) : 0)121                .stroke(color, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round))122                .rotationEffect(.degrees(-90))123            Text(value.map { String(Int($0.rounded())) } ?? "–")124                .font(.system(size: size * 0.34, weight: .semibold)).num().foregroundStyle(Theme.ink)125        }126        .frame(width: size, height: size)127        .onAppear {128            if reduceMotion { shown = true } else { withAnimation(.easeOut(duration: 0.9)) { shown = true } }129        }130        .accessibilityElement(children: .ignore)131        .accessibilityLabel(value.map { "Score de quartier : \(Int($0.rounded())) sur 100" } ?? "Score de quartier non disponible")132    }133}134135/// Pastille compacte pour les cartes d'annonce.136struct ScoreBadge: View {137    let value: Double?138    var body: some View {139        if let value {140            HStack(spacing: 5) {141                Circle().fill(Theme.scoreColor(value)).frame(width: 6, height: 6)142                Text(String(Int(value.rounded()))).font(.caption.weight(.semibold)).num()143            }144            .foregroundStyle(Theme.ink2)145            .padding(.horizontal, 8).padding(.vertical, 5)146            .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))147            .accessibilityElement(children: .ignore)148            .accessibilityLabel("Score de quartier \(Int(value.rounded())) sur 100")149        }150    }151}152153/// Radar à cinq axes.154struct ScoreRadar: View {155    let scores: ScoreSet156    var size: CGFloat = 230157    /// déploiement du polygone à l'apparition (0 → 1)158    @State private var grow: Double = 0159160    var body: some View {161        let axes = ScoreAxis.all162        let center = CGPoint(x: size / 2, y: size / 2)163        let radius = size / 2 - 44164        let point: (Int, Double) -> CGPoint = { i, v in165            let a = Double.pi * 2 * Double(i) / Double(axes.count) - Double.pi / 2166            return CGPoint(x: center.x + CGFloat(cos(a)) * radius * CGFloat(v), y: center.y + CGFloat(sin(a)) * radius * CGFloat(v))167        }168        let polygon: (Double?) -> Path = { fixed in169            Path { p in170                for (i, ax) in axes.enumerated() {171                    let v = fixed ?? max(0.04, (scores.value(ax.key) ?? 0) / 100 * grow)172                    let pt = point(i, v)173                    if i == 0 { p.move(to: pt) } else { p.addLine(to: pt) }174                }175                p.closeSubpath()176            }177        }178        ZStack {179            ForEach([0.25, 0.5, 0.75, 1.0], id: \.self) { k in polygon(k).stroke(Theme.line2, lineWidth: 1) }180            ForEach(Array(axes.enumerated()), id: \.offset) { i, _ in181                Path { p in p.move(to: center); p.addLine(to: point(i, 1)) }.stroke(Theme.line, lineWidth: 1)182            }183            polygon(nil).fill(Theme.brand.opacity(0.16))184            polygon(nil).stroke(Theme.brand, style: StrokeStyle(lineWidth: 2.2, lineJoin: .round))185            ForEach(Array(axes.enumerated()), id: \.offset) { i, ax in186                let pt = point(i, max(0.04, (scores.value(ax.key) ?? 0) / 100 * grow))187                Circle().fill(Theme.surface).frame(width: 8, height: 8)188                    .overlay(Circle().stroke(Theme.brand, lineWidth: 2)).position(pt)189                Text(ax.label).font(.caption2.weight(.semibold)).foregroundStyle(Theme.ink2).position(point(i, 1.32))190            }191        }192        .frame(width: size, height: size)193        .drawOnAppear($grow, duration: 0.8)194        .accessibilityElement(children: .ignore)195        .accessibilityLabel("Profil du quartier : " + axes.map { "\($0.label) \(scores.value($0.key).map { String(Int($0.rounded())) } ?? "non disponible")" }.joined(separator: ", "))196    }197}198199/// Une ligne par axe : icône, libellé, barre, valeur.200struct ScoreBars: View {201    let scores: ScoreSet202    @State private var fill: Double = 0203    var body: some View {204        VStack(spacing: 14) {205            ForEach(ScoreAxis.all) { ax in206                let v = scores.value(ax.key)207                HStack(spacing: 12) {208                    Image(systemName: ax.icon).font(.system(size: 15, weight: .medium)).foregroundStyle(Theme.ink2)209                        .frame(width: 36, height: 36)210                        .background(Theme.surface2, in: RoundedRectangle(cornerRadius: 11, style: .continuous))211                    VStack(alignment: .leading, spacing: 5) {212                        HStack {213                            Text(ax.label).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)214                            Spacer()215                            Text(v.map { String(Int($0.rounded())) } ?? "—").font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)216                        }217                        GeometryReader { geo in218                            ZStack(alignment: .leading) {219                                Capsule().fill(Theme.surface3)220                                Capsule().fill(Theme.scoreColor(v)).frame(width: geo.size.width * CGFloat((v ?? 0) / 100 * fill))221                            }222                        }223                        .frame(height: 6)224                        Text(ax.hint).font(.caption2).foregroundStyle(Theme.ink3)225                    }226                }227                .accessibilityElement(children: .ignore)228                .accessibilityLabel("\(ax.label) : \(v.map { "\(Int($0.rounded())) sur 100" } ?? "non disponible")")229            }230        }231        .drawOnAppear($fill, duration: 0.8, delay: 0.12)232    }233}234
Files main
Menu

Theme