diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..969d294 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,307 @@ +name: "FSLineChart CI" + +on: + push: + branches: + - main + paths: + - 'Sources/**' + - 'Tests/**' + - '.github/workflows/**' + - 'Package.swift' + pull_request: + paths: + - 'Sources/**' + - 'Tests/**' + - '.github/workflows/**' + - 'Package.swift' + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true + +# Keep this up to date with https://github.com/FSLineChart/FSLineChart/blob/main/.github/workflows/ci.yml +# And also https://github.com/Alamofire/Alamofire/blob/master/.github/workflows/ci.yml +jobs: + macOS: + name: ${{ matrix.name }} + runs-on: ${{ matrix.runsOn }} + env: + DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - xcode: "Xcode_15.4" + runsOn: firebreak + name: "macOS 14, Xcode 15.4, Swift 5.10" + testPlan: "macOS" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.2" + runsOn: firebreak + name: "macOS 13, Xcode 15.2, Swift 5.9.2" + testPlan: "macOS" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.1" + runsOn: macOS-14 + name: "macOS 14, Xcode 15.1, Swift 5.9.1" + testPlan: "macOS" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.0.1" + runsOn: macOS-14 + name: "macOS 14, Xcode 15.0.1, Swift 5.9.0" + testPlan: "macOS" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_14.3.1" + runsOn: macOS-13 + name: "macOS 13, Xcode 14.3.1, Swift 5.8.0" + testPlan: "macOS" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_14.2" + runsOn: macOS-12 + name: "macOS 12, Xcode 14.2, Swift 5.7.2" + testPlan: "macOS" + outputFilter: xcpretty + - xcode: "Xcode_14.1" + runsOn: macOS-12 + name: "macOS 12, Xcode 14.1, Swift 5.7.1" + testPlan: "macOS" + outputFilter: xcpretty + steps: + - uses: actions/checkout@v4 + - name: ${{ matrix.name }} + run: |- + set -o pipefail + env NSUnbufferedIO=YES xcodebuild -project "FSLineChart.xcodeproj" -scheme "Example" -destination "platform=iOS" -testPlan "${{ matrix.testPlan }}" clean test | ${{ matrix.outputFilter }} + Catalyst: + name: ${{ matrix.name }} + runs-on: ${{ matrix.runsOn }} + env: + DEVELOPER_DIR: /Applications/${{ matrix.xcode }}.app/Contents/Developer + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - xcode: "Xcode_15.4" + name: "Catalyst 15.4" + runsOn: firebreak + - xcode: "Xcode_15.2" + name: "Catalyst 15.2" + runsOn: firebreak + - xcode: "Xcode_15.1" + name: "Catalyst 15.1" + runsOn: macOS-14 + - xcode: "Xcode_15.0.1" + name: "Catalyst 15.0" + runsOn: macOS-14 + - xcode: "Xcode_14.3.1" + name: "Catalyst 14.3.1" + runsOn: macOS-13 + steps: + - uses: actions/checkout@v4 + - name: Catalyst + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "FSLineChart.xcodeproj" -scheme "Example" -destination "platform=iOS" clean test 2>&1 | xcbeautify --renderer github-actions + iOS: + name: ${{ matrix.name }} + runs-on: ${{ matrix.runsOn }} + env: + DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - destination: "OS=17.5,name=iPhone 15 Pro" + name: "iOS 17.5" + testPlan: "iOS" + xcode: "Xcode_15.4" + runsOn: firebreak + - destination: "OS=17.2,name=iPhone 15 Pro" + name: "iOS 17.2" + testPlan: "iOS" + xcode: "Xcode_15.2" + runsOn: firebreak + - destination: "OS=17.0,name=iPhone 15 Pro" + name: "iOS 17.0" + testPlan: "iOS" + xcode: "Xcode_15.0.1" + runsOn: macOS-14 + - destination: "OS=16.4,name=iPhone 14 Pro" + name: "iOS 16.4" + testPlan: "iOS" + xcode: "Xcode_14.3.1" + runsOn: macOS-13 + - destination: "OS=15.5,name=iPhone 13 Pro" + name: "iOS 15.5" + testPlan: "iOS-NoTS" + xcode: "Xcode_14.3.1" + runsOn: firebreak + steps: + - uses: actions/checkout@v4 + - name: ${{ matrix.name }} + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "FSLineChart.xcodeproj" -scheme "Example" -destination "${{ matrix.destination }}" -testPlan "${{ matrix.testPlan }}" clean test 2>&1 | xcbeautify --renderer github-actions + tvOS: + name: ${{ matrix.name }} + runs-on: ${{ matrix.runsOn }} + env: + DEVELOPER_DIR: /Applications/${{ matrix.xcode }}.app/Contents/Developer + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - destination: "OS=17.5,name=Apple TV" + name: "tvOS 17.5" + testPlan: "tvOS" + xcode: "Xcode_15.4" + runsOn: firebreak + - destination: "OS=17.2,name=Apple TV" + name: "tvOS 17.2" + testPlan: "tvOS" + xcode: "Xcode_15.2" + runsOn: firebreak + - destination: "OS=17.0,name=Apple TV" + name: "tvOS 17.0" + testPlan: "tvOS" + xcode: "Xcode_15.0.1" + runsOn: macOS-14 + - destination: "OS=16.4,name=Apple TV" + name: "tvOS 16.4" + testPlan: "tvOS" + xcode: "Xcode_14.3.1" + runsOn: macOS-13 + - destination: "OS=15.4,name=Apple TV" + name: "tvOS 15.4" + testPlan: "tvOS-NoTS" + xcode: "Xcode_14.3.1" + runsOn: firebreak + steps: + - uses: actions/checkout@v4 + - name: ${{ matrix.name }} + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "FSLineChart.xcodeproj" -scheme "Example" -destination "${{ matrix.destination }}" -testPlan "${{ matrix.testPlan }}" clean test 2>&1 | xcbeautify --renderer github-actions + SPM: + name: ${{ matrix.name }} + runs-on: ${{ matrix.runsOn }} + env: + DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - xcode: "Xcode_15.4" + runsOn: firebreak + name: "macOS 14, SPM 5.10 Test" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.2" + runsOn: firebreak + name: "macOS 13, SPM 5.9.2 Test" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.1" + runsOn: macOS-14 + name: "macOS 14, SPM 5.9.1 Test" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_15.0.1" + runsOn: macOS-14 + name: "macOS 14, SPM 5.9.0 Test" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_14.3.1" + runsOn: macOS-13 + name: "macOS 13, SPM 5.8.0 Test" + outputFilter: xcbeautify --renderer github-actions + - xcode: "Xcode_14.2" + runsOn: macOS-12 + name: "macOS 12, SPM 5.7.2 Test" + outputFilter: xcpretty + - xcode: "Xcode_14.1" + runsOn: macOS-12 + name: "macOS 12, SPM 5.7.1 Test" + outputFilter: xcpretty + steps: + - uses: actions/checkout@v4 + - name: Test SPM + run: swift test -c debug | ${{ matrix.outputFilter }} + Linux: + name: Linux + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - image: swift:5.8-focal + - image: swift:5.8-jammy + - image: swift:5.8-centos7 + - image: swift:5.8-amazonlinux2 + - image: swift:5.8-rhel-ubi9 + - image: swift:5.9-focal + - image: swift:5.9-jammy + - image: swift:5.9-centos7 + - image: swift:5.9-amazonlinux2 + - image: swift:5.9-rhel-ubi9 + - image: swiftlang/swift:nightly-focal + - image: swiftlang/swift:nightly-jammy + - image: swiftlang/swift:nightly-amazonlinux2 + container: + image: ${{ matrix.image }} + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: ${{ matrix.image }} + run: swift build --build-tests -c debug + Android: + name: Android + uses: hggz/swift-android-sdk/.github/workflows/sdks.yml@ci + strategy: + fail-fast: false + with: + target-repo: ${{ github.repository }} + checkout-hash: ${{ github.sha }} + Windows: + name: ${{ matrix.name }} + runs-on: windows-latest + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - branch: swift-5.8-release + tag: 5.8-RELEASE + name: Windows Swift 5.8 + - branch: swift-5.9-release + tag: 5.9-RELEASE + name: Windows Swift 5.9 + - branch: swift-5.10-release + tag: 5.10-RELEASE + name: Windows Swift 5.10 + steps: + - name: Setup + uses: compnerd/gha-setup-swift@main + with: + branch: ${{ matrix.branch }} + tag: ${{ matrix.tag }} + - name: Clone + uses: actions/checkout@v4 + - name: SPM ${{ matrix.name }} + run: | + swift build --build-tests -c debug -Xlinker /INCREMENTAL:NO -v + CodeQL: + name: Analyze with CodeQL + runs-on: macOS-13 + env: + DEVELOPER_DIR: "/Applications/Xcode_14.3.1.app/Contents/Developer" + timeout-minutes: 10 + steps: + - name: Clone + uses: actions/checkout@v4 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: swift + - name: Build macOS + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "FSLineChart.xcodeproj" -scheme "Example" -destination "platform=macOS" clean build | xcpretty + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:swift" diff --git a/.gitignore b/.gitignore index a3cd143..52fe2f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,62 @@ # Xcode # -build/ -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -xcuserdata -*.xccheckout -*.moved-aside -DerivedData +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## Obj-C/Swift specific *.hmap + +## App packaging *.ipa -*.xcuserstate +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ # CocoaPods # # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: -# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control # # Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output diff --git a/FSLineChart.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata similarity index 69% rename from FSLineChart.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata index f03d496..919434a 100644 --- a/FSLineChart.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..71f77b5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Change Log +All notable changes to this project will be documented in this file. +FSLineChart adheres to [Semantic Versioning](http://semver.org/). + +## [Main](https://github.com/fulldecent/FSLineChart) +### Added + +### Changed + +### Removed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..047279a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,19 @@ +# Contributing + +All contributors are welcome. Please use issues and pull requests to contribute to the project. And update [CHANGELOG.md](CHANGELOG.md) when committing. + +## Making a change + +When you commit a change, please add a note to [CHANGELOG.md](CHANGELOG.md). + +## Release process + +1. Confirm the build is [passing in GitHub Actions](https://github.com/fulldecent/FSLineChart/actions) +2. Push a release commit + 1. Create a new Main section at the top + 2. Rename the old Main section like: + ## [1.0.5](https://github.com/fulldecent/FSLineChart/releases/tag/1.0.5) + Released on 2019-10-15. +3. Create a GitHub release + 1. Tag the release (like `1.0.5`) + 2. Paste notes from [CHANGELOG.md](CHANGELOG.md) \ No newline at end of file diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj new file mode 100644 index 0000000..2e572d5 --- /dev/null +++ b/Example/Example.xcodeproj/project.pbxproj @@ -0,0 +1,578 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXBuildFile section */ + D93672892DA620E500F3D5DC /* FSLineChart in Frameworks */ = {isa = PBXBuildFile; productRef = D93672882DA620E500F3D5DC /* FSLineChart */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + D936726B2DA61EF300F3D5DC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D93672552DA61EF200F3D5DC /* Project object */; + proxyType = 1; + remoteGlobalIDString = D936725C2DA61EF200F3D5DC; + remoteInfo = Example; + }; + D93672752DA61EF300F3D5DC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D93672552DA61EF200F3D5DC /* Project object */; + proxyType = 1; + remoteGlobalIDString = D936725C2DA61EF200F3D5DC; + remoteInfo = Example; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + D936725D2DA61EF200F3D5DC /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + D936726A2DA61EF300F3D5DC /* ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + D93672742DA61EF300F3D5DC /* ExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + D936725F2DA61EF200F3D5DC /* Sources */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = Sources; + sourceTree = ""; + }; + D936726D2DA61EF300F3D5DC /* ExampleTests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = ExampleTests; + sourceTree = ""; + }; + D93672772DA61EF300F3D5DC /* ExampleUITests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = ExampleUITests; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + D936725A2DA61EF200F3D5DC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + D93672892DA620E500F3D5DC /* FSLineChart in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672672DA61EF300F3D5DC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672712DA61EF300F3D5DC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + D93672542DA61EF200F3D5DC = { + isa = PBXGroup; + children = ( + D936725F2DA61EF200F3D5DC /* Sources */, + D936726D2DA61EF300F3D5DC /* ExampleTests */, + D93672772DA61EF300F3D5DC /* ExampleUITests */, + D936725E2DA61EF200F3D5DC /* Products */, + ); + sourceTree = ""; + }; + D936725E2DA61EF200F3D5DC /* Products */ = { + isa = PBXGroup; + children = ( + D936725D2DA61EF200F3D5DC /* Example.app */, + D936726A2DA61EF300F3D5DC /* ExampleTests.xctest */, + D93672742DA61EF300F3D5DC /* ExampleUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + D936725C2DA61EF200F3D5DC /* Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = D936727E2DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "Example" */; + buildPhases = ( + D93672592DA61EF200F3D5DC /* Sources */, + D936725A2DA61EF200F3D5DC /* Frameworks */, + D936725B2DA61EF200F3D5DC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + D936725F2DA61EF200F3D5DC /* Sources */, + ); + name = Example; + packageProductDependencies = ( + D93672882DA620E500F3D5DC /* FSLineChart */, + ); + productName = Example; + productReference = D936725D2DA61EF200F3D5DC /* Example.app */; + productType = "com.apple.product-type.application"; + }; + D93672692DA61EF300F3D5DC /* ExampleTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = D93672812DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "ExampleTests" */; + buildPhases = ( + D93672662DA61EF300F3D5DC /* Sources */, + D93672672DA61EF300F3D5DC /* Frameworks */, + D93672682DA61EF300F3D5DC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + D936726C2DA61EF300F3D5DC /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + D936726D2DA61EF300F3D5DC /* ExampleTests */, + ); + name = ExampleTests; + packageProductDependencies = ( + ); + productName = ExampleTests; + productReference = D936726A2DA61EF300F3D5DC /* ExampleTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + D93672732DA61EF300F3D5DC /* ExampleUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = D93672842DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "ExampleUITests" */; + buildPhases = ( + D93672702DA61EF300F3D5DC /* Sources */, + D93672712DA61EF300F3D5DC /* Frameworks */, + D93672722DA61EF300F3D5DC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + D93672762DA61EF300F3D5DC /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + D93672772DA61EF300F3D5DC /* ExampleUITests */, + ); + name = ExampleUITests; + packageProductDependencies = ( + ); + productName = ExampleUITests; + productReference = D93672742DA61EF300F3D5DC /* ExampleUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D93672552DA61EF200F3D5DC /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1630; + LastUpgradeCheck = 1630; + TargetAttributes = { + D936725C2DA61EF200F3D5DC = { + CreatedOnToolsVersion = 16.3; + }; + D93672692DA61EF300F3D5DC = { + CreatedOnToolsVersion = 16.3; + TestTargetID = D936725C2DA61EF200F3D5DC; + }; + D93672732DA61EF300F3D5DC = { + CreatedOnToolsVersion = 16.3; + TestTargetID = D936725C2DA61EF200F3D5DC; + }; + }; + }; + buildConfigurationList = D93672582DA61EF200F3D5DC /* Build configuration list for PBXProject "Example" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = D93672542DA61EF200F3D5DC; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + D93672872DA620E500F3D5DC /* XCLocalSwiftPackageReference "../../FSLineChart" */, + ); + preferredProjectObjectVersion = 77; + productRefGroup = D936725E2DA61EF200F3D5DC /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + D936725C2DA61EF200F3D5DC /* Example */, + D93672692DA61EF300F3D5DC /* ExampleTests */, + D93672732DA61EF300F3D5DC /* ExampleUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + D936725B2DA61EF200F3D5DC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672682DA61EF300F3D5DC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672722DA61EF300F3D5DC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + D93672592DA61EF200F3D5DC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672662DA61EF300F3D5DC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D93672702DA61EF300F3D5DC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + D936726C2DA61EF300F3D5DC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D936725C2DA61EF200F3D5DC /* Example */; + targetProxy = D936726B2DA61EF300F3D5DC /* PBXContainerItemProxy */; + }; + D93672762DA61EF300F3D5DC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D936725C2DA61EF200F3D5DC /* Example */; + targetProxy = D93672752DA61EF300F3D5DC /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + D936727C2DA61EF300F3D5DC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + D936727D2DA61EF300F3D5DC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + D936727F2DA61EF300F3D5DC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.Example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + D93672802DA61EF300F3D5DC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.Example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + D93672822DA61EF300F3D5DC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.ExampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Example"; + }; + name = Debug; + }; + D93672832DA61EF300F3D5DC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.ExampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Example"; + }; + name = Release; + }; + D93672852DA61EF300F3D5DC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.ExampleUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = Example; + }; + name = Debug; + }; + D93672862DA61EF300F3D5DC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.phor.ExampleUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = Example; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + D93672582DA61EF200F3D5DC /* Build configuration list for PBXProject "Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D936727C2DA61EF300F3D5DC /* Debug */, + D936727D2DA61EF300F3D5DC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D936727E2DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D936727F2DA61EF300F3D5DC /* Debug */, + D93672802DA61EF300F3D5DC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D93672812DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "ExampleTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D93672822DA61EF300F3D5DC /* Debug */, + D93672832DA61EF300F3D5DC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D93672842DA61EF300F3D5DC /* Build configuration list for PBXNativeTarget "ExampleUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D93672852DA61EF300F3D5DC /* Debug */, + D93672862DA61EF300F3D5DC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + D93672872DA620E500F3D5DC /* XCLocalSwiftPackageReference "../../FSLineChart" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../../FSLineChart; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + D93672882DA620E500F3D5DC /* FSLineChart */ = { + isa = XCSwiftPackageProductDependency; + productName = FSLineChart; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = D93672552DA61EF200F3D5DC /* Project object */; +} diff --git a/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/ExampleTests/ExampleTests.swift b/Example/ExampleTests/ExampleTests.swift new file mode 100644 index 0000000..9498955 --- /dev/null +++ b/Example/ExampleTests/ExampleTests.swift @@ -0,0 +1,10 @@ +import Testing +@testable import Example + +struct ExampleTests { + + @Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + } + +} diff --git a/Example/ExampleUITests/ExampleUITests.swift b/Example/ExampleUITests/ExampleUITests.swift new file mode 100644 index 0000000..75fbf7f --- /dev/null +++ b/Example/ExampleUITests/ExampleUITests.swift @@ -0,0 +1,34 @@ +import XCTest + +final class ExampleUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + @MainActor + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + @MainActor + func testLaunchPerformance() throws { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } +} diff --git a/Example/ExampleUITests/ExampleUITestsLaunchTests.swift b/Example/ExampleUITests/ExampleUITestsLaunchTests.swift new file mode 100644 index 0000000..2910808 --- /dev/null +++ b/Example/ExampleUITests/ExampleUITestsLaunchTests.swift @@ -0,0 +1,26 @@ +import XCTest + +final class ExampleUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + @MainActor + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +} diff --git a/Example/Sources/Assets.xcassets/AccentColor.colorset/Contents.json b/Example/Sources/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/Example/Sources/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/Sources/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Sources/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2305880 --- /dev/null +++ b/Example/Sources/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/Sources/Assets.xcassets/Contents.json b/Example/Sources/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Example/Sources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/Sources/ExampleApp.swift b/Example/Sources/ExampleApp.swift new file mode 100644 index 0000000..c18ed9d --- /dev/null +++ b/Example/Sources/ExampleApp.swift @@ -0,0 +1,302 @@ +import SwiftUI +import FSLineChart + +/// A chart view demonstrating various FSLineChart configurations. +class ExampleChart: FSLineChart { + struct Configuration { + let data: [Double] + let labels: ChartLabels? + let style: ChartStyle + let title: String + } + + /// Configures the chart with the provided settings. + /// - Parameter configuration: The chart configuration. + func load(configuration: Configuration) { + try? setChartData(configuration.data) + setLabels(configuration.labels) + applyStyle(configuration.style) + } +} + +/// SwiftUI wrapper for ExampleChart. +struct SwiftUIExampleChart: UIViewRepresentable { + let configuration: ExampleChart.Configuration + + func makeUIView(context: Context) -> ExampleChart { + let chart = ExampleChart() + chart.load(configuration: configuration) + return chart + } + + func updateUIView(_ uiView: ExampleChart, context: Context) { + uiView.load(configuration: configuration) + } +} + +/// The main content view displaying multiple chart configurations. +struct ContentView: View { + private let configurations: [ExampleChart.Configuration] = [ + ExampleChart.Configuration( + data: (0..<10).map { _ in Double(Int.random(in: 20...120)) }, + labels: ChartLabels( + indexLabel: { "\($0)" }, + valueLabel: { String(format: "$%.0f", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsOrange, + fillColor: UIColor.fsOrange.withAlphaComponent(0.25), + lineWidth: 1, + displayDataPoints: true, + dataPointColor: .fsOrange, + dataPointBackgroundColor: .fsOrange, + dataPointRadius: 3, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 5, horizontal: 9), + margin: 20, + bezierSmoothing: true, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "basic chart with random data" + ), + ExampleChart.Configuration( + data: (0..<7).map { Double($0) / 30.0 + Double(Int.random(in: 0...100)) / 500 }, + labels: ChartLabels( + indexLabel: { ["January", "February", "March", "April", "May", "June", "July"][$0] }, + valueLabel: { String(format: "%.02f €", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsGreen, + fillColor: nil, + lineWidth: 1, + displayDataPoints: true, + dataPointColor: .fsGreen, + dataPointBackgroundColor: .fsGreen, + dataPointRadius: 2, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 6, horizontal: 3), + margin: 20, + bezierSmoothing: false, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "monthly chart without smoothing" + ), + ExampleChart.Configuration( + data: (0..<20).map { _ in Double(Int.random(in: 50...200)) }, + labels: ChartLabels( + indexLabel: { "Day \($0 + 1)" }, + valueLabel: { String(format: "%.0f units", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsDarkBlue, + fillColor: UIColor.fsDarkBlue.withAlphaComponent(0.3), + lineWidth: 1, + displayDataPoints: false, + dataPointColor: .fsDarkBlue, + dataPointBackgroundColor: .fsDarkBlue, + dataPointRadius: 0, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 8, horizontal: 5), + margin: 20, + bezierSmoothing: true, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "dense data with blue theme" + ), + ExampleChart.Configuration( + data: (0..<5).map { _ in Double(Int.random(in: 10...50)) }, + labels: ChartLabels( + indexLabel: { "\($0)" }, + valueLabel: { String(format: "%.0f", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsRed, + fillColor: nil, + lineWidth: 1, + displayDataPoints: true, + dataPointColor: .fsRed, + dataPointBackgroundColor: .fsRed, + dataPointRadius: 4, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 4, horizontal: 4), + margin: 20, + bezierSmoothing: true, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "minimal chart with red theme" + ) + ] + + var body: some View { + ScrollView { + VStack(alignment: .leading, spacing: 20) { + Text("FSLineChart examples") + .font(.title) + .padding(.horizontal) + + ForEach(configurations, id: \.title) { config in + VStack(alignment: .leading) { + Text(config.title) + .font(.headline) + .padding(.horizontal) + + SwiftUIExampleChart(configuration: config) + .frame(height: 250) + .padding(.horizontal) + .background(Color.white) + .cornerRadius(10) + .shadow(radius: 5) + } + } + + Spacer() + } + .padding(.vertical) + } + .background(Color(UIColor.systemGray6)) + } +} + +#Preview("Basic Chart") { + ContentView() + .previewDisplayName("Basic Chart") +} + +#Preview("Monthly Chart") { + SwiftUIExampleChart(configuration: ExampleChart.Configuration( + data: (0..<7).map { Double($0) / 30.0 + Double(Int.random(in: 0...100)) / 500 }, + labels: ChartLabels( + indexLabel: { ["January", "February", "March", "April", "May", "June", "July"][$0] }, + valueLabel: { String(format: "%.02f €", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsGreen, + fillColor: nil, + lineWidth: 1, + displayDataPoints: true, + dataPointColor: .fsGreen, + dataPointBackgroundColor: .fsGreen, + dataPointRadius: 2, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 6, horizontal: 3), + margin: 20, + bezierSmoothing: false, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "monthly chart without smoothing" + )) + .frame(height: 250) + .padding() + .background(Color.white) + .previewDisplayName("Monthly Chart") +} + +#Preview("Dense Data") { + SwiftUIExampleChart(configuration: ExampleChart.Configuration( + data: (0..<20).map { _ in Double(Int.random(in: 50...200)) }, + labels: ChartLabels( + indexLabel: { "Day \($0 + 1)" }, + valueLabel: { String(format: "%.0f units", $0) } + ), + style: ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsDarkBlue, + fillColor: UIColor.fsDarkBlue.withAlphaComponent(0.3), + lineWidth: 1, + displayDataPoints: false, + dataPointColor: .fsDarkBlue, + dataPointBackgroundColor: .fsDarkBlue, + dataPointRadius: 0, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 8, horizontal: 5), + margin: 20, + bezierSmoothing: true, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored + ), + title: "dense data with blue theme" + )) + .frame(height: 250) + .padding() + .background(Color.white) + .previewDisplayName("Dense Data") +} + +@main +struct ExampleApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/FSLineChart.podspec b/FSLineChart.podspec deleted file mode 100644 index 9d2a89d..0000000 --- a/FSLineChart.podspec +++ /dev/null @@ -1,16 +0,0 @@ -Pod::Spec.new do |s| - s.name = "FSLineChart" - s.version = "0.1.8" - s.summary = "FSLineChart is a simple chart library for iOS." - s.description = <<-DESC - FSLineChart is a simple chart library for iOS. You can change whatever you want: size, color, units,... - DESC - s.homepage = "https://github.com/ArthurGuibert/FSLineChart" - s.screenshots = "https://github.com/ArthurGuibert/FSLineChart/raw/master/Screenshots/fslinechart.png" - s.author = { "Arthur Guibert" => "birslip@gmail.com" } - s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' } - s.platform = :ios, '7.0' - s.source = { :git => "https://github.com/ArthurGuibert/FSLineChart.git",:tag => "#{s.version}" } - s.source_files = 'Classes', 'FSLineChart/FSLineChart/*.{h,m}' - s.requires_arc = true -end diff --git a/FSLineChart.xcodeproj/project.pbxproj b/FSLineChart.xcodeproj/project.pbxproj deleted file mode 100644 index 1fe4b73..0000000 --- a/FSLineChart.xcodeproj/project.pbxproj +++ /dev/null @@ -1,481 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 8E67717B1DC89E3F00EA02FA /* ExampleChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E67717A1DC89E3F00EA02FA /* ExampleChart.swift */; }; - 8EA19AEC19DB55E9005F4BD1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19AEB19DB55E9005F4BD1 /* main.m */; }; - 8EA19AEF19DB55E9005F4BD1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19AEE19DB55E9005F4BD1 /* AppDelegate.m */; }; - 8EA19AF219DB55E9005F4BD1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19AF119DB55E9005F4BD1 /* ViewController.m */; }; - 8EA19AF519DB55E9005F4BD1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8EA19AF319DB55E9005F4BD1 /* Main.storyboard */; }; - 8EA19AF719DB55E9005F4BD1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EA19AF619DB55E9005F4BD1 /* Images.xcassets */; }; - 8EA19AFA19DB55E9005F4BD1 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8EA19AF819DB55E9005F4BD1 /* LaunchScreen.xib */; }; - 8EA19B0619DB55E9005F4BD1 /* FSLineChartTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19B0519DB55E9005F4BD1 /* FSLineChartTests.m */; }; - 8EA19B1119DB5696005F4BD1 /* FSLineChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19B1019DB5696005F4BD1 /* FSLineChart.m */; }; - 8EA19B1519DB56E8005F4BD1 /* UIColor+FSPalette.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA19B1419DB56E8005F4BD1 /* UIColor+FSPalette.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 8EA19B0019DB55E9005F4BD1 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8EA19ADE19DB55E9005F4BD1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 8EA19AE519DB55E9005F4BD1; - remoteInfo = FSLineChart; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 8E6771791DC89E3F00EA02FA /* FSLineChart-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FSLineChart-Bridging-Header.h"; sourceTree = ""; }; - 8E67717A1DC89E3F00EA02FA /* ExampleChart.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleChart.swift; sourceTree = ""; }; - 8EA19AE619DB55E9005F4BD1 /* FSLineChart.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FSLineChart.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 8EA19AEA19DB55E9005F4BD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8EA19AEB19DB55E9005F4BD1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 8EA19AED19DB55E9005F4BD1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 8EA19AEE19DB55E9005F4BD1 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8EA19AF019DB55E9005F4BD1 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 8EA19AF119DB55E9005F4BD1 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 8EA19AF419DB55E9005F4BD1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 8EA19AF619DB55E9005F4BD1 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 8EA19AF919DB55E9005F4BD1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - 8EA19AFF19DB55E9005F4BD1 /* FSLineChartTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FSLineChartTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 8EA19B0419DB55E9005F4BD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8EA19B0519DB55E9005F4BD1 /* FSLineChartTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FSLineChartTests.m; sourceTree = ""; }; - 8EA19B0F19DB5696005F4BD1 /* FSLineChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FSLineChart.h; path = FSLineChart/FSLineChart.h; sourceTree = ""; }; - 8EA19B1019DB5696005F4BD1 /* FSLineChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FSLineChart.m; path = FSLineChart/FSLineChart.m; sourceTree = ""; }; - 8EA19B1319DB56E8005F4BD1 /* UIColor+FSPalette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIColor+FSPalette.h"; path = "FSLineChart/UIColor+FSPalette.h"; sourceTree = ""; }; - 8EA19B1419DB56E8005F4BD1 /* UIColor+FSPalette.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIColor+FSPalette.m"; path = "FSLineChart/UIColor+FSPalette.m"; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 8EA19AE319DB55E9005F4BD1 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8EA19AFC19DB55E9005F4BD1 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 8EA19ADD19DB55E9005F4BD1 = { - isa = PBXGroup; - children = ( - 8EA19AE819DB55E9005F4BD1 /* FSLineChart */, - 8EA19B0219DB55E9005F4BD1 /* FSLineChartTests */, - 8EA19AE719DB55E9005F4BD1 /* Products */, - ); - sourceTree = ""; - }; - 8EA19AE719DB55E9005F4BD1 /* Products */ = { - isa = PBXGroup; - children = ( - 8EA19AE619DB55E9005F4BD1 /* FSLineChart.app */, - 8EA19AFF19DB55E9005F4BD1 /* FSLineChartTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 8EA19AE819DB55E9005F4BD1 /* FSLineChart */ = { - isa = PBXGroup; - children = ( - 8EA19B1219DB569A005F4BD1 /* FSLineChart */, - 8EA19AED19DB55E9005F4BD1 /* AppDelegate.h */, - 8EA19AEE19DB55E9005F4BD1 /* AppDelegate.m */, - 8EA19AF019DB55E9005F4BD1 /* ViewController.h */, - 8EA19AF119DB55E9005F4BD1 /* ViewController.m */, - 8E67717A1DC89E3F00EA02FA /* ExampleChart.swift */, - 8E6771791DC89E3F00EA02FA /* FSLineChart-Bridging-Header.h */, - 8EA19AF319DB55E9005F4BD1 /* Main.storyboard */, - 8EA19AF619DB55E9005F4BD1 /* Images.xcassets */, - 8EA19AF819DB55E9005F4BD1 /* LaunchScreen.xib */, - 8EA19AE919DB55E9005F4BD1 /* Supporting Files */, - ); - path = FSLineChart; - sourceTree = ""; - }; - 8EA19AE919DB55E9005F4BD1 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 8EA19AEA19DB55E9005F4BD1 /* Info.plist */, - 8EA19AEB19DB55E9005F4BD1 /* main.m */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 8EA19B0219DB55E9005F4BD1 /* FSLineChartTests */ = { - isa = PBXGroup; - children = ( - 8EA19B0519DB55E9005F4BD1 /* FSLineChartTests.m */, - 8EA19B0319DB55E9005F4BD1 /* Supporting Files */, - ); - path = FSLineChartTests; - sourceTree = ""; - }; - 8EA19B0319DB55E9005F4BD1 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 8EA19B0419DB55E9005F4BD1 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 8EA19B1219DB569A005F4BD1 /* FSLineChart */ = { - isa = PBXGroup; - children = ( - 8EA19B1319DB56E8005F4BD1 /* UIColor+FSPalette.h */, - 8EA19B1419DB56E8005F4BD1 /* UIColor+FSPalette.m */, - 8EA19B0F19DB5696005F4BD1 /* FSLineChart.h */, - 8EA19B1019DB5696005F4BD1 /* FSLineChart.m */, - ); - name = FSLineChart; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 8EA19AE519DB55E9005F4BD1 /* FSLineChart */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8EA19B0919DB55E9005F4BD1 /* Build configuration list for PBXNativeTarget "FSLineChart" */; - buildPhases = ( - 8EA19AE219DB55E9005F4BD1 /* Sources */, - 8EA19AE319DB55E9005F4BD1 /* Frameworks */, - 8EA19AE419DB55E9005F4BD1 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = FSLineChart; - productName = FSLineChart; - productReference = 8EA19AE619DB55E9005F4BD1 /* FSLineChart.app */; - productType = "com.apple.product-type.application"; - }; - 8EA19AFE19DB55E9005F4BD1 /* FSLineChartTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8EA19B0C19DB55E9005F4BD1 /* Build configuration list for PBXNativeTarget "FSLineChartTests" */; - buildPhases = ( - 8EA19AFB19DB55E9005F4BD1 /* Sources */, - 8EA19AFC19DB55E9005F4BD1 /* Frameworks */, - 8EA19AFD19DB55E9005F4BD1 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 8EA19B0119DB55E9005F4BD1 /* PBXTargetDependency */, - ); - name = FSLineChartTests; - productName = FSLineChartTests; - productReference = 8EA19AFF19DB55E9005F4BD1 /* FSLineChartTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 8EA19ADE19DB55E9005F4BD1 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0800; - ORGANIZATIONNAME = "Arthur GUIBERT"; - TargetAttributes = { - 8EA19AE519DB55E9005F4BD1 = { - CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0800; - }; - 8EA19AFE19DB55E9005F4BD1 = { - CreatedOnToolsVersion = 6.0.1; - TestTargetID = 8EA19AE519DB55E9005F4BD1; - }; - }; - }; - buildConfigurationList = 8EA19AE119DB55E9005F4BD1 /* Build configuration list for PBXProject "FSLineChart" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 8EA19ADD19DB55E9005F4BD1; - productRefGroup = 8EA19AE719DB55E9005F4BD1 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 8EA19AE519DB55E9005F4BD1 /* FSLineChart */, - 8EA19AFE19DB55E9005F4BD1 /* FSLineChartTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 8EA19AE419DB55E9005F4BD1 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8EA19AF519DB55E9005F4BD1 /* Main.storyboard in Resources */, - 8EA19AFA19DB55E9005F4BD1 /* LaunchScreen.xib in Resources */, - 8EA19AF719DB55E9005F4BD1 /* Images.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8EA19AFD19DB55E9005F4BD1 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 8EA19AE219DB55E9005F4BD1 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8EA19AF219DB55E9005F4BD1 /* ViewController.m in Sources */, - 8E67717B1DC89E3F00EA02FA /* ExampleChart.swift in Sources */, - 8EA19AEF19DB55E9005F4BD1 /* AppDelegate.m in Sources */, - 8EA19AEC19DB55E9005F4BD1 /* main.m in Sources */, - 8EA19B1119DB5696005F4BD1 /* FSLineChart.m in Sources */, - 8EA19B1519DB56E8005F4BD1 /* UIColor+FSPalette.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8EA19AFB19DB55E9005F4BD1 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8EA19B0619DB55E9005F4BD1 /* FSLineChartTests.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 8EA19B0119DB55E9005F4BD1 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 8EA19AE519DB55E9005F4BD1 /* FSLineChart */; - targetProxy = 8EA19B0019DB55E9005F4BD1 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin PBXVariantGroup section */ - 8EA19AF319DB55E9005F4BD1 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 8EA19AF419DB55E9005F4BD1 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 8EA19AF819DB55E9005F4BD1 /* LaunchScreen.xib */ = { - isa = PBXVariantGroup; - children = ( - 8EA19AF919DB55E9005F4BD1 /* Base */, - ); - name = LaunchScreen.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 8EA19B0719DB55E9005F4BD1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 8EA19B0819DB55E9005F4BD1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = YES; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 8EA19B0A19DB55E9005F4BD1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = NO; - INFOPLIST_FILE = FSLineChart/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.slipcorp.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "FSLineChart/FSLineChart-Bridging-Header.h"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 8EA19B0B19DB55E9005F4BD1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = NO; - INFOPLIST_FILE = FSLineChart/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.slipcorp.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "FSLineChart/FSLineChart-Bridging-Header.h"; - SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - 8EA19B0D19DB55E9005F4BD1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = FSLineChartTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.slipcorp.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FSLineChart.app/FSLineChart"; - }; - name = Debug; - }; - 8EA19B0E19DB55E9005F4BD1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - INFOPLIST_FILE = FSLineChartTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.slipcorp.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FSLineChart.app/FSLineChart"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 8EA19AE119DB55E9005F4BD1 /* Build configuration list for PBXProject "FSLineChart" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8EA19B0719DB55E9005F4BD1 /* Debug */, - 8EA19B0819DB55E9005F4BD1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 8EA19B0919DB55E9005F4BD1 /* Build configuration list for PBXNativeTarget "FSLineChart" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8EA19B0A19DB55E9005F4BD1 /* Debug */, - 8EA19B0B19DB55E9005F4BD1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 8EA19B0C19DB55E9005F4BD1 /* Build configuration list for PBXNativeTarget "FSLineChartTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8EA19B0D19DB55E9005F4BD1 /* Debug */, - 8EA19B0E19DB55E9005F4BD1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 8EA19ADE19DB55E9005F4BD1 /* Project object */; -} diff --git a/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/0253AE25-533E-4348-B0B5-CFFA60E20AAE.plist b/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/0253AE25-533E-4348-B0B5-CFFA60E20AAE.plist deleted file mode 100644 index d17a092..0000000 --- a/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/0253AE25-533E-4348-B0B5-CFFA60E20AAE.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - classNames - - FSLineChartTests - - testPerformanceExample - - com.apple.XCTPerformanceMetric_WallClockTime - - baselineAverage - 0.015 - baselineIntegrationDisplayName - Local Baseline - - - - - - diff --git a/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/Info.plist b/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/Info.plist deleted file mode 100644 index 41b5b18..0000000 --- a/FSLineChart.xcodeproj/xcshareddata/xcbaselines/8EA19AFE19DB55E9005F4BD1.xcbaseline/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - runDestinationsByUUID - - 0253AE25-533E-4348-B0B5-CFFA60E20AAE - - localComputer - - busSpeedInMHz - 100 - cpuCount - 1 - cpuKind - Intel Core i5 - cpuSpeedInMHz - 2600 - logicalCPUCoresPerPackage - 4 - modelCode - MacBookPro11,1 - physicalCPUCoresPerPackage - 2 - platformIdentifier - com.apple.platform.macosx - - targetArchitecture - i386 - targetDevice - - modelCode - iPhone5,1 - platformIdentifier - com.apple.platform.iphonesimulator - - - - - diff --git a/FSLineChart/AppDelegate.h b/FSLineChart/AppDelegate.h deleted file mode 100644 index cdb6f7e..0000000 --- a/FSLineChart/AppDelegate.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// AppDelegate.h -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import - -@interface AppDelegate : UIResponder - -@property (strong, nonatomic) UIWindow *window; - - -@end - diff --git a/FSLineChart/AppDelegate.m b/FSLineChart/AppDelegate.m deleted file mode 100644 index 1d9a091..0000000 --- a/FSLineChart/AppDelegate.m +++ /dev/null @@ -1,45 +0,0 @@ -// -// AppDelegate.m -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import "AppDelegate.h" - -@interface AppDelegate () - -@end - -@implementation AppDelegate - - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - -@end diff --git a/FSLineChart/Base.lproj/LaunchScreen.xib b/FSLineChart/Base.lproj/LaunchScreen.xib deleted file mode 100644 index 01f74aa..0000000 --- a/FSLineChart/Base.lproj/LaunchScreen.xib +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FSLineChart/Base.lproj/Main.storyboard b/FSLineChart/Base.lproj/Main.storyboard deleted file mode 100644 index 6beb148..0000000 --- a/FSLineChart/Base.lproj/Main.storyboard +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FSLineChart/ExampleChart.swift b/FSLineChart/ExampleChart.swift deleted file mode 100644 index 2cb8855..0000000 --- a/FSLineChart/ExampleChart.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// ExampleChart.swift -// FSLineChart -// -// Created by Arthur GUIBERT on 01/11/2016. -// Copyright © 2016 Arthur GUIBERT. All rights reserved. -// - -import UIKit - -class ExampleChart: FSLineChart { - override func awakeFromNib() { - load() - } - - public func load() { - var data: [Int] = [] - - // Generate some dummy data - for _ in 0...10 { - data.append(Int(20 + (arc4random() % 100))) - } - - verticalGridStep = 5 - horizontalGridStep = 9 - labelForIndex = { "\($0)" } - labelForValue = { "$\($0)" } - setChartData(data) - } - -} diff --git a/FSLineChart/FSLineChart-Bridging-Header.h b/FSLineChart/FSLineChart-Bridging-Header.h deleted file mode 100644 index bdcb1d8..0000000 --- a/FSLineChart/FSLineChart-Bridging-Header.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import "FSLineChart.h" diff --git a/FSLineChart/FSLineChart/FSLineChart.h b/FSLineChart/FSLineChart/FSLineChart.h deleted file mode 100644 index 0b0989e..0000000 --- a/FSLineChart/FSLineChart/FSLineChart.h +++ /dev/null @@ -1,100 +0,0 @@ -// -// FSLineChart.h -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -@interface FSLineChart : UIView - -// Block definition for getting a label for a set index (use case: date, units,...) -typedef NSString *(^FSLabelForIndexGetter)(NSUInteger index); - -// Same as above, but for the value (for adding a currency, or a unit symbol for example) -typedef NSString *(^FSLabelForValueGetter)(CGFloat value); - -typedef NS_ENUM(NSInteger, ValueLabelPositionType) { - ValueLabelLeft, - ValueLabelRight, - ValueLabelLeftMirrored -}; - -// Index label properties -@property (copy) FSLabelForIndexGetter labelForIndex; -@property (nonatomic, strong) UIFont* indexLabelFont; -@property (nonatomic) UIColor* indexLabelTextColor; -@property (nonatomic) UIColor* indexLabelBackgroundColor; - -// Value label properties -@property (copy) FSLabelForValueGetter labelForValue; -@property (nonatomic, strong) UIFont* valueLabelFont; -@property (nonatomic) UIColor* valueLabelTextColor; -@property (nonatomic) UIColor* valueLabelBackgroundColor; -@property (nonatomic) ValueLabelPositionType valueLabelPosition; - -// Number of visible step in the chart -@property (nonatomic) int gridStep; -@property (nonatomic) int verticalGridStep; -@property (nonatomic) int horizontalGridStep; - -// Margin of the chart -@property (nonatomic) CGFloat margin; - -@property (nonatomic) CGFloat axisWidth; -@property (nonatomic) CGFloat axisHeight; - -// Decoration parameters, let you pick the color of the line as well as the color of the axis -@property (nonatomic, strong) UIColor* axisColor; -@property (nonatomic) CGFloat axisLineWidth; - -// Chart parameters -@property (nonatomic, strong) UIColor* color; -@property (nonatomic, strong) UIColor* fillColor; -@property (nonatomic) CGFloat lineWidth; - -// Data points -@property (nonatomic) BOOL displayDataPoint; -@property (nonatomic, strong) UIColor* dataPointColor; -@property (nonatomic, strong) UIColor* dataPointBackgroundColor; -@property (nonatomic) CGFloat dataPointRadius; - -// Grid parameters -@property (nonatomic) BOOL drawInnerGrid; -@property (nonatomic, strong) UIColor* innerGridColor; -@property (nonatomic) CGFloat innerGridLineWidth; - -// Smoothing -@property (nonatomic) BOOL bezierSmoothing; -@property (nonatomic) CGFloat bezierSmoothingTension; - -// Animations -@property (nonatomic) CGFloat animationDuration; - -// Set the actual data for the chart, and then render it to the view. -- (void)setChartData:(NSArray *)chartData; - -// Clear all rendered data from the view. -- (void)clearChartData; - -// Get the bounds of the chart -- (CGFloat)minVerticalBound; -- (CGFloat)maxVerticalBound; - - -@end diff --git a/FSLineChart/FSLineChart/FSLineChart.m b/FSLineChart/FSLineChart/FSLineChart.m deleted file mode 100644 index a3a2fb6..0000000 --- a/FSLineChart/FSLineChart/FSLineChart.m +++ /dev/null @@ -1,638 +0,0 @@ -// -// FSLineChart.m -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import -#import "FSLineChart.h" -#import "UIColor+FSPalette.h" - -@interface FSLineChart () - -@property (nonatomic, strong) NSMutableArray* data; -@property (nonatomic, strong) NSMutableArray* layers; - -@property (nonatomic) CGFloat min; -@property (nonatomic) CGFloat max; -@property (nonatomic) CGMutablePathRef initialPath; -@property (nonatomic) CGMutablePathRef newPath; - -@end - -@implementation FSLineChart - -#pragma mark - Initialisation - -- (id)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - [self commonInit]; - } - return self; -} - -- (id)initWithCoder:(NSCoder *)aDecoder -{ - self = [super initWithCoder:aDecoder]; - if (self) { - [self commonInit]; - } - return self; -} - -- (void)awakeFromNib -{ - [super awakeFromNib]; - [self commonInit]; -} - -- (void)commonInit -{ - _layers = [NSMutableArray array]; - self.backgroundColor = [UIColor whiteColor]; - [self setDefaultParameters]; -} - -- (void)setDefaultParameters -{ - _color = [UIColor fsLightBlue]; - _fillColor = [_color colorWithAlphaComponent:0.25]; - _verticalGridStep = 3; - _horizontalGridStep = 3; - _margin = 5.0f; - _axisWidth = self.frame.size.width - 2 * _margin; - _axisHeight = self.frame.size.height - 2 * _margin; - _axisColor = [UIColor colorWithWhite:0.7 alpha:1.0]; - _innerGridColor = [UIColor colorWithWhite:0.9 alpha:1.0]; - _drawInnerGrid = YES; - _bezierSmoothing = YES; - _bezierSmoothingTension = 0.2; - _lineWidth = 1; - _innerGridLineWidth = 0.5; - _axisLineWidth = 1; - _animationDuration = 0.5; - _displayDataPoint = NO; - _dataPointRadius = 1; - _dataPointColor = _color; - _dataPointBackgroundColor = _color; - - // Labels attributes - _indexLabelBackgroundColor = [UIColor clearColor]; - _indexLabelTextColor = [UIColor grayColor]; - _indexLabelFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:10]; - - _valueLabelBackgroundColor = [UIColor colorWithWhite:1 alpha:0.75]; - _valueLabelTextColor = [UIColor grayColor]; - _valueLabelFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:11]; - _valueLabelPosition = ValueLabelRight; -} - -- (void)layoutSubviews -{ - _axisWidth = self.frame.size.width - 2 * _margin; - _axisHeight = self.frame.size.height - 2 * _margin; - - // Removing the old label views as well as the chart layers. - [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - [obj removeFromSuperview]; - }]; - - [self.layers enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - CALayer* layer = (CALayer*)obj; - [layer removeFromSuperlayer]; - }]; - - [self layoutChart]; - [super layoutSubviews]; -} - -- (void)layoutChart -{ - if(_data == nil) { - return; - } - - [self computeBounds]; - - // No data - if(isnan(_max)) { - _max = 1; - } - - [self strokeChart]; - - if(_displayDataPoint) { - [self strokeDataPoints]; - } - - if(_labelForValue) { - for(int i=0;i<_verticalGridStep;i++) { - UILabel* label = [self createLabelForValue:i]; - - if(label) { - [self addSubview:label]; - } - } - } - - if(_labelForIndex) { - for(int i=0;i<_horizontalGridStep + 1;i++) { - UILabel* label = [self createLabelForIndex:i]; - - if(label) { - [self addSubview:label]; - } - } - } - - [self setNeedsDisplay]; -} - -- (void)setChartData:(NSArray *)chartData -{ - if (chartData == nil || chartData.count == 0) { - return; - } - - _data = [NSMutableArray arrayWithArray:chartData]; - [self layoutChart]; -} - -#pragma mark - Labels creation - -- (UILabel*)createLabelForValue: (NSUInteger)index -{ - CGFloat minBound = [self minVerticalBound]; - CGFloat maxBound = [self maxVerticalBound]; - - CGPoint p = CGPointMake(_margin + (_valueLabelPosition == ValueLabelRight ? _axisWidth : 0), _axisHeight + _margin - (index + 1) * _axisHeight / _verticalGridStep); - - NSString* text = _labelForValue(minBound + (maxBound - minBound) / _verticalGridStep * (index + 1)); - - if(!text) - { - return nil; - } - - CGRect rect = CGRectMake(_margin, p.y + 2, self.frame.size.width - _margin * 2 - 4.0f, 14); - - float width = [text boundingRectWithSize:rect.size - options:NSStringDrawingUsesLineFragmentOrigin - attributes:@{ NSFontAttributeName:_valueLabelFont } - context:nil].size.width; - - CGFloat xPadding = 6; - CGFloat xOffset = width + xPadding; - - if (_valueLabelPosition == ValueLabelLeftMirrored) { - xOffset = -xPadding; - } - - UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(p.x - xOffset, p.y + 2, width + 2, 14)]; - label.text = text; - label.font = _valueLabelFont; - label.textColor = _valueLabelTextColor; - label.textAlignment = NSTextAlignmentCenter; - label.backgroundColor = _valueLabelBackgroundColor; - - return label; -} - -- (UILabel*)createLabelForIndex: (NSUInteger)index -{ - CGFloat scale = [self horizontalScale]; - NSInteger q = (int)_data.count / _horizontalGridStep; - NSInteger itemIndex = q * index; - - if(itemIndex >= _data.count) - { - itemIndex = _data.count - 1; - } - - NSString* text = _labelForIndex(itemIndex); - - if(!text) - { - return nil; - } - - CGPoint p = CGPointMake(_margin + index * (_axisWidth / _horizontalGridStep) * scale, _axisHeight + _margin); - - CGRect rect = CGRectMake(_margin, p.y + 2, self.frame.size.width - _margin * 2 - 4.0f, 14); - - float width = [text boundingRectWithSize:rect.size - options:NSStringDrawingUsesLineFragmentOrigin - attributes:@{ NSFontAttributeName:_indexLabelFont } - context:nil].size.width; - - UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(p.x - 4.0f, p.y + 2, width + 2, 14)]; - label.text = text; - label.font = _indexLabelFont; - label.textColor = _indexLabelTextColor; - label.backgroundColor = _indexLabelBackgroundColor; - - return label; -} - -#pragma mark - Drawing - -- (void)drawRect:(CGRect)rect -{ - if (_data.count > 0) { - [self drawGrid]; - } -} - -- (void)drawGrid -{ - CGContextRef ctx = UIGraphicsGetCurrentContext(); - UIGraphicsPushContext(ctx); - CGContextSetLineWidth(ctx, _axisLineWidth); - CGContextSetStrokeColorWithColor(ctx, [_axisColor CGColor]); - - // draw coordinate axis - CGContextMoveToPoint(ctx, _margin, _margin); - CGContextAddLineToPoint(ctx, _margin, _axisHeight + _margin + 3); - CGContextStrokePath(ctx); - - CGFloat scale = [self horizontalScale]; - CGFloat minBound = [self minVerticalBound]; - CGFloat maxBound = [self maxVerticalBound]; - - // draw grid - if(_drawInnerGrid) { - for(int i=0;i<_horizontalGridStep;i++) { - CGContextSetStrokeColorWithColor(ctx, [_innerGridColor CGColor]); - CGContextSetLineWidth(ctx, _innerGridLineWidth); - - CGPoint point = CGPointMake((1 + i) * _axisWidth / _horizontalGridStep * scale + _margin, _margin); - - CGContextMoveToPoint(ctx, point.x, point.y); - CGContextAddLineToPoint(ctx, point.x, _axisHeight + _margin); - CGContextStrokePath(ctx); - - CGContextSetStrokeColorWithColor(ctx, [_axisColor CGColor]); - CGContextSetLineWidth(ctx, _axisLineWidth); - CGContextMoveToPoint(ctx, point.x - 0.5f, _axisHeight + _margin); - CGContextAddLineToPoint(ctx, point.x - 0.5f, _axisHeight + _margin + 3); - CGContextStrokePath(ctx); - } - - for(int i=0;i<_verticalGridStep + 1;i++) { - // If the value is zero then we display the horizontal axis - CGFloat v = maxBound - (maxBound - minBound) / _verticalGridStep * i; - - if(v == 0) { - CGContextSetLineWidth(ctx, _axisLineWidth); - CGContextSetStrokeColorWithColor(ctx, [_axisColor CGColor]); - } else { - CGContextSetStrokeColorWithColor(ctx, [_innerGridColor CGColor]); - CGContextSetLineWidth(ctx, _innerGridLineWidth); - } - - CGPoint point = CGPointMake(_margin, (i) * _axisHeight / _verticalGridStep + _margin); - - CGContextMoveToPoint(ctx, point.x, point.y); - CGContextAddLineToPoint(ctx, _axisWidth + _margin, point.y); - CGContextStrokePath(ctx); - } - } - - UIGraphicsPopContext(); -} - -- (void)clearChartData -{ - for (CAShapeLayer *layer in self.layers) { - [layer removeFromSuperlayer]; - } - [self.layers removeAllObjects]; -} - -- (void)strokeChart -{ - CGFloat minBound = [self minVerticalBound]; - CGFloat scale = [self verticalScale]; - - UIBezierPath *noPath = [self getLinePath:0 withSmoothing:_bezierSmoothing close:NO]; - UIBezierPath *path = [self getLinePath:scale withSmoothing:_bezierSmoothing close:NO]; - - UIBezierPath *noFill = [self getLinePath:0 withSmoothing:_bezierSmoothing close:YES]; - UIBezierPath *fill = [self getLinePath:scale withSmoothing:_bezierSmoothing close:YES]; - - if(_fillColor) { - CAShapeLayer* fillLayer = [CAShapeLayer layer]; - fillLayer.frame = CGRectMake(self.bounds.origin.x, self.bounds.origin.y + minBound * scale, self.bounds.size.width, self.bounds.size.height); - fillLayer.bounds = self.bounds; - fillLayer.path = fill.CGPath; - fillLayer.strokeColor = nil; - fillLayer.fillColor = _fillColor.CGColor; - fillLayer.lineWidth = 0; - fillLayer.lineJoin = kCALineJoinRound; - - [self.layer addSublayer:fillLayer]; - [self.layers addObject:fillLayer]; - - CABasicAnimation *fillAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; - fillAnimation.duration = _animationDuration; - fillAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; - fillAnimation.fillMode = kCAFillModeForwards; - fillAnimation.fromValue = (id)noFill.CGPath; - fillAnimation.toValue = (id)fill.CGPath; - [fillLayer addAnimation:fillAnimation forKey:@"path"]; - } - - CAShapeLayer *pathLayer = [CAShapeLayer layer]; - pathLayer.frame = CGRectMake(self.bounds.origin.x, self.bounds.origin.y + minBound * scale, self.bounds.size.width, self.bounds.size.height); - pathLayer.bounds = self.bounds; - pathLayer.path = path.CGPath; - pathLayer.strokeColor = [_color CGColor]; - pathLayer.fillColor = nil; - pathLayer.lineWidth = _lineWidth; - pathLayer.lineJoin = kCALineJoinRound; - - [self.layer addSublayer:pathLayer]; - [self.layers addObject:pathLayer]; - - if(_fillColor) { - CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; - pathAnimation.duration = _animationDuration; - pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; - pathAnimation.fromValue = (__bridge id)(noPath.CGPath); - pathAnimation.toValue = (__bridge id)(path.CGPath); - [pathLayer addAnimation:pathAnimation forKey:@"path"]; - } else { - CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; - pathAnimation.duration = _animationDuration; - pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; - pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; - pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; - [pathLayer addAnimation:pathAnimation forKey:@"path"]; - } - -} - -- (void)strokeDataPoints -{ - CGFloat minBound = [self minVerticalBound]; - CGFloat scale = [self verticalScale]; - - for(int i=0;i<_data.count;i++) { - CGPoint p = [self getPointForIndex:i withScale:scale]; - p.y += minBound * scale; - - UIBezierPath* circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(p.x - _dataPointRadius, p.y - _dataPointRadius, _dataPointRadius * 2, _dataPointRadius * 2)]; - - CAShapeLayer *fillLayer = [CAShapeLayer layer]; - fillLayer.frame = CGRectMake(p.x, p.y, _dataPointRadius, _dataPointRadius); - fillLayer.bounds = CGRectMake(p.x, p.y, _dataPointRadius, _dataPointRadius); - fillLayer.path = circle.CGPath; - fillLayer.strokeColor = _dataPointColor.CGColor; - fillLayer.fillColor = _dataPointBackgroundColor.CGColor; - fillLayer.lineWidth = 1; - fillLayer.lineJoin = kCALineJoinRound; - - [self.layer addSublayer:fillLayer]; - [self.layers addObject:fillLayer]; - } -} - -#pragma mark - Chart scale & boundaries - -- (CGFloat)horizontalScale -{ - CGFloat scale = 1.0f; - NSInteger q = (int)_data.count / _horizontalGridStep; - - if(_data.count > 1) { - scale = (CGFloat)(q * _horizontalGridStep) / (CGFloat)(_data.count - 1); - } - - return scale; -} - -- (CGFloat)verticalScale -{ - CGFloat minBound = [self minVerticalBound]; - CGFloat maxBound = [self maxVerticalBound]; - CGFloat spread = maxBound - minBound; - CGFloat scale = 0; - - if (spread != 0) { - scale = _axisHeight / spread; - } - - return scale; -} - -- (CGFloat)minVerticalBound -{ - return MIN(_min, 0); -} - -- (CGFloat)maxVerticalBound -{ - return MAX(_max, 0); -} - -- (void)computeBounds -{ - _min = MAXFLOAT; - _max = -MAXFLOAT; - - for(int i=0;i<_data.count;i++) { - NSNumber* number = _data[i]; - if([number floatValue] < _min) - _min = [number floatValue]; - - if([number floatValue] > _max) - _max = [number floatValue]; - } - - // The idea is to adjust the minimun and the maximum value to display the whole chart in the view, and if possible with nice "round" steps. - _max = [self getUpperRoundNumber:_max forGridStep:_verticalGridStep]; - - if(_min < 0) { - // If the minimum is negative then we want to have one of the step to be zero so that the chart is displayed nicely and more comprehensively - float step; - - if(_verticalGridStep > 3) { - step = fabs(_max - _min) / (float)(_verticalGridStep - 1); - } else { - step = MAX(fabs(_max - _min) / 2, MAX(fabs(_min), fabs(_max))); - } - - step = [self getUpperRoundNumber:step forGridStep:_verticalGridStep]; - - float newMin,newMax; - - if(fabs(_min) > fabs(_max)) { - int m = ceilf(fabs(_min) / step); - - newMin = step * m * (_min > 0 ? 1 : -1); - newMax = step * (_verticalGridStep - m) * (_max > 0 ? 1 : -1); - - } else { - int m = ceilf(fabs(_max) / step); - - newMax = step * m * (_max > 0 ? 1 : -1); - newMin = step * (_verticalGridStep - m) * (_min > 0 ? 1 : -1); - } - - if(_min < newMin) { - newMin -= step; - newMax -= step; - } - - if(_max > newMax + step) { - newMin += step; - newMax += step; - } - - _min = newMin; - _max = newMax; - - if(_max < _min) { - float tmp = _max; - _max = _min; - _min = tmp; - } - - } -} - -#pragma mark - Chart utils - -- (CGFloat)getUpperRoundNumber:(CGFloat)value forGridStep:(int)gridStep -{ - if(value <= 0) - return 0; - - // We consider a round number the following by 0.5 step instead of true round number (with step of 1) - CGFloat logValue = log10f(value); - CGFloat scale = powf(10, floorf(logValue)); - CGFloat n = ceilf(value / scale * 4); - - int tmp = (int)(n) % gridStep; - - if(tmp != 0) { - n += gridStep - tmp; - } - - return n * scale / 4.0f; -} - -- (void)setGridStep:(int)gridStep -{ - _verticalGridStep = gridStep; - _horizontalGridStep = gridStep; -} - -- (CGPoint)getPointForIndex:(NSUInteger)idx withScale:(CGFloat)scale -{ - if(idx >= _data.count) { - return CGPointZero; - } - - // Compute the point position in the view from the data with a set scale value - NSNumber* number = _data[idx]; - - if(_data.count < 2) { - return CGPointMake(_margin, _axisHeight + _margin - [number floatValue] * scale); - } else { - return CGPointMake(_margin + idx * (_axisWidth / (_data.count - 1)), _axisHeight + _margin - [number floatValue] * scale); - } -} - -- (UIBezierPath*)getLinePath:(float)scale withSmoothing:(BOOL)smoothed close:(BOOL)closed -{ - UIBezierPath* path = [UIBezierPath bezierPath]; - - if(smoothed) { - for(int i=0;i<_data.count - 1;i++) { - CGPoint controlPoint[2]; - CGPoint p = [self getPointForIndex:i withScale:scale]; - - // Start the path drawing - if(i == 0) - [path moveToPoint:p]; - - CGPoint nextPoint, previousPoint, m; - - // First control point - nextPoint = [self getPointForIndex:i + 1 withScale:scale]; - previousPoint = [self getPointForIndex:i - 1 withScale:scale]; - m = CGPointZero; - - if(i > 0) { - m.x = (nextPoint.x - previousPoint.x) / 2; - m.y = (nextPoint.y - previousPoint.y) / 2; - } else { - m.x = (nextPoint.x - p.x) / 2; - m.y = (nextPoint.y - p.y) / 2; - } - - controlPoint[0].x = p.x + m.x * _bezierSmoothingTension; - controlPoint[0].y = p.y + m.y * _bezierSmoothingTension; - - // Second control point - nextPoint = [self getPointForIndex:i + 2 withScale:scale]; - previousPoint = [self getPointForIndex:i withScale:scale]; - p = [self getPointForIndex:i + 1 withScale:scale]; - m = CGPointZero; - - if(i < _data.count - 2) { - m.x = (nextPoint.x - previousPoint.x) / 2; - m.y = (nextPoint.y - previousPoint.y) / 2; - } else { - m.x = (p.x - previousPoint.x) / 2; - m.y = (p.y - previousPoint.y) / 2; - } - - controlPoint[1].x = p.x - m.x * _bezierSmoothingTension; - controlPoint[1].y = p.y - m.y * _bezierSmoothingTension; - - [path addCurveToPoint:p controlPoint1:controlPoint[0] controlPoint2:controlPoint[1]]; - } - - } else { - for(int i=0;i<_data.count;i++) { - if(i > 0) { - [path addLineToPoint:[self getPointForIndex:i withScale:scale]]; - } else { - [path moveToPoint:[self getPointForIndex:i withScale:scale]]; - } - } - } - - if(closed) { - // Closing the path for the fill drawing - [path addLineToPoint:[self getPointForIndex:_data.count - 1 withScale:scale]]; - [path addLineToPoint:[self getPointForIndex:_data.count - 1 withScale:0]]; - [path addLineToPoint:[self getPointForIndex:0 withScale:0]]; - [path addLineToPoint:[self getPointForIndex:0 withScale:scale]]; - } - - return path; -} - - - -@end diff --git a/FSLineChart/FSLineChart/UIColor+FSPalette.h b/FSLineChart/FSLineChart/UIColor+FSPalette.h deleted file mode 100644 index 333dc7c..0000000 --- a/FSLineChart/FSLineChart/UIColor+FSPalette.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// UIColor+FSPalette.h -// FlurrySummary -// -// Created by Arthur GUIBERT on 16/07/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import - -@interface UIColor (FSPalette) - -+ (instancetype)fsRed; -+ (instancetype)fsOrange; -+ (instancetype)fsYellow; -+ (instancetype)fsGreen; -+ (instancetype)fsLightBlue; -+ (instancetype)fsDarkBlue; -+ (instancetype)fsPurple; -+ (instancetype)fsPink; -+ (instancetype)fsDarkGray; -+ (instancetype)fsLightGray; - - -@end diff --git a/FSLineChart/FSLineChart/UIColor+FSPalette.m b/FSLineChart/FSLineChart/UIColor+FSPalette.m deleted file mode 100644 index 1ee1348..0000000 --- a/FSLineChart/FSLineChart/UIColor+FSPalette.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// UIColor+FSPalette.m -// FlurrySummary -// -// Created by Arthur GUIBERT on 16/07/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import "UIColor+FSPalette.h" - -@implementation UIColor (FSPalette) - -+ (instancetype)fsRed -{ - return [UIColor colorWithRed:1.0f green:0.22f blue:0.22f alpha:1.0f]; -} - -+ (instancetype)fsOrange -{ - return [UIColor colorWithRed:1.0f green:0.58f blue:0.21f alpha:1.0f]; -} - -+ (instancetype)fsYellow -{ - return [UIColor colorWithRed:1.0f green:0.79f blue:0.28f alpha:1.0f]; -} - -+ (instancetype)fsGreen -{ - return [UIColor colorWithRed:0.27f green:0.85f blue:0.46f alpha:1.0f]; -} - -+ (instancetype)fsLightBlue -{ - return [UIColor colorWithRed:0.18f green:0.67f blue:0.84f alpha:1.0f]; -} - -+ (instancetype)fsDarkBlue -{ - return [UIColor colorWithRed:0.0f green:0.49f blue:0.96f alpha:1.0f]; -} - -+ (instancetype)fsPurple -{ - return [UIColor colorWithRed:0.35f green:0.35f blue:0.81f alpha:1.0f]; -} - -+ (instancetype)fsPink -{ - return [UIColor colorWithRed:1.0f green:0.17f blue:0.34f alpha:1.0f]; -} - -+ (instancetype)fsDarkGray -{ - return [UIColor colorWithRed:0.56f green:0.56f blue:0.58f alpha:1.0f]; -} - -+ (instancetype)fsLightGray -{ - return [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0f]; -} - -@end diff --git a/FSLineChart/Images.xcassets/AppIcon.appiconset/Contents.json b/FSLineChart/Images.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 118c98f..0000000 --- a/FSLineChart/Images.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/FSLineChart/Info.plist b/FSLineChart/Info.plist deleted file mode 100644 index 6905cc6..0000000 --- a/FSLineChart/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - - diff --git a/FSLineChart/ViewController.h b/FSLineChart/ViewController.h deleted file mode 100644 index 427b30a..0000000 --- a/FSLineChart/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/FSLineChart/ViewController.m b/FSLineChart/ViewController.m deleted file mode 100644 index 873111c..0000000 --- a/FSLineChart/ViewController.m +++ /dev/null @@ -1,59 +0,0 @@ -// -// ViewController.m -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import "ViewController.h" -#import "FSLineChart.h" -#import "UIColor+FSPalette.h" - -@interface ViewController () - -@property (nonatomic, strong) IBOutlet FSLineChart *chartWithDates; - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - [self loadChartWithDates]; -} - -#pragma mark - Setting up the chart - -- (void)loadChartWithDates { - // Generating some dummy data - NSMutableArray* chartData = [NSMutableArray arrayWithCapacity:7]; - for(int i=0;i<7;i++) { - chartData[i] = [NSNumber numberWithFloat: (float)i / 30.0f + (float)(rand() % 100) / 500.0f]; - } - - NSArray* months = @[@"January", @"February", @"March", @"April", @"May", @"June", @"July"]; - - // Setting up the line chart - _chartWithDates.verticalGridStep = 6; - _chartWithDates.horizontalGridStep = 3; - _chartWithDates.fillColor = nil; - _chartWithDates.displayDataPoint = YES; - _chartWithDates.dataPointColor = [UIColor fsOrange]; - _chartWithDates.dataPointBackgroundColor = [UIColor fsOrange]; - _chartWithDates.dataPointRadius = 2; - _chartWithDates.color = [_chartWithDates.dataPointColor colorWithAlphaComponent:0.3]; - _chartWithDates.valueLabelPosition = ValueLabelLeftMirrored; - - _chartWithDates.labelForIndex = ^(NSUInteger item) { - return months[item]; - }; - - _chartWithDates.labelForValue = ^(CGFloat value) { - return [NSString stringWithFormat:@"%.02f €", value]; - }; - - [_chartWithDates setChartData:chartData]; -} - -@end diff --git a/FSLineChart/main.m b/FSLineChart/main.m deleted file mode 100644 index 13fc67d..0000000 --- a/FSLineChart/main.m +++ /dev/null @@ -1,16 +0,0 @@ -// -// main.m -// FSLineChart -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import -#import "AppDelegate.h" - -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); - } -} diff --git a/FSLineChartTests/FSLineChartTests.m b/FSLineChartTests/FSLineChartTests.m deleted file mode 100644 index 62ddfbb..0000000 --- a/FSLineChartTests/FSLineChartTests.m +++ /dev/null @@ -1,81 +0,0 @@ -// -// FSLineChartTests.m -// FSLineChartTests -// -// Created by Arthur GUIBERT on 30/09/2014. -// Copyright (c) 2014 Arthur GUIBERT. All rights reserved. -// - -#import -#import -#import "FSLineChart.h" - -@interface FSLineChartTests : XCTestCase - -@end - -@implementation FSLineChartTests - -- (void)setUp { - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -- (void)testInitialisation { - FSLineChart* chart = [[FSLineChart alloc] init]; - XCTAssertNotNil(chart); -} - -- (void)testBoundsNilChart { - FSLineChart* chart = [[FSLineChart alloc] init]; - [chart setChartData:nil]; - - XCTAssertEqual([chart minVerticalBound], 0); - XCTAssertEqual([chart maxVerticalBound], 0); -} - -- (void)testBoundsEmptyChart { - FSLineChart* chart = [[FSLineChart alloc] init]; - [chart setChartData:@[]]; - - XCTAssertEqual([chart minVerticalBound], 0); - XCTAssertEqual([chart maxVerticalBound], 0); -} - -- (void)testBoundsAllValuesToZero { - FSLineChart* chart = [[FSLineChart alloc] init]; - [chart setChartData:@[@0,@0,@0]]; - - XCTAssertEqual([chart minVerticalBound], 0); - XCTAssertEqual([chart maxVerticalBound], 0); -} - -- (void)testBounds { - FSLineChart* chart = [[FSLineChart alloc] init]; - [chart setChartData:@[@0, @1, @-1]]; - - XCTAssertGreaterThan([chart maxVerticalBound], 1); - XCTAssertLessThan([chart minVerticalBound], -1); -} - -- (void)testPerformanceExample { - FSLineChart* chart = [[FSLineChart alloc] init]; - NSMutableArray* array = [[NSMutableArray alloc] init]; - - for(int i=0;i<1000;i++) { - [array addObject:[NSNumber numberWithInt:rand()]]; - } - - // Testing whether a 1000 values are processed between two frames (1/60th of a second) - [self measureBlock:^{ - // Put the code you want to measure the time of here. - [chart setChartData:array]; - }]; -} - -@end diff --git a/FSLineChartTests/Info.plist b/FSLineChartTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/FSLineChartTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/LICENSE b/LICENSE index e06d208..d87f4c6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,20 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - +Copyright (c) 2019–2025 William Entriken +Copyright (c) 2019 Yaroslav Zhurakovskiy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..3077655 --- /dev/null +++ b/Package.swift @@ -0,0 +1,24 @@ +// swift-tools-version: 6.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "FSLineChart", + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "FSLineChart", + targets: ["FSLineChart"]), + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target( + name: "FSLineChart"), + .testTarget( + name: "FSLineChartTests", + dependencies: ["FSLineChart"] + ), + ] +) diff --git a/README.md b/README.md index dd8a38c..8adbd23 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,115 @@ -FSLineChart -=========== +# FSLineChart A line chart library for iOS. -Screenshots ---- -  - +## Screenshots -Installing FSLineChart ---- -Add the contents of the FSLineChart project to your directory or simply add the following line to your Podfile: +![Action shot](Screenshots/screenshot-1.webp) +![Action shot](Screenshots/screenshot-2.webp) - pod "FSLineChart" +## Installing FSLineChart -How to use ---- -FSLineChart is a subclass of UIView so it can be added as regular view. The block structure allows you to format the values displayed on the chart the way you want. Here is a simple swift example: +Add this to your project using Swift Package Manager. In Xcode, go to: File > Swift Packages > Add Package Dependency... and follow the prompts. Alternative installation options are available for legacy projects. -```swift -var data: [Int] = [] - -// Generate some dummy data -for _ in 0...10 { - data.append(Int(20 + (arc4random() % 100))) -} +## How to use -verticalGridStep = 5 -horizontalGridStep = 9 -labelForIndex = { "\($0)" } -labelForValue = { "$\($0)" } -setChartData(data) -``` +FSLineChart is a subclass of `UIView`, so it can be added as a regular view. Use the `ChartLabels` structure to format the values displayed on the chart. Here’s a simple Swift example: -Or in objective-c +```swift +import FSLineChart -```objc -NSArray* months = @[@"January", @"February", @"March", @"April", @"May", @"June", @"July"]; - -FSLineChart* lineChart = [[FSLineChart alloc] initWithFrame:frame]; +let chart = FSLineChart(frame: CGRect(x: 0, y: 0, width: 300, height: 200)) -lineChart.labelForIndex = ^(NSUInteger item) { - return months[item]; -}; +// Generate some dummy data +let data = (0..<10).map { _ in Double.random(in: 20...120) } + +// Configure labels +let labels = ChartLabels( + indexLabel: { "\($0)" }, + valueLabel: { String(format: "$%.0f", $0) } +) +chart.setLabels(labels) + +// Configure style +let style = ChartStyle( + axisColor: .gray, + axisLineWidth: 1, + lineColor: .fsOrange, + fillColor: UIColor.fsOrange.withAlphaComponent(0.25), + lineWidth: 1, + displayDataPoints: true, + dataPointColor: .fsOrange, + dataPointBackgroundColor: .fsOrange, + dataPointRadius: 3, + drawInnerGrid: true, + innerGridColor: UIColor(white: 0.9, alpha: 1.0), + innerGridLineWidth: 0.5, + gridSteps: (vertical: 5, horizontal: 9), + margin: 20, + bezierSmoothing: true, + bezierSmoothingTension: 0.2, + animationDuration: 0.5, + indexLabelFont: .systemFont(ofSize: 10), + indexLabelColor: .gray, + indexLabelBackgroundColor: .clear, + valueLabelFont: .systemFont(ofSize: 11), + valueLabelColor: .gray, + valueLabelBackgroundColor: UIColor(white: 1, alpha: 0.75), + valueLabelPosition: .mirrored +) +chart.applyStyle(style) + +// Set data and render +try? chart.setChartData(data) +``` -lineChart.labelForValue = ^(CGFloat value) { - return [NSString stringWithFormat:@"%.02f €", powf(10,value)]; -}; +You can customize the chart’s appearance using the `ChartStyle` structure. The style and labels must be set before calling `setChartData`. Here are the available `ChartStyle` properties: -[lineChart setChartData:chartData]; +```swift +public struct ChartStyle { + public let axisColor: UIColor + public let axisLineWidth: CGFloat + public let lineColor: UIColor + public let fillColor: UIColor? + public let lineWidth: CGFloat + public let displayDataPoints: Bool + public let dataPointColor: UIColor + public let dataPointBackgroundColor: UIColor + public let dataPointRadius: CGFloat + public let drawInnerGrid: Bool + public let innerGridColor: UIColor + public let innerGridLineWidth: CGFloat + public let gridSteps: (vertical: Int, horizontal: Int) + public let margin: CGFloat + public let bezierSmoothing: Bool + public let bezierSmoothingTension: CGFloat + public let animationDuration: TimeInterval + public let indexLabelFont: UIFont + public let indexLabelColor: UIColor + public let indexLabelBackgroundColor: UIColor + public let valueLabelFont: UIFont + public let valueLabelColor: UIColor + public let valueLabelBackgroundColor: UIColor + public let valueLabelPosition: ValueLabelPosition + + public enum ValueLabelPosition { + case left + case right + case mirrored + } +} ``` -You can also set several parameters. Some of the parameters including `color` and `fillColor` must be set before calling the `setChartData` method. All those properties are available: - -```objc -// Index label properties -@property (copy) FSLabelForIndexGetter labelForIndex; -@property (nonatomic, strong) UIFont* indexLabelFont; -@property (nonatomic) UIColor* indexLabelTextColor; -@property (nonatomic) UIColor* indexLabelBackgroundColor; - -// Value label properties -@property (copy) FSLabelForValueGetter labelForValue; -@property (nonatomic, strong) UIFont* valueLabelFont; -@property (nonatomic) UIColor* valueLabelTextColor; -@property (nonatomic) UIColor* valueLabelBackgroundColor; -@property (nonatomic) ValueLabelPositionType valueLabelPosition; - -// Number of visible step in the chart -@property (nonatomic) int gridStep; -@property (nonatomic) int verticalGridStep; -@property (nonatomic) int horizontalGridStep; - -// Margin of the chart -@property (nonatomic) CGFloat margin; - -@property (nonatomic) CGFloat axisWidth; -@property (nonatomic) CGFloat axisHeight; - -// Decoration parameters, let you pick the color of the line as well as the color of the axis -@property (nonatomic, strong) UIColor* axisColor; -@property (nonatomic) CGFloat axisLineWidth; - -// Chart parameters -@property (nonatomic, strong) UIColor* color; -@property (nonatomic, strong) UIColor* fillColor; -@property (nonatomic) CGFloat lineWidth; - -// Data points -@property (nonatomic) BOOL displayDataPoint; -@property (nonatomic, strong) UIColor* dataPointColor; -@property (nonatomic, strong) UIColor* dataPointBackgroundColor; -@property (nonatomic) CGFloat dataPointRadius; - -// Grid parameters -@property (nonatomic) BOOL drawInnerGrid; -@property (nonatomic, strong) UIColor* innerGridColor; -@property (nonatomic) CGFloat innerGridLineWidth; - -// Smoothing -@property (nonatomic) BOOL bezierSmoothing; -@property (nonatomic) CGFloat bezierSmoothingTension; - -// Animations -@property (nonatomic) CGFloat animationDuration; +The `setChartData` method may throw errors if the data is empty or contains invalid values (e.g., NaN or infinite). Handle these errors appropriately: + +```swift +do { + try chart.setChartData(data) +} catch { + print("Failed to set chart data: \(error)") +} ``` +## Examples -Examples ---- -You can clone the repo to see a simple example. I'm also using FSLineChart on [ChartLoot](https://github.com/ArthurGuibert/ChartLoot) if you want to see the integration in a bigger project. +Clone the repository to explore a simple example project showcasing various chart configurations. For a larger integration, see FSLineChart in action in [ChartLoot](https://github.com/ArthurGuibert/ChartLoot). diff --git a/Screenshots/fslinechart.png b/Screenshots/fslinechart.png deleted file mode 100644 index bc9e94c..0000000 Binary files a/Screenshots/fslinechart.png and /dev/null differ diff --git a/Screenshots/fslinechart2.png b/Screenshots/fslinechart2.png deleted file mode 100644 index 72b10de..0000000 Binary files a/Screenshots/fslinechart2.png and /dev/null differ diff --git a/Screenshots/screenshot-1.webp b/Screenshots/screenshot-1.webp new file mode 100644 index 0000000..b47e947 Binary files /dev/null and b/Screenshots/screenshot-1.webp differ diff --git a/Screenshots/screenshot-2.webp b/Screenshots/screenshot-2.webp new file mode 100644 index 0000000..8497a77 Binary files /dev/null and b/Screenshots/screenshot-2.webp differ diff --git a/Sources/FSLineChart/BoundsCalculator.swift b/Sources/FSLineChart/BoundsCalculator.swift new file mode 100644 index 0000000..ddb25ce --- /dev/null +++ b/Sources/FSLineChart/BoundsCalculator.swift @@ -0,0 +1,121 @@ +import CoreGraphics +import Foundation + +/// Calculates the minimum and maximum bounds for a chart's vertical axis, ensuring rounded steps for readability. +class BoundsCalculator { + private(set) var min: Double = Double.greatestFiniteMagnitude + private(set) var max: Double = -Double.greatestFiniteMagnitude + + /// Computes the bounds for the given dataset, adjusting for rounded steps and ensuring zero is included if negative values are present. + /// - Parameters: + /// - data: The dataset to analyze. + /// - verticalGridStep: The number of vertical grid lines. + func computeBounds(data: [Double], verticalGridStep: Int) throws { + guard !data.isEmpty else { + throw ChartError.emptyData + } + guard data.allSatisfy({ !$0.isNaN && !$0.isInfinite }) else { + throw ChartError.invalidData + } + + min = Double.greatestFiniteMagnitude + max = -Double.greatestFiniteMagnitude + + for number in data { + if number < min { + min = number + } + if number > max { + max = number + } + } + + max = getUpperRoundNumber(max, forGridStep: verticalGridStep) + + if min < 0 { + let step: Double + if verticalGridStep > 3 { + step = abs(max - min) / Double(verticalGridStep - 1) + } else { + step = Swift.max(abs(max - min) / 2, Swift.max(abs(min), abs(max))) + } + + let roundedStep = getUpperRoundNumber(step, forGridStep: verticalGridStep) + + var newMin: Double + var newMax: Double + + if abs(min) > abs(max) { + let m = ceil(abs(min) / roundedStep) + newMin = roundedStep * Double(m) * (min > 0 ? 1 : -1) + newMax = roundedStep * (Double(verticalGridStep) - m) * (max > 0 ? 1 : -1) + } else { + let m = ceil(abs(max) / roundedStep) + newMax = roundedStep * Double(m) * (max > 0 ? 1 : -1) + newMin = roundedStep * (Double(verticalGridStep) - m) * (min > 0 ? 1 : -1) + } + + if min < newMin { + newMin -= roundedStep + newMax -= roundedStep + } + + if max > newMax + roundedStep { + newMin += roundedStep + newMax += roundedStep + } + + min = newMin + max = newMax + + if max < min { + swap(&max, &min) + } + } + + if max.isNaN { + max = 1 + } + } + + /// Rounds a value to a number suitable for grid steps, using a 0.5 step increment. + /// - Parameters: + /// - value: The value to round. + /// - gridStep: The number of grid steps. + /// - Returns: The rounded value. + func getUpperRoundNumber(_ value: Double, forGridStep gridStep: Int) -> Double { + guard value > 0 else { + return 0 + } + + let logValue = log10(value) + let scale = pow(10, floor(logValue)) + var n = ceil(value / scale * 4) + + let tmp = Int(n) % gridStep + if tmp != 0 { + n += Double(gridStep - tmp) + } + + return n * scale / 4.0 + } +} + +extension BoundsCalculator { + /// The minimum vertical bound, ensuring it’s at least zero. + var minVerticalBound: CGFloat { + return CGFloat(Swift.min(min, 0)) + } + + /// The maximum vertical bound, ensuring it’s at least zero. + var maxVerticalBound: CGFloat { + return CGFloat(Swift.max(max, 0)) + } +} + +/// Errors related to chart data processing. +enum ChartError: Error { + case emptyData + case invalidData + case invalidIndex +} diff --git a/Sources/FSLineChart/ChartUtilities.swift b/Sources/FSLineChart/ChartUtilities.swift new file mode 100644 index 0000000..a67e85f --- /dev/null +++ b/Sources/FSLineChart/ChartUtilities.swift @@ -0,0 +1,216 @@ +import CoreGraphics +import UIKit + +/// Utility functions for chart calculations, designed for testability and reusability. +struct ChartUtilities { + /// Calculates the horizontal scale for a chart based on data and grid steps. + /// - Parameters: + /// - data: The dataset to scale. + /// - horizontalGridStep: The number of horizontal grid lines. + /// - Returns: The calculated scale factor. + static func calculateHorizontalScale(data: [Double], horizontalGridStep: Int) -> CGFloat { + var scale: CGFloat = 1.0 + let q = data.count / horizontalGridStep + if data.count > 1 { + scale = CGFloat(q * horizontalGridStep) / CGFloat(data.count - 1) + } + return scale + } + + /// Computes the point position for a data index in the chart. + /// - Parameters: + /// - index: The index of the data point. + /// - data: The dataset. + /// - scale: The vertical scale factor. + /// - axisWidth: The width of the chart’s axis. + /// - axisHeight: The height of the chart’s axis. + /// - margin: The chart’s margin. + /// - Returns: The computed point. + static func getPointForIndex( + index: Int, + data: [Double], + scale: CGFloat, + axisWidth: CGFloat, + axisHeight: CGFloat, + margin: CGFloat + ) throws -> CGPoint { + guard index >= 0 && index < data.count else { + return .zero + } + + let number = CGFloat(data[index]) + if data.count < 2 { + return CGPoint(x: margin, y: axisHeight + margin - number * scale) + } else { + return CGPoint( + x: margin + CGFloat(index) * (axisWidth / CGFloat(data.count - 1)), + y: axisHeight + margin - number * scale + ) + } + } + + /// Generates a path for the chart’s line or fill area. + /// - Parameters: + /// - data: The dataset. + /// - scale: The vertical scale factor. + /// - axisWidth: The width of the chart’s axis. + /// - axisHeight: The height of the chart’s axis. + /// - margin: The chart’s margin. + /// - smoothed: Whether to apply Bezier smoothing. + /// - smoothingTension: The tension for Bezier smoothing. + /// - closed: Whether to close the path for filling. + /// - Returns: The computed path. + static func getLinePath( + data: [Double], + scale: CGFloat, + axisWidth: CGFloat, + axisHeight: CGFloat, + margin: CGFloat, + smoothed: Bool, + smoothingTension: CGFloat, + closed: Bool + ) throws -> UIBezierPath { + let path = UIBezierPath() + + if smoothed { + for i in 0.. 0 ? try getPointForIndex( + index: i - 1, + data: data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: margin + ) : p + + var m = CGPoint.zero + if i > 0 { + m.x = (nextPoint.x - previousPoint.x) / 2 + m.y = (nextPoint.y - previousPoint.y) / 2 + } else { + m.x = (nextPoint.x - p.x) / 2 + m.y = (nextPoint.y - p.y) / 2 + } + + controlPoint[0].x = p.x + m.x * smoothingTension + controlPoint[0].y = p.y + m.y * smoothingTension + + let nextIndex = i < data.count - 2 ? i + 2 : i + 1 + let nextPoint2 = try getPointForIndex( + index: nextIndex, + data: data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: margin + ) + let previousPoint2 = try getPointForIndex( + index: i, + data: data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: margin + ) + let p2 = try getPointForIndex( + index: i + 1, + data: data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: margin + ) + + m = CGPoint.zero + if i < data.count - 2 { + m.x = (nextPoint2.x - previousPoint2.x) / 2 + m.y = (nextPoint2.y - previousPoint2.y) / 2 + } else { + m.x = (p2.x - previousPoint2.x) / 2 + m.y = (p2.y - previousPoint2.y) / 2 + } + + controlPoint[1].x = p2.x - m.x * smoothingTension + controlPoint[1].y = p2.y - m.y * smoothingTension + + path.addCurve(to: p2, controlPoint1: controlPoint[0], controlPoint2: controlPoint[1]) + } + } else { + for i in 0.. String + public let valueLabel: (CGFloat) -> String + + public init(indexLabel: @escaping (Int) -> String, valueLabel: @escaping (CGFloat) -> String) { + self.indexLabel = indexLabel + self.valueLabel = valueLabel + } +} diff --git a/Sources/FSLineChart/GridRenderer.swift b/Sources/FSLineChart/GridRenderer.swift new file mode 100644 index 0000000..da67912 --- /dev/null +++ b/Sources/FSLineChart/GridRenderer.swift @@ -0,0 +1,78 @@ +import CoreGraphics +import UIKit + +/// Renders the grid and axes for a chart. +class GridRenderer { + /// Draws the chart’s grid and axes using the provided configuration. + /// - Parameters: + /// - configuration: The chart’s configuration. + /// - layoutManager: The layout manager for axis dimensions. + @MainActor + func render(configuration: ChartConfiguration, layoutManager: LayoutManager) throws { + guard !configuration.data.isEmpty else { return } + + guard let ctx = UIGraphicsGetCurrentContext() else { return } + UIGraphicsPushContext(ctx) + + ctx.setLineWidth(configuration.style.axisLineWidth) + ctx.setStrokeColor(configuration.style.axisColor.cgColor) + + // Draw coordinate axis + ctx.move(to: CGPoint(x: configuration.style.margin, y: configuration.style.margin)) + ctx.addLine(to: CGPoint(x: configuration.style.margin, y: layoutManager.axisHeight + configuration.style.margin + 3)) + ctx.strokePath() + + let scale = layoutManager.calculateHorizontalScale( + data: configuration.data, + horizontalGridStep: configuration.style.gridSteps.horizontal + ) + let minBound = layoutManager.minVerticalBound + let maxBound = layoutManager.maxVerticalBound + + // Draw grid + if configuration.style.drawInnerGrid { + for i in 0.. CGFloat { + if let cached = cachedHorizontalScale { return cached } + let scale = ChartUtilities.calculateHorizontalScale(data: data, horizontalGridStep: horizontalGridStep) + cachedHorizontalScale = scale + return scale + } + + /// The minimum vertical bound from the bounds calculator. + var minVerticalBound: CGFloat { + return boundsCalculator.minVerticalBound + } + + /// The maximum vertical bound from the bounds calculator. + var maxVerticalBound: CGFloat { + return boundsCalculator.maxVerticalBound + } + + @MainActor + private func strokeChart(configuration: ChartConfiguration, in view: FSLineChart) throws { + let minBound = boundsCalculator.minVerticalBound + let scale = verticalScale(configuration: configuration) + + let noPath = try ChartUtilities.getLinePath( + data: configuration.data, + scale: 0, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: configuration.style.margin, + smoothed: configuration.style.bezierSmoothing, + smoothingTension: configuration.style.bezierSmoothingTension, + closed: false + ) + let path = try ChartUtilities.getLinePath( + data: configuration.data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: configuration.style.margin, + smoothed: configuration.style.bezierSmoothing, + smoothingTension: configuration.style.bezierSmoothingTension, + closed: false + ) + + let noFill = try ChartUtilities.getLinePath( + data: configuration.data, + scale: 0, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: configuration.style.margin, + smoothed: configuration.style.bezierSmoothing, + smoothingTension: configuration.style.bezierSmoothingTension, + closed: true + ) + let fill = try ChartUtilities.getLinePath( + data: configuration.data, + scale: scale, + axisWidth: axisWidth, + axisHeight: axisHeight, + margin: configuration.style.margin, + smoothed: configuration.style.bezierSmoothing, + smoothingTension: configuration.style.bezierSmoothingTension, + closed: true + ) + + if let fillColor = configuration.style.fillColor { + let fillLayer = CAShapeLayer() + fillLayer.frame = CGRect( + x: view.bounds.origin.x, + y: view.bounds.origin.y + minBound * scale, + width: view.bounds.size.width, + height: view.bounds.size.height + ) + fillLayer.bounds = view.bounds + fillLayer.path = noFill.cgPath + fillLayer.strokeColor = nil + fillLayer.fillColor = fillColor.cgColor + fillLayer.lineWidth = 0 + fillLayer.lineJoin = .round + + view.layer.addSublayer(fillLayer) + layers.append(fillLayer) + + let animator = UIViewPropertyAnimator(duration: configuration.style.animationDuration, curve: .easeInOut) { + fillLayer.path = fill.cgPath + } + animator.startAnimation() + } + + let pathLayer = CAShapeLayer() + pathLayer.frame = CGRect( + x: view.bounds.origin.x, + y: view.bounds.origin.y + minBound * scale, + width: view.bounds.size.width, + height: view.bounds.size.height + ) + pathLayer.bounds = view.bounds + pathLayer.path = noPath.cgPath + pathLayer.strokeColor = configuration.style.lineColor.cgColor + pathLayer.fillColor = nil + pathLayer.lineWidth = configuration.style.lineWidth + pathLayer.lineJoin = .round + + view.layer.addSublayer(pathLayer) + layers.append(pathLayer) + + let animator = UIViewPropertyAnimator(duration: configuration.style.animationDuration, curve: .easeInOut) { + pathLayer.path = path.cgPath + pathLayer.strokeEnd = 1.0 + } + animator.startAnimation() + } + + @MainActor + private func strokeDataPoints(configuration: ChartConfiguration, in view: FSLineChart) throws { + let minBound = boundsCalculator.minVerticalBound + let scale = verticalScale(configuration: configuration) + + for i in 0.. UILabel? { + let minBound = boundsCalculator.minVerticalBound + let maxBound = boundsCalculator.maxVerticalBound + + let value = minBound + (maxBound - minBound) / CGFloat(configuration.style.gridSteps.vertical * (index + 1)) + let text = labels.valueLabel(value) + + let p = CGPoint( + x: configuration.style.margin + (configuration.style.valueLabelPosition == .right ? axisWidth : 0), + y: axisHeight + configuration.style.margin - CGFloat(index + 1) * axisHeight / CGFloat(configuration.style.gridSteps.vertical) + ) + + let rect = CGRect( + x: configuration.style.margin, + y: p.y + 2, + width: axisWidth - configuration.style.margin * 2 - 4.0, + height: 14 + ) + + let width = (text as NSString).boundingRect( + with: rect.size, + options: [.usesLineFragmentOrigin], + attributes: [.font: configuration.style.valueLabelFont], + context: nil + ).size.width + + let xPadding: CGFloat = 6 + var xOffset: CGFloat = width + xPadding + if configuration.style.valueLabelPosition == .mirrored { + xOffset = -xPadding + } + + let label = UILabel( + frame: CGRect( + x: p.x - xOffset, + y: p.y + 2, + width: width + 2, + height: 14 + ) + ) + label.text = text + label.font = configuration.style.valueLabelFont + label.textColor = configuration.style.valueLabelColor + label.textAlignment = .center + label.backgroundColor = configuration.style.valueLabelBackgroundColor + + return label + } + + @MainActor + private func createLabelForIndex(index: Int, configuration: ChartConfiguration, labels: ChartLabels) -> UILabel? { + let scale = calculateHorizontalScale(data: configuration.data, horizontalGridStep: configuration.style.gridSteps.horizontal) + let q = configuration.data.count / configuration.style.gridSteps.horizontal + var itemIndex = q * index + + if itemIndex >= configuration.data.count { + itemIndex = configuration.data.count - 1 + } + + let text = labels.indexLabel(itemIndex) + + let p = CGPoint( + x: configuration.style.margin + CGFloat(index) * (axisWidth / CGFloat(configuration.style.gridSteps.horizontal)) * scale, + y: axisHeight + configuration.style.margin + ) + + let rect = CGRect( + x: configuration.style.margin, + y: p.y + 2, + width: axisWidth - configuration.style.margin * 2 - 4.0, + height: 14 + ) + + let width = (text as NSString).boundingRect( + with: rect.size, + options: [.usesLineFragmentOrigin], + attributes: [.font: configuration.style.indexLabelFont], + context: nil + ).size.width + + let label = UILabel( + frame: CGRect( + x: p.x - 4.0, + y: p.y + 2, + width: width + 2, + height: 14 + ) + ) + label.text = text + label.font = configuration.style.indexLabelFont + label.textColor = configuration.style.indexLabelColor + label.backgroundColor = configuration.style.indexLabelBackgroundColor + + return label + } + + private func verticalScale(configuration: ChartConfiguration) -> CGFloat { + if let cached = cachedVerticalScale { return cached } + let minBound = boundsCalculator.minVerticalBound + let maxBound = boundsCalculator.maxVerticalBound + + let spread = maxBound - minBound + let scale: CGFloat = spread != 0 ? axisHeight / spread : 0 + cachedVerticalScale = scale + return scale + } +} diff --git a/Sources/FSLineChart/UIColor+FS.swift b/Sources/FSLineChart/UIColor+FS.swift new file mode 100644 index 0000000..970e1cc --- /dev/null +++ b/Sources/FSLineChart/UIColor+FS.swift @@ -0,0 +1,44 @@ +import UIKit + +/// Custom colors used in FSLineChart for consistent styling. +public extension UIColor { + static var fsRed: UIColor { + return UIColor(red: 1.0, green: 0.22, blue: 0.22, alpha: 1.0) + } + + static var fsOrange: UIColor { + return UIColor(red: 1.0, green: 0.58, blue: 0.21, alpha: 1.0) + } + + static var fsYellow: UIColor { + return UIColor(red: 1.0, green: 0.79, blue: 0.28, alpha: 1.0) + } + + static var fsGreen: UIColor { + return UIColor(red: 0.27, green: 0.85, blue: 0.46, alpha: 1.0) + } + + static var fsLightBlue: UIColor { + return UIColor(red: 0.18, green: 0.67, blue: 0.84, alpha: 1.0) + } + + static var fsDarkBlue: UIColor { + return UIColor(red: 0.0, green: 0.49, blue: 0.96, alpha: 1.0) + } + + static var fsPurple: UIColor { + return UIColor(red: 0.35, green: 0.35, blue: 0.81, alpha: 1.0) + } + + static var fsPink: UIColor { + return UIColor(red: 1.0, green: 0.17, blue: 0.34, alpha: 1.0) + } + + static var fsDarkGray: UIColor { + return UIColor(red: 0.56, green: 0.56, blue: 0.58, alpha: 1.0) + } + + static var fsLightGray: UIColor { + return UIColor(red: 0.78, green: 0.78, blue: 0.8, alpha: 1.0) + } +} diff --git a/Tests/FSLineChartTests/FSLineChartTests.swift b/Tests/FSLineChartTests/FSLineChartTests.swift new file mode 100644 index 0000000..6de5c9d --- /dev/null +++ b/Tests/FSLineChartTests/FSLineChartTests.swift @@ -0,0 +1,74 @@ +// +// FSLineChartTests.swift +// FSLineChart +// +// Created by Yaroslav Zhurakovskiy on 25.11.2019. +// Copyright © 2019 William Entriken. All rights reserved. +// + +import XCTest +@testable import FSLineChart + +class FSLineChartTests: XCTestCase { + func testInitialisation() { + let chart = FSLineChart() + XCTAssertNotNil(chart); + } + + func testBoundsEmptyChart() { + let chart = FSLineChart() + chart.setChartData([]) + + XCTAssertEqual(chart.minVerticalBound, 0) + XCTAssertEqual(chart.maxVerticalBound, 0) + } + + func testBoundsAllValuesToZero() { + let chart = FSLineChart() + chart.setChartData([0, 0, 0]) + + XCTAssertEqual(chart.minVerticalBound, 0) + XCTAssertEqual(chart.maxVerticalBound, 0) + } + + func testBounds() { + let chart = FSLineChart() + chart.setChartData([0, 1, -1]) + + XCTAssertEqual(chart.minVerticalBound, -3) + XCTAssertEqual(chart.maxVerticalBound, 1.5) + } + + func testPerformanceExample() { + let chart = FSLineChart() + let testData = (0..<1000).map { Double($0) } + + // Testing whether a 1000 values are processed between two frames (1/60th of a second) + measure { + chart.setChartData(testData); + } + } + + func testDataWithAllZeroesShouldNotCrash() { + let chart = FSLineChart( + frame: CGRect( + x: 0, + y: 0, + width: 320, + height: 176 + ) + ) + chart.verticalGridStep = 5 + chart.horizontalGridStep = 9 + chart.labelForIndex = { "\($0)" } + chart.labelForValue = { String(format: "%.f", $0) } + chart.setChartData((1...10).map { _ in Double(0) }) + + UIGraphicsBeginImageContext(chart.bounds.size) + chart.layer.render(in: UIGraphicsGetCurrentContext()!) + let image = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + XCTAssertNotNil(image) + } +}