Skip to content

Commit 4626dfe

Browse files
authored
Fix stacked area chart order issue (#25)
* Update StackedAreaChartStyle.swift
1 parent 2cb15a0 commit 4626dfe

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/Charts/Chart/Styles/Area/StackedAreaChartStyle.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ public struct StackedAreaChartStyle: ChartStyle {
77

88
public func makeBody(configuration: Self.Configuration) -> some View {
99
ZStack {
10-
ForEach(Array(configuration.dataMatrix.flipDirection().stacked().reversed().enumerated()), id: \.self.offset) { enumeratedData in
11-
self.colors.prefix(configuration.dataMatrix.count).reversed()[enumeratedData.offset % self.colors.count].clipShape(
10+
ForEach(Array(configuration.dataMatrix.transpose().stacked().enumerated()), id: \.self.offset) { enumeratedData in
11+
colors[enumeratedData.offset % colors.count].clipShape(
1212
AreaChart(
1313
unitData: enumeratedData.element,
1414
lineType: self.lineType
1515
)
1616
)
17+
.zIndex(-Double(enumeratedData.offset))
1718
}
1819
}
1920
.drawingGroup()
@@ -38,14 +39,14 @@ extension Collection where Element == [CGFloat] {
3839
}
3940

4041
extension Array where Element == [CGFloat] {
41-
func flipDirection() -> [[CGFloat]] {
42+
func transpose() -> [[CGFloat]] {
4243
let columnsCount = self.first?.count ?? 0
4344
let rowCount = self.count
4445

4546
return (0..<columnsCount).map { columnIndex in
4647
(0..<rowCount).map { rowIndex in
4748
return self[rowIndex][columnIndex]
48-
}.reversed()
49+
}
4950
}
5051
}
5152
}

0 commit comments

Comments
 (0)