Skip to content

Commit

Permalink
feat: add chart view
Browse files Browse the repository at this point in the history
  • Loading branch information
betterhee committed Nov 20, 2021
1 parent b84385c commit 753da1d
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 83 deletions.
8 changes: 4 additions & 4 deletions Coins.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
5DD4667A2744797000D1B730 /* HistoricalCoinViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD466792744797000D1B730 /* HistoricalCoinViewModel.swift */; };
5DD4667C274509F500D1B730 /* HistoricalCoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD4667B274509F400D1B730 /* HistoricalCoin.swift */; };
5DD4667E27450C8700D1B730 /* HistoricalCoinRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD4667D27450C8700D1B730 /* HistoricalCoinRequest.swift */; };
5DD466822745338800D1B730 /* Period.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD466812745338800D1B730 /* Period.swift */; };
5DD466822745338800D1B730 /* Duration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD466812745338800D1B730 /* Duration.swift */; };
5DD466852745BF6F00D1B730 /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = 5DD466842745BF6F00D1B730 /* Charts */; };
5DD466992745C75800D1B730 /* GraphikRegularItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 5DD4668F2745C73D00D1B730 /* GraphikRegularItalic.otf */; };
5DD4669A2745C75800D1B730 /* GraphikSemiboldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 5DD4668A2745C73D00D1B730 /* GraphikSemiboldItalic.otf */; };
Expand Down Expand Up @@ -68,7 +68,7 @@
5DD466792744797000D1B730 /* HistoricalCoinViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalCoinViewModel.swift; sourceTree = "<group>"; };
5DD4667B274509F400D1B730 /* HistoricalCoin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalCoin.swift; sourceTree = "<group>"; };
5DD4667D27450C8700D1B730 /* HistoricalCoinRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalCoinRequest.swift; sourceTree = "<group>"; };
5DD466812745338800D1B730 /* Period.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Period.swift; sourceTree = "<group>"; };
5DD466812745338800D1B730 /* Duration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Duration.swift; sourceTree = "<group>"; };
5DD4668A2745C73D00D1B730 /* GraphikSemiboldItalic.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = GraphikSemiboldItalic.otf; sourceTree = "<group>"; };
5DD4668C2745C73D00D1B730 /* GraphikSemibold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = GraphikSemibold.otf; sourceTree = "<group>"; };
5DD4668F2745C73D00D1B730 /* GraphikRegularItalic.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = GraphikRegularItalic.otf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,7 +130,7 @@
children = (
5DBF026A27423C1900FE6C1D /* Coin.swift */,
5DD4667B274509F400D1B730 /* HistoricalCoin.swift */,
5DD466812745338800D1B730 /* Period.swift */,
5DD466812745338800D1B730 /* Duration.swift */,
5DBF02282741FAD600FE6C1D /* Article.swift */,
);
path = Models;
Expand Down Expand Up @@ -331,7 +331,7 @@
5DBF02692742394500FE6C1D /* CoinRequest.swift in Sources */,
5DBF02162741FA9B00FE6C1D /* ArticlesViewController.swift in Sources */,
5DD4667A2744797000D1B730 /* HistoricalCoinViewModel.swift in Sources */,
5DD466822745338800D1B730 /* Period.swift in Sources */,
5DD466822745338800D1B730 /* Duration.swift in Sources */,
5DF277012743841F003C434B /* CoinsViewModel.swift in Sources */,
5DBF02122741FA9B00FE6C1D /* AppDelegate.swift in Sources */,
5DD4667C274509F500D1B730 /* HistoricalCoin.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Coins/Models/Period.swift → Coins/Models/Duration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation

enum Period: Int {
enum Duration: Int {
case day
case week
}

extension Period {
extension Duration {
var limit: Int {
switch self {
case .day:
Expand Down
4 changes: 2 additions & 2 deletions Coins/Networking/CoinServiceApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ final class CoinServiceApi {
}
}

func historicalCoins(from: Coin, period: Period, completion: @escaping (Result<[HistoricalCoin], Error>) -> Void) {
let endpoint = HistoricalCoinRequest.historicalCoin(from: from, to: nil, period: period)
func historicalCoins(from: Coin, duration: Duration, completion: @escaping (Result<[HistoricalCoin], Error>) -> Void) {
let endpoint = HistoricalCoinRequest.historicalCoin(from: from, to: nil, duration: duration)
apiRequestLoader.request(with: endpoint) { result in
switch result {
case .success(let value):
Expand Down
10 changes: 5 additions & 5 deletions Coins/Networking/HistoricalCoinRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

enum HistoricalCoinRequest {
case historicalCoin(from: Coin, to: String?, period: Period)
case historicalCoin(from: Coin, to: String?, duration: Duration)
}

extension HistoricalCoinRequest: RequestType {
Expand All @@ -21,9 +21,9 @@ extension HistoricalCoinRequest: RequestType {

var path: String {
switch self {
case .historicalCoin(_, _, let period) where period == .day:
case .historicalCoin(_, _, let duration) where duration == .day:
return "/data/v2/histohour"
case .historicalCoin(_, _, let period) where period == .week:
case .historicalCoin(_, _, let duration) where duration == .week:
return "/data/v2/histoday"
default:
fatalError()
Expand All @@ -40,11 +40,11 @@ extension HistoricalCoinRequest: RequestType {

var parameters: Parameters? {
switch self {
case .historicalCoin(let from, let to, let period):
case .historicalCoin(let from, let to, let duration):
return [
"fsym": from.name,
"tsym": to ?? "USD",
"limit": "\(period.limit)"
"limit": "\(duration.limit)"
]
}
}
Expand Down
43 changes: 26 additions & 17 deletions Coins/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="oKt-f7-5rF">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="oKt-f7-5rF">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -206,10 +206,10 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="yNB-4O-w9n">
<rect key="frame" x="16" y="225" width="382" height="446"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="R8t-5y-VfS">
<rect key="frame" x="16" y="156" width="382" height="641"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Rw3-58-Ejj">
<stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="252" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Rw3-58-Ejj">
<rect key="frame" x="0.0" y="0.0" width="382" height="48"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="BTC" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iem-I2-Cbe">
Expand All @@ -218,47 +218,53 @@
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USD 0.00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Wd-vm-4Vu">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USD" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Wd-vm-4Vu">
<rect key="frame" x="0.0" y="22" width="382" height="26"/>
<fontDescription key="fontDescription" name="Graphik-Medium" family="Graphik" pointSize="26"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ghV-fW-w2x" customClass="LineChartView" customModule="Charts">
<rect key="frame" x="0.0" y="56" width="382" height="351"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<view contentMode="scaleToFill" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="ghV-fW-w2x" customClass="LineChartView" customModule="Charts">
<rect key="frame" x="0.0" y="56" width="382" height="300"/>
<color key="backgroundColor" systemColor="systemGroupedBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="351" id="qQx-tB-akS"/>
<constraint firstAttribute="height" constant="300" id="HI9-2R-1Tc"/>
</constraints>
</view>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Io6-j6-74X">
<rect key="frame" x="0.0" y="415" width="382" height="32"/>
<segmentedControl opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="252" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Io6-j6-74X">
<rect key="frame" x="0.0" y="364" width="382" height="32"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<segments>
<segment title="1D"/>
<segment title="1W"/>
</segments>
<connections>
<action selector="periodSegmentedControlDidTap:" destination="dcD-N1-n1g" eventType="valueChanged" id="Ai0-5Q-xSZ"/>
<action selector="durationSegmentedControlDidTap:" destination="dcD-N1-n1g" eventType="valueChanged" id="96O-7i-yD4"/>
</connections>
</segmentedControl>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1Aa-ss-KNz">
<rect key="frame" x="0.0" y="403" width="382" height="238"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="f1v-xF-ETq"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="yNB-4O-w9n" firstAttribute="leading" secondItem="f1v-xF-ETq" secondAttribute="leading" constant="16" id="V5A-j4-L90"/>
<constraint firstItem="yNB-4O-w9n" firstAttribute="centerX" secondItem="D5N-8O-MRf" secondAttribute="centerX" id="gcd-rb-0f5"/>
<constraint firstItem="yNB-4O-w9n" firstAttribute="centerY" secondItem="D5N-8O-MRf" secondAttribute="centerY" id="iDj-Qg-fnD"/>
<constraint firstItem="f1v-xF-ETq" firstAttribute="bottom" secondItem="R8t-5y-VfS" secondAttribute="bottom" constant="16" id="0uA-0k-lBH"/>
<constraint firstItem="R8t-5y-VfS" firstAttribute="top" secondItem="f1v-xF-ETq" secondAttribute="top" constant="16" id="NcA-wq-6MI"/>
<constraint firstItem="f1v-xF-ETq" firstAttribute="trailing" secondItem="R8t-5y-VfS" secondAttribute="trailing" constant="16" id="eMy-Gq-T4l"/>
<constraint firstItem="R8t-5y-VfS" firstAttribute="leading" secondItem="f1v-xF-ETq" secondAttribute="leading" constant="16" id="vin-8o-UB7"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="ggc-pi-UIl"/>
<connections>
<outlet property="chartView" destination="ghV-fW-w2x" id="g51-RC-1hx"/>
<outlet property="coinLabel" destination="iem-I2-Cbe" id="QUG-yf-KHe"/>
<outlet property="periodSegmentedControl" destination="Io6-j6-74X" id="9ON-OE-AtG"/>
<outlet property="durationSegmentedControl" destination="Io6-j6-74X" id="9ON-OE-AtG"/>
<outlet property="priceLabel" destination="4Wd-vm-4Vu" id="UZG-dG-U3c"/>
</connections>
</viewController>
Expand Down Expand Up @@ -335,5 +341,8 @@
<systemColor name="systemGreenColor">
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGroupedBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Loading

0 comments on commit 753da1d

Please sign in to comment.