Skip to content

Commit

Permalink
New: 1.Support input array with any length 2.Add a demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Tian authored and Qu Tian committed Jul 31, 2024
1 parent 12b6b4b commit a13edc4
Show file tree
Hide file tree
Showing 13 changed files with 833 additions and 3 deletions.
609 changes: 609 additions & 0 deletions DemoApp/DemoApp/DemoApp.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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 DemoApp/DemoApp/DemoApp/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
40 changes: 40 additions & 0 deletions DemoApp/DemoApp/DemoApp/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ContentView.swift
// DemoApp
//
// Created by Qu Tian on 2024/7/31.
//

import SwiftUI
import ContributionChart


struct ContentView: View {
@State private var data = [0.87, 0.17, 0.6, 0.21, 0.88, 0.41, 0.37, 0.39, 0.34, 0.91, 0.45, 0.51, 0.1, 0.97, 0.32, 0.72, 0.15, 0.2, 0.87, 0.86, 0.35, 0.12, 0.77, 0.56]

var body: some View {
RecordBlock {
ContributionChartView(data: data, rows: 3, columns: 8, targetValue: 1.0)
}
.frame(width: 210, height: 95)
.padding()
}
}

fileprivate struct RecordBlock<Content:View>: View {
@ViewBuilder var content:Content

var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 16)
.fill(Color.white)
.shadow(color: Color.black.opacity(0.3), radius: 16.0, y: 16.0)
content
}
}
}


#Preview {
ContentView()
}
17 changes: 17 additions & 0 deletions DemoApp/DemoApp/DemoApp/DemoAppApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DemoAppApp.swift
// DemoApp
//
// Created by Qu Tian on 2024/7/31.
//

import SwiftUI

@main
struct DemoAppApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
36 changes: 36 additions & 0 deletions DemoApp/DemoApp/DemoAppTests/DemoAppTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// DemoAppTests.swift
// DemoAppTests
//
// Created by Qu Tian on 2024/7/31.
//

import XCTest
@testable import DemoApp

final class DemoAppTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
41 changes: 41 additions & 0 deletions DemoApp/DemoApp/DemoAppUITests/DemoAppUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DemoAppUITests.swift
// DemoAppUITests
//
// Created by Qu Tian on 2024/7/31.
//

import XCTest

final class DemoAppUITests: 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.
}

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.
}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
32 changes: 32 additions & 0 deletions DemoApp/DemoApp/DemoAppUITests/DemoAppUITestsLaunchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// DemoAppUITestsLaunchTests.swift
// DemoAppUITests
//
// Created by Qu Tian on 2024/7/31.
//

import XCTest

final class DemoAppUITestsLaunchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
}

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)
}
}
10 changes: 7 additions & 3 deletions Sources/ContributionChart/ContributionChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public struct ContributionChartView: View {
self.data = data
self.rows = rows
self.columns = columns
if data.count < rows * columns {
let elementsToAdd = Array(repeating: 0.0, count: rows * columns - data.count)
self.data.append(contentsOf: elementsToAdd)
}
self.targetValue = targetValue
self.blockColor = blockColor
self.heatMapRectangleWidth = RectangleWidth
Expand Down Expand Up @@ -103,7 +107,7 @@ struct ContributionChartRowView: View {
}

func opacityRatio(index: Int) -> Double {
var opacityRatio: Double = Double(rowData[index]) / Double(targetValue)
let opacityRatio: Double = Double(rowData[index]) / Double(targetValue)
return opacityRatio > 1.0 ? 1.0 : opacityRatio
}

Expand Down Expand Up @@ -137,7 +141,7 @@ extension Color {
static let secondaryBackground = Color(UIColor.secondarySystemBackground)
static let tertiaryBackground = Color(UIColor.tertiarySystemBackground)
#endif
#if os(watchOS)
#if os(watchOS)
static let background = Color.black
#endif
#endif
}

0 comments on commit a13edc4

Please sign in to comment.