-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new Line chart (also interactive) Added new color schemes
- Loading branch information
Showing
23 changed files
with
723 additions
and
191 deletions.
There are no files selected for viewing
Binary file added
BIN
+9.92 KB
...code/package.xcworkspace/xcuserdata/andrassamu.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
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
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,39 @@ | ||
// | ||
// ChartRow.swift | ||
// ChartView | ||
// | ||
// Created by András Samu on 2019. 06. 12.. | ||
// Copyright © 2019. András Samu. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct BarChartRow : View { | ||
var data: [Int] | ||
var accentColor: Color | ||
var secondGradientAccentColor: Color? | ||
var maxValue: Int { | ||
data.max() ?? 0 | ||
} | ||
@Binding var touchLocation: CGFloat | ||
public var body: some View { | ||
GeometryReader { geometry in | ||
HStack(alignment: .bottom, spacing: (geometry.frame(in: .local).width-22)/CGFloat(self.data.count * 3)){ | ||
ForEach(0..<self.data.count) { i in | ||
BarChartCell(value: Double(self.data[i])/Double(self.maxValue), index: i, width: Float(geometry.frame(in: .local).width - 22), numberOfDataPoints: self.data.count, accentColor: self.accentColor, secondGradientAccentColor: self.secondGradientAccentColor, touchLocation: self.$touchLocation) | ||
.scaleEffect(self.touchLocation > CGFloat(i)/CGFloat(self.data.count) && self.touchLocation < CGFloat(i+1)/CGFloat(self.data.count) ? CGSize(width: 1.4, height: 1.1) : CGSize(width: 1, height: 1), anchor: .bottom) | ||
|
||
} | ||
} | ||
.padding([.top, .leading, .trailing], 10) | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct ChartRow_Previews : PreviewProvider { | ||
static var previews: some View { | ||
BarChartRow(data: [8,23,54,32,12,37,7], accentColor: Colors.OrangeStart, touchLocation: .constant(-1)) | ||
} | ||
} | ||
#endif |
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,104 @@ | ||
// | ||
// ChartView.swift | ||
// ChartView | ||
// | ||
// Created by András Samu on 2019. 06. 12.. | ||
// Copyright © 2019. András Samu. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct BarChartView : View { | ||
public var data: [Int] | ||
public var title: String | ||
public var legend: String? | ||
public var style: ChartStyle | ||
let selectionFeedbackGenerator = UISelectionFeedbackGenerator() | ||
|
||
@State private var touchLocation: CGFloat = -1.0 | ||
@State private var showValue: Bool = false | ||
@State private var currentValue: Int = 0 { | ||
didSet{ | ||
if(oldValue != self.currentValue && self.showValue) { | ||
selectionFeedbackGenerator.selectionChanged() | ||
} | ||
} | ||
} | ||
var isFullWidth:Bool { | ||
return self.style.chartFormSize == Form.large | ||
} | ||
public init(data: [Int], title: String, legend: String? = nil, style: ChartStyle = Styles.barChartStyleOne ){ | ||
self.data = data | ||
self.title = title | ||
self.legend = legend | ||
self.style = style | ||
} | ||
|
||
public var body: some View { | ||
ZStack{ | ||
Rectangle() | ||
.fill(self.style.backgroundColor) | ||
.cornerRadius(20) | ||
.shadow(color: Color.gray, radius: 8 ) | ||
VStack(alignment: .leading){ | ||
HStack{ | ||
if(!showValue){ | ||
Text(self.title) | ||
.font(.headline) | ||
.foregroundColor(self.style.textColor) | ||
}else{ | ||
Text("\(self.currentValue)") | ||
.font(.headline) | ||
.foregroundColor(self.style.textColor) | ||
} | ||
if(self.style.chartFormSize == Form.large && self.legend != nil && !showValue) { | ||
Text(self.legend!) | ||
.font(.callout) | ||
.foregroundColor(self.style.accentColor) | ||
.transition(.opacity) | ||
.animation(.easeOut) | ||
} | ||
Spacer() | ||
Image(systemName: "waveform.path.ecg") | ||
.imageScale(.large) | ||
.foregroundColor(self.style.legendTextColor) | ||
}.padding() | ||
BarChartRow(data: data, accentColor: self.style.accentColor, secondGradientAccentColor: self.style.secondGradientColor, touchLocation: self.$touchLocation) | ||
if self.legend != nil && self.style.chartFormSize == Form.medium { | ||
Text(self.legend!) | ||
.font(.headline) | ||
.foregroundColor(self.style.legendTextColor) | ||
.padding() | ||
} | ||
|
||
} | ||
}.frame(minWidth:self.style.chartFormSize.width, maxWidth: self.isFullWidth ? .infinity : self.style.chartFormSize.width, minHeight:self.style.chartFormSize.height, maxHeight:self.style.chartFormSize.height) | ||
.gesture(DragGesture() | ||
.onChanged({ value in | ||
self.touchLocation = value.location.x/self.style.chartFormSize.width | ||
self.showValue = true | ||
self.currentValue = self.getCurrentValue() | ||
}) | ||
.onEnded({ value in | ||
self.showValue = false | ||
self.touchLocation = -1 | ||
}) | ||
) | ||
.gesture(TapGesture() | ||
) | ||
} | ||
|
||
func getCurrentValue()-> Int{ | ||
let index = max(0,min(self.data.count-1,Int(floor((self.touchLocation*self.style.chartFormSize.width)/(self.style.chartFormSize.width/CGFloat(self.data.count)))))) | ||
print(index) | ||
return self.data[index] | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct ChartView_Previews : PreviewProvider { | ||
static var previews: some View { | ||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", legend: "Legendary") | ||
} | ||
} | ||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.