Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from denniscm190/denniscm190
Browse files Browse the repository at this point in the history
Denniscm190
  • Loading branch information
denniscmcom authored May 7, 2021
2 parents 390cac9 + 4c422b5 commit 9852635
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 23 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>StockCharts.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
16 changes: 8 additions & 8 deletions DemoProject/DemoProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
9553737B26454C37003BDDEC /* StockCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 9553737A26454C37003BDDEC /* StockCharts */; };
95770BDF263C5F85003FA924 /* DemoProjectApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BDE263C5F85003FA924 /* DemoProjectApp.swift */; };
95770BE1263C5F85003FA924 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BE0263C5F85003FA924 /* ContentView.swift */; };
95770BE3263C5F86003FA924 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95770BE2263C5F86003FA924 /* Assets.xcassets */; };
95770BE6263C5F86003FA924 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95770BE5263C5F86003FA924 /* Preview Assets.xcassets */; };
95770BEE263C5FCD003FA924 /* View1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BED263C5FCD003FA924 /* View1.swift */; };
9584AA90264048AD00626769 /* StockCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 9584AA8F264048AD00626769 /* StockCharts */; };
9584AA92264048D700626769 /* View2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9584AA91264048D700626769 /* View2.swift */; };
/* End PBXBuildFile section */

Expand All @@ -32,7 +32,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9584AA90264048AD00626769 /* StockCharts in Frameworks */,
9553737B26454C37003BDDEC /* StockCharts in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -94,7 +94,7 @@
);
name = DemoProject;
packageProductDependencies = (
9584AA8F264048AD00626769 /* StockCharts */,
9553737A26454C37003BDDEC /* StockCharts */,
);
productName = DemoProject;
productReference = 95770BDB263C5F85003FA924 /* DemoProject.app */;
Expand Down Expand Up @@ -124,7 +124,7 @@
);
mainGroup = 95770BD2263C5F85003FA924;
packageReferences = (
9584AA8E264048AD00626769 /* XCRemoteSwiftPackageReference "StockCharts" */,
9553737926454C37003BDDEC /* XCRemoteSwiftPackageReference "StockCharts" */,
);
productRefGroup = 95770BDC263C5F85003FA924 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -346,20 +346,20 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
9584AA8E264048AD00626769 /* XCRemoteSwiftPackageReference "StockCharts" */ = {
9553737926454C37003BDDEC /* XCRemoteSwiftPackageReference "StockCharts" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/denniscm190/StockCharts.git";
requirement = {
branch = main;
branch = denniscm190;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
9584AA8F264048AD00626769 /* StockCharts */ = {
9553737A26454C37003BDDEC /* StockCharts */ = {
isa = XCSwiftPackageProductDependency;
package = 9584AA8E264048AD00626769 /* XCRemoteSwiftPackageReference "StockCharts" */;
package = 9553737926454C37003BDDEC /* XCRemoteSwiftPackageReference "StockCharts" */;
productName = StockCharts;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"package": "StockCharts",
"repositoryURL": "https://github.com/denniscm190/StockCharts.git",
"state": {
"branch": "main",
"revision": "63798e38d49dfd38625aae730b6d062fbc6288f2",
"branch": "denniscm190",
"revision": "838eb395f952ad7271e53429f7cd91fb21c84108",
"version": null
}
}
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion DemoProject/DemoProject/View1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct View1: View {
var data: [Double]
var dates: [String]?
var hours: [String]?
var dragGesture: Bool?

var range = ["5D", "1M", "3M", "1Y", "5Y"]
@State private var selectedRange = "3M"
Expand All @@ -31,7 +32,7 @@ struct View1: View {
.pickerStyle(SegmentedPickerStyle())
.padding(.horizontal)

ChartView(data: data, dates: dates, hours: hours)
LineChartView(data: data, dates: dates, hours: hours, dragGesture: dragGesture)
.padding(.vertical)

List(1..<7) { i in
Expand Down
2 changes: 1 addition & 1 deletion DemoProject/DemoProject/View2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct ItemView2: View {

}
.padding(.leading)
ChartView(data: data, dates: nil, hours: nil)
LineChartView(data: data, dates: nil, hours: nil, dragGesture: false)
.padding(.bottom)
.clipShape(RoundedRectangle(cornerRadius: 15))
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import StockCharts

### Line chart
```swift
ChartView(data: [Double], dates: [String]?, hours: [String]?)
LineChartView(data: [Double], dates: [String]?, hours: [String]?, dragGesture: Bool?)
```

#### Arguments
```swift
data: [120.3, 121.0, 132.4, ...]
dates: ["yyyy-MM-dd", "2021-01-01", "2021-01-02", ...]
hours: ["10:20", "10:21", "10:22", ...] // It could be any format
dragGesture: false // By default is true
```
<img width="374" alt="LineChartVideo" src="https://user-images.githubusercontent.com/66180929/116899623-137c6e80-ac38-11eb-8ec0-e678aea54062.gif">
2 changes: 1 addition & 1 deletion Sources/StockCharts/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
4 changes: 3 additions & 1 deletion Sources/StockCharts/LineChart/Helpers/LineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct LineView: View {
public var data: [Double]
public var dates: [String]?
public var hours: [String]?
public var dragGesture: Bool?

@Binding var showingIndicators: Bool
@Binding var indexPosition: Int
Expand All @@ -32,7 +33,7 @@ public struct LineView: View {
.rotationEffect(.degrees(180), anchor: .center)
.rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0))
.contentShape(Rectangle()) // Control tappable area
.gesture(
.gesture(dragGesture ?? true ?
LongPressGesture(minimumDuration: 0.2)
.sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local))
.onChanged({ value in // Get value of the gesture
Expand All @@ -49,6 +50,7 @@ public struct LineView: View {
.onEnded({ value in
self.showingIndicators = false
})
: nil // On dragGesture = false
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
//
// ChartView.swift
// LineChartView.swift
// StockCharts
//
// Created by Dennis Concepción Martín on 30/4/21.
//

import SwiftUI

public struct ChartView: View {
public struct LineChartView: View {
public var data: [Double]
public var dates: [String]?
public var hours: [String]?
public var dragGesture: Bool?

@State var showingIndicators = false
@State var indexPosition = Int()

public init(data: [Double], dates: [String]?, hours: [String]?) {
public init(data: [Double], dates: [String]?, hours: [String]?, dragGesture: Bool?) {
self.data = data
self.dates = dates
self.hours = hours
self.dragGesture = dragGesture
}

public var body: some View {
Expand All @@ -27,7 +29,7 @@ public struct ChartView: View {
.opacity(showingIndicators ? 1: 0)
.padding(.vertical)

LineView(data: data, showingIndicators: $showingIndicators, indexPosition: $indexPosition)
LineView(data: data, dates: dates, hours: hours, dragGesture: dragGesture, showingIndicators: $showingIndicators, indexPosition: $indexPosition)
}
}
}
10 changes: 6 additions & 4 deletions StockCharts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
95770B8B263C57B5003FA924 /* StockCharts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95770B81263C57B5003FA924 /* StockCharts.framework */; };
95770B90263C57B5003FA924 /* StockChartsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770B8F263C57B5003FA924 /* StockChartsTests.swift */; };
95770B92263C57B5003FA924 /* StockCharts.h in Headers */ = {isa = PBXBuildFile; fileRef = 95770B84263C57B5003FA924 /* StockCharts.h */; settings = {ATTRIBUTES = (Public, ); }; };
95770BA0263C590C003FA924 /* ChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770B9F263C590C003FA924 /* ChartView.swift */; };
95770BA0263C590C003FA924 /* LineChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770B9F263C590C003FA924 /* LineChartView.swift */; };
95770BA3263C5934003FA924 /* ChartLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BA2263C5934003FA924 /* ChartLabel.swift */; };
95770BA5263C594C003FA924 /* IndicatorPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BA4263C594C003FA924 /* IndicatorPoint.swift */; };
95770BA7263C596E003FA924 /* LinePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770BA6263C596E003FA924 /* LinePath.swift */; };
Expand All @@ -35,7 +35,7 @@
95770B8F263C57B5003FA924 /* StockChartsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StockChartsTests.swift; sourceTree = "<group>"; };
95770B91263C57B5003FA924 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
95770B9D263C58B1003FA924 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
95770B9F263C590C003FA924 /* ChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartView.swift; sourceTree = "<group>"; };
95770B9F263C590C003FA924 /* LineChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineChartView.swift; sourceTree = "<group>"; };
95770BA2263C5934003FA924 /* ChartLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartLabel.swift; sourceTree = "<group>"; };
95770BA4263C594C003FA924 /* IndicatorPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndicatorPoint.swift; sourceTree = "<group>"; };
95770BA6263C596E003FA924 /* LinePath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinePath.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -122,7 +122,7 @@
95770B9E263C58F4003FA924 /* LineChart */ = {
isa = PBXGroup;
children = (
95770B9F263C590C003FA924 /* ChartView.swift */,
95770B9F263C590C003FA924 /* LineChartView.swift */,
95770BA1263C5927003FA924 /* Helpers */,
);
path = LineChart;
Expand Down Expand Up @@ -248,7 +248,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
95770BA0263C590C003FA924 /* ChartView.swift in Sources */,
95770BA0263C590C003FA924 /* LineChartView.swift in Sources */,
95770BA3263C5934003FA924 /* ChartLabel.swift in Sources */,
95770BA7263C596E003FA924 /* LinePath.swift in Sources */,
95770BA9263C5988003FA924 /* LineView.swift in Sources */,
Expand Down Expand Up @@ -414,6 +414,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = io.dennistech.StockCharts;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -441,6 +442,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = io.dennistech.StockCharts;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
Binary file not shown.

0 comments on commit 9852635

Please sign in to comment.