File tree 4 files changed +21
-2
lines changed
Sources/ChartUI/LineChart
4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
Pod ::Spec . new do |spec |
2
2
3
3
spec . name = "ChartUI"
4
- spec . version = "0.4 .0"
4
+ spec . version = "0.5 .0"
5
5
spec . summary = "📈 A SwiftUI chart library"
6
6
spec . homepage = "https://github.com/theo-brlle/chart-ui"
7
7
spec . license = { :type => "MIT" , :file => "LICENSE" }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ Just add this repo as a dependency of your project. Here is the repo URL: https:
15
15
Add ChartUI as a dependency in your ` Podfile ` .
16
16
17
17
```
18
- pod 'ChartUI', '~> 0.4 .0'
18
+ pod 'ChartUI', '~> 0.5 .0'
19
19
```
20
20
21
21
Then run ` pod install ` and open the ` .xcworkspace ` file in Xcode.
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ final class LineChartViewModel: ObservableObject {
25
25
@Published var plotDetailsViewSize : CGSize = . zero
26
26
@Published var rightLabelsViewSize : CGSize = . zero
27
27
28
+ // MARK: - Callbacks
29
+
30
+ var onDragAction : ( ( Bool ) -> Void ) ?
31
+
28
32
// MARK: - Computed properties
29
33
30
34
var chartColor : Color {
Original file line number Diff line number Diff line change @@ -238,20 +238,35 @@ private extension LineChartView {
238
238
var dragGesture : some Gesture {
239
239
DragGesture ( minimumDistance: 0 )
240
240
. onChanged { value in
241
+ if !viewModel. isPlotDetailsViewPresented {
242
+ viewModel. onDragAction ? ( true )
243
+ }
244
+
241
245
withAnimation {
242
246
viewModel. isPlotDetailsViewPresented = true
243
247
}
244
248
245
249
viewModel. updateSelectedPlot ( from: value. location. x)
246
250
}
247
251
. onEnded { value in
252
+ viewModel. onDragAction ? ( false )
253
+
248
254
withAnimation {
249
255
viewModel. isPlotDetailsViewPresented = false
250
256
}
251
257
}
252
258
}
253
259
}
254
260
261
+ // MARK: - Callbacks
262
+
263
+ public extension LineChartView {
264
+ func onDrag( _ action: @escaping ( Bool ) -> Void ) -> Self {
265
+ self . viewModel. onDragAction = action
266
+ return self
267
+ }
268
+ }
269
+
255
270
// MARK: - Previews
256
271
257
272
struct LineChartView_Previews : PreviewProvider {
You can’t perform that action at this time.
0 commit comments