Skip to content

Commit

Permalink
hori, vert reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyday567 committed Dec 21, 2024
1 parent 40b8aee commit 8f4b6fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
packages:
chart-svg.cabal
../numhask-space/numhask-space.cabal

write-ghc-environment-files: always

tests: True
2 changes: 1 addition & 1 deletion chart-svg.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: chart-svg
version: 0.7.0.0
version: 0.8.0.0
license: BSD-3-Clause
license-file: LICENSE
copyright: Tony Day (c) 2017
Expand Down
6 changes: 3 additions & 3 deletions src/Chart/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ isEmptyChart _ = False

-- | Horizontally stack a list of trees (proceeding to the right), at the supplied Align and with the supplied gap intercalated.
hori :: Align -> Double -> [ChartTree] -> ChartTree
hori align gap cs = foldl' step mempty cs
hori align gap cs = foldl' step mempty (reverse cs)
where
step x c = x <> over chart' (moveChart (Point (movex x c) (aligny x - aligny c))) c
movex x c =
Expand All @@ -486,7 +486,7 @@ hori align gap cs = foldl' step mempty cs

-- | Vertically stack a list of trees (proceeding upwards), at the supplied Align and with the supplied gap intercalated.
vert :: Align -> Double -> [ChartTree] -> ChartTree
vert align gap cs = foldl' step mempty cs
vert align gap cs = foldl' step mempty (reverse cs)
where
step x c = x <> over chart' (moveChart (Point (alignx x - alignx c) (movey x c))) c
movey x c =
Expand All @@ -507,7 +507,7 @@ vert align gap cs = foldl' step mempty cs

-- | Stack a list of tree charts horizontally, then vertically (proceeding downwards which is opposite to the usual coordinate reference system but intuitively the way people read charts)
stack :: Int -> Align -> Align -> Double -> [ChartTree] -> ChartTree
stack n alignV alignH gap cs = vert alignV gap (reverse $ hori alignH gap <$> group' cs [])
stack n alignV alignH gap cs = vert alignV gap (hori alignH gap <$> group' cs [])
where
group' [] acc = reverse acc
group' x acc = group' (drop n x) (take n x : acc)
Expand Down

0 comments on commit 8f4b6fb

Please sign in to comment.