-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7249630
Showing
46 changed files
with
3,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
11 changes: 11 additions & 0 deletions
11
Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// ContentView.swift | ||
// Example | ||
// | ||
// Created by andooown on 2023/08/29. | ||
// | ||
|
||
import SwiftUI | ||
import ChartCore | ||
|
||
struct ContentView: View { | ||
enum Destination: Hashable { | ||
case simple | ||
case lines | ||
case fill | ||
case interaction | ||
case smooth | ||
case animation | ||
case demo | ||
} | ||
|
||
var body: some View { | ||
NavigationStack { | ||
List { | ||
Section("Basic") { | ||
NavigationLink("Simple Chart", value: Destination.simple) | ||
NavigationLink("Lines", value: Destination.lines) | ||
NavigationLink("Fill", value: Destination.fill) | ||
NavigationLink("Interaction", value: Destination.interaction) | ||
NavigationLink("Smoothing", value: Destination.smooth) | ||
NavigationLink("Animation", value: Destination.animation) | ||
} | ||
Section("Advanced") { | ||
NavigationLink("Demo", value: Destination.demo) | ||
} | ||
} | ||
.navigationTitle("Example") | ||
.navigationDestination(for: Destination.self) { | ||
switch $0 { | ||
case .simple: | ||
SimpleChart() | ||
|
||
case .lines: | ||
LinesChart() | ||
|
||
case .fill: | ||
FillChart() | ||
|
||
case .interaction: | ||
InteractionChart() | ||
|
||
case .smooth: | ||
SmoothChart() | ||
|
||
case .animation: | ||
AnimationChart() | ||
|
||
case .demo: | ||
DemoChart() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ExampleApp.swift | ||
// Example | ||
// | ||
// Created by andooown on 2023/08/29. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct ExampleApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// AnimationChart.swift | ||
// Example | ||
// | ||
// Created by andooown on 2023/08/30. | ||
// | ||
|
||
import SwiftUI | ||
import ChartCore | ||
import LineChart | ||
|
||
struct AnimationChart: View { | ||
@State | ||
private var showsDetail = false | ||
@State | ||
private var showsPoints = true | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
AnimatableChart( | ||
entries: SampleData.entries, | ||
showsPoints: showsPoints, | ||
ratio: showsDetail ? 1 : 0 | ||
) | ||
|
||
Divider() | ||
.padding(.vertical) | ||
|
||
Button("Toggle", action: { | ||
withAnimation { | ||
showsDetail.toggle() | ||
} | ||
}) | ||
.frame(maxWidth: .infinity) | ||
|
||
Toggle("Show Points:", isOn: $showsPoints) | ||
|
||
Spacer() | ||
} | ||
.padding() | ||
.navigationTitle("Animation") | ||
} | ||
} | ||
|
||
private struct AnimatableChart: View, Animatable { | ||
let entries: [OptionalEntry] | ||
let showsPoints: Bool | ||
var ratio: Double | ||
|
||
var animatableData: Double { | ||
get { ratio } | ||
set { ratio = newValue } | ||
} | ||
|
||
var body: some View { | ||
LineChart(entries) { context in | ||
let mixed = mixedContext(context) | ||
|
||
ZStack { | ||
if ratio < 0.5 { | ||
SplineLine(context: mixed) | ||
.stroke(style: StrokeStyle(lineWidth: 1, lineCap: .round)) | ||
.fill(Color.orange) | ||
} else { | ||
LinearLine(context: mixed) | ||
.stroke(style: StrokeStyle(lineWidth: 1, lineCap: .round)) | ||
.fill(Color.orange) | ||
} | ||
|
||
if showsPoints { | ||
Point(context: mixed, radius: 3) | ||
.fill(Color.orange) | ||
} | ||
} | ||
.frame(height: 200) | ||
.markAsChartContent() | ||
} | ||
.chartScale(y: 0.8) | ||
} | ||
|
||
func mixedContext(_ context: ChartContext) -> ChartContext { | ||
context.transformEntries { entries in | ||
let base = MovingAverageCalculator(range: 3)(entries) | ||
let detail = entries | ||
|
||
return MixedValueCalculator(ratio: ratio)(base, detail) | ||
} | ||
} | ||
} |
Oops, something went wrong.