Compare commits

...

4 Commits

Author SHA1 Message Date
Andras Samu d3d0b086f1 updated readme 2019-11-11 21:50:33 +01:00
Andras Samu 6cc43d9dc0 fixed legend in dark mode 2019-11-11 21:20:13 +01:00
Andras Samu e081d3a88d fixed loupe 2019-11-11 21:13:10 +01:00
Andras Samu e5c309eac4 set to public 2019-11-11 20:41:42 +01:00
7 changed files with 40 additions and 15 deletions
+17 -1
View File
@@ -26,6 +26,17 @@ You can display a Chart by adding a chart view to your parent view:
Added an example project, with **iOS, watchOS** target: https://github.com/AppPear/ChartViewDemo
## Line charts
**New full screen view called LineView!!!**
![Line Charts](./fullscreen1.gif "Line Charts")![Line Charts](./fullscreen2.gif "Line Charts")
```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 Charts](./showcase3.gif "Line Charts")
**Line chart is interactive, so you can drag across to reveal the data points**
@@ -36,6 +47,8 @@ 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
![Bar Charts](./showcase2.gif "Bar Charts")
@@ -56,7 +69,8 @@ You can add different formats:
```swift
BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", form: Form.small)
```
**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`**
### You can customize styling of the chart with a ChartStyle object:
Customizable:
@@ -114,3 +128,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`**
+1
View File
@@ -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")
+3 -2
View File
@@ -12,7 +12,8 @@ struct Legend: View {
@ObservedObject var data: ChartData
@Binding var frame: CGRect
@Binding var hideHorizontalLines: Bool
@Environment(\.colorScheme) var colorScheme: ColorScheme
var stepWidth: CGFloat {
return frame.size.width / CGFloat(data.points.count-1)
}
@@ -28,7 +29,7 @@ struct Legend: View {
.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]))
.stroke(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))
+19 -12
View File
@@ -8,7 +8,7 @@
import SwiftUI
struct LineView: View {
public struct LineView: View {
@ObservedObject var data: ChartData
public var title: String?
public var legend: String?
@@ -30,7 +30,7 @@ struct LineView: View {
self.style = style!
}
public var body: some View {
public var body: some View {
GeometryReader{ geometry in
VStack(alignment: .leading, spacing: 8) {
Group{
@@ -40,7 +40,7 @@ struct LineView: View {
if (self.legend != nil){
Text(self.legend!).font(.callout).foregroundColor(self.colorScheme == .dark ? Color.white : self.style.legendTextColor)
}
}.offset(x: 0, y: 46)
}.offset(x: 0, y: 20)
ZStack{
GeometryReader{ reader in
Rectangle().foregroundColor(self.colorScheme == .dark ? Color.black : self.style.backgroundColor)
@@ -56,7 +56,7 @@ struct LineView: View {
}.frame(width: geometry.frame(in: .local).size.width, height: 240).offset(x: 0, y: 40 )
MagnifierRect(currentNumber: self.$currentDataNumber)
.opacity(self.opacity)
.offset(x: self.dragLocation.x - geometry.frame(in: .local).size.width/2, y: 50)
.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()
@@ -91,7 +91,7 @@ struct LineView: View {
struct LineView_Previews: PreviewProvider {
static var previews: some View {
LineView(data: [37,72,51,22,39,47,66,85,50], title: "Full chart", style: Styles.lineChartStyleOne).environment(\.colorScheme, .dark)
LineView(data: [8,23,54,32,12,37,7,23,43], title: "Full chart", style: Styles.lineChartStyleOne)
}
}
@@ -110,15 +110,22 @@ struct MagnifierRect: View {
ZStack{
Text("\(self.currentNumber)")
.font(.system(size: 18, weight: .bold))
.offset(x: 0, y:-96)
.offset(x: 0, y:-110)
.animation(.spring())
.foregroundColor(self.colorScheme == .dark ? Color.white : Color.black)
RoundedRectangle(cornerRadius: 16)
.stroke(Color.white, lineWidth: self.colorScheme == .dark ? 2 : 0)
.frame(width: 60, height: 240)
.foregroundColor(self.colorScheme == .dark ? Color.black : Color.white)
.shadow(color: Colors.LegendText, radius: 12, x: 0, y: 6 )
.blendMode(self.colorScheme == .dark ? .normal : .multiply)
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)
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 514 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 502 KiB