Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e362b9eea | |||
| f7d9895e36 | |||
| 04b6e385ea | |||
| 9f2e3d32df | |||
| 524aec2a04 | |||
| 03f90728b4 | |||
| 0d95dbd3d4 | |||
| fd14ca2327 | |||
| 20fb782a3e | |||
| 9fa7e20221 | |||
| b5e3aa897c | |||
| 1b45a6a922 | |||
| d3d0b086f1 | |||
| 6cc43d9dc0 | |||
| e081d3a88d | |||
| e5c309eac4 | |||
| 3f542f92e3 | |||
| 7a9f013631 | |||
| 8dffe79e28 | |||
| d5a1c0065c | |||
| b9761d3eb9 | |||
| c3c0a8a7c4 | |||
| b597faac76 | |||
| fc1099f486 |
@@ -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>SwiftUICharts.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Swift package for displaying charts effortlessly.
|
||||
|
||||

|
||||

|
||||
|
||||
It supports:
|
||||
* Line charts
|
||||
@@ -11,9 +11,9 @@ It supports:
|
||||
|
||||
### Installation:
|
||||
|
||||
It requires iOS 13 and xCode 11!
|
||||
It requires iOS 13 and Xcode 11!
|
||||
|
||||
In xCode got to `File -> Swift Packages -> Add Package Dependency` and paste inthe repo's url: `https://github.com/AppPear/ChartView`
|
||||
In Xcode got to `File -> Swift Packages -> Add Package Dependency` and paste inthe repo's url: `https://github.com/AppPear/ChartView`
|
||||
|
||||
### Usage:
|
||||
|
||||
@@ -21,8 +21,23 @@ import the package in the file you would like to use it: `import SwiftUICharts`
|
||||
|
||||
You can display a Chart by adding a chart view to your parent view:
|
||||
|
||||
### Demo
|
||||
|
||||
Added an example project, with **iOS, watchOS** target: https://github.com/AppPear/ChartViewDemo
|
||||
|
||||
## Line charts
|
||||

|
||||
|
||||
**New full screen view called LineView!!!**
|
||||
|
||||

|
||||
|
||||
```swift
|
||||
LineView(data: [8,23,54,32,12,37,7,23,43], title: "Line chart", legend: "Full screen") // legend is optional, use optional .padding()
|
||||
```
|
||||
|
||||
Adopts to dark mode automatically
|
||||
|
||||

|
||||
|
||||
**Line chart is interactive, so you can drag across to reveal the data points**
|
||||
|
||||
@@ -32,27 +47,61 @@ You can add a line chart with the following code:
|
||||
LineChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", legend: "Legendary") // legend is optional
|
||||
```
|
||||
|
||||
**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`**
|
||||
|
||||
|
||||
## Bar charts
|
||||

|
||||

|
||||
|
||||
**[New feature] you can display labels also along values and points for each bar to descirbe your data better!**
|
||||
**Bar chart is interactive, so you can drag across to reveal the data points**
|
||||
|
||||
You can add a bar chart with the following code:
|
||||
|
||||
Labels and points:
|
||||
|
||||
```swift
|
||||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", legend: "Legendary") // legend is optional
|
||||
BarChartView(data: ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)]), title: "Sales", legend: "Quarterly") // legend is optional
|
||||
```
|
||||
Only points:
|
||||
|
||||
```swift
|
||||
BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", legend: "Legendary") // legend is optional
|
||||
```
|
||||
|
||||
You can add different formats:
|
||||
* Small `Form.small`
|
||||
* Medium `Form.medium`
|
||||
* Large `Form.large`
|
||||
**ChartData** structure
|
||||
Stores values in data pairs (actually tuple): `(String,Double)`
|
||||
* you can have duplicate values
|
||||
* keeps the data order
|
||||
|
||||
You can initialise ChartData multiple ways:
|
||||
* For integer values: `ChartData(points: [8,23,54,32,12,37,7,23,43])`
|
||||
* For floating point values: `ChartData(points: [2.34,3.14,4.56])`
|
||||
* For label,value pairs: `ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900)])`
|
||||
|
||||
|
||||
You can add different formats:
|
||||
* Small `ChartForm.small`
|
||||
* Medium `ChartForm.medium`
|
||||
* Large `ChartForm.large`
|
||||
|
||||
```swift
|
||||
BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", form: ChartForm.small)
|
||||
```
|
||||
|
||||
For floating point numbers, you can set a custom specifier:
|
||||
|
||||
```swift
|
||||
BarChartView(data: ChartData(points:[1.23,2.43,3.37]) ,title: "A", valueSpecifier: "%.2f")
|
||||
```
|
||||
For integers you can disable by passing: `valueSpecifier: "%.0f"`
|
||||
|
||||
|
||||
You can set your custom image in the upper right corner by passing in the initialiser: `cornerImage:Image(systemName: "waveform.path.ecg")`
|
||||
|
||||
|
||||
**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`**
|
||||
|
||||
```swift
|
||||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", style: ChartStyle(formSize: Form.small))
|
||||
```
|
||||
|
||||
### You can customize styling of the chart with a ChartStyle object:
|
||||
|
||||
Customizable:
|
||||
@@ -63,7 +112,7 @@ Customizable:
|
||||
* legend text color
|
||||
|
||||
```swift
|
||||
let chartStyle = ChartStyle(backgroundColor: Color.black, accentColor: Colors.OrangeStart, secondGradientColor: Colors.OrangeEnd, chartFormSize: Form.medium, textColor: Color.white, legendTextColor: Color.white )
|
||||
let chartStyle = ChartStyle(backgroundColor: Color.black, accentColor: Colors.OrangeStart, secondGradientColor: Colors.OrangeEnd, chartFormSize: ChartForm.medium, textColor: Color.white, legendTextColor: Color.white )
|
||||
...
|
||||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", style: chartStyle)
|
||||
```
|
||||
@@ -80,29 +129,29 @@ You can access built-in styles:
|
||||
* barChartMidnightGreenLight
|
||||
* barChartMidnightGreenDark
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
### You can customize the size of the chart with a Form object:
|
||||
### You can customize the size of the chart with a ChartForm object:
|
||||
|
||||
**Form**
|
||||
**ChartForm**
|
||||
* `.small`
|
||||
* `.medium`
|
||||
* `.large`
|
||||
* `.detail`
|
||||
|
||||
```swift
|
||||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", form: Form.small)
|
||||
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", form: ChartForm.small)
|
||||
```
|
||||
|
||||
### WatchOS support for Bar charts:
|
||||
|
||||

|
||||

|
||||
|
||||
## Pie charts
|
||||

|
||||

|
||||
|
||||
You can add a line chart with the following code:
|
||||
|
||||
@@ -110,3 +159,5 @@ You can add a line chart with the following code:
|
||||
PieChartView(data: [8,23,54,32], title: "Title", legend: "Legendary") // legend is optional
|
||||
```
|
||||
|
||||
**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`**
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 514 KiB |
|
After Width: | Height: | Size: 502 KiB |
|
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 222 KiB |
|
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 278 KiB After Width: | Height: | Size: 278 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 73 KiB |
@@ -9,10 +9,10 @@
|
||||
import SwiftUI
|
||||
|
||||
public struct BarChartRow : View {
|
||||
var data: [Int]
|
||||
var data: [Double]
|
||||
var accentColor: Color
|
||||
var secondGradientAccentColor: Color?
|
||||
var maxValue: Int {
|
||||
var maxValue: Double {
|
||||
data.max() ?? 0
|
||||
}
|
||||
@Binding var touchLocation: CGFloat
|
||||
@@ -22,6 +22,7 @@ public struct BarChartRow : View {
|
||||
ForEach(0..<self.data.count) { i in
|
||||
BarChartCell(value: self.normalizedValue(index: i), 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)
|
||||
.animation(.spring())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,32 +9,37 @@
|
||||
import SwiftUI
|
||||
|
||||
public struct BarChartView : View {
|
||||
public var data: [Int]
|
||||
private var data: ChartData
|
||||
public var title: String
|
||||
public var legend: String?
|
||||
public var style: ChartStyle
|
||||
public var formSize:CGSize
|
||||
// let selectionFeedbackGenerator = UISelectionFeedbackGenerator()
|
||||
public var dropShadow: Bool
|
||||
public var cornerImage: Image
|
||||
public var valueSpecifier:String
|
||||
|
||||
@State private var touchLocation: CGFloat = -1.0
|
||||
@State private var showValue: Bool = false
|
||||
@State private var currentValue: Int = 0 {
|
||||
@State private var showLabelValue: Bool = false
|
||||
@State private var currentValue: Double = 0 {
|
||||
didSet{
|
||||
if(oldValue != self.currentValue && self.showValue) {
|
||||
// selectionFeedbackGenerator.selectionChanged()
|
||||
HapticFeedback.playSelection()
|
||||
}
|
||||
}
|
||||
}
|
||||
var isFullWidth:Bool {
|
||||
return self.formSize == Form.large
|
||||
return self.formSize == ChartForm.large
|
||||
}
|
||||
public init(data: [Int], title: String, legend: String? = nil, style: ChartStyle = Styles.barChartStyleOrangeLight, form: CGSize? = Form.medium){
|
||||
public init(data:ChartData, title: String, legend: String? = nil, style: ChartStyle = Styles.barChartStyleOrangeLight, form: CGSize? = ChartForm.medium, dropShadow: Bool? = true, cornerImage:Image? = Image(systemName: "waveform.path.ecg"), valueSpecifier: String? = "%.1f"){
|
||||
self.data = data
|
||||
self.title = title
|
||||
self.legend = legend
|
||||
self.style = style
|
||||
self.formSize = form!
|
||||
self.dropShadow = dropShadow!
|
||||
self.cornerImage = cornerImage!
|
||||
self.valueSpecifier = valueSpecifier!
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
@@ -42,7 +47,7 @@ public struct BarChartView : View {
|
||||
Rectangle()
|
||||
.fill(self.style.backgroundColor)
|
||||
.cornerRadius(20)
|
||||
.shadow(color: Color.gray, radius: 8 )
|
||||
.shadow(color: Color.gray, radius: self.dropShadow ? 8 : 0)
|
||||
VStack(alignment: .leading){
|
||||
HStack{
|
||||
if(!showValue){
|
||||
@@ -50,11 +55,11 @@ public struct BarChartView : View {
|
||||
.font(.headline)
|
||||
.foregroundColor(self.style.textColor)
|
||||
}else{
|
||||
Text("\(self.currentValue)")
|
||||
Text("\(self.currentValue, specifier: self.valueSpecifier)")
|
||||
.font(.headline)
|
||||
.foregroundColor(self.style.textColor)
|
||||
}
|
||||
if(self.formSize == Form.large && self.legend != nil && !showValue) {
|
||||
if(self.formSize == ChartForm.large && self.legend != nil && !showValue) {
|
||||
Text(self.legend!)
|
||||
.font(.callout)
|
||||
.foregroundColor(self.style.accentColor)
|
||||
@@ -62,16 +67,18 @@ public struct BarChartView : View {
|
||||
.animation(.easeOut)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "waveform.path.ecg")
|
||||
self.cornerImage
|
||||
.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.formSize == Form.medium {
|
||||
BarChartRow(data: data.points.map{$0.1}, accentColor: self.style.accentColor, secondGradientAccentColor: self.style.secondGradientColor, touchLocation: self.$touchLocation)
|
||||
if self.legend != nil && self.formSize == ChartForm.medium && !self.showLabelValue{
|
||||
Text(self.legend!)
|
||||
.font(.headline)
|
||||
.foregroundColor(self.style.legendTextColor)
|
||||
.padding()
|
||||
}else if (self.data.valuesGiven) {
|
||||
LabelView(arrowOffset: self.getArrowOffset(touchLocation: self.touchLocation), title: .constant(self.getCurrentValue().0)).offset(x: self.getLabelViewOffset(touchLocation: self.touchLocation), y: -6)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,10 +87,14 @@ public struct BarChartView : View {
|
||||
.onChanged({ value in
|
||||
self.touchLocation = value.location.x/self.formSize.width
|
||||
self.showValue = true
|
||||
self.currentValue = self.getCurrentValue()
|
||||
self.currentValue = self.getCurrentValue().1
|
||||
if(self.data.valuesGiven && self.formSize == ChartForm.medium) {
|
||||
self.showLabelValue = true
|
||||
}
|
||||
})
|
||||
.onEnded({ value in
|
||||
self.showValue = false
|
||||
self.showLabelValue = false
|
||||
self.touchLocation = -1
|
||||
})
|
||||
)
|
||||
@@ -91,17 +102,31 @@ public struct BarChartView : View {
|
||||
)
|
||||
}
|
||||
|
||||
func getCurrentValue()-> Int{
|
||||
let index = max(0,min(self.data.count-1,Int(floor((self.touchLocation*self.formSize.width)/(self.formSize.width/CGFloat(self.data.count))))))
|
||||
print(index)
|
||||
return self.data[index]
|
||||
func getArrowOffset(touchLocation:CGFloat) -> Binding<CGFloat> {
|
||||
let realLoc = (self.touchLocation * self.formSize.width) - 50
|
||||
if realLoc < 10 {
|
||||
return .constant(realLoc - 10)
|
||||
}else if realLoc > self.formSize.width-110 {
|
||||
return .constant((self.formSize.width-110 - realLoc) * -1)
|
||||
} else {
|
||||
return .constant(0)
|
||||
}
|
||||
}
|
||||
|
||||
func getLabelViewOffset(touchLocation:CGFloat) -> CGFloat {
|
||||
return min(self.formSize.width-110,max(10,(self.touchLocation * self.formSize.width) - 50))
|
||||
}
|
||||
|
||||
func getCurrentValue()-> (String,Double) {
|
||||
let index = max(0,min(self.data.points.count-1,Int(floor((self.touchLocation*self.formSize.width)/(self.formSize.width/CGFloat(self.data.points.count))))))
|
||||
return self.data.points[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")
|
||||
BarChartView(data: TestData.values ,title: "Model 3 sales", legend: "Quarterly", valueSpecifier: "%.0f")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// LabelView.swift
|
||||
// BarChart
|
||||
//
|
||||
// Created by Samu András on 2020. 01. 08..
|
||||
// Copyright © 2020. Samu András. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct LabelView: View {
|
||||
@Binding var arrowOffset: CGFloat
|
||||
@Binding var title:String
|
||||
var body: some View {
|
||||
VStack{
|
||||
ArrowUp().fill(Color.white).frame(width: 20, height: 12, alignment: .center).shadow(color: Color.gray, radius: 8, x: 0, y: 0).offset(x: getArrowOffset(offset:self.arrowOffset), y: 12)
|
||||
ZStack{
|
||||
RoundedRectangle(cornerRadius: 8).frame(width: 100, height: 32, alignment: .center).foregroundColor(Color.white).shadow(radius: 8)
|
||||
Text(self.title).font(.caption).bold()
|
||||
ArrowUp().fill(Color.white).frame(width: 20, height: 12, alignment: .center).zIndex(999).offset(x: getArrowOffset(offset:self.arrowOffset), y: -20)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getArrowOffset(offset: CGFloat) -> CGFloat {
|
||||
return max(-36,min(36, offset))
|
||||
}
|
||||
}
|
||||
|
||||
struct ArrowUp: Shape {
|
||||
func path(in rect: CGRect) -> Path {
|
||||
var path = Path()
|
||||
path.move(to: CGPoint(x: 0, y: rect.height))
|
||||
path.addLine(to: CGPoint(x: rect.width/2, y: 0))
|
||||
path.addLine(to: CGPoint(x: rect.width, y: rect.height))
|
||||
path.closeSubpath()
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
struct LabelView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
LabelView(arrowOffset: .constant(0), title: .constant("Tesla model 3"))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by András Samu on 2019. 07. 19..
|
||||
//
|
||||
@@ -19,6 +19,7 @@ public struct Colors {
|
||||
public static let OrangeEnd:Color = Color(hexString: "#EC2301")
|
||||
public static let LegendText:Color = Color(hexString: "#A7A6A8")
|
||||
public static let LegendColor:Color = Color(hexString: "#E8E7EA")
|
||||
public static let LegendDarkColor:Color = Color(hexString: "#545454")
|
||||
public static let IndicatorKnob:Color = Color(hexString: "#FF57A6")
|
||||
public static let GradientUpperBlue:Color = Color(hexString: "#C2E8FF")
|
||||
public static let GradinetUpperBlue1:Color = Color(hexString: "#A8E1FF")
|
||||
@@ -87,7 +88,7 @@ public struct Styles {
|
||||
legendTextColor: Color.gray)
|
||||
}
|
||||
|
||||
public struct Form {
|
||||
public struct ChartForm {
|
||||
#if os(watchOS)
|
||||
public static let small = CGSize(width:120, height:90)
|
||||
public static let medium = CGSize(width:120, height:160)
|
||||
@@ -127,25 +128,51 @@ public struct ChartStyle {
|
||||
}
|
||||
}
|
||||
|
||||
class ChartData: ObservableObject {
|
||||
@Published var points: [Int] = [Int]()
|
||||
@Published var currentPoint: Int? = nil
|
||||
public class ChartData: ObservableObject {
|
||||
@Published var points: [(String,Double)] = [(String,Double)]()
|
||||
var valuesGiven: Bool = false
|
||||
public init<N: BinaryFloatingPoint>(points:[N]) {
|
||||
self.points = points.map{("", Double($0))}
|
||||
}
|
||||
public init<N: BinaryInteger>(values:[(String,N)]){
|
||||
self.points = values.map{($0.0, Double($0.1))}
|
||||
self.valuesGiven = true
|
||||
}
|
||||
public init<N: BinaryFloatingPoint>(values:[(String,N)]){
|
||||
self.points = values.map{($0.0, Double($0.1))}
|
||||
self.valuesGiven = true
|
||||
}
|
||||
public init<N: BinaryInteger>(numberValues:[(N,N)]){
|
||||
self.points = numberValues.map{(String($0.0), Double($0.1))}
|
||||
self.valuesGiven = true
|
||||
}
|
||||
public init<N: BinaryFloatingPoint & LosslessStringConvertible>(numberValues:[(N,N)]){
|
||||
self.points = numberValues.map{(String($0.0), Double($0.1))}
|
||||
self.valuesGiven = true
|
||||
}
|
||||
|
||||
init(points:[Int]) {
|
||||
self.points = points
|
||||
public func onlyPoints() -> [Double] {
|
||||
return self.points.map{ $0.1 }
|
||||
}
|
||||
}
|
||||
|
||||
class TestData{
|
||||
public class TestData{
|
||||
static public var data:ChartData = ChartData(points: [37,72,51,22,39,47,66,85,50])
|
||||
static public var values:ChartData = ChartData(values: [("2017 Q3",220),
|
||||
("2017 Q4",1550),
|
||||
("2018 Q1",8180),
|
||||
("2018 Q2",18440),
|
||||
("2018 Q3",55840),
|
||||
("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)])
|
||||
|
||||
}
|
||||
|
||||
extension Color {
|
||||
init(hexString: String) {
|
||||
let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
|
||||
var int = UInt32()
|
||||
Scanner(string: hex).scanHexInt32(&int)
|
||||
let r, g, b: UInt32
|
||||
var int = UInt64()
|
||||
Scanner(string: hex).scanHexInt64(&int)
|
||||
let r, g, b: UInt64
|
||||
switch hex.count {
|
||||
case 3: // RGB (12-bit)
|
||||
(r, g, b) = ((int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
|
||||
|
||||
@@ -12,23 +12,41 @@ struct Legend: View {
|
||||
@ObservedObject var data: ChartData
|
||||
@Binding var frame: CGRect
|
||||
@Binding var hideHorizontalLines: Bool
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
||||
let padding:CGFloat = 3
|
||||
|
||||
var stepWidth: CGFloat {
|
||||
if data.points.count < 2 {
|
||||
return 0
|
||||
}
|
||||
return frame.size.width / CGFloat(data.points.count-1)
|
||||
}
|
||||
var stepHeight: CGFloat {
|
||||
return frame.size.height / CGFloat(data.points.max()! + data.points.min()!)
|
||||
let points = self.data.onlyPoints()
|
||||
if let min = points.min(), let max = points.max(), min != max {
|
||||
if (min < 0){
|
||||
return (frame.size.height-padding) / CGFloat(max - min)
|
||||
}else{
|
||||
return (frame.size.height-padding) / CGFloat(max + min)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var min: CGFloat {
|
||||
let points = self.data.onlyPoints()
|
||||
return CGFloat(points.min() ?? 0)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topLeading){
|
||||
ForEach((0...4), id: \.self) { height in
|
||||
HStack(alignment: .center){
|
||||
Text("\(self.getYLegend()![height])").offset(x: 0, y: (self.frame.height-CGFloat(self.getYLegend()![height])*self.stepHeight)-(self.frame.height/2))
|
||||
Text("\(self.getYLegendSafe(height: height), specifier: "%.2f")").offset(x: 0, y: self.getYposition(height: height) )
|
||||
.foregroundColor(Colors.LegendText)
|
||||
.font(.caption)
|
||||
self.line(atHeight: CGFloat(self.getYLegend()![height]), width: self.frame.width)
|
||||
.stroke(Colors.LegendColor, style: StrokeStyle(lineWidth: 1.5, lineCap: .round, dash: [5,height == 0 ? 0 : 10]))
|
||||
self.line(atHeight: self.getYLegendSafe(height: height), width: self.frame.width)
|
||||
.stroke(self.colorScheme == .dark ? Colors.LegendDarkColor : Colors.LegendColor, style: StrokeStyle(lineWidth: 1.5, lineCap: .round, dash: [5,height == 0 ? 0 : 10]))
|
||||
.opacity((self.hideHorizontalLines && height != 0) ? 0 : 1)
|
||||
.rotationEffect(.degrees(180), anchor: .center)
|
||||
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
|
||||
@@ -41,30 +59,41 @@ struct Legend: View {
|
||||
}
|
||||
}
|
||||
|
||||
func getYLegendSafe(height:Int)->CGFloat{
|
||||
if let legend = getYLegend() {
|
||||
return CGFloat(legend[height])
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func getYposition(height: Int)-> CGFloat {
|
||||
if let legend = getYLegend() {
|
||||
return (self.frame.height-((CGFloat(legend[height]) - min)*self.stepHeight))-(self.frame.height/2)
|
||||
}
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
func line(atHeight: CGFloat, width: CGFloat) -> Path {
|
||||
var hLine = Path()
|
||||
hLine.move(to: CGPoint(x:5, y: atHeight*stepHeight))
|
||||
hLine.addLine(to: CGPoint(x: width, y: atHeight*stepHeight))
|
||||
hLine.move(to: CGPoint(x:5, y: (atHeight-min)*stepHeight))
|
||||
hLine.addLine(to: CGPoint(x: width, y: (atHeight-min)*stepHeight))
|
||||
return hLine
|
||||
}
|
||||
|
||||
func getYLegend() -> [Int]? {
|
||||
guard let max = data.points.max() else { return nil }
|
||||
guard let min = data.points.min() else { return nil }
|
||||
if(min > 0){
|
||||
let upperBound = ((max/10)+1) * 10
|
||||
let step = upperBound/4
|
||||
return [step * 0,step * 1, step * 2, step * 3, step * 4]
|
||||
}
|
||||
|
||||
return nil
|
||||
func getYLegend() -> [Double]? {
|
||||
let points = self.data.onlyPoints()
|
||||
guard let max = points.max() else { return nil }
|
||||
guard let min = points.min() else { return nil }
|
||||
let step = Double(max - min)/4
|
||||
return [min+step * 0, min+step * 1, min+step * 2, min+step * 3, min+step * 4]
|
||||
}
|
||||
}
|
||||
|
||||
struct Legend_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
GeometryReader{ geometry in
|
||||
Legend(data: TestData.data, frame: .constant(geometry.frame(in: .local)), hideHorizontalLines: .constant(false))
|
||||
Legend(data: ChartData(points: [0.2,0.4,1.4,4.5]), frame: .constant(geometry.frame(in: .local)), hideHorizontalLines: .constant(false))
|
||||
}.frame(width: 320, height: 200)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,31 @@ struct Line: View {
|
||||
@Binding var showIndicator: Bool
|
||||
@State private var showFull: Bool = false
|
||||
@State var showBackground: Bool = true
|
||||
|
||||
let padding:CGFloat = 30
|
||||
var stepWidth: CGFloat {
|
||||
if data.points.count < 2 {
|
||||
return 0
|
||||
}
|
||||
return frame.size.width / CGFloat(data.points.count-1)
|
||||
}
|
||||
var stepHeight: CGFloat {
|
||||
return frame.size.height / CGFloat(data.points.max()! + data.points.min()!)
|
||||
let points = self.data.onlyPoints()
|
||||
if let min = points.min(), let max = points.max(), min != max {
|
||||
if (min <= 0){
|
||||
return (frame.size.height-padding) / CGFloat(points.max()! - points.min()!)
|
||||
}else{
|
||||
return (frame.size.height-padding) / CGFloat(points.max()! + points.min()!)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
var path: Path {
|
||||
return Path.quadCurvedPathWithPoints(points: data.points, step: CGPoint(x: stepWidth, y: stepHeight))
|
||||
let points = self.data.onlyPoints()
|
||||
return Path.quadCurvedPathWithPoints(points: points, step: CGPoint(x: stepWidth, y: stepHeight))
|
||||
}
|
||||
var closedPath: Path {
|
||||
return Path.quadClosedCurvedPathWithPoints(points: data.points, step: CGPoint(x: stepWidth, y: stepHeight))
|
||||
let points = self.data.onlyPoints()
|
||||
return Path.quadClosedCurvedPathWithPoints(points: points, step: CGPoint(x: stepWidth, y: stepHeight))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -67,24 +80,24 @@ struct Line: View {
|
||||
|
||||
extension CGPoint {
|
||||
static func getMidPoint(point1: CGPoint, point2: CGPoint) -> CGPoint {
|
||||
return CGPoint(
|
||||
x: point1.x + (point2.x - point1.x) / 2,
|
||||
y: point1.y + (point2.y - point1.y) / 2
|
||||
)
|
||||
return CGPoint(
|
||||
x: point1.x + (point2.x - point1.x) / 2,
|
||||
y: point1.y + (point2.y - point1.y) / 2
|
||||
)
|
||||
}
|
||||
|
||||
func dist(to: CGPoint) -> CGFloat {
|
||||
return sqrt((pow(self.x - to.x, 2) + pow(self.y - to.y, 2)))
|
||||
return sqrt((pow(self.x - to.x, 2) + pow(self.y - to.y, 2)))
|
||||
}
|
||||
|
||||
static func midPointForPoints(p1:CGPoint, p2:CGPoint) -> CGPoint {
|
||||
return CGPoint(x:(p1.x + p2.x) / 2,y: (p1.y + p2.y) / 2)
|
||||
}
|
||||
|
||||
|
||||
static func controlPointForPoints(p1:CGPoint, p2:CGPoint) -> CGPoint {
|
||||
var controlPoint = CGPoint.midPointForPoints(p1:p1, p2:p2)
|
||||
let diffY = abs(p2.y - controlPoint.y)
|
||||
|
||||
|
||||
if (p1.y < p2.y){
|
||||
controlPoint.y += diffY
|
||||
} else if (p1.y > p2.y) {
|
||||
@@ -94,16 +107,17 @@ extension CGPoint {
|
||||
}
|
||||
}
|
||||
extension Path {
|
||||
static func quadCurvedPathWithPoints(points:[Int], step:CGPoint) -> Path {
|
||||
static func quadCurvedPathWithPoints(points:[Double], step:CGPoint) -> Path {
|
||||
var path = Path()
|
||||
var p1 = CGPoint(x: 0, y: CGFloat(points[0])*step.y)
|
||||
path.move(to: p1)
|
||||
if(points.count < 2){
|
||||
path.addLine(to: CGPoint(x: step.x, y: step.y*CGFloat(points[1])))
|
||||
if (points.count < 2){
|
||||
return path
|
||||
}
|
||||
guard var offset = points.min() else { return path }
|
||||
offset -= 3
|
||||
var p1 = CGPoint(x: 0, y: CGFloat(points[0]-offset)*step.y)
|
||||
path.move(to: p1)
|
||||
for pointIndex in 1..<points.count {
|
||||
let p2 = CGPoint(x: step.x * CGFloat(pointIndex), y: step.y*CGFloat(points[pointIndex]))
|
||||
let p2 = CGPoint(x: step.x * CGFloat(pointIndex), y: step.y*CGFloat(points[pointIndex]-offset))
|
||||
let midPoint = CGPoint.midPointForPoints(p1: p1, p2: p2)
|
||||
path.addQuadCurve(to: midPoint, control: CGPoint.controlPointForPoints(p1: midPoint, p2: p1))
|
||||
path.addQuadCurve(to: p2, control: CGPoint.controlPointForPoints(p1: midPoint, p2: p2))
|
||||
@@ -112,17 +126,18 @@ extension Path {
|
||||
return path
|
||||
}
|
||||
|
||||
static func quadClosedCurvedPathWithPoints(points:[Int], step:CGPoint) -> Path {
|
||||
static func quadClosedCurvedPathWithPoints(points:[Double], step:CGPoint) -> Path {
|
||||
var path = Path()
|
||||
path.move(to: .zero)
|
||||
var p1 = CGPoint(x: 0, y: CGFloat(points[0])*step.y)
|
||||
path.addLine(to: p1)
|
||||
if(points.count < 2){
|
||||
path.addLine(to: CGPoint(x: step.x, y: step.y*CGFloat(points[1])))
|
||||
if (points.count < 2){
|
||||
return path
|
||||
}
|
||||
guard var offset = points.min() else { return path }
|
||||
offset -= 3
|
||||
path.move(to: .zero)
|
||||
var p1 = CGPoint(x: 0, y: CGFloat(points[0]-offset)*step.y)
|
||||
path.addLine(to: p1)
|
||||
for pointIndex in 1..<points.count {
|
||||
let p2 = CGPoint(x: step.x * CGFloat(pointIndex), y: step.y*CGFloat(points[pointIndex]))
|
||||
let p2 = CGPoint(x: step.x * CGFloat(pointIndex), y: step.y*CGFloat(points[pointIndex]-offset))
|
||||
let midPoint = CGPoint.midPointForPoints(p1: p1, p2: p2)
|
||||
path.addQuadCurve(to: midPoint, control: CGPoint.controlPointForPoints(p1: midPoint, p2: p1))
|
||||
path.addQuadCurve(to: p2, control: CGPoint.controlPointForPoints(p1: midPoint, p2: p2))
|
||||
@@ -153,7 +168,7 @@ extension Path {
|
||||
struct Line_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
GeometryReader{ geometry in
|
||||
Line(data: TestData.data, frame: .constant(geometry.frame(in: .local)), touchLocation: .constant(CGPoint(x: 300, y: 12)), showIndicator: .constant(true))
|
||||
Line(data: ChartData(points: [12,-230,10,54]), frame: .constant(geometry.frame(in: .local)), touchLocation: .constant(CGPoint(x: 100, y: 12)), showIndicator: .constant(true))
|
||||
}.frame(width: 320, height: 160)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,12 @@ public struct LineChartView: View {
|
||||
public var legend: String?
|
||||
public var style: ChartStyle
|
||||
public var formSize:CGSize
|
||||
public var dropShadow: Bool
|
||||
public var valueSpecifier:String
|
||||
|
||||
@State private var touchLocation:CGPoint = .zero
|
||||
@State private var showIndicatorDot: Bool = false
|
||||
@State private var currentValue: Int = 2 {
|
||||
@State private var currentValue: Double = 2 {
|
||||
didSet{
|
||||
if (oldValue != self.currentValue && showIndicatorDot) {
|
||||
// selectionFeedbackGenerator.selectionChanged()
|
||||
@@ -27,18 +30,22 @@ public struct LineChartView: View {
|
||||
}
|
||||
}
|
||||
let frame = CGSize(width: 180, height: 120)
|
||||
private var rateValue: Int
|
||||
|
||||
public init(data: [Int], title: String, legend: String? = nil, style: ChartStyle = Styles.lineChartStyleOne, form: CGSize? = Form.medium){
|
||||
public init(data: [Double], title: String, legend: String? = nil, style: ChartStyle = Styles.lineChartStyleOne, form: CGSize? = ChartForm.medium ,rateValue: Int? = 14, dropShadow: Bool? = true, valueSpecifier: String? = "%.1f"){
|
||||
self.data = ChartData(points: data)
|
||||
self.title = title
|
||||
self.legend = legend
|
||||
self.style = style
|
||||
self.formSize = form!
|
||||
self.rateValue = rateValue!
|
||||
self.dropShadow = dropShadow!
|
||||
self.valueSpecifier = valueSpecifier!
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
ZStack(alignment: .center){
|
||||
RoundedRectangle(cornerRadius: 20).fill(self.style.backgroundColor).frame(width: frame.width, height: 240, alignment: .center).shadow(radius: 8)
|
||||
RoundedRectangle(cornerRadius: 20).fill(self.style.backgroundColor).frame(width: frame.width, height: 240, alignment: .center).shadow(radius: self.dropShadow ? 8 : 0)
|
||||
VStack(alignment: .leading){
|
||||
if(!self.showIndicatorDot){
|
||||
VStack(alignment: .leading, spacing: 8){
|
||||
@@ -47,8 +54,12 @@ public struct LineChartView: View {
|
||||
Text(self.legend!).font(.callout).foregroundColor(self.style.legendTextColor)
|
||||
}
|
||||
HStack {
|
||||
Image(systemName: "arrow.up")
|
||||
Text("14%")
|
||||
if (self.rateValue >= 0){
|
||||
Image(systemName: "arrow.up")
|
||||
}else{
|
||||
Image(systemName: "arrow.down")
|
||||
}
|
||||
Text("\(self.rateValue)%")
|
||||
}
|
||||
}
|
||||
.transition(.opacity)
|
||||
@@ -57,20 +68,20 @@ public struct LineChartView: View {
|
||||
}else{
|
||||
HStack{
|
||||
Spacer()
|
||||
Text("\(self.currentValue)")
|
||||
Text("\(self.currentValue, specifier: self.valueSpecifier)")
|
||||
.font(.system(size: 41, weight: .bold, design: .default))
|
||||
.offset(x: 0, y: 30)
|
||||
Spacer()
|
||||
}
|
||||
.transition(.scale)
|
||||
.animation(.spring())
|
||||
// .animation(.spring())
|
||||
|
||||
}
|
||||
Spacer()
|
||||
GeometryReader{ geometry in
|
||||
Line(data: self.data, frame: .constant(geometry.frame(in: .local)), touchLocation: self.$touchLocation, showIndicator: self.$showIndicatorDot)
|
||||
}
|
||||
.frame(width: frame.width, height: frame.height)
|
||||
.frame(width: frame.width, height: frame.height + 30)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 20))
|
||||
.offset(x: 0, y: 0)
|
||||
}.frame(width: self.formSize.width, height: self.formSize.height)
|
||||
@@ -87,14 +98,15 @@ public struct LineChartView: View {
|
||||
)
|
||||
}
|
||||
|
||||
func getClosestDataPoint(toPoint: CGPoint, width:CGFloat, height: CGFloat) -> CGPoint {
|
||||
let stepWidth: CGFloat = width / CGFloat(data.points.count-1)
|
||||
let stepHeight: CGFloat = height / CGFloat(data.points.max()! + data.points.min()!)
|
||||
@discardableResult func getClosestDataPoint(toPoint: CGPoint, width:CGFloat, height: CGFloat) -> CGPoint {
|
||||
let points = self.data.onlyPoints()
|
||||
let stepWidth: CGFloat = width / CGFloat(points.count-1)
|
||||
let stepHeight: CGFloat = height / CGFloat(points.max()! + points.min()!)
|
||||
|
||||
let index:Int = Int(round((toPoint.x)/stepWidth))
|
||||
if (index >= 0 && index < data.points.count){
|
||||
self.currentValue = self.data.points[index]
|
||||
return CGPoint(x: CGFloat(index)*stepWidth, y: CGFloat(self.data.points[index])*stepHeight)
|
||||
if (index >= 0 && index < points.count){
|
||||
self.currentValue = points[index]
|
||||
return CGPoint(x: CGFloat(index)*stepWidth, y: CGFloat(points[index])*stepHeight)
|
||||
}
|
||||
return .zero
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// LineView.swift
|
||||
// LineChart
|
||||
//
|
||||
// Created by András Samu on 2019. 09. 02..
|
||||
// Copyright © 2019. András Samu. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
public struct LineView: View {
|
||||
@ObservedObject var data: ChartData
|
||||
public var title: String?
|
||||
public var legend: String?
|
||||
public var style: ChartStyle
|
||||
public var valueSpecifier:String
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
||||
@State private var showLegend = false
|
||||
@State private var dragLocation:CGPoint = .zero
|
||||
@State private var indicatorLocation:CGPoint = .zero
|
||||
@State private var closestPoint: CGPoint = .zero
|
||||
@State private var opacity:Double = 0
|
||||
@State private var currentDataNumber: Double = 0
|
||||
@State private var hideHorizontalLines: Bool = false
|
||||
|
||||
public init(data: [Double], title: String? = nil, legend: String? = nil, style: ChartStyle? = Styles.lineChartStyleOne, valueSpecifier: String? = "%.1f"){
|
||||
self.data = ChartData(points: data)
|
||||
self.title = title
|
||||
self.legend = legend
|
||||
self.style = style!
|
||||
self.valueSpecifier = valueSpecifier!
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
GeometryReader{ geometry in
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Group{
|
||||
if (self.title != nil){
|
||||
Text(self.title!).font(.title).bold().foregroundColor(self.colorScheme == .dark ? Color.white : self.style.textColor)
|
||||
}
|
||||
if (self.legend != nil){
|
||||
Text(self.legend!).font(.callout).foregroundColor(self.colorScheme == .dark ? Color.white : self.style.legendTextColor)
|
||||
}
|
||||
}.offset(x: 0, y: 20)
|
||||
ZStack{
|
||||
GeometryReader{ reader in
|
||||
Rectangle().foregroundColor(self.colorScheme == .dark ? Color.black : self.style.backgroundColor)
|
||||
if(self.showLegend){
|
||||
Legend(data: self.data, frame: .constant(reader.frame(in: .local)), hideHorizontalLines: self.$hideHorizontalLines)
|
||||
.transition(.opacity)
|
||||
.animation(Animation.easeOut(duration: 1).delay(1))
|
||||
}
|
||||
Line(data: self.data, frame: .constant(CGRect(x: 0, y: 0, width: reader.frame(in: .local).width - 30, height: reader.frame(in: .local).height)), touchLocation: self.$indicatorLocation,showIndicator: self.$hideHorizontalLines ,showBackground: false).offset(x: 30, y: 0)
|
||||
.onAppear(){
|
||||
self.showLegend.toggle()
|
||||
}
|
||||
}.frame(width: geometry.frame(in: .local).size.width, height: 240).offset(x: 0, y: 40 )
|
||||
MagnifierRect(currentNumber: self.$currentDataNumber, valueSpecifier: self.valueSpecifier)
|
||||
.opacity(self.opacity)
|
||||
.offset(x: self.dragLocation.x - geometry.frame(in: .local).size.width/2, y: 36)
|
||||
}
|
||||
.frame(width: geometry.frame(in: .local).size.width, height: 240)
|
||||
.gesture(DragGesture()
|
||||
.onChanged({ value in
|
||||
self.dragLocation = value.location
|
||||
self.indicatorLocation = CGPoint(x: max(value.location.x-30,0), y: 32)
|
||||
self.opacity = 1
|
||||
self.closestPoint = self.getClosestDataPoint(toPoint: value.location, width: geometry.frame(in: .local).size.width-30, height: 240)
|
||||
self.hideHorizontalLines = true
|
||||
})
|
||||
.onEnded({ value in
|
||||
self.opacity = 0
|
||||
self.hideHorizontalLines = false
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getClosestDataPoint(toPoint: CGPoint, width:CGFloat, height: CGFloat) -> CGPoint {
|
||||
let points = self.data.onlyPoints()
|
||||
let stepWidth: CGFloat = width / CGFloat(points.count-1)
|
||||
let stepHeight: CGFloat = height / CGFloat(points.max()! + points.min()!)
|
||||
|
||||
let index:Int = Int(floor((toPoint.x-15)/stepWidth))
|
||||
if (index >= 0 && index < points.count){
|
||||
self.currentDataNumber = points[index]
|
||||
return CGPoint(x: CGFloat(index)*stepWidth, y: CGFloat(points[index])*stepHeight)
|
||||
}
|
||||
return .zero
|
||||
}
|
||||
}
|
||||
|
||||
struct LineView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
LineView(data: [8,23,54,32,12,37,7,23,43], title: "Full chart", style: Styles.lineChartStyleOne)
|
||||
}
|
||||
}
|
||||
|
||||
struct IndicatorCircle: View {
|
||||
var body: some View {
|
||||
Circle()
|
||||
.size(width: 12, height: 12)
|
||||
.fill(Colors.BorderBlue)
|
||||
}
|
||||
}
|
||||
|
||||
struct MagnifierRect: View {
|
||||
@Binding var currentNumber: Double
|
||||
var valueSpecifier:String
|
||||
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
||||
var body: some View {
|
||||
ZStack{
|
||||
Text("\(self.currentNumber, specifier: valueSpecifier)")
|
||||
.font(.system(size: 18, weight: .bold))
|
||||
.offset(x: 0, y:-110)
|
||||
// .animation(.spring())
|
||||
.foregroundColor(self.colorScheme == .dark ? Color.white : Color.black)
|
||||
if (self.colorScheme == .dark ){
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
.stroke(Color.white, lineWidth: self.colorScheme == .dark ? 2 : 0)
|
||||
.frame(width: 60, height: 260)
|
||||
|
||||
}else{
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
.frame(width: 60, height: 280)
|
||||
.foregroundColor(Color.white)
|
||||
.shadow(color: Colors.LegendText, radius: 12, x: 0, y: 6 )
|
||||
.blendMode(.multiply)
|
||||
}
|
||||
|
||||
|
||||
}//.animation(.linear)
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ struct PieSlice: Identifiable {
|
||||
var id = UUID()
|
||||
var startDeg: Double
|
||||
var endDeg: Double
|
||||
var value: Int
|
||||
var value: Double
|
||||
var normalizedValue: Double
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import SwiftUI
|
||||
|
||||
public struct PieChartRow : View {
|
||||
var data: [Int]
|
||||
var data: [Double]
|
||||
var backgroundColor: Color
|
||||
var accentColor: Color
|
||||
var slices: [PieSlice] {
|
||||
|
||||
@@ -9,17 +9,20 @@
|
||||
import SwiftUI
|
||||
|
||||
public struct PieChartView : View {
|
||||
public var data: [Int]
|
||||
public var data: [Double]
|
||||
public var title: String
|
||||
public var legend: String?
|
||||
public var style: ChartStyle
|
||||
public var formSize:CGSize
|
||||
public init(data: [Int], title: String, legend: String? = nil, style: ChartStyle = Styles.pieChartStyleOne, form: CGSize? = Form.medium ){
|
||||
public var dropShadow: Bool
|
||||
|
||||
public init(data: [Double], title: String, legend: String? = nil, style: ChartStyle = Styles.pieChartStyleOne, form: CGSize? = ChartForm.medium, dropShadow: Bool? = true ){
|
||||
self.data = data
|
||||
self.title = title
|
||||
self.legend = legend
|
||||
self.style = style
|
||||
self.formSize = form!
|
||||
self.dropShadow = dropShadow!
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
@@ -27,7 +30,7 @@ public struct PieChartView : View {
|
||||
Rectangle()
|
||||
.fill(self.style.backgroundColor)
|
||||
.cornerRadius(20)
|
||||
.shadow(color: Color.gray, radius: 12)
|
||||
.shadow(color: Color.gray, radius: self.dropShadow ? 12 : 0)
|
||||
VStack(alignment: .leading){
|
||||
HStack{
|
||||
Text(self.title)
|
||||
|
||||
|
Before Width: | Height: | Size: 445 KiB |