Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mercari-oss-bot committed Sep 4, 2023
0 parents commit 7249630
Show file tree
Hide file tree
Showing 46 changed files with 3,304 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
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
425 changes: 425 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json
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 Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json
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
}
}
6 changes: 6 additions & 0 deletions Example/Example/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
70 changes: 70 additions & 0 deletions Example/Example/ContentView.swift
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()
}
}
17 changes: 17 additions & 0 deletions Example/Example/ExampleApp.swift
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()
}
}
}
89 changes: 89 additions & 0 deletions Example/Example/Examples/AnimationChart.swift
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)
}
}
}
Loading

0 comments on commit 7249630

Please sign in to comment.