Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tomosaaan committed Nov 22, 2024
1 parent 7883076 commit f8bebf3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ContentView: View {
id: \.x,
selectedData: $selectedData
)
.hiddenChart(true)
// .hiddenChart(true)
// .frame(height: 300, alignment: .bottom)
// .hiddenChart(true)
// .minCount(3)
Expand Down
46 changes: 13 additions & 33 deletions Sources/GraphRangeSlider/GraphRangeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,8 @@ public struct GraphRangeSlider<Data, ID>: View where Data: RandomAccessCollectio
@Environment(\.isHiddenChart) private var isHiddenChart: Bool

public var body: some View {
Group {
if isHiddenChart {
Group {
if !positions.isEmpty {
Slider(
positions: positions,
onEnded: { builder.onEnded.call(selectedData) },
leftCurrentIndex: $leftCurrentIndex,
rightCurrentIndex: $rightCurrentIndex
)
.frame(height: toggleRadius * 2)
}
}
.onAppear {
if positions.isEmpty {
updatePositions()
updateIndices()
}
}
} else {
VStack(spacing: margin) {
if !isHiddenChart {
Chart(data, id: id) { data in
BarMark(
x: .value(PlottableKeys.x, String(describing: data.x)),
Expand All @@ -60,26 +42,24 @@ public struct GraphRangeSlider<Data, ID>: View where Data: RandomAccessCollectio
)
)
}
.padding(.horizontal, toggleRadius * 2)
.padding(.bottom, toggleRadius + sliderBarHeight / 2 + margin)
.chartXAxis(.hidden)
.chartYAxis(.hidden)
.chartLegend(.hidden)
.chartForegroundStyleScale([
Status.active: activeColor,
Status.inactive: inactiveColor
])
.overlay(alignment: .bottom) {
if !positions.isEmpty {
Slider(
positions: positions,
onEnded: { builder.onEnded.call(selectedData) },
leftCurrentIndex: $leftCurrentIndex,
rightCurrentIndex: $rightCurrentIndex
)
.frame(height: toggleRadius * 2)
}
}
.padding(.horizontal, toggleRadius * 2)
}

if !positions.isEmpty {
Slider(
positions: positions,
onEnded: { builder.onEnded.call(selectedData) },
leftCurrentIndex: $leftCurrentIndex,
rightCurrentIndex: $rightCurrentIndex
)
.frame(height: toggleRadius * 2)
}
}
.background(
Expand Down

0 comments on commit f8bebf3

Please sign in to comment.