├── .gitignore ├── AxisContributionExample ├── AxisContributionExample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── AxisContribution.xcscheme ├── Shared │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── AxisContributionExampleApp.swift │ ├── ContentView.swift │ └── Extensions │ │ ├── Color+Extensions.swift │ │ └── Date+Extensions.swift └── macOS │ └── macOS.entitlements ├── LICENSE ├── Markdown ├── Horizontal.png ├── Horizontal_heart.png ├── Vertical.png └── Vertical_heart.png ├── Package.swift ├── README.md ├── Sources └── AxisContribution │ ├── AxisContribution.swift │ ├── Extentions │ ├── Color+Extensions.swift │ └── Date+Extensions.swift │ ├── Model │ ├── ACConstant.swift │ ├── ACData.swift │ └── ACIndexSet.swift │ ├── Util │ └── SizeModifier.swift │ ├── View │ └── ACGridStack.swift │ └── ViewModel │ ├── ACDataProvider.swift │ └── ACDataStore.swift └── Tests └── AxisContributionTests └── AxisContributionTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /AxisContributionExample/AxisContributionExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B261F3E27C5D52C00D56A66 /* AxisContributionExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F2E27C5D52C00D56A66 /* AxisContributionExampleApp.swift */; }; 11 | 4B261F3F27C5D52C00D56A66 /* AxisContributionExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F2E27C5D52C00D56A66 /* AxisContributionExampleApp.swift */; }; 12 | 4B261F4027C5D52C00D56A66 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F2F27C5D52C00D56A66 /* ContentView.swift */; }; 13 | 4B261F4127C5D52C00D56A66 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F2F27C5D52C00D56A66 /* ContentView.swift */; }; 14 | 4B261F4227C5D52C00D56A66 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B261F3027C5D52C00D56A66 /* Assets.xcassets */; }; 15 | 4B261F4327C5D52C00D56A66 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B261F3027C5D52C00D56A66 /* Assets.xcassets */; }; 16 | 4B261F5A27C5E3B400D56A66 /* AxisContribution in Frameworks */ = {isa = PBXBuildFile; productRef = 4B261F5927C5E3B400D56A66 /* AxisContribution */; }; 17 | 4B261F5C27C5E3B700D56A66 /* AxisContribution in Frameworks */ = {isa = PBXBuildFile; productRef = 4B261F5B27C5E3B700D56A66 /* AxisContribution */; }; 18 | 4B261F5E27C60ED900D56A66 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F5D27C60ED800D56A66 /* Color+Extensions.swift */; }; 19 | 4B261F5F27C60ED900D56A66 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B261F5D27C60ED800D56A66 /* Color+Extensions.swift */; }; 20 | 4B8B9C1127C64C3E00B700D7 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B9C1027C64C3E00B700D7 /* Date+Extensions.swift */; }; 21 | 4B8B9C1227C64C3E00B700D7 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B9C1027C64C3E00B700D7 /* Date+Extensions.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 4B261F2E27C5D52C00D56A66 /* AxisContributionExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AxisContributionExampleApp.swift; sourceTree = ""; }; 26 | 4B261F2F27C5D52C00D56A66 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 27 | 4B261F3027C5D52C00D56A66 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 4B261F3527C5D52C00D56A66 /* AxisContributionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AxisContributionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 4B261F3B27C5D52C00D56A66 /* AxisContributionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AxisContributionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 4B261F3D27C5D52C00D56A66 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = ""; }; 31 | 4B261F4D27C5D54200D56A66 /* AxisContribution */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = AxisContribution; path = ..; sourceTree = ""; }; 32 | 4B261F5D27C60ED800D56A66 /* Color+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Color+Extensions.swift"; sourceTree = ""; }; 33 | 4B8B9C1027C64C3E00B700D7 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 4B261F3227C5D52C00D56A66 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | 4B261F5A27C5E3B400D56A66 /* AxisContribution in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | 4B261F3827C5D52C00D56A66 /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | 4B261F5C27C5E3B700D56A66 /* AxisContribution in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 4B261F2827C5D52C00D56A66 = { 57 | isa = PBXGroup; 58 | children = ( 59 | 4B261F4C27C5D54200D56A66 /* Packages */, 60 | 4B261F2D27C5D52C00D56A66 /* Shared */, 61 | 4B261F3C27C5D52C00D56A66 /* macOS */, 62 | 4B261F3627C5D52C00D56A66 /* Products */, 63 | 4B261F5127C5D7EA00D56A66 /* Frameworks */, 64 | ); 65 | sourceTree = ""; 66 | }; 67 | 4B261F2D27C5D52C00D56A66 /* Shared */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 4B261F2E27C5D52C00D56A66 /* AxisContributionExampleApp.swift */, 71 | 4B8B9C0C27C647D800B700D7 /* Extensions */, 72 | 4B261F2F27C5D52C00D56A66 /* ContentView.swift */, 73 | 4B261F3027C5D52C00D56A66 /* Assets.xcassets */, 74 | ); 75 | path = Shared; 76 | sourceTree = ""; 77 | }; 78 | 4B261F3627C5D52C00D56A66 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 4B261F3527C5D52C00D56A66 /* AxisContributionExample.app */, 82 | 4B261F3B27C5D52C00D56A66 /* AxisContributionExample.app */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | 4B261F3C27C5D52C00D56A66 /* macOS */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 4B261F3D27C5D52C00D56A66 /* macOS.entitlements */, 91 | ); 92 | path = macOS; 93 | sourceTree = ""; 94 | }; 95 | 4B261F4C27C5D54200D56A66 /* Packages */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 4B261F4D27C5D54200D56A66 /* AxisContribution */, 99 | ); 100 | name = Packages; 101 | sourceTree = ""; 102 | }; 103 | 4B261F5127C5D7EA00D56A66 /* Frameworks */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | ); 107 | name = Frameworks; 108 | sourceTree = ""; 109 | }; 110 | 4B8B9C0C27C647D800B700D7 /* Extensions */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 4B261F5D27C60ED800D56A66 /* Color+Extensions.swift */, 114 | 4B8B9C1027C64C3E00B700D7 /* Date+Extensions.swift */, 115 | ); 116 | path = Extensions; 117 | sourceTree = ""; 118 | }; 119 | /* End PBXGroup section */ 120 | 121 | /* Begin PBXNativeTarget section */ 122 | 4B261F3427C5D52C00D56A66 /* AxisContributionExample (iOS) */ = { 123 | isa = PBXNativeTarget; 124 | buildConfigurationList = 4B261F4627C5D52C00D56A66 /* Build configuration list for PBXNativeTarget "AxisContributionExample (iOS)" */; 125 | buildPhases = ( 126 | 4B261F3127C5D52C00D56A66 /* Sources */, 127 | 4B261F3227C5D52C00D56A66 /* Frameworks */, 128 | 4B261F3327C5D52C00D56A66 /* Resources */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | ); 134 | name = "AxisContributionExample (iOS)"; 135 | packageProductDependencies = ( 136 | 4B261F5927C5E3B400D56A66 /* AxisContribution */, 137 | ); 138 | productName = "AxisContributionExample (iOS)"; 139 | productReference = 4B261F3527C5D52C00D56A66 /* AxisContributionExample.app */; 140 | productType = "com.apple.product-type.application"; 141 | }; 142 | 4B261F3A27C5D52C00D56A66 /* AxisContributionExample (macOS) */ = { 143 | isa = PBXNativeTarget; 144 | buildConfigurationList = 4B261F4927C5D52C00D56A66 /* Build configuration list for PBXNativeTarget "AxisContributionExample (macOS)" */; 145 | buildPhases = ( 146 | 4B261F3727C5D52C00D56A66 /* Sources */, 147 | 4B261F3827C5D52C00D56A66 /* Frameworks */, 148 | 4B261F3927C5D52C00D56A66 /* Resources */, 149 | ); 150 | buildRules = ( 151 | ); 152 | dependencies = ( 153 | ); 154 | name = "AxisContributionExample (macOS)"; 155 | packageProductDependencies = ( 156 | 4B261F5B27C5E3B700D56A66 /* AxisContribution */, 157 | ); 158 | productName = "AxisContributionExample (macOS)"; 159 | productReference = 4B261F3B27C5D52C00D56A66 /* AxisContributionExample.app */; 160 | productType = "com.apple.product-type.application"; 161 | }; 162 | /* End PBXNativeTarget section */ 163 | 164 | /* Begin PBXProject section */ 165 | 4B261F2927C5D52C00D56A66 /* Project object */ = { 166 | isa = PBXProject; 167 | attributes = { 168 | BuildIndependentTargetsInParallel = 1; 169 | LastSwiftUpdateCheck = 1320; 170 | LastUpgradeCheck = 1320; 171 | TargetAttributes = { 172 | 4B261F3427C5D52C00D56A66 = { 173 | CreatedOnToolsVersion = 13.2.1; 174 | }; 175 | 4B261F3A27C5D52C00D56A66 = { 176 | CreatedOnToolsVersion = 13.2.1; 177 | }; 178 | }; 179 | }; 180 | buildConfigurationList = 4B261F2C27C5D52C00D56A66 /* Build configuration list for PBXProject "AxisContributionExample" */; 181 | compatibilityVersion = "Xcode 13.0"; 182 | developmentRegion = en; 183 | hasScannedForEncodings = 0; 184 | knownRegions = ( 185 | en, 186 | Base, 187 | ); 188 | mainGroup = 4B261F2827C5D52C00D56A66; 189 | packageReferences = ( 190 | ); 191 | productRefGroup = 4B261F3627C5D52C00D56A66 /* Products */; 192 | projectDirPath = ""; 193 | projectRoot = ""; 194 | targets = ( 195 | 4B261F3427C5D52C00D56A66 /* AxisContributionExample (iOS) */, 196 | 4B261F3A27C5D52C00D56A66 /* AxisContributionExample (macOS) */, 197 | ); 198 | }; 199 | /* End PBXProject section */ 200 | 201 | /* Begin PBXResourcesBuildPhase section */ 202 | 4B261F3327C5D52C00D56A66 /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 4B261F4227C5D52C00D56A66 /* Assets.xcassets in Resources */, 207 | ); 208 | runOnlyForDeploymentPostprocessing = 0; 209 | }; 210 | 4B261F3927C5D52C00D56A66 /* Resources */ = { 211 | isa = PBXResourcesBuildPhase; 212 | buildActionMask = 2147483647; 213 | files = ( 214 | 4B261F4327C5D52C00D56A66 /* Assets.xcassets in Resources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXResourcesBuildPhase section */ 219 | 220 | /* Begin PBXSourcesBuildPhase section */ 221 | 4B261F3127C5D52C00D56A66 /* Sources */ = { 222 | isa = PBXSourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | 4B261F4027C5D52C00D56A66 /* ContentView.swift in Sources */, 226 | 4B8B9C1127C64C3E00B700D7 /* Date+Extensions.swift in Sources */, 227 | 4B261F3E27C5D52C00D56A66 /* AxisContributionExampleApp.swift in Sources */, 228 | 4B261F5E27C60ED900D56A66 /* Color+Extensions.swift in Sources */, 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | 4B261F3727C5D52C00D56A66 /* Sources */ = { 233 | isa = PBXSourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | 4B261F4127C5D52C00D56A66 /* ContentView.swift in Sources */, 237 | 4B8B9C1227C64C3E00B700D7 /* Date+Extensions.swift in Sources */, 238 | 4B261F3F27C5D52C00D56A66 /* AxisContributionExampleApp.swift in Sources */, 239 | 4B261F5F27C60ED900D56A66 /* Color+Extensions.swift in Sources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXSourcesBuildPhase section */ 244 | 245 | /* Begin XCBuildConfiguration section */ 246 | 4B261F4427C5D52C00D56A66 /* Debug */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_ANALYZER_NONNULL = YES; 251 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_ENABLE_OBJC_WEAK = YES; 257 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 258 | CLANG_WARN_BOOL_CONVERSION = YES; 259 | CLANG_WARN_COMMA = YES; 260 | CLANG_WARN_CONSTANT_CONVERSION = YES; 261 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 262 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 263 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 264 | CLANG_WARN_EMPTY_BODY = YES; 265 | CLANG_WARN_ENUM_CONVERSION = YES; 266 | CLANG_WARN_INFINITE_RECURSION = YES; 267 | CLANG_WARN_INT_CONVERSION = YES; 268 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 269 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 270 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 271 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 272 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 273 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 274 | CLANG_WARN_STRICT_PROTOTYPES = YES; 275 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 276 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 277 | CLANG_WARN_UNREACHABLE_CODE = YES; 278 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 279 | COPY_PHASE_STRIP = NO; 280 | DEBUG_INFORMATION_FORMAT = dwarf; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | ENABLE_TESTABILITY = YES; 283 | GCC_C_LANGUAGE_STANDARD = gnu11; 284 | GCC_DYNAMIC_NO_PIC = NO; 285 | GCC_NO_COMMON_BLOCKS = YES; 286 | GCC_OPTIMIZATION_LEVEL = 0; 287 | GCC_PREPROCESSOR_DEFINITIONS = ( 288 | "DEBUG=1", 289 | "$(inherited)", 290 | ); 291 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 292 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 293 | GCC_WARN_UNDECLARED_SELECTOR = YES; 294 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 295 | GCC_WARN_UNUSED_FUNCTION = YES; 296 | GCC_WARN_UNUSED_VARIABLE = YES; 297 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 298 | MTL_FAST_MATH = YES; 299 | ONLY_ACTIVE_ARCH = YES; 300 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 301 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 302 | }; 303 | name = Debug; 304 | }; 305 | 4B261F4527C5D52C00D56A66 /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_ANALYZER_NONNULL = YES; 310 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 311 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 312 | CLANG_CXX_LIBRARY = "libc++"; 313 | CLANG_ENABLE_MODULES = YES; 314 | CLANG_ENABLE_OBJC_ARC = YES; 315 | CLANG_ENABLE_OBJC_WEAK = YES; 316 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 317 | CLANG_WARN_BOOL_CONVERSION = YES; 318 | CLANG_WARN_COMMA = YES; 319 | CLANG_WARN_CONSTANT_CONVERSION = YES; 320 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 323 | CLANG_WARN_EMPTY_BODY = YES; 324 | CLANG_WARN_ENUM_CONVERSION = YES; 325 | CLANG_WARN_INFINITE_RECURSION = YES; 326 | CLANG_WARN_INT_CONVERSION = YES; 327 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 328 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 329 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 330 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 331 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 332 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 333 | CLANG_WARN_STRICT_PROTOTYPES = YES; 334 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 335 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 336 | CLANG_WARN_UNREACHABLE_CODE = YES; 337 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 338 | COPY_PHASE_STRIP = NO; 339 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 340 | ENABLE_NS_ASSERTIONS = NO; 341 | ENABLE_STRICT_OBJC_MSGSEND = YES; 342 | GCC_C_LANGUAGE_STANDARD = gnu11; 343 | GCC_NO_COMMON_BLOCKS = YES; 344 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 345 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 346 | GCC_WARN_UNDECLARED_SELECTOR = YES; 347 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 348 | GCC_WARN_UNUSED_FUNCTION = YES; 349 | GCC_WARN_UNUSED_VARIABLE = YES; 350 | MTL_ENABLE_DEBUG_INFO = NO; 351 | MTL_FAST_MATH = YES; 352 | SWIFT_COMPILATION_MODE = wholemodule; 353 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 354 | }; 355 | name = Release; 356 | }; 357 | 4B261F4727C5D52C00D56A66 /* Debug */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 361 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 362 | CODE_SIGN_STYLE = Automatic; 363 | CURRENT_PROJECT_VERSION = 1; 364 | DEVELOPMENT_TEAM = 5FRV5G4F5S; 365 | ENABLE_PREVIEWS = YES; 366 | GENERATE_INFOPLIST_FILE = YES; 367 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 368 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 369 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 370 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 371 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 372 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 373 | LD_RUNPATH_SEARCH_PATHS = ( 374 | "$(inherited)", 375 | "@executable_path/Frameworks", 376 | ); 377 | MARKETING_VERSION = 1.0; 378 | PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisContributionExample; 379 | PRODUCT_NAME = AxisContributionExample; 380 | SDKROOT = iphoneos; 381 | SWIFT_EMIT_LOC_STRINGS = YES; 382 | SWIFT_VERSION = 5.0; 383 | TARGETED_DEVICE_FAMILY = "1,2"; 384 | }; 385 | name = Debug; 386 | }; 387 | 4B261F4827C5D52C00D56A66 /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 391 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 392 | CODE_SIGN_STYLE = Automatic; 393 | CURRENT_PROJECT_VERSION = 1; 394 | DEVELOPMENT_TEAM = 5FRV5G4F5S; 395 | ENABLE_PREVIEWS = YES; 396 | GENERATE_INFOPLIST_FILE = YES; 397 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 398 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 399 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 400 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 401 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 402 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 403 | LD_RUNPATH_SEARCH_PATHS = ( 404 | "$(inherited)", 405 | "@executable_path/Frameworks", 406 | ); 407 | MARKETING_VERSION = 1.0; 408 | PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisContributionExample; 409 | PRODUCT_NAME = AxisContributionExample; 410 | SDKROOT = iphoneos; 411 | SWIFT_EMIT_LOC_STRINGS = YES; 412 | SWIFT_VERSION = 5.0; 413 | TARGETED_DEVICE_FAMILY = "1,2"; 414 | VALIDATE_PRODUCT = YES; 415 | }; 416 | name = Release; 417 | }; 418 | 4B261F4A27C5D52C00D56A66 /* Debug */ = { 419 | isa = XCBuildConfiguration; 420 | buildSettings = { 421 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 422 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 423 | CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; 424 | CODE_SIGN_STYLE = Automatic; 425 | COMBINE_HIDPI_IMAGES = YES; 426 | CURRENT_PROJECT_VERSION = 1; 427 | DEVELOPMENT_TEAM = 5FRV5G4F5S; 428 | ENABLE_HARDENED_RUNTIME = YES; 429 | ENABLE_PREVIEWS = YES; 430 | GENERATE_INFOPLIST_FILE = YES; 431 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 432 | LD_RUNPATH_SEARCH_PATHS = ( 433 | "$(inherited)", 434 | "@executable_path/../Frameworks", 435 | ); 436 | MACOSX_DEPLOYMENT_TARGET = 11.0; 437 | MARKETING_VERSION = 1.0; 438 | PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisContributionExample; 439 | PRODUCT_NAME = AxisContributionExample; 440 | SDKROOT = macosx; 441 | SWIFT_EMIT_LOC_STRINGS = YES; 442 | SWIFT_VERSION = 5.0; 443 | }; 444 | name = Debug; 445 | }; 446 | 4B261F4B27C5D52C00D56A66 /* Release */ = { 447 | isa = XCBuildConfiguration; 448 | buildSettings = { 449 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 450 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 451 | CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; 452 | CODE_SIGN_STYLE = Automatic; 453 | COMBINE_HIDPI_IMAGES = YES; 454 | CURRENT_PROJECT_VERSION = 1; 455 | DEVELOPMENT_TEAM = SM6445X39C; 456 | ENABLE_HARDENED_RUNTIME = YES; 457 | ENABLE_PREVIEWS = YES; 458 | GENERATE_INFOPLIST_FILE = YES; 459 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 460 | LD_RUNPATH_SEARCH_PATHS = ( 461 | "$(inherited)", 462 | "@executable_path/../Frameworks", 463 | ); 464 | MACOSX_DEPLOYMENT_TARGET = 11.0; 465 | MARKETING_VERSION = 1.0; 466 | PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisContributionExample; 467 | PRODUCT_NAME = AxisContributionExample; 468 | SDKROOT = macosx; 469 | SWIFT_EMIT_LOC_STRINGS = YES; 470 | SWIFT_VERSION = 5.0; 471 | }; 472 | name = Release; 473 | }; 474 | /* End XCBuildConfiguration section */ 475 | 476 | /* Begin XCConfigurationList section */ 477 | 4B261F2C27C5D52C00D56A66 /* Build configuration list for PBXProject "AxisContributionExample" */ = { 478 | isa = XCConfigurationList; 479 | buildConfigurations = ( 480 | 4B261F4427C5D52C00D56A66 /* Debug */, 481 | 4B261F4527C5D52C00D56A66 /* Release */, 482 | ); 483 | defaultConfigurationIsVisible = 0; 484 | defaultConfigurationName = Release; 485 | }; 486 | 4B261F4627C5D52C00D56A66 /* Build configuration list for PBXNativeTarget "AxisContributionExample (iOS)" */ = { 487 | isa = XCConfigurationList; 488 | buildConfigurations = ( 489 | 4B261F4727C5D52C00D56A66 /* Debug */, 490 | 4B261F4827C5D52C00D56A66 /* Release */, 491 | ); 492 | defaultConfigurationIsVisible = 0; 493 | defaultConfigurationName = Release; 494 | }; 495 | 4B261F4927C5D52C00D56A66 /* Build configuration list for PBXNativeTarget "AxisContributionExample (macOS)" */ = { 496 | isa = XCConfigurationList; 497 | buildConfigurations = ( 498 | 4B261F4A27C5D52C00D56A66 /* Debug */, 499 | 4B261F4B27C5D52C00D56A66 /* Release */, 500 | ); 501 | defaultConfigurationIsVisible = 0; 502 | defaultConfigurationName = Release; 503 | }; 504 | /* End XCConfigurationList section */ 505 | 506 | /* Begin XCSwiftPackageProductDependency section */ 507 | 4B261F5927C5E3B400D56A66 /* AxisContribution */ = { 508 | isa = XCSwiftPackageProductDependency; 509 | productName = AxisContribution; 510 | }; 511 | 4B261F5B27C5E3B700D56A66 /* AxisContribution */ = { 512 | isa = XCSwiftPackageProductDependency; 513 | productName = AxisContribution; 514 | }; 515 | /* End XCSwiftPackageProductDependency section */ 516 | }; 517 | rootObject = 4B261F2927C5D52C00D56A66 /* Project object */; 518 | } 519 | -------------------------------------------------------------------------------- /AxisContributionExample/AxisContributionExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AxisContributionExample/AxisContributionExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AxisContributionExample/AxisContributionExample.xcodeproj/xcshareddata/xcschemes/AxisContribution.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | }, 93 | { 94 | "idiom" : "mac", 95 | "scale" : "1x", 96 | "size" : "16x16" 97 | }, 98 | { 99 | "idiom" : "mac", 100 | "scale" : "2x", 101 | "size" : "16x16" 102 | }, 103 | { 104 | "idiom" : "mac", 105 | "scale" : "1x", 106 | "size" : "32x32" 107 | }, 108 | { 109 | "idiom" : "mac", 110 | "scale" : "2x", 111 | "size" : "32x32" 112 | }, 113 | { 114 | "idiom" : "mac", 115 | "scale" : "1x", 116 | "size" : "128x128" 117 | }, 118 | { 119 | "idiom" : "mac", 120 | "scale" : "2x", 121 | "size" : "128x128" 122 | }, 123 | { 124 | "idiom" : "mac", 125 | "scale" : "1x", 126 | "size" : "256x256" 127 | }, 128 | { 129 | "idiom" : "mac", 130 | "scale" : "2x", 131 | "size" : "256x256" 132 | }, 133 | { 134 | "idiom" : "mac", 135 | "scale" : "1x", 136 | "size" : "512x512" 137 | }, 138 | { 139 | "idiom" : "mac", 140 | "scale" : "2x", 141 | "size" : "512x512" 142 | } 143 | ], 144 | "info" : { 145 | "author" : "xcode", 146 | "version" : 1 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/AxisContributionExampleApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AxisContributionExampleApp.swift 3 | // AxisContributionExample 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | @main 12 | struct AxisContributionExampleApp: App { 13 | var body: some Scene { 14 | WindowGroup { 15 | ContentView() 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // AxisContributionExample 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import AxisContribution 11 | 12 | struct ContentView: View { 13 | 14 | @Environment(\.colorScheme) private var colorScheme 15 | 16 | @State private var constant: ACConstant = .init(axisMode: .horizontal, levelLabel: .number) 17 | @State private var rowSize: CGFloat = 11 18 | @State private var rowImageName: String = "" 19 | @State private var dataSet: [Date: ACData] = [:] 20 | 21 | var body: some View { 22 | VStack { 23 | Spacer() 24 | // AxisContribution(constant: constant, source: getDates()) 25 | AxisContribution(constant: constant, source: dataSet) { indexSet, data in 26 | if rowImageName.isEmpty { 27 | defaultBackground 28 | }else { 29 | background 30 | } 31 | } foreground: { indexSet, data in 32 | if rowImageName.isEmpty { 33 | defaultForeground 34 | }else { 35 | foreground 36 | } 37 | } 38 | .padding(8) 39 | .background( 40 | RoundedRectangle(cornerRadius: 12) 41 | .stroke(lineWidth: 1) 42 | .fill(Color.gray) 43 | .opacity(0.5) 44 | ) 45 | .frame(maxWidth: 600, maxHeight: 600) 46 | 47 | Spacer() 48 | Picker("", selection: $rowImageName) { 49 | Text("Default").tag("") 50 | Image(systemName: "heart.fill").tag("heart.fill") 51 | Image(systemName: "umbrella.fill").tag("umbrella.fill") 52 | Image(systemName: "flame.fill").tag("flame.fill") 53 | Image(systemName: "seal.fill").tag("seal.fill") 54 | } 55 | .pickerStyle(.segmented) 56 | HStack { 57 | Text("Row Size : ") 58 | Slider(value: $rowSize, in: 11...40) 59 | Text("\(rowSize, specifier: "%.2f")") 60 | } 61 | Picker("", selection: $constant.axisMode) { 62 | Text("Horizontal").tag(ACAxisMode.horizontal) 63 | Text("Vertical").tag(ACAxisMode.vertical) 64 | } 65 | .pickerStyle(.segmented) 66 | Button("Refresh Dates") { 67 | dataSet = getDates() 68 | } 69 | .padding() 70 | } 71 | .padding() 72 | .onAppear { 73 | dataSet = getDates() 74 | } 75 | } 76 | 77 | private var defaultBackground: some View { 78 | Rectangle() 79 | .fill(Color(hex: colorScheme == .dark ? 0x171B21 : 0xF0F0F0)) 80 | .frame(width: rowSize, height: rowSize) 81 | .cornerRadius(2) 82 | } 83 | 84 | private var defaultForeground: some View { 85 | Rectangle() 86 | .fill(Color(hex: 0x6CD164)) 87 | .frame(width: rowSize, height: rowSize) 88 | .border(Color.white.opacity(0.2), width: 1) 89 | .cornerRadius(2) 90 | } 91 | 92 | private var background: some View { 93 | Image(systemName: rowImageName) 94 | .foregroundColor(Color(hex: colorScheme == .dark ? 0x171B21 : 0xF0F0F0)) 95 | .font(.system(size: rowSize)) 96 | .frame(width: rowSize, height: rowSize) 97 | } 98 | 99 | private var foreground: some View { 100 | Image(systemName: rowImageName) 101 | .foregroundColor(Color(hex: 0x6CD164)) 102 | .font(.system(size: rowSize)) 103 | .frame(width: rowSize, height: rowSize) 104 | } 105 | 106 | private func getDates() -> [Date: ACData] { 107 | var sequenceDatas = [Date: ACData]() 108 | for _ in 0..<300 { 109 | let date = Date.randomBetween(start: Date().dateHalfAyear, end: Date()) 110 | sequenceDatas[date.startOfDay] = .init(date: date.startOfDay, count: Int.random(in: 0...10)) 111 | } 112 | return sequenceDatas 113 | } 114 | } 115 | 116 | struct ContentView_Previews: PreviewProvider { 117 | static var previews: some View { 118 | ContentView().preferredColorScheme(.dark) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/Extensions/Color+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Color+Extensions.swift 3 | // AxisContributionExample 4 | // 5 | // Created by jasu on 2021/12/08. 6 | // Copyright (c) 2021 jasu All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | extension Color { 12 | 13 | init(hex: UInt, alpha: Double = 1) { 14 | self.init( 15 | .sRGB, 16 | red: Double((hex >> 16) & 0xff) / 255, 17 | green: Double((hex >> 08) & 0xff) / 255, 18 | blue: Double((hex >> 00) & 0xff) / 255, 19 | opacity: alpha 20 | ) 21 | } 22 | 23 | init(hex: String) { 24 | let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) 25 | var int: UInt64 = 0 26 | Scanner(string: hex).scanHexInt64(&int) 27 | let a, r, g, b: UInt64 28 | switch hex.count { 29 | case 3: // RGB (12-bit) 30 | (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) 31 | case 6: // RGB (24-bit) 32 | (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) 33 | case 8: // ARGB (32-bit) 34 | (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) 35 | default: 36 | (a, r, g, b) = (1, 1, 1, 0) 37 | } 38 | 39 | self.init( 40 | .sRGB, 41 | red: Double(r) / 255, 42 | green: Double(g) / 255, 43 | blue: Double(b) / 255, 44 | opacity: Double(a) / 255 45 | ) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AxisContributionExample/Shared/Extensions/Date+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Date+Extensions.swift 3 | // AxisContributionExample 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | extension Date { 12 | static func randomBetween(start: Date, end: Date) -> Date { 13 | var date1 = start 14 | var date2 = end 15 | if date2 < date1 { 16 | let temp = date1 17 | date1 = date2 18 | date2 = temp 19 | } 20 | let span = TimeInterval.random(in: date1.timeIntervalSinceNow...date2.timeIntervalSinceNow) 21 | return Date(timeIntervalSinceNow: span) 22 | } 23 | 24 | var dateHalfAyear: Date { 25 | var components = DateComponents() 26 | components.month = -6 27 | guard let date = Calendar.current.date(byAdding: components, to: startOfDay) else { return Date() } 28 | return date 29 | } 30 | 31 | var startOfDay: Date { 32 | return Calendar.current.startOfDay(for: self) 33 | } 34 | 35 | var day: Int { 36 | let calendar = Calendar.current 37 | let components = calendar.dateComponents([.day], from: self) 38 | return components.day ?? 1 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AxisContributionExample/macOS/macOS.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 jasu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Markdown/Horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasudev/AxisContribution/219ca810cd7ea40fea2813bc313c2239133c61f3/Markdown/Horizontal.png -------------------------------------------------------------------------------- /Markdown/Horizontal_heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasudev/AxisContribution/219ca810cd7ea40fea2813bc313c2239133c61f3/Markdown/Horizontal_heart.png -------------------------------------------------------------------------------- /Markdown/Vertical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasudev/AxisContribution/219ca810cd7ea40fea2813bc313c2239133c61f3/Markdown/Vertical.png -------------------------------------------------------------------------------- /Markdown/Vertical_heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasudev/AxisContribution/219ca810cd7ea40fea2813bc313c2239133c61f3/Markdown/Vertical_heart.png -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "AxisContribution", 8 | platforms: [ 9 | .iOS(.v14), 10 | .macOS(.v11) 11 | ], 12 | products: [ 13 | // Products define the executables and libraries a package produces, and make them visible to other packages. 14 | .library( 15 | name: "AxisContribution", 16 | targets: ["AxisContribution"]), 17 | ], 18 | dependencies: [ 19 | // Dependencies declare other packages that this package depends on. 20 | // .package(url: /* package url */, from: "1.0.0"), 21 | ], 22 | targets: [ 23 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 24 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 25 | .target( 26 | name: "AxisContribution", 27 | dependencies: []), 28 | .testTarget( 29 | name: "AxisContributionTests", 30 | dependencies: ["AxisContribution"]), 31 | ] 32 | ) 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **AxisContribution for SwiftUI** 2 | A library that expresses a github contribution calendar through an array of dates. Supports iOS and macOS. 3 | 4 | [![Platforms](https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS-blue?style=flat-square)](https://developer.apple.com/macOS) 5 | [![iOS](https://img.shields.io/badge/iOS-14.0-blue.svg)](https://developer.apple.com/iOS) 6 | [![macOS](https://img.shields.io/badge/macOS-11.0-blue.svg)](https://developer.apple.com/macOS) 7 | [![instagram](https://img.shields.io/badge/instagram-@dev.fabula-orange.svg?style=flat-square)](https://www.instagram.com/dev.fabula) 8 | [![SPM](https://img.shields.io/badge/SPM-compatible-red?style=flat-square)](https://developer.apple.com/documentation/swift_packages/package/) 9 | [![MIT](https://img.shields.io/badge/licenses-MIT-red.svg)](https://opensource.org/licenses/MIT) 10 | 11 | ## Screenshot 12 | |Horizontal|Vertical| 13 | |:---:|:---:| 14 | ||| 15 | ||| 16 | 17 | https://user-images.githubusercontent.com/1617304/155326706-f3c7400a-797c-44a0-8dcf-3e113b9943cc.mov 18 | 19 | ## Example 20 | [https://fabulaapp.page.link/231](https://fabulaapp.page.link/231) 21 | 22 | ## Usages 23 | ```swift 24 | /// Initializes `ACConstant` 25 | /// - Parameters: 26 | /// - fromDate: The start date to display the list of contributions. The default value is `1 year from today.`. 27 | /// - toDate: The end date to display the list of contributions. The default value is `today`. 28 | /// - spacing: The spacing in the row view showing the list of contributions. The default value is `4`. 29 | /// - levelSpacing: A number that separates units between contribution levels. The default value is `3`. 30 | /// - axisMode: The axis mode of the component. The default value is `.horizontal`. 31 | /// - font: The font used for text. The default value is `.system(size: 9)`. 32 | 33 | AxisContribution(constant: .init(), source: [Date(), Date()]) 34 | // or 35 | AxisContribution(constant: .init(), source: [Date(), Date()]) { indexSet, data in 36 | Image(systemName: "heart.fill") 37 | .foregroundColor(Color(hex: colorScheme == .dark ? 0x171B21 : 0xF0F0F0)) 38 | .font(.system(size: rowSize)) 39 | .frame(width: rowSize, height: rowSize) 40 | } foreground: { indexSet, data in 41 | Image(systemName: "heart.fill") 42 | .foregroundColor(Color(hex: 0x6CD164)) 43 | .font(.system(size: rowSize)) 44 | .frame(width: rowSize, height: rowSize) 45 | } 46 | ``` 47 | 48 | ## Swift Package Manager 49 | The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. Once you have your Swift package set up, adding AxisContribution as a dependency is as easy as adding it to the dependencies value of your Package.swift. 50 | 51 | ```swift 52 | dependencies: [ 53 | .package(url: "https://github.com/jasudev/AxisContribution.git", .branch("main")) 54 | ] 55 | ``` 56 | 57 | ## Contact 58 | instagram : [@dev.fabula](https://www.instagram.com/dev.fabula) 59 | email : [dev.fabula@gmail.com](mailto:dev.fabula@gmail.com) 60 | 61 | ## License 62 | AxisContribution is available under the MIT license. See the [LICENSE](LICENSE) file for more info. 63 | -------------------------------------------------------------------------------- /Sources/AxisContribution/AxisContribution.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AxisContribution.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// Defines the unit of contribution level. 29 | enum ACLevel: Int, CaseIterable { 30 | case zero = 0, first, second, third, fourth 31 | 32 | /// Opacity value according to level. 33 | var opacity: CGFloat { 34 | switch self { 35 | case .zero: return 0 36 | case .first: return 0.3 37 | case .second: return 0.5 38 | case .third: return 0.7 39 | case .fourth: return 0.9 40 | } 41 | } 42 | } 43 | 44 | public struct AxisContribution: View where B: View, F: View { 45 | 46 | @Environment(\.colorScheme) private var colorScheme 47 | @StateObject private var store = ACDataStore() 48 | 49 | private var constant: ACConstant = .init() 50 | private var sourceDatas: [Date: ACData] = [:] 51 | private var externalDatas: [[ACData]]? = nil 52 | 53 | public var background: ((ACIndexSet?, ACData?) -> B)? = nil 54 | public var foreground: ((ACIndexSet?, ACData?) -> F)? = nil 55 | 56 | private var defaultRowSize: CGFloat = 11 57 | @Namespace private var trailing 58 | 59 | public var body: some View { 60 | ScrollViewReader { proxy in 61 | VStack(alignment: .trailing, spacing: constant.spacing * 1.6) { 62 | ScrollView(constant.axisMode == .horizontal ? .horizontal : .vertical, showsIndicators: false) { 63 | if constant.axisMode == .horizontal { 64 | HStack(spacing: 0) { 65 | content 66 | Spacer() 67 | .frame(width: 0, height: 0) 68 | .id(trailing) 69 | .onAppear { 70 | proxy.scrollTo(trailing, anchor: .trailing) 71 | } 72 | } 73 | .contentShape(Rectangle()) 74 | }else { 75 | VStack(spacing: 0) { 76 | content 77 | } 78 | .contentShape(Rectangle()) 79 | } 80 | } 81 | levelView 82 | } 83 | } 84 | .environmentObject(store) 85 | .onChange(of: sourceDatas) { newValue in 86 | store.setup(constant: self.constant, source: newValue) 87 | } 88 | .onAppear(perform: { 89 | self.fetch() 90 | }) 91 | } 92 | 93 | //MARK: - Properties 94 | 95 | /// A content view that displays a grid view. 96 | private var content: some View { 97 | ACGridStack(constant: constant) { indexSet, data in 98 | getBackgroundView(indexSet, data) 99 | } foreground: { indexSet, data in 100 | getForegroundView(indexSet, data) 101 | } 102 | } 103 | 104 | /// The background view of the default row view. 105 | private var defaultBackground: some View { 106 | Rectangle() 107 | .fill(Color(hex: colorScheme == .dark ? 0x171B21 : 0xF0F0F0)) 108 | .frame(width: defaultRowSize, height: defaultRowSize) 109 | .cornerRadius(2) 110 | } 111 | 112 | /// The foreground view of the default row view. 113 | private var defaultForeground: some View { 114 | Rectangle() 115 | .fill(Color(hex: 0x6CD164)) 116 | .frame(width: defaultRowSize, height: defaultRowSize) 117 | .border(Color.white.opacity(0.2), width: 1) 118 | .cornerRadius(2) 119 | } 120 | 121 | /// A view that displays level unit information. 122 | @ViewBuilder 123 | private var levelView: some View { 124 | if constant.showLevelView { 125 | HStack(spacing: constant.spacing * 0.5) { 126 | Text(constant.levelLabel == .moreOrLess ? "Less" : "0") 127 | .font(constant.font) 128 | .opacity(0.6) 129 | HStack(spacing: 0) { 130 | ForEach(ACLevel.allCases, id:\.self) { level in 131 | ZStack { 132 | getBackgroundView(nil, nil) 133 | getForegroundView(nil, nil) 134 | .opacity(level.opacity) 135 | } 136 | }.scaleEffect(0.82) 137 | } 138 | Text(constant.levelLabel == .moreOrLess ? "More" : "\(constant.levelSpacing * 4)+") 139 | .font(constant.font) 140 | .opacity(0.6) 141 | } 142 | } 143 | } 144 | 145 | //MARK: - Methods 146 | 147 | /// The background view of the row view. 148 | /// - Parameters: 149 | /// - indexSet: The location index information of the row view displayed in the grid. 150 | /// - data: The model that defines the row view. 151 | /// - Returns: - 152 | private func getBackgroundView(_ indexSet: ACIndexSet? = nil, _ data: ACData? = nil) -> some View { 153 | Group { 154 | if let background = background { 155 | background(indexSet, data) 156 | }else { 157 | defaultBackground 158 | } 159 | } 160 | } 161 | 162 | /// The foreground view of the row view. 163 | /// - Parameters: 164 | /// - indexSet: The location index information of the row view displayed in the grid. 165 | /// - data: The model that defines the row view. 166 | /// - Returns: - 167 | private func getForegroundView(_ indexSet: ACIndexSet? = nil, _ data: ACData? = nil) -> some View { 168 | Group { 169 | if let foreground = foreground { 170 | foreground(indexSet, data) 171 | }else { 172 | defaultForeground 173 | } 174 | } 175 | } 176 | 177 | /// Fetch data. 178 | private func fetch() { 179 | if let externalDatas = externalDatas { 180 | store.setup(constant: self.constant, external: externalDatas) 181 | }else { 182 | store.setup(constant: self.constant, source: self.sourceDatas) 183 | } 184 | } 185 | } 186 | 187 | public extension AxisContribution where B == EmptyView, F == EmptyView { 188 | 189 | /// Initializes `AxisContribution` 190 | /// - Parameters: 191 | /// - constant: Settings that define the contribution view. 192 | /// - sourceDates: An array of contributed dates. 193 | init(constant: ACConstant = .init(), source sourceDates: [Date: ACData] = [:]) { 194 | self.constant = constant 195 | self.sourceDatas = sourceDates 196 | } 197 | 198 | /// Initializes `AxisContribution` 199 | /// - Parameters: 200 | /// - constant: Settings that define the contribution view. 201 | /// - externalDatas: Externally passed data. If data exists, external data takes precedence. 202 | init(constant: ACConstant = .init(), external externalDatas: [[ACData]]? = nil) { 203 | self.constant = constant 204 | self.externalDatas = externalDatas 205 | } 206 | } 207 | 208 | public extension AxisContribution where B : View, F : View { 209 | 210 | /// Initializes `AxisContribution` 211 | /// - Parameters: 212 | /// - constant: Settings that define the contribution view. 213 | /// - sourceDates: An array of contributed dates. 214 | /// - background: The view that is the background of the row view. 215 | /// - foreground: The view that is the foreground of the row view. 216 | init(constant: ACConstant = .init(), 217 | source sourceDates: [Date: ACData] = [:], 218 | @ViewBuilder background: @escaping (ACIndexSet?, ACData?) -> B, 219 | @ViewBuilder foreground: @escaping (ACIndexSet?, ACData?) -> F) { 220 | self.constant = constant 221 | self.sourceDatas = sourceDates 222 | self.background = background 223 | self.foreground = foreground 224 | } 225 | 226 | /// Initializes `AxisContribution` 227 | /// - Parameters: 228 | /// - constant: Settings that define the contribution view. 229 | /// - background: The view that is the background of the row view. 230 | /// - foreground: The view that is the foreground of the row view. 231 | /// - externalDatas: Externally passed data. If data exists, external data takes precedence. 232 | init(constant: ACConstant = .init(), external externalDatas: [[ACData]]? = nil, 233 | @ViewBuilder background: @escaping (ACIndexSet?, ACData?) -> B, 234 | @ViewBuilder foreground: @escaping (ACIndexSet?, ACData?) -> F) { 235 | self.constant = constant 236 | self.background = background 237 | self.foreground = foreground 238 | self.externalDatas = externalDatas 239 | } 240 | } 241 | 242 | struct AxisContribution_Previews: PreviewProvider { 243 | static var previews: some View { 244 | AxisContribution(constant: .init(), source: [:]) 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Extentions/Color+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Color+Extensions.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2021/12/08. 6 | // Copyright (c) 2021 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | extension Color { 29 | 30 | init(hex: UInt, alpha: Double = 1) { 31 | self.init( 32 | .sRGB, 33 | red: Double((hex >> 16) & 0xff) / 255, 34 | green: Double((hex >> 08) & 0xff) / 255, 35 | blue: Double((hex >> 00) & 0xff) / 255, 36 | opacity: alpha 37 | ) 38 | } 39 | 40 | init(hex: String) { 41 | let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) 42 | var int: UInt64 = 0 43 | Scanner(string: hex).scanHexInt64(&int) 44 | let a, r, g, b: UInt64 45 | switch hex.count { 46 | case 3: // RGB (12-bit) 47 | (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) 48 | case 6: // RGB (24-bit) 49 | (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) 50 | case 8: // ARGB (32-bit) 51 | (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) 52 | default: 53 | (a, r, g, b) = (1, 1, 1, 0) 54 | } 55 | 56 | self.init( 57 | .sRGB, 58 | red: Double(r) / 255, 59 | green: Double(g) / 255, 60 | blue: Double(b) / 255, 61 | opacity: Double(a) / 255 62 | ) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Extentions/Date+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Date+Extensions.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/22. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | extension Date { 29 | static func datesWeekly(from fromDate: Date, to toDate: Date) -> [Date] { 30 | var dates: [Date] = [] 31 | var date = fromDate 32 | 33 | while date <= toDate { 34 | dates.append(date) 35 | guard let newDate = Calendar.current.date(byAdding: .day, value: 7, to: date) else { break } 36 | date = newDate.startOfWeek 37 | } 38 | return dates 39 | } 40 | 41 | var dateYearAgo: Date { 42 | var components = DateComponents() 43 | components.year = -1 44 | guard let date = Calendar.current.date(byAdding: components, to: startOfDay) else { return Date() } 45 | return date 46 | } 47 | 48 | var dateMonthAgo: Date { 49 | var components = DateComponents() 50 | components.month = -1 51 | guard let date = Calendar.current.date(byAdding: components, to: startOfDay) else { return Date() } 52 | return date 53 | } 54 | 55 | var datesInWeek: [Date] { 56 | var dates: [Date] = [] 57 | for i in 0..<7 { 58 | if let date = Calendar.current.date(byAdding: .weekday, value: i, to: startOfWeek) { 59 | dates.append(date) 60 | } 61 | } 62 | return dates 63 | } 64 | 65 | var isToday: Bool { 66 | let currentDate = Calendar.current.dateComponents([.day, .month, .year], from: self) 67 | let today = Calendar.current.dateComponents([.day, .month, .year], from: Date()) 68 | return currentDate == today 69 | } 70 | 71 | var yesterday: Date { 72 | var components = DateComponents() 73 | components.day = -1 74 | guard let date = Calendar.current.date(byAdding: components, to: startOfDay) else { return Date() } 75 | return date 76 | } 77 | 78 | var tomorrow: Date { 79 | var components = DateComponents() 80 | components.day = 1 81 | guard let date = Calendar.current.date(byAdding: components, to: startOfDay) else { return Date() } 82 | return date 83 | } 84 | 85 | var startOfDay: Date { 86 | return Calendar.current.startOfDay(for: self) 87 | } 88 | 89 | var startOfWeek: Date { 90 | let current = Calendar.current 91 | let monday = current.date(from: current.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) 92 | return monday! 93 | } 94 | 95 | var day: Int { 96 | let calendar = Calendar.current 97 | let components = calendar.dateComponents([.day], from: self) 98 | return components.day ?? 1 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Model/ACConstant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACConstant.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// Defines the horizontal/vertical orientation of the contribution view. 29 | public enum ACAxisMode: Equatable { 30 | /// Display the view horizontally. 31 | case horizontal 32 | /// Displays the view vertically. 33 | case vertical 34 | } 35 | 36 | /// Defines the label type of level label below the grid view. 37 | public enum ACLevelLavel: Equatable { 38 | case moreOrLess 39 | case number 40 | } 41 | 42 | /// Settings that define the contribution view. 43 | public struct ACConstant: Equatable { 44 | 45 | /// The start date to display the list of contributions. 46 | public var fromDate: Date 47 | 48 | /// The end date to display the list of contributions. 49 | public var toDate: Date 50 | 51 | /// The spacing in the row view showing the list of contributions. 52 | public var spacing: CGFloat 53 | 54 | /// A number that separates units between contribution levels. 55 | public var levelSpacing: Int 56 | 57 | /// The axis mode of the component. 58 | public var axisMode: ACAxisMode 59 | 60 | /// The font used for text. 61 | public var font: Font 62 | 63 | /// Whether the level label below the grid view is visible 64 | public var showLevelView: Bool 65 | 66 | /// The label type of the level label. 67 | public var levelLabel: ACLevelLavel 68 | 69 | /// Whether the January month should be replaced by the year 70 | public var showYearForJan: Bool 71 | 72 | /// Initializes `ACConstant` 73 | /// - Parameters: 74 | /// - fromDate: The start date to display the list of contributions. The default value is `1 year from today.`. 75 | /// - toDate: The end date to display the list of contributions. The default value is `today`. 76 | /// - spacing: The spacing in the row view showing the list of contributions. The default value is `4`. 77 | /// - levelSpacing: A number that separates units between contribution levels. The default value is `3`. 78 | /// - axisMode: The axis mode of the component. The default value is `.horizontal`. 79 | /// - font: The font used for text. The default value is `.system(size: 9)`. 80 | /// - showLevelView: Whether the level label below the grid view is visible. The default value is `true`. 81 | /// - levelLabel: The label type of the level label. The default value is `.moreOrLess`. 82 | /// - showYearForJan: Show the year instead of the January label. The default value is `false`. 83 | public init(from fromDate: Date? = nil, 84 | to toDate: Date? = nil, 85 | spacing: CGFloat = 4, 86 | levelSpacing: Int = 3, 87 | axisMode: ACAxisMode = .horizontal, 88 | font: Font = .system(size: 9), 89 | showLevelView: Bool = true, 90 | levelLabel: ACLevelLavel = .moreOrLess, 91 | showYearForJan: Bool = false) { 92 | self.fromDate = fromDate == nil ? Date().dateYearAgo : fromDate! 93 | self.toDate = toDate == nil ? Date() : toDate! 94 | self.spacing = spacing 95 | self.levelSpacing = levelSpacing 96 | self.axisMode = axisMode 97 | self.font = font 98 | self.showLevelView = showLevelView 99 | self.levelLabel = levelLabel 100 | self.showYearForJan = showYearForJan 101 | } 102 | 103 | public static func == (lhs: Self, rhs: Self) -> Bool { 104 | lhs.fromDate == rhs.fromDate && 105 | lhs.toDate == rhs.toDate && 106 | lhs.spacing == rhs.spacing && 107 | lhs.levelSpacing == rhs.levelSpacing && 108 | lhs.axisMode == rhs.axisMode && 109 | lhs.font == rhs.font && 110 | lhs.showLevelView == rhs.showLevelView 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Model/ACData.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACData.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// The model that defines the row view. 29 | public class ACData: Equatable { 30 | 31 | /// Current date. 32 | public var date: Date 33 | 34 | /// The number contributed to the current date. 35 | public var count: Int 36 | 37 | /// Initializes `ACData` 38 | /// - Parameters: 39 | /// - date: Current date. 40 | /// - count: The number contributed to the current date. The default value is `0`. 41 | public init(date: Date, count: Int = 0) { 42 | self.date = date 43 | self.count = count 44 | } 45 | 46 | public static func == (lhs: ACData, rhs: ACData) -> Bool { 47 | lhs.date == rhs.date && lhs.count == lhs.count 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Model/ACIndexSet.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACIndexSet.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// The location index information of the row view displayed in the grid. 29 | public struct ACIndexSet: Equatable { 30 | let column: Int 31 | let row: Int 32 | } 33 | -------------------------------------------------------------------------------- /Sources/AxisContribution/Util/SizeModifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SizeModifier.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// A modifier used to check the size of a child view. 29 | struct SizeModifier: ViewModifier { 30 | 31 | @Binding var size: CGSize 32 | 33 | init(_ size: Binding) { 34 | _size = size 35 | } 36 | 37 | func body(content: Content) -> some View { 38 | content 39 | .background( 40 | GeometryReader { proxy in 41 | Color.clear.preference(key: SizePreferenceKey.self, value: proxy.size) 42 | } 43 | ) 44 | .onPreferenceChange(SizePreferenceKey.self) { preference in 45 | self.size = preference 46 | } 47 | } 48 | } 49 | 50 | extension View { 51 | func takeSize(_ size: Binding) -> some View { 52 | self.modifier(SizeModifier(size)) 53 | } 54 | } 55 | 56 | struct SizePreferenceKey: PreferenceKey { 57 | typealias V = CGSize 58 | static var defaultValue: V = .zero 59 | static func reduce(value: inout V, nextValue: () -> V) { 60 | value = nextValue() 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sources/AxisContribution/View/ACGridStack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACGridStack.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// A view that represents a grid view. 29 | struct ACGridStack: View where B: View, F: View { 30 | @EnvironmentObject private var store: ACDataStore 31 | 32 | let constant: ACConstant 33 | var background: ((ACIndexSet?, ACData?) -> B)? 34 | var foreground: ((ACIndexSet?, ACData?) -> F)? 35 | 36 | @State private var rowSize: CGSize = .zero 37 | @State private var titleWidth: CGFloat = .zero 38 | @State private var _titleSize: CGSize = .zero 39 | 40 | var body: some View { 41 | content 42 | .font(store.constant.font) 43 | } 44 | 45 | // MARK: - Properties 46 | 47 | /// Property that displays the grid view. 48 | private var content: some View { 49 | let spacing = store.constant.spacing 50 | return ZStack { 51 | if constant.axisMode == .horizontal { 52 | HStack(alignment: .top, spacing: spacing) { 53 | VStack(alignment: .trailing, spacing: 0) { 54 | Text("M") 55 | .frame(height: rowSize.height) 56 | .padding(.top, rowSize.height * 2 + spacing * 2) 57 | Text("W") 58 | .frame(height: rowSize.height) 59 | .padding(.top, rowSize.height + spacing * 2) 60 | Text("F") 61 | .frame(height: rowSize.height) 62 | .padding(.top, rowSize.height + spacing * 2) 63 | } 64 | ForEach(Array(store.datas.enumerated()), id: \.offset) { column, datas in 65 | LazyVStack(alignment: .leading, spacing: spacing) { 66 | Rectangle() 67 | .fill(Color.clear) 68 | .frame(width: rowSize.height, height: rowSize.height) 69 | .overlay(getMonthTitle(column), alignment: .leading) 70 | ForEach(Array(datas.enumerated()), id: \.offset) { row, data in 71 | getRowView(column: column, row: row, data: data) 72 | } 73 | } 74 | } 75 | } 76 | } else { 77 | VStack(alignment: .leading, spacing: spacing) { 78 | ZStack(alignment: .bottom) { 79 | let size = titleWidth 80 | Text("M") 81 | .offset(x: size + (rowSize.width * 1 + spacing * 2)) 82 | Text("W") 83 | .offset(x: size + (rowSize.width * 3 + spacing * 4)) 84 | Text("F") 85 | .offset(x: size + (rowSize.width * 5 + spacing * 5)) 86 | } 87 | ForEach(Array(store.datas.enumerated()), id: \.offset) { column, datas in 88 | HStack(alignment: .top, spacing: spacing) { 89 | Rectangle() 90 | .fill(Color.clear) 91 | .frame(width: titleWidth, height: rowSize.height) 92 | .overlay(getMonthTitle(column), alignment: .trailing) 93 | ForEach(Array(datas.enumerated()), id: \.offset) { row, data in 94 | getRowView(column: column, row: row, data: data) 95 | } 96 | } 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | // MARK: - Methods 104 | 105 | /// A method that returns a row view. 106 | /// - Parameters: 107 | /// - column: The column position index. 108 | /// - row: The row position index. 109 | /// - data: The model that defines the row view. 110 | /// - Returns: - 111 | private func getRowView(column: Int, row: Int, data: ACData) -> some View { 112 | ZStack { 113 | background?(ACIndexSet(column: column, row: row), data) 114 | foreground?(ACIndexSet(column: column, row: row), data) 115 | .opacity(getOpacity(count: data.count)) 116 | .takeSize($rowSize) 117 | } 118 | } 119 | 120 | /// A method returns the month title. 121 | /// - Parameter column: The column position index. 122 | /// - Returns: - 123 | private func getMonthTitle(_ column: Int) -> some View { 124 | ZStack { 125 | if !store.datas[0].isEmpty { 126 | if column >= 1 { 127 | if monthTitle(store.datas[column - 1][0].date) != monthTitle(store.datas[column][0].date) { 128 | Text(monthTitle(store.datas[column][0].date)) 129 | .lineLimit(1) 130 | .fixedSize(horizontal: true, vertical: false) 131 | .takeSize($_titleSize) 132 | } 133 | } else { 134 | let date = store.datas[column][0].date 135 | if date > constant.fromDate && date < constant.toDate { 136 | Text(monthTitle(date)) 137 | .lineLimit(1) 138 | .fixedSize(horizontal: true, vertical: false) 139 | .takeSize($_titleSize) 140 | } 141 | } 142 | } 143 | } 144 | .onChange(of: _titleSize) { _ in 145 | titleWidth = max(titleWidth, _titleSize.width) 146 | } 147 | } 148 | 149 | private func monthTitle(_ date: Date) -> String { 150 | let calendar = Calendar.current 151 | let monthTitles = calendar.shortMonthSymbols 152 | let components = calendar.dateComponents([.month, .year], from: date) 153 | let month = components.month 154 | if month == 1, constant.showYearForJan { 155 | return String(components.year!) 156 | } 157 | return monthTitles[month! - 1] 158 | } 159 | 160 | /// Returns the opacity value based on the level. 161 | /// - Parameter count: The number contributed to the current date. 162 | /// - Returns: Transparency value. 163 | private func getOpacity(count: Int) -> CGFloat { 164 | if count == 0 { 165 | return ACLevel.zero.opacity 166 | } else if ACLevel.first.rawValue * store.constant.levelSpacing >= count { 167 | return ACLevel.first.opacity 168 | } else if ACLevel.second.rawValue * store.constant.levelSpacing >= count { 169 | return ACLevel.second.opacity 170 | } else if ACLevel.third.rawValue * store.constant.levelSpacing >= count { 171 | return ACLevel.third.opacity 172 | } else if ACLevel.fourth.rawValue * store.constant.levelSpacing >= count { 173 | return ACLevel.fourth.opacity 174 | } 175 | return 1.0 176 | } 177 | } 178 | 179 | extension ACGridStack where B: View, F: View { 180 | /// Initializes `ACGridStack` 181 | /// - Parameters: 182 | /// - constant: Settings that define the contribution view. 183 | /// - background: The view that is the background of the row view. 184 | /// - foreground: The view that is the foreground of the row view. 185 | init(constant: ACConstant, 186 | @ViewBuilder background: @escaping (ACIndexSet?, ACData?) -> B, 187 | @ViewBuilder foreground: @escaping (ACIndexSet?, ACData?) -> F) 188 | { 189 | self.constant = constant 190 | self.background = background 191 | self.foreground = foreground 192 | } 193 | } 194 | 195 | struct ACGridStack_Previews: PreviewProvider { 196 | static var previews: some View { 197 | AxisContribution( 198 | constant: .init(), 199 | source: [:] 200 | ) 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /Sources/AxisContribution/ViewModel/ACDataProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACDataProvider.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/26. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// Create and provide data. 29 | public class ACDataProvider { 30 | 31 | public static let shared = ACDataProvider() 32 | 33 | /// Generate data from start date to end date. 34 | /// - Parameters: 35 | /// - constant: Settings that define the contribution view. 36 | /// - sourceDates: An array of contributed dates. 37 | /// - Returns: mapped data 38 | public func mappedData(constant: ACConstant, source sourceDates: [Date: ACData]) -> [[ACData]] { 39 | var newDatas = [[ACData]]() 40 | var dateWeekly = Date.datesWeekly(from: constant.fromDate, to: constant.toDate) 41 | if constant.axisMode == .vertical { 42 | dateWeekly = dateWeekly.reversed() 43 | } 44 | dateWeekly.forEach { date in 45 | let datas = date.datesInWeek.map { date -> ACData in 46 | if let data = sourceDates[date] { 47 | return data 48 | } else { 49 | return ACData(date: date, count: 0) 50 | } 51 | } 52 | newDatas.append(datas) 53 | } 54 | return newDatas 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Sources/AxisContribution/ViewModel/ACDataStore.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ACDataStore.swift 3 | // AxisContribution 4 | // 5 | // Created by jasu on 2022/02/23. 6 | // Copyright (c) 2022 jasu All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is furnished 13 | // to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 23 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | import SwiftUI 27 | 28 | /// A ViewModel that manages grid data. 29 | public class ACDataStore: ObservableObject { 30 | 31 | @Published var constant: ACConstant = .init() 32 | @Published var datas: [[ACData]] = [[]] 33 | 34 | /// A method that creates data. 35 | /// - Parameters: 36 | /// - constant: Settings that define the contribution view. 37 | /// - externalDatas: Externally passed data. If data exists, external data takes precedence. 38 | func setup(constant: ACConstant, external externalDatas: [[ACData]]) { 39 | self.constant = constant 40 | self.datas = externalDatas 41 | } 42 | 43 | /// A method that creates data. 44 | /// - Parameters: 45 | /// - constant: Settings that define the contribution view. 46 | /// - sourceDates: An array of contributed dates. 47 | func setup(constant: ACConstant, source sourceDates: [Date: ACData]? = nil) { 48 | self.constant = constant 49 | if let sourceDates = sourceDates { 50 | self.datas = ACDataProvider.shared.mappedData(constant: constant, source: sourceDates) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tests/AxisContributionTests/AxisContributionTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import AxisContribution 3 | 4 | final class AxisContributionTests: XCTestCase { 5 | func testExample() throws { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | // XCTAssertEqual(AxisContribution().text, "Hello, World!") 10 | } 11 | } 12 | --------------------------------------------------------------------------------